From 23d0fa132414faab93acb46214c7c6197938044e Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 8 Sep 2019 23:37:10 +0800 Subject: [PATCH] [balsheet-pnl] bugfix last pnl period must not be decreased by 1 day logic error to calculate last period date pair for col-header. pnl report-dates are stored as a list of time64. consider a regular profit&loss for "quarterly income & expense amounts for last calendar year". dates are 1-jan to 31-dec. the report-dates are '(1-jan 1-apr 1-jul 1-oct 31-dec). the inc/exp accounts balances are queried for the above dates, and the delta change (sans closing entries) constitutes the desired answer. the col-header needs to report "1-jan to 31-mar", which it does by retrieving 2 consecutive dates in the list (1-jan 1-apr), then decrease second date by 1 day to obtain "1-jan to 31-mar" . however this fails for the last period which would return '1-oct to 30-dec'. this commit changes display for last period to return last report-date so that the header is fixed to '1-oct to 31-dec'. this is cosmetic for header dates only, calculations of periodic income/expense amounts were never affected and included entries on the last report-date (e.g. 31-dec as above). --- .../report/standard-reports/balsheet-pnl.scm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm index 2a4d511b4d..76a8782285 100644 --- a/gnucash/report/standard-reports/balsheet-pnl.scm +++ b/gnucash/report/standard-reports/balsheet-pnl.scm @@ -1081,14 +1081,17 @@ also show overall period profit & loss.")) (closing-regexp (get-option pagename-entries optname-closing-regexp)) (include-overall-period? (get-option gnc:pagename-general optname-include-overall-period)) - (col-idx->datepair (lambda (idx) - (if (eq? idx 'overall-period) - (cons (car report-dates) (last report-dates)) - (cons (list-ref report-dates idx) - (gnc:time64-end-day-time - (decdate - (list-ref report-dates (1+ idx)) - DayDelta)))))) + (col-idx->datepair + (lambda (idx) + (cond + ((eq? idx 'overall-period) + (cons (car report-dates) (last report-dates))) + ((= idx (- (length report-dates) 2)) + (cons (list-ref report-dates idx) (last report-dates))) + (else + (cons (list-ref report-dates idx) + (decdate (list-ref report-dates (1+ idx)) DayDelta)))))) + (col-idx->monetarypair (lambda (balancelist idx) (if (eq? idx 'overall-period) (cons (car balancelist) (last balancelist))