r17855 - gnucash/trunk/src/report/standard-reports - Bug #568473 – Add option to average-balance report.

Derek Atkins warlord at cvs.gnucash.org
Thu Jan 29 10:35:21 EST 2009


Author: warlord
Date: 2009-01-29 10:35:21 -0500 (Thu, 29 Jan 2009)
New Revision: 17855
Trac: http://svn.gnucash.org/trac/changeset/17855

Modified:
   gnucash/trunk/src/report/standard-reports/average-balance.scm
Log:
Bug #568473 – Add option to average-balance report.
It allows transactions that go from one selected account
to another to be ignored.

Modified: gnucash/trunk/src/report/standard-reports/average-balance.scm
===================================================================
--- gnucash/trunk/src/report/standard-reports/average-balance.scm	2009-01-29 11:42:39 UTC (rev 17854)
+++ gnucash/trunk/src/report/standard-reports/average-balance.scm	2009-01-29 15:35:21 UTC (rev 17855)
@@ -23,6 +23,7 @@
 (define optname-report-currency (N_ "Report's currency"))
 (define optname-price-source (N_ "Price Source"))
 (define optname-subacct (N_ "Include Sub-Accounts"))
+(define optname-internal (N_ "Exclude transactions between selected accounts?"))
 
   ;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Options
@@ -56,11 +57,18 @@
       gnc:pagename-accounts optname-subacct
       "a" (N_ "Include sub-accounts of all selected accounts") #t))
 
+    (register-option
+     (gnc:make-simple-boolean-option
+      gnc:pagename-accounts optname-internal
+      "b"
+      (N_ "Exclude transactions that only involve two accounts, both of which are selected below.  This only affects the profit and loss columns of the table.")
+      #f))
+
     ;; account(s) to do report on
     (register-option
      (gnc:make-account-list-option
       gnc:pagename-accounts (N_ "Accounts")
-      "b" (N_ "Do transaction report on this account")
+      "c" (N_ "Do transaction report on this account")
       (lambda ()
         ;; FIXME : gnc:get-current-accounts disappeared
         (let ((current-accounts '()))
@@ -128,7 +136,8 @@
 ;; the report-currency by means of the monetary->double
 ;; function. 
 (define (analyze-splits splits start-bal-double 
-                        start-date end-date interval monetary->double)
+                        start-date end-date interval monetary->double
+			internal)
   (let ((interval-list 
          (gnc:make-date-interval-list start-date end-date interval))
         (data-rows '()))
@@ -205,23 +214,41 @@
                                 (xaccSplitGetParent split)))
                    ;; FIXME: Which date should we use here? The 'to'
                    ;; date? the 'split-time'?
-                   (split-amt (get-split-value split split-time)))
-                
-                
-                (gnc:debug "split " split)
-                (gnc:debug "split-time " split-time)
-                (gnc:debug "split-amt " split-amt)
-                ;; gnc:debug converts its input to a string before
-                ;; deciding whether to print it, and converting
-                ;; |splits| to a string is O(N) in its length.  Since
-                ;; this code runs for every split, leaving that
-                ;; gnc:debug in makes the whole thing O(N^2) in number
-                ;; of splits.  If someone really needs this output,
-                ;; they should uncomment the gnc:debug call.
-                ; (gnc:debug "splits " splits)
-                (update-stats split-amt split-time)
-                (set! splits (cdr splits))
-		(split-recurse))))
+		   (split-amt (get-split-value split split-time))
+		   (next (cdr splits)))
+		
+		(if 
+		 ;; Check whether this split and next one are a pair
+		 ;; from the same transaction, and the only ones in
+		 ;; this transaction.
+		 ;; If they are and the flag is set appropriately,
+		 ;; then skip both.
+		 (or internal
+		     (null? next)
+		     (let* ((next-split (car next))
+			    (trans (xaccSplitGetParent split))
+			    (next-trans (xaccSplitGetParent next-split))
+			    (count (xaccTransCountSplits trans)))
+		       (not (and (eqv? count 2)
+				 (equal? trans next-trans)))))                
+		 (begin
+		  (gnc:debug "split " split)
+		  (gnc:debug "split-time " split-time)
+		  (gnc:debug "split-amt " split-amt)
+		  ;; gnc:debug converts its input to a string before
+		  ;; deciding whether to print it, and converting
+		  ;; |splits| to a string is O(N) in its length.  Since
+		  ;; this code runs for every split, leaving that
+		  ;; gnc:debug in makes the whole thing O(N^2) in number
+		  ;; of splits.  If someone really needs this output,
+		  ;; they should uncomment the gnc:debug call.
+					; (gnc:debug "splits " splits)
+		  (update-stats split-amt split-time)
+		  (set! splits next)
+		  (split-recurse))
+		 (begin
+		  (set! splits (cdr next))
+		  (split-recurse))))))
 
                                         ;  the minmax accumulator
 
@@ -288,6 +315,7 @@
          (price-source (get-option gnc:pagename-general
                                    optname-price-source))
 
+         (internal-included (not (get-option gnc:pagename-accounts optname-internal)))
          (accounts   (get-option gnc:pagename-accounts (N_ "Accounts")))
          (dosubs?    (get-option gnc:pagename-accounts optname-subacct))
 
@@ -408,7 +436,8 @@
           ;; and analyze the data 
           (set! data (analyze-splits splits startbal
                                      begindate enddate 
-                                     stepsize monetary->double))
+                                     stepsize monetary->double
+				     internal-included))
 	  (gnc:report-percent-done 70)
           
           ;; make a plot (optionally)... if both plot and table, 



More information about the gnucash-changes mailing list