On Mon, Aug 3, 2009 at 12:44 PM, Colin Law <clan...@googlemail.com> wrote:

> 2009/8/3 Phil Longstaff <plongst...@rogers.com>:
> > The budget report is my current itch, so I've been upgrading it.
> >
> > My latest change is to provide more control over the columns.  To do
> this, the
> > top level creates a scheme list where each element controls a set of
> > budget/actual/diff columns:
> >  - if an element is a number, that is the period (origin 0) for the set
> of
> > columns
> >  - if an element is a list, the list contains period numbers to be
> grouped
> > and accumulated for the set of columns
> >  - if an element is 'total, the set of columns contains the total.
> >
> > For a monthly budget, the current budget report is created by the list
> '(0 1 2
> > 3 4 5 6 7 8 9 10 11).  I'm looking at using '((0 1 2 3 4 5) 6 7 (8 9 10
> 11)
> > total) which will give me Jan-Jun, July, Aug, Sep-Dec, Total for the
> year.
> > This allows it to fit on my screen.
> >
> > To make this more readily available, I think the proper thing to do is
> add a
> > new tab to the options to allow the user to set up the columns.
>  Eventually,
> > besides a "diff" column, a "percentage" column would be useful.
>

I have been hacking on the budget report too.  It isn't really finished but
I haven't had much time to clean it up.
I thought I would throw the patch out here in case you were interested in
some of the pieces.

Two things I mainly tried to accomplish was to increase the width of the
first column to allow the account names to sit on one line.  The second
thing was to have  gnc:html-table-add-budget-line! create the account labels
instead of doing it in two steps.  As a result I can pass back a 0 or 1 if
the account was zero or not.  This is useful later on when people like me
don't feel like looking at a table full of zero'd out accounts, but instead
only want to look at accounts that were used.  This sort of mimics other
report options of 'do not show zero-balanced accounts'.

Anyway feel free to use any of it below if interested.  I have no free time
the next couple of weeks to work on this.  But I figured while you were in
there scratching your itch.. ;-)

