r20404 - gnucash/trunk/src/report - Bug #570042: Better default for book-closing entries in Income Statement Report Options
Christian Stimming
cstim at code.gnucash.org
Sat Mar 12 10:52:20 EST 2011
Author: cstim
Date: 2011-03-12 10:52:20 -0500 (Sat, 12 Mar 2011)
New Revision: 20404
Trac: http://svn.gnucash.org/trac/changeset/20404
Modified:
gnucash/trunk/src/report/report-system/report-system.scm
gnucash/trunk/src/report/report-system/report-utilities.scm
gnucash/trunk/src/report/standard-reports/equity-statement.scm
gnucash/trunk/src/report/standard-reports/income-statement.scm
Log:
Bug #570042: Better default for book-closing entries in Income Statement Report Options
Patch by Tristan Faujour:
Proposed patch: make reports ignore book-closing entries
I chose to:
- Change the reports' default behavior to have them ignore the book-closing
entries.
- Do not change anything in reports that deal explicitly with them.
Here is the content of this patch (everything is under gnucash/src/report):
- In function gnc:account-get-trans-type-balance-interval, depending on an
argument, closing entries can be ignored (they are identified by
xaccTransGetIsClosingTxn).
- Some report utility functions are duplicated (with a "-with closing" suffix)
to provide the legacy feature.
- Equity statement and Profit & Loss reports are modified to call the
*-with-closing functions.
Modified: gnucash/trunk/src/report/report-system/report-system.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report-system.scm 2011-03-12 15:47:15 UTC (rev 20403)
+++ gnucash/trunk/src/report/report-system/report-system.scm 2011-03-12 15:52:20 UTC (rev 20404)
@@ -663,7 +663,9 @@
(export gnc:account-get-balance-interval)
(export gnc:account-get-comm-balance-interval)
(export gnc:accountlist-get-comm-balance-interval)
+(export gnc:accountlist-get-comm-balance-interval-with-closing)
(export gnc:accountlist-get-comm-balance-at-date)
+(export gnc:accountlist-get-comm-balance-at-date-with-closing)
(export gnc:query-set-match-non-voids-only!)
(export gnc:query-set-match-voids-only!)
(export gnc:split-voided?)
@@ -674,6 +676,7 @@
(export gnc:accounts-count-splits)
(export gnc-commodity-collector-allzero?)
(export gnc:account-get-trans-type-balance-interval)
+(export gnc:account-get-trans-type-balance-interval-with-closing)
(export gnc:account-get-pos-trans-total-interval)
(export gnc:account-get-trans-type-splits-interval)
(export gnc:double-col)
Modified: gnucash/trunk/src/report/report-system/report-utilities.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report-utilities.scm 2011-03-12 15:47:15 UTC (rev 20403)
+++ gnucash/trunk/src/report/report-system/report-utilities.scm 2011-03-12 15:52:20 UTC (rev 20404)
@@ -643,9 +643,15 @@
(define (gnc:accountlist-get-comm-balance-interval accountlist from to)
(gnc:account-get-trans-type-balance-interval accountlist #f from to))
+(define (gnc:accountlist-get-comm-balance-interval-with-closing accountlist from to)
+ (gnc:account-get-trans-type-balance-interval-with-closing accountlist #f from to))
+
(define (gnc:accountlist-get-comm-balance-at-date accountlist date)
(gnc:account-get-trans-type-balance-interval accountlist #f #f date))
+(define (gnc:accountlist-get-comm-balance-at-date-with-closing accountlist date)
+ (gnc:account-get-trans-type-balance-interval-with-closing accountlist #f #f date))
+
;; utility function - ensure that a query matches only non-voids. Destructive.
(define (gnc:query-set-match-non-voids-only! query book)
(let ((temp-query (qof-query-create-for-splits)))
@@ -708,7 +714,7 @@
;; Sums up any splits of a certain type affecting a set of accounts.
;; the type is an alist '((str "match me") (cased #f) (regexp #f))
-;; If type is #f, sums all splits in the interval
+;; If type is #f, sums all non-closing splits in the interval
(define (gnc:account-get-trans-type-balance-interval
account-list type start-date-tp end-date-tp)
(let* ((total (gnc:make-commodity-collector)))
@@ -716,8 +722,33 @@
(let* ((shares (xaccSplitGetAmount split))
(acct-comm (xaccAccountGetCommodity
(xaccSplitGetAccount split)))
+ (txn (xaccSplitGetParent split))
)
- (gnc-commodity-collector-add total acct-comm shares)
+ (if type
+ (gnc-commodity-collector-add total acct-comm shares)
+ (if (not (xaccTransGetIsClosingTxn txn))
+ (gnc-commodity-collector-add total acct-comm shares)
+ )))
+ )
+ (gnc:account-get-trans-type-splits-interval
+ account-list type start-date-tp end-date-tp)
+ )
+ total
+ )
+ )
+
+;; Sums up any splits of a certain type affecting a set of accounts.
+;; the type is an alist '((str "match me") (cased #f) (regexp #f))
+;; If type is #f, sums all splits in the interval (even closing splits)
+(define (gnc:account-get-trans-type-balance-interval-with-closing
+ account-list type start-date-tp end-date-tp)
+ (let* ((total (gnc:make-commodity-collector)))
+ (map (lambda (split)
+ (let* ((shares (xaccSplitGetAmount split))
+ (acct-comm (xaccAccountGetCommodity
+ (xaccSplitGetAccount split)))
+ )
+ (gnc-commodity-collector-add total acct-comm shares)
)
)
(gnc:account-get-trans-type-splits-interval
@@ -726,7 +757,6 @@
total
)
)
-
;; similar, but only counts transactions with non-negative shares and
;; *ignores* any closing entries
(define (gnc:account-get-pos-trans-total-interval
Modified: gnucash/trunk/src/report/standard-reports/equity-statement.scm
===================================================================
--- gnucash/trunk/src/report/standard-reports/equity-statement.scm 2011-03-12 15:47:15 UTC (rev 20403)
+++ gnucash/trunk/src/report/standard-reports/equity-statement.scm 2011-03-12 15:52:20 UTC (rev 20404)
@@ -444,10 +444,10 @@
;; start and end retained earnings (income - expenses)
(set! neg-pre-start-retained-earnings
- (gnc:accountlist-get-comm-balance-at-date
+ (gnc:accountlist-get-comm-balance-at-date-with-closing
income-expense-accounts start-date-tp)) ; OK
(set! neg-pre-end-retained-earnings
- (gnc:accountlist-get-comm-balance-at-date
+ (gnc:accountlist-get-comm-balance-at-date-with-closing
income-expense-accounts end-date-tp)) ; OK
;; neg-pre-end-retained-earnings is not used to calculate
;; profit but is used to calculate unrealized gains
@@ -455,13 +455,13 @@
;; calculate net income
;; first, ask out how much profit/loss was closed
(set! income-expense-closing
- (gnc:account-get-trans-type-balance-interval
+ (gnc:account-get-trans-type-balance-interval-with-closing
income-expense-accounts closing-pattern
start-date-tp end-date-tp)
)
;; find retained earnings for the period
(set! neg-net-income
- (gnc:accountlist-get-comm-balance-interval
+ (gnc:accountlist-get-comm-balance-interval-with-closing
income-expense-accounts
start-date-tp end-date-tp)) ; OK
;; revert the income/expense to its pre-closing balance
@@ -532,7 +532,7 @@
;;
(set! equity-closing
- (gnc:account-get-trans-type-balance-interval
+ (gnc:account-get-trans-type-balance-interval-with-closing
equity-accounts closing-pattern
start-date-tp end-date-tp)
)
Modified: gnucash/trunk/src/report/standard-reports/income-statement.scm
===================================================================
--- gnucash/trunk/src/report/standard-reports/income-statement.scm 2011-03-12 15:47:15 UTC (rev 20403)
+++ gnucash/trunk/src/report/standard-reports/income-statement.scm 2011-03-12 15:52:20 UTC (rev 20404)
@@ -516,29 +516,29 @@
;; sum revenues and expenses
(set! revenue-closing
- (gnc:account-get-trans-type-balance-interval
+ (gnc:account-get-trans-type-balance-interval-with-closing
revenue-accounts closing-pattern
start-date-tp end-date-tp)
) ;; this is norm positive (debit)
(set! expense-closing
- (gnc:account-get-trans-type-balance-interval
+ (gnc:account-get-trans-type-balance-interval-with-closing
expense-accounts closing-pattern
start-date-tp end-date-tp)
) ;; this is norm negative (credit)
(set! expense-total
- (gnc:accountlist-get-comm-balance-interval
+ (gnc:accountlist-get-comm-balance-interval-with-closing
expense-accounts
start-date-tp end-date-tp))
(expense-total 'minusmerge expense-closing #f)
(set! neg-revenue-total
- (gnc:accountlist-get-comm-balance-interval
+ (gnc:accountlist-get-comm-balance-interval-with-closing
revenue-accounts
start-date-tp end-date-tp))
(neg-revenue-total 'minusmerge revenue-closing #f)
(set! revenue-total (gnc:make-commodity-collector))
(revenue-total 'minusmerge neg-revenue-total #f)
(set! trading-total
- (gnc:accountlist-get-comm-balance-interval
+ (gnc:accountlist-get-comm-balance-interval-with-closing
trading-accounts
start-date-tp end-date-tp))
;; calculate net income
More information about the gnucash-changes
mailing list