r20641 - gnucash/branches/2.4/src/report/business-reports - [20637] Bug #649992: Let owner-report aging table include due date / post date options in aging.

Christian Stimming cstim at code.gnucash.org
Fri May 13 16:22:11 EDT 2011


Author: cstim
Date: 2011-05-13 16:22:11 -0400 (Fri, 13 May 2011)
New Revision: 20641
Trac: http://svn.gnucash.org/trac/changeset/20641

Modified:
   gnucash/branches/2.4/src/report/business-reports/owner-report.scm
Log:
[20637] Bug #649992: Let owner-report aging table include due date / post date options in aging.

Patch by "Bert":

Follow up on bug:
https://bugzilla.gnome.org/show_bug.cgi?id=502066 #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/branches/2.4/src/report/business-reports/owner-report.scm
===================================================================
--- gnucash/branches/2.4/src/report/business-reports/owner-report.scm	2011-05-13 20:21:59 UTC (rev 20640)
+++ gnucash/branches/2.4/src/report/business-reports/owner-report.scm	2011-05-13 20:22:11 UTC (rev 20641)
@@ -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")
@@ -150,7 +151,7 @@
     (reverse heading-list)))
 
 
-(define num-buckets 4)
+(define num-buckets 5)
 (define (new-bucket-vector)
   (make-vector num-buckets (gnc-numeric-zero)))
 
@@ -161,8 +162,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))
@@ -194,21 +200,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))
 	     (begin
 	       (if reverse?
 		   (set! bal (gnc-numeric-neg bal)))
 	       (if (not (null? invoice))
 		   (begin
-		     (apply-invoice post-date bal))
+		     (apply-invoice date bal))
 		   (apply-payment bal))))))
      lots)
 
     (gnc:html-table-set-col-headers!
      table
-     (list (_ "0-30 days")
+     (list (_ "Current")
+           (_ "0-30 days")
 	   (_ "31-60 days")
 	   (_ "61-90 days")
 	   (_ "91+ days")))
@@ -321,7 +331,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))
@@ -375,14 +385,14 @@
 		    "total-number-cell"
 		    (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))))
       (gnc:html-table-append-row/markup!
        table
        "grand-total"
        (list (gnc:make-html-table-cell/size/markup
 	      1 (+ 1 (value-col used-columns))
 	      "centered-label-cell"
-	      (make-aging-table options query interval-vec reverse?)))))
+	      (make-aging-table options query interval-vec reverse? date-type)))))
 
     table))
 
@@ -456,6 +466,17 @@
     gnc:pagename-general (N_ "Today Date Format")
     "p" (N_ "The format for the date->string conversion for today's date.")
     (gnc-default-strftime-date-format)))
+  
+  (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")
 
@@ -604,6 +625,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)))
 
     (gnc:html-document-set-title!
@@ -629,7 +651,7 @@
 	  (if (not (null? account))
 	      (begin
 		(set! table (make-txn-table (gnc:report-options report-obj)
-					    query account start-date end-date))
+					    query account start-date end-date date-type))
 		(gnc:html-table-set-style!
 		 table "table"
 		 'attribute (list "border" 1)



More information about the gnucash-changes mailing list