The "balance" row should show the total for all transactions (if any)
occurring before the "From" date selected in the report's options (defaults
to beginning of current year). If all the transactions occurred before the
"From" date then the "balance" row was not added to the table because the
check for the "balance" row only occurred if there was a transaction being
added that was after the "From" date.
I split the code for the "balance" row off into a separate routine that gets
called in the same place as the old code AND also gets run after all the
transactions have been processed for being added to the table. Running it
after all the transactions are processed ensures that if none of the
transactions were before the "From" date then the "balance" row is still
added to the table.
(Note: While this was a very minor bug, it was a good way to get a better
grasp on Scheme and the way reports are generated)
Jeff
Index: owner-report.scm
===================================================================
--- owner-report.scm (revision 16581)
+++ owner-report.scm (working copy)
@@ -185,6 +185,27 @@
table))
;;
+;; Adds the 'Balance' row to the table if it has not been printed and
+;; total is not zero
+;;
+;; Returns printed?
+;;
+(define (add-balance-row table txn odd-row? printed? start-date total)
+ (if (not printed?)
+ (begin
+ (set! printed? #t)
+ (if (not (gnc-numeric-zero-p total))
+ (let ((row (list (gnc-print-date start-date) "" "" "Balance" ""
+ (gnc:make-html-table-cell/markup "number-cell"
+ (gnc:make-gnc-monetary (xaccTransGetCurrency txn) total))))
+ (row-style (if odd-row? "normal-row" "alternate-row")))
+ (gnc:html-table-append-row/markup! table row-style row)
+ (set! odd-row? (not odd-row?))
+ (set! row-style (if odd-row? "normal-row" "alternate-row")))
+ )))
+ printed?)
+
+;;
;; Make sure the caller checks the type first and only calls us with
;; invoice and payment transactions. we don't verify it here.
;;
@@ -240,20 +261,10 @@
(if (gnc:timepair-later start-date date)
(begin
-
- ; Maybe print out the 'balance' row
- (if (not printed?)
- (begin
- (set! printed? #t)
- (if (not (gnc-numeric-zero-p total))
- (let ((row (make-row start-date #f "" (_ "Balance") "" total))
- (row-style (if odd-row? "normal-row" "alternate-row")))
- (gnc:html-table-append-row/markup! table row-style
- (reverse row))
- (set! odd-row? (not odd-row?))
- (set! row-style (if odd-row? "normal-row" "alternate-row")))
- )))
+ ; Adds 'balance' row if needed
+ (set! printed? (add-balance-row table txn odd-row? printed? start-date total))
+
; Now print out the invoice row
(if (not (null? invoice))
(set! due-date (gncInvoiceGetDateDue invoice)))
@@ -305,7 +316,11 @@
(set! total (gnc-numeric-add-fixed total (cadr result)))
(set! odd-row? (caddr result))
))))
- txns))
+ txns)
+ ;Balance row may not have been added if all transactions were before
+ ;start-date (and no other rows would be added either) so add it now
+ (add-balance-row table (car txns) odd-row? printed? start-date total)
+ )
(gnc:html-table-append-row/markup!
table
_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel