mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
[budgets.scm] budget reports handle both natural & reversed budgets
This commit is contained in:
parent
775200ef34
commit
b5f9cd0b32
@ -256,7 +256,8 @@
|
||||
(gnc:report-options report-obj) pagename optname)))
|
||||
|
||||
(define (get-budget-account-budget-balance budget account)
|
||||
(gnc:budget-account-get-net budget account #f #f))
|
||||
(let ((bal (gnc:budget-account-get-net budget account #f #f)))
|
||||
(if (gnc-reverse-budget-balance account #t) (gnc:collector- bal) bal)))
|
||||
|
||||
(define (get-budget-account-initial-balance budget account)
|
||||
(gnc:budget-account-get-initial-balance budget account))
|
||||
|
@ -308,7 +308,8 @@
|
||||
(get-balance-fn budget account period-start period-end))))
|
||||
|
||||
(define (get-budget-account-budget-balance budget account period-start period-end)
|
||||
(gnc:budget-account-get-net budget account period-start period-end))
|
||||
(let ((bal (gnc:budget-account-get-net budget account period-start period-end)))
|
||||
(if (gnc-reverse-budget-balance account #t) (gnc:collector- bal) bal)))
|
||||
|
||||
(gnc:report-starting reportname)
|
||||
|
||||
|
@ -331,6 +331,9 @@
|
||||
column-list exchange-fn)
|
||||
(let* ((comm (xaccAccountGetCommodity acct))
|
||||
(reverse-balance? (gnc-reverse-balance acct))
|
||||
(maybe-negate (lambda (amt) (if reverse-balance? (- amt) amt)))
|
||||
(unreversed? (gnc-using-unreversed-budgets
|
||||
(gnc-get-current-book))) ;fwd-compatibility
|
||||
(allperiods (filter number? (gnc:list-flatten column-list)))
|
||||
(total-periods (if (and accumulate? (not (null? allperiods)))
|
||||
(iota (1+ (apply max allperiods)))
|
||||
@ -379,6 +382,19 @@
|
||||
((null? column-list)
|
||||
#f)
|
||||
|
||||
;; fwd-compatibility: the next cond may be removed in master
|
||||
((and (eq? (car column-list) 'total) unreversed?)
|
||||
(let* ((bgt-total (maybe-negate
|
||||
(gnc:get-account-periodlist-budget-value
|
||||
budget acct total-periods)))
|
||||
(act-total (maybe-negate
|
||||
(gnc:get-account-periodlist-actual-value
|
||||
budget acct total-periods)))
|
||||
(dif-total (- bgt-total act-total)))
|
||||
(loop (cdr column-list)
|
||||
(disp-cols "total-number-cell" current-col
|
||||
bgt-total act-total dif-total))))
|
||||
|
||||
((eq? (car column-list) 'total)
|
||||
(let* ((bgt-total (gnc:get-account-periodlist-budget-value
|
||||
budget acct total-periods))
|
||||
@ -392,6 +408,23 @@
|
||||
(disp-cols "total-number-cell" current-col
|
||||
bgt-total act-total dif-total))))
|
||||
|
||||
;; fwd-compatibility: the next cond may be removed in master
|
||||
(unreversed?
|
||||
(let* ((period-list (cond
|
||||
((list? (car column-list)) (car column-list))
|
||||
(accumulate? (iota (1+ (car column-list))))
|
||||
(else (list (car column-list)))))
|
||||
(bgt-val (maybe-negate
|
||||
(gnc:get-account-periodlist-budget-value
|
||||
budget acct period-list)))
|
||||
(act-val (maybe-negate
|
||||
(gnc:get-account-periodlist-actual-value
|
||||
budget acct period-list)))
|
||||
(dif-val (- bgt-val act-val)))
|
||||
(loop (cdr column-list)
|
||||
(disp-cols "number-cell" current-col
|
||||
bgt-val act-val dif-val))))
|
||||
|
||||
(else
|
||||
(let* ((period-list (cond
|
||||
((list? (car column-list)) (car column-list))
|
||||
|
Loading…
Reference in New Issue
Block a user