r20480 - gnucash/trunk/src/report/business-reports - Bug #645352: Customer and Vendor Reports should have separate income and expense subtotals per period; error if 'Amount' is not selected

Christian Stimming cstim at code.gnucash.org
Fri Mar 25 15:57:20 EDT 2011


Author: cstim
Date: 2011-03-25 15:57:20 -0400 (Fri, 25 Mar 2011)
New Revision: 20480
Trac: http://svn.gnucash.org/trac/changeset/20480

Modified:
   gnucash/trunk/src/report/business-reports/owner-report.scm
Log:
Bug #645352: Customer and Vendor Reports should have separate income and expense subtotals per period; error if 'Amount' is not selected

Patch by Chris Curtis:

Add 'Credit' and 'Debit' columns and options; fix error if 'Amount' is not
selected.

For tax purposes it would be helpful if the customer and vendor reports
included the totals for the amounts earned, received, or billed for a given
time period.

The reports currently give a total, which is (if you're lucky) zero because the
credits cancel out the debits.  But for verifying or providing the amounts of a
1099-MISC, for instance, the report should show just the amounts credited or
debited depending on your business' accounting method.


Secondarily, if the 'Amount' column is deselected the report fails with an
error.

The attached patch both corrects this problem and adds the requested features.


The new columns are labeled simply 'Credit' and 'Debit' and do not attempt
context-aware naming ("Paid", "Billed", etc.) for simplicity and applicability
(cash versus accrual accounting).  The columns contain a running total, and the
final totals appear in a line above the Amount (running) total.

If the beginning period splits an invoice/payment pair an opening balance
appears and is accounted for in the Amount total as before, but is not included
in the Credit/Debit totals as it is outside the reporting period.  If the
Amount column is not selected for display then neither is the opening balance,
even if it otherwise would have been.

Modified: gnucash/trunk/src/report/business-reports/owner-report.scm
===================================================================
--- gnucash/trunk/src/report/business-reports/owner-report.scm	2011-03-25 19:57:07 UTC (rev 20479)
+++ gnucash/trunk/src/report/business-reports/owner-report.scm	2011-03-25 19:57:20 UTC (rev 20480)
@@ -53,6 +53,8 @@
 (define reference-header (N_ "Reference"))
 (define type-header (N_ "Type"))
 (define desc-header (N_ "Description"))
+(define credit-header (N_ "Credits"))
+(define debit-header (N_ "Debits"))
 (define amount-header (N_ "Amount"))
 
 ;; Depending on the report type we want to set up some lists/cases 
@@ -105,10 +107,14 @@
   (vector-ref columns-used 3))
 (define (memo-col columns-used)
   (vector-ref columns-used 4))
+(define (credit-col columns-used)
+  (vector-ref columns-used 5))
+(define (debit-col columns-used)
+  (vector-ref columns-used 6))
 (define (value-col columns-used)
-  (vector-ref columns-used 5))
+  (vector-ref columns-used 7))
 
-(define columns-used-size 6)
+(define columns-used-size 8)
 
 (define (build-column-used options)   
   (define (opt-val section name)
@@ -130,7 +136,9 @@
     (set-col (opt-val "Display Columns" reference-header) 2)
     (set-col (opt-val "Display Columns" type-header) 3)
     (set-col (opt-val "Display Columns" desc-header) 4)
-    (set-col (opt-val "Display Columns" amount-header) 5)
+    (set-col (opt-val "Display Columns" credit-header) 5)
+    (set-col (opt-val "Display Columns" debit-header) 6)
+    (set-col (opt-val "Display Columns" amount-header) 7)
     col-vector))
 
 (define (make-heading-list column-vector)
@@ -145,6 +153,10 @@
 	(addto! heading-list (_ type-header)))
     (if (memo-col column-vector)
 	(addto! heading-list (_ desc-header)))
+    (if (credit-col column-vector)
+	(addto! heading-list (_ credit-header)))
+    (if (debit-col column-vector)
+	(addto! heading-list (_ debit-header)))
     (if (value-col column-vector)
 	(addto! heading-list (_ amount-header)))
     (reverse heading-list)))
@@ -224,7 +236,7 @@
 ;;
 ;; Make a row list based on the visible columns
 ;;
