[report-utilities.scm] gnc:budget-account-get-rolledup-net bugfix

This function accepts start-period and end-period, either/both can
be #f which signifies budget start and end respectively.

If end-period of #f, numperiods was then defined
as (budget->num_periods + 1) which was incorrect.

Bugfix and refactor to be cleaner.
This commit is contained in:
Christopher Lam 2022-01-13 23:06:15 +08:00
parent b1176b4614
commit ebfe0a4716

View File

@ -940,14 +940,12 @@ query instead.")
;; ;;
;; Returns a gnc-numeric value ;; Returns a gnc-numeric value
(define (gnc:budget-account-get-rolledup-net budget account start-period end-period) (define (gnc:budget-account-get-rolledup-net budget account start-period end-period)
(let* ((start (or start-period 0)) (define end (or end-period (1- (gnc-budget-get-num-periods budget))))
(end (or end-period (gnc-budget-get-num-periods budget))) (let lp ((period (or start-period 0)) (sum 0))
(numperiods (- end start -1))) (cond
(apply + ((> period end) sum)
(map (else (lp (1+ period) (+ sum (gnc:get-account-period-rolledup-budget-value
(lambda (period) budget account period)))))))
(gnc:get-account-period-rolledup-budget-value budget account period))
(iota numperiods start 1)))))
;; *************************************************************************** ;; ***************************************************************************
;; The following 3 functions belong together ;; The following 3 functions belong together