From ec886fd223543de68bbc22915823d4f47f40dae0 Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Thu, 29 Jan 2009 15:35:21 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20#568473=20=E2=80=93=20Add=20option=20to?= =?UTF-8?q?=20average-balance=20report.=20It=20allows=20transactions=20tha?= =?UTF-8?q?t=20go=20from=20one=20selected=20account=20to=20another=20to=20?= =?UTF-8?q?be=20ignored.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17855 57a11ea4-9604-0410-9ed3-97b8803252fd --- .../standard-reports/average-balance.scm | 69 +++++++++++++------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/src/report/standard-reports/average-balance.scm b/src/report/standard-reports/average-balance.scm index 904b87bf19..5b2f26a0e3 100644 --- a/src/report/standard-reports/average-balance.scm +++ b/src/report/standard-reports/average-balance.scm @@ -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,