From ebfe0a4716e3bfde6d4da0c69e0d5db34532c4d6 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Thu, 13 Jan 2022 23:06:15 +0800 Subject: [PATCH] [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. --- gnucash/report/report-utilities.scm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm index cbb87301b7..126e2aaaed 100644 --- a/gnucash/report/report-utilities.scm +++ b/gnucash/report/report-utilities.scm @@ -940,14 +940,12 @@ query instead.") ;; ;; Returns a gnc-numeric value (define (gnc:budget-account-get-rolledup-net budget account start-period end-period) - (let* ((start (or start-period 0)) - (end (or end-period (gnc-budget-get-num-periods budget))) - (numperiods (- end start -1))) - (apply + - (map - (lambda (period) - (gnc:get-account-period-rolledup-budget-value budget account period)) - (iota numperiods start 1))))) + (define end (or end-period (1- (gnc-budget-get-num-periods budget)))) + (let lp ((period (or start-period 0)) (sum 0)) + (cond + ((> period end) sum) + (else (lp (1+ period) (+ sum (gnc:get-account-period-rolledup-budget-value + budget account period))))))) ;; *************************************************************************** ;; The following 3 functions belong together