-(define (make-row column-vector date due-date num type-str memo monetary)
+(define (make-row column-vector date due-date num type-str memo monetary credit debit)
   (let ((row-contents '()))
     (if (date-col column-vector)
 	(addto! row-contents (gnc-print-date date)))
@@ -240,6 +252,12 @@
 	(addto! row-contents type-str))
     (if (memo-col column-vector)
 	(addto! row-contents memo))
+    (if (credit-col column-vector)
+	(addto! row-contents
+		(gnc:make-html-table-cell/markup "number-cell" credit)))
+    (if (debit-col column-vector)
+	(addto! row-contents
+		(gnc:make-html-table-cell/markup "number-cell" debit)))
     (if (value-col column-vector)
 	(addto! row-contents
 		(gnc:make-html-table-cell/markup "number-cell" monetary)))
@@ -255,9 +273,9 @@
   (if (not printed?)
       (begin
 	(set! printed? #t)
-	(if (not (gnc-numeric-zero-p total))
+	(if (and (value-col column-vector) (not (gnc-numeric-zero-p total)))
 	    (let ((row (make-row column-vector start-date #f "" (_ "Balance") ""
-				 (gnc:make-gnc-monetary (xaccTransGetCurrency txn) total)))
+				 (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 (reverse row))
 	      (set! odd-row? (not odd-row?))
@@ -308,7 +326,12 @@
 
 	  (let ((row (make-row column-vector date due-date (xaccTransGetNum txn)
 			       type-str (xaccSplitGetMemo split)
-			       (gnc:make-gnc-monetary currency value)))
+			       (gnc:make-gnc-monetary currency value)
+		   (if (not (gnc-numeric-negative-p value))
+		       (gnc:make-gnc-monetary currency value) "")
+		   (if (gnc-numeric-negative-p value)
+		       (gnc:make-gnc-monetary currency value) "")
+		))
 		(row-style (if odd-row? "normal-row" "alternate-row")))
 
 	    (gnc:html-table-append-row/markup! table row-style
@@ -325,6 +348,8 @@
   (let ((txns (xaccQueryGetTransactions query QUERY-TXN-MATCH-ANY))
 	(used-columns (build-column-used options))
 	(total (gnc-numeric-zero))
+	(debit (gnc-numeric-zero))
+	(credit (gnc-numeric-zero))
 	(currency (gnc-default-currency)) ;XXX
 	(table (gnc:make-html-table))
 	(inv-str (gnc:option-value (gnc:lookup-option options "__reg"
@@ -351,6 +376,10 @@
 				       inv-str reverse? start-date total)))
 
 	      (set! printed? (car result))
+	      (if (and printed? total)
+		(if (gnc-numeric-negative-p (cadr result))
+		    (set! debit (gnc-numeric-add-fixed debit (cadr result)))
+		    (set! credit (gnc-numeric-add-fixed credit (cadr result)))))
 	      (set! total (gnc-numeric-add-fixed total (cadr result)))
 	      (set! odd-row? (caddr result))
 	      ))))
@@ -361,11 +390,38 @@
 	  (add-balance-row table used-columns (car txns) odd-row? printed? start-date total)
 		))
 
+    (if (or (credit-col used-columns) (debit-col used-columns))
     (gnc:html-table-append-row/markup! 
      table
      "grand-total"
      (append (cons (gnc:make-html-table-cell/markup
 		    "total-label-cell"
+		    (_ "Period Totals"))
+		   '())
+
+	; This is hard-coded to expect 'debits' to follow 'credits'
+	(let ((row-contents '())
+	    (credit-span (credit-col used-columns))
+	    (debit-span
+		(if (credit-col used-columns) 1 (debit-col used-columns))))
+
+	; HTML gets generated in reverse order
+	(if (debit-col used-columns) (addto! row-contents
+	    (gnc:make-html-table-cell/size/markup
+		1 debit-span "total-number-cell"
+		(gnc:make-gnc-monetary currency debit))))
+	(if (credit-col used-columns) (addto! row-contents
+	    (gnc:make-html-table-cell/size/markup
+		1 credit-span "total-number-cell"
+		(gnc:make-gnc-monetary currency credit))))
+	row-contents))))
+
+    (if (value-col used-columns)
+    (gnc:html-table-append-row/markup! 
+     table
+     "grand-total"
+     (append (cons (gnc:make-html-table-cell/markup
+		    "total-label-cell"
 		    (if (gnc-numeric-negative-p total)
 			(_ "Total Credit")
 			(_ "Total Due")))
@@ -373,14 +429,14 @@
 	     (list (gnc:make-html-table-cell/size/markup
 		    1 (value-col used-columns)
 		    "total-number-cell"
-		    (gnc:make-gnc-monetary currency total)))))
+		    (gnc:make-gnc-monetary currency total))))))
 
     (let* ((interval-vec (list->vector (make-interval-list end-date))))
       (gnc:html-table-append-row/markup!
        table
        "grand-total"
        (list (gnc:make-html-table-cell/size/markup
-	      1 (+ 1 (value-col used-columns))
+	      1 columns-used-size
 	      "centered-label-cell"
 	      (make-aging-table options query interval-vec reverse?)))))
 
@@ -448,6 +504,16 @@
 
   (gnc:register-inv-option
    (gnc:make-simple-boolean-option
+    (N_ "Display Columns") credit-header
+    "haa" (N_ "Display the period credits column?") #t))
+
+  (gnc:register-inv-option
+   (gnc:make-simple-boolean-option
+    (N_ "Display Columns") debit-header
+    "hab" (N_ "Display a period debits column?") #t))
+
+  (gnc:register-inv-option
+   (gnc:make-simple-boolean-option
     (N_ "Display Columns") amount-header
     "hb" (N_ "Display the transaction amount?") #t)) 
 



More information about the gnucash-changes mailing list