Cheers,
Don
Index: src/report/standard-reports/budget.scm
===================================================================
--- src/report/standard-reports/budget.scm	(revision 18213)
+++ src/report/standard-reports/budget.scm	(working copy)
@@ -147,19 +147,21 @@
          (show-diff? (get-val params 'show-difference))
          (show-totalcol? (get-val params 'show-totalcol))
         )
-  
   (define (gnc:html-table-add-budget-line!
-           html-table rownum colnum
-           budget acct exchange-fn)
+           html-table rownum colspan
+           budget acct exchange-fn label)
     (let* ((num-periods (gnc-budget-get-num-periods budget))
            (period 0)
-           (current-col (+ colnum 1))
+           (current-col 1)
 		   (bgt-total (gnc-numeric-zero))
 		   (bgt-total-unset? #t)
 		   (act-total (gnc-numeric-zero))
            (comm (xaccAccountGetCommodity acct))
            (reverse-balance? (gnc-reverse-balance acct))
            )
+      ;;(gnc:html-table-set-cell/size! html-table rownum current-col colspan
+       ;;   (gnc:make-html-text (gnc:budget-make-nbsps lbl-depth)) label)
+      ;;(set! current-col (+ current-col 1))
       (while (< period num-periods)
              (let* (
                     
@@ -252,13 +254,18 @@
                )
 	        )
 		 )
+      (if (and (= 0 (gnc-numeric-compare act-total (gnc-numeric-zero)))
+               (= 0 (gnc-numeric-compare bgt-total (gnc-numeric-zero))))
+          0
+          1
       )
+      )
     )
   (define (gnc:html-table-add-budget-headers!
-           html-table colnum budget)
+           html-table colspan budget)
     (let* ((num-periods (gnc-budget-get-num-periods budget))
            (period 0)
-           (current-col (+ colnum 1))
+           (current-col colspan)
            )
 
       ;; prepend 2 empty rows
@@ -334,18 +341,18 @@
 
   (let* ((num-rows (gnc:html-acct-table-num-rows acct-table))
          (rownum 0)
-         (numcolumns (gnc:html-table-num-columns html-table))
-	 ;;(html-table (or html-table (gnc:make-html-table)))
-         ;; WARNING: we implicitly depend here on the details of
-         ;; gnc:html-table-add-account-balances.  Specifically, we
-         ;; assume that it makes twice as many columns as it uses for
-          ;; account labels.  For now, that seems to be a valid
-         ;; assumption.
-         (colnum (quotient numcolumns 2))
-
+         ;;arbituary number below to give room for account names in
+         ;;the first column
+         (colspan 20)
+         (maxline 1)
+         (test 0)
 	 )
 
-    ''(display (list "colnum: " colnum  "numcolumns: " numcolumns))
+    (define (make-nbsps n)
+      (if (> n 0)
+          (string-append "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" (make-nbsps (- n 1)))
+          ""))
+
     ;; call gnc:html-table-add-budget-line! for each account
     (while (< rownum num-rows)
            (let* ((env (append
@@ -353,16 +360,21 @@
 			params))
                   (acct (get-val env 'account))
                   (exchange-fn (get-val env 'exchange-fn))
+                  (indent (gnc:make-html-text
+                      (make-nbsps (or (get-val env 'indented-depth) 0))))
+                  (label (get-val env 'account-label))
                   )
-             (gnc:html-table-add-budget-line!
-              html-table rownum colnum
-              budget acct exchange-fn)
+             (gnc:html-table-set-cell/size! html-table test 0 colspan
+                indent label)
+             (set! test (+ (gnc:html-table-add-budget-line!
+              html-table test colspan
+              budget acct exchange-fn label) test))
              (set! rownum (+ rownum 1)) ;; increment rownum
              )
            ) ;; end of while
 
     ;; column headers
-    (gnc:html-table-add-budget-headers! html-table colnum budget)
+    (gnc:html-table-add-budget-headers! html-table colspan budget)
 
     )
     )
@@ -507,22 +519,10 @@
           (set! acct-table
                 (gnc:make-html-acct-table/env/accts env accounts))
 
-          ;; We do this in two steps: First the account names...  the
-          ;; add-account-balances will actually compute and add a
-          ;; bunch of current account balances, too, but we'll
-          ;; overwrite them.
-          (set! html-table (gnc:html-table-add-account-balances
-                            #f acct-table params))
-
           ;; ... then the budget values
           (gnc:html-table-add-budget-values!
            html-table acct-table budget paramsBudget)
 
-          ;; hmmm... I expected that add-budget-values would have to
-          ;; clear out any unused columns to the right, out to the
-          ;; table width, since the add-account-balance had put stuff
-          ;; there, but it doesn't seem to matter.
-
           (gnc:html-document-add-object! doc html-table))))
       ) ;; end cond
 
Index: src/report/report-system/html-table.scm
===================================================================
--- src/report/report-system/html-table.scm	(revision 18213)
+++ src/report/report-system/html-table.scm	(working copy)
@@ -495,6 +495,44 @@
               (gnc:html-table-data table) 
               row-loc rowdata)))))
 
+;; if the 4th arg is a cell, overwrite the existing cell,
+;; otherwise, append all remaining objects to the existing cell
+(define (gnc:html-table-set-cell/size! table row col colspan . objects)
+  (let ((rowdata #f)
+        (row-loc #f)
+        (l (length (gnc:html-table-data table)))
+        (num-objs (length objects))
+        )
+    ;; ensure the row-data is there 
+    (if (>= row l)
+        (begin
+          (let loop ((i l))
+            (gnc:html-table-append-row! table (list))
+            (if (< i row)
+                (loop (+ i 1))))
+          (set! l (gnc:html-table-num-rows table))
+          (set! row-loc (- (- l 1) row))
+          (set! rowdata (list)))
+        (begin
+          (set! row-loc (- (- l 1) row))
+          (set! rowdata (list-ref (gnc:html-table-data table) row-loc))))
+    
+    ;; make a table-cell and set the data 
+    (let* ((tc (gnc:make-html-table-cell))
+           (first (car objects)))
+      (if (and (equal? num-objs 1) (gnc:html-table-cell? first))
+          (set! tc first)
+          (apply gnc:html-table-cell-append-objects! tc objects)
+          )
+      (gnc:html-table-cell-set-colspan! tc colspan)
+      (set! rowdata (list-set-safe! rowdata col tc))
+      
+      ;; add the row-data back to the table 
+      (gnc:html-table-set-data! 
+       table (list-set-safe! 
+              (gnc:html-table-data table) 
+              row-loc rowdata)))))
+
 (define (gnc:html-table-append-column! table newcol)
   (define (maxwidth table-data)
     (if (null? table-data) 0
Index: src/report/report-system/report-system.scm
===================================================================
--- src/report/report-system/report-system.scm	(revision 18213)
+++ src/report/report-system/report-system.scm	(working copy)
@@ -581,6 +581,7 @@
 (export gnc:html-table-get-cell)
 (export gnc:html-table-set-cell!)
 (export gnc:html-table-set-cell/tag!)
+(export gnc:html-table-set-cell/size!)
 (export gnc:html-table-append-column!)
 (export gnc:html-table-prepend-column!)
 (export gnc:html-table-merge)
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to