mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[budgets.scm] budget reports handle both natural & reversed budgets
This commit is contained in:
@@ -256,7 +256,8 @@
|
|||||||
(gnc:report-options report-obj) pagename optname)))
|
(gnc:report-options report-obj) pagename optname)))
|
||||||
|
|
||||||
(define (get-budget-account-budget-balance budget account)
|
(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)
|
(define (get-budget-account-initial-balance budget account)
|
||||||
(gnc:budget-account-get-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))))
|
(get-balance-fn budget account period-start period-end))))
|
||||||
|
|
||||||
(define (get-budget-account-budget-balance 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)
|
(gnc:report-starting reportname)
|
||||||
|
|
||||||
|
|||||||
@@ -331,6 +331,9 @@
|
|||||||
column-list exchange-fn)
|
column-list exchange-fn)
|
||||||
(let* ((comm (xaccAccountGetCommodity acct))
|
(let* ((comm (xaccAccountGetCommodity acct))
|
||||||
(reverse-balance? (gnc-reverse-balance 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)))
|
(allperiods (filter number? (gnc:list-flatten column-list)))
|
||||||
(total-periods (if (and accumulate? (not (null? allperiods)))
|
(total-periods (if (and accumulate? (not (null? allperiods)))
|
||||||
(iota (1+ (apply max allperiods)))
|
(iota (1+ (apply max allperiods)))
|
||||||
@@ -379,6 +382,19 @@
|
|||||||
((null? column-list)
|
((null? column-list)
|
||||||
#f)
|
#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)
|
((eq? (car column-list) 'total)
|
||||||
(let* ((bgt-total (gnc:get-account-periodlist-budget-value
|
(let* ((bgt-total (gnc:get-account-periodlist-budget-value
|
||||||
budget acct total-periods))
|
budget acct total-periods))
|
||||||
@@ -392,6 +408,23 @@
|
|||||||
(disp-cols "total-number-cell" current-col
|
(disp-cols "total-number-cell" current-col
|
||||||
bgt-total act-total dif-total))))
|
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
|
(else
|
||||||
(let* ((period-list (cond
|
(let* ((period-list (cond
|
||||||
((list? (car column-list)) (car column-list))
|
((list? (car column-list)) (car column-list))
|
||||||
|
|||||||
Reference in New Issue
Block a user