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.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20404 57a11ea4-9604-0410-9ed3-97b8803252fd
pull/1/head
Christian Stimming 15 years ago
parent 8cf578b069
commit a59cf2759e

@ -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)

@ -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,9 +722,13 @@
(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)
@ -727,6 +737,26 @@
)
)
;; 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
account-list type start-date-tp end-date-tp)
)
total
)
)
;; similar, but only counts transactions with non-negative shares and
;; *ignores* any closing entries
(define (gnc:account-get-pos-trans-total-interval

@ -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)
)

@ -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

Loading…
Cancel
Save