AUDIT: r20637 - gnucash/trunk/src/report/business-reports - Bug #649992: Let owner-report aging table include due date / post date options in aging.

Christian Stimming cstim at
Fri May 13 16:17:28 EDT 2011

Author: cstim
Date: 2011-05-13 16:17:28 -0400 (Fri, 13 May 2011)
New Revision: 20637

Bug #649992: Let owner-report aging table include due date / post date options in aging.

Patch by "Bert":

Follow up on bug: #502066 called "The aging in
business reports should use the due date instead of the post date".

In that bug the aging reports were extended to use the due date when reporting
overdue in buckets such as Current - 0-30 etc.

This created an inconsistency since the owner reports (such as Customer Report)
did not report the Current bucket and did not include the option to select Date
Posted or Date due.

The attached patch patches the owner report to:
*Allow a choice between the use of Due Date and Date Posted
*Report with the current bucket


Modified: gnucash/trunk/src/report/business-reports/owner-report.scm
--- gnucash/trunk/src/report/business-reports/owner-report.scm	2011-05-12 18:18:52 UTC (rev 20636)
+++ gnucash/trunk/src/report/business-reports/owner-report.scm	2011-05-13 20:17:28 UTC (rev 20637)
@@ -40,6 +40,7 @@
 ;; Option names
 (define optname-from-date (N_ "From"))
 (define optname-to-date (N_ "To"))
+(define optname-date-driver (N_ "Due or Post Date"))
 ;; let's define a name for the report-guid's, much prettier
 (define employee-report-guid "08ae9c2e884b4f9787144f47eacd7f44")
@@ -162,7 +163,7 @@
     (reverse heading-list)))
-(define num-buckets 4)
+(define num-buckets 5)
 (define (new-bucket-vector)
   (make-vector num-buckets (gnc-numeric-zero)))
@@ -173,8 +174,13 @@
     (set! begindate (decdate begindate ThirtyDayDelta))
     (gnc:make-date-list begindate to-date ThirtyDayDelta)))
+;; Have make-list create a stepped list, then add a date in the future for the "current" bucket 
+(define (make-extended-interval-list to-date) 
+    (define dayforcurrent (incdate to-date YearDelta)) ;; MAGIC CONSTANT 
+    (define oldintervalreversed (reverse (make-interval-list to-date)))          
+  (reverse (cons dayforcurrent oldintervalreversed))) 
-(define (make-aging-table options query bucket-intervals reverse?)
+(define (make-aging-table options query bucket-intervals reverse? date-type)
   (let ((lots (xaccQueryGetLots query QUERY-TXN-MATCH-ANY))
 	(buckets (new-bucket-vector))
 	(payments (gnc-numeric-zero))
@@ -206,21 +212,25 @@
      (lambda (lot)
        (let* ((bal (gnc-lot-get-balance lot))
 	      (invoice (gncInvoiceGetInvoiceFromLot lot))
-	      (post-date (gncInvoiceGetDatePosted invoice)))
+              (date (if (eq? date-type 'postdate)
+               (gncInvoiceGetDatePosted invoice) 
+               (gncInvoiceGetDateDue invoice)))
+              )
 	 (if (not (gnc-numeric-zero-p bal))
 	       (if reverse?
 		   (set! bal (gnc-numeric-neg bal)))
 	       (if (not (null? invoice))
-		     (apply-invoice post-date bal))
+		     (apply-invoice date bal))
 		   (apply-payment bal))))))
-     (list (_ "0-30 days")
+     (list (_ "Current")
+           (_ "0-30 days")
 	   (_ "31-60 days")
 	   (_ "61-90 days")
 	   (_ "91+ days")))
@@ -344,7 +354,7 @@
-(define (make-txn-table options query acc start-date end-date)
+(define (make-txn-table options query acc start-date end-date date-type)
   (let ((txns (xaccQueryGetTransactions query QUERY-TXN-MATCH-ANY))
 	(used-columns (build-column-used options))
 	(total (gnc-numeric-zero))
@@ -431,14 +441,14 @@
 		    (gnc:make-gnc-monetary currency total))))))
-    (let* ((interval-vec (list->vector (make-interval-list end-date))))
+    (let* ((interval-vec (list->vector (make-extended-interval-list end-date))))
        (list (gnc:make-html-table-cell/size/markup
 	      1 columns-used-size
-	      (make-aging-table options query interval-vec reverse?)))))
+	      (make-aging-table options query interval-vec reverse? date-type)))))
@@ -522,6 +532,17 @@
     gnc:pagename-general (N_ "Today Date Format")
     "p" (N_ "The format for the date->string conversion for today's date.")
+  (gnc:register-inv-option 
+   (gnc:make-multichoice-option 
+    gnc:pagename-general 
+    optname-date-driver 
+    "k" 
+    (N_ "Leading date") 
+    'duedate 
+    (list 
+     (vector 'duedate (N_ "Due date") (N_ "Due date is leading")) ;; Should be using standard label for due date? 
+     (vector 'postdate (N_ "Post date") (N_ "Post date is leading"))))) ;; Should be using standard label for post date? 
   (gnc:options-set-default-section gnc:*report-options* "General")
@@ -670,6 +691,7 @@
 	 (book (gnc-get-current-book)) ;XXX Grab this from elsewhere
          (type (opt-val "__reg" "owner-type"))
          (owner-descr (owner-string type))
+         (date-type (opt-val gnc:pagename-general optname-date-driver)) 
 	 (owner (opt-val owner-page owner-descr)))
@@ -695,7 +717,7 @@
 	  (if (not (null? account))
 		(set! table (make-txn-table (gnc:report-options report-obj)
-					    query account start-date end-date))
+					    query account start-date end-date date-type))
 		 table "table"
 		 'attribute (list "border" 1)

More information about the gnucash-changes mailing list