From c5adac66c37bce995a232712b9dd5b2ca38de6ff Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 3 Sep 2013 14:02:02 +0000 Subject: [PATCH] Bug 603183 - Equity statement shows incorrect changes Add function gnc:account-get-total-flow to report-utilities.scm This function filters the splits from the source to the target accounts and returns a commodity collector. It does NOT do currency exchanges. Author: Carsten Rinke git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23156 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/report/report-system/report-utilities.scm | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/report/report-system/report-utilities.scm b/src/report/report-system/report-utilities.scm index 1d5b86cba0..eed68b78ba 100644 --- a/src/report/report-system/report-utilities.scm +++ b/src/report/report-system/report-utilities.scm @@ -759,6 +759,74 @@ total ) ) + +;; Filters the splits from the source to the target accounts +;; returns a commodity collector +;; does NOT do currency exchanges +(define (gnc:account-get-total-flow direction target-account-list from-date-tp to-date-tp) + + (let* ( + (total-flow (gnc:make-commodity-collector)) + ) + + ;; ------------------------------------------------------------------ + ;; process all target accounts + ;; ------------------------------------------------------------------ + (for-each + (lambda (target-account) + ;; ------------------------------------- + ;; process all splits of current account + ;; ------------------------------------- + (for-each + (lambda (target-account-split) + ;; ---------------------------------------------------- + ;; only target account splits that are within the specified time range + ;; ---------------------------------------------------- + (let* ( + (transaction (xaccSplitGetParent target-account-split)) + (transaction-date-posted (gnc-transaction-get-date-posted transaction)) + ) + (if (and + (gnc:timepair-le transaction-date-posted to-date-tp) + (gnc:timepair-ge transaction-date-posted from-date-tp) + ) + ;; ------------------------------------------------------------- + ;; get the split information + ;; ------------------------------------------------------------- + (let* ( + (transaction-currency (xaccTransGetCurrency transaction)) + (transaction-value (gnc-numeric-zero)) + (split-value (xaccSplitGetAmount target-account-split)) + ) + ;; ------------------------------------------------------------- + ;; update the return value + ;; ------------------------------------------------------------- + (case direction + ((in) + (if (gnc-numeric-positive-p split-value) + (total-flow 'add transaction-currency split-value) + ) + ) + ((out) + (if (gnc-numeric-negative-p split-value) + (total-flow 'add transaction-currency split-value) + ) + ) + (else (gnc:warn "bad gnc:account-get-total-flow action: " direction)) + ) + ) + ) + ) + ) + (xaccAccountGetSplitList target-account) + ) + ) + target-account-list + ) + total-flow ;; RETURN + ) +) + ;; similar, but only counts transactions with non-negative shares and ;; *ignores* any closing entries (define (gnc:account-get-pos-trans-total-interval