From 2c7f347cefcdc1def6c2bb0ad66d68fd26feaa4a Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sat, 22 Feb 2025 23:39:05 +1100 Subject: [PATCH] Allow comparing by calendar month in comparative income statement report --- src/reports/IncomeStatementReport.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/reports/IncomeStatementReport.vue b/src/reports/IncomeStatementReport.vue index d3442cd..7319739 100644 --- a/src/reports/IncomeStatementReport.vue +++ b/src/reports/IncomeStatementReport.vue @@ -124,8 +124,14 @@ thisReportDtStart = dayjs(dtStart.value!).subtract(i, 'year').format('YYYY-MM-DD'); thisReportLabel = dayjs(dt.value!).subtract(i, 'year').format('YYYY'); } else if (compareUnit.value === 'months') { - thisReportDt = dayjs(dt.value!).subtract(i, 'month').format('YYYY-MM-DD'); - thisReportDtStart = dayjs(dtStart.value!).subtract(i, 'month').format('YYYY-MM-DD'); + if (dayjs(dt.value!).add(1, 'day').isSame(dayjs(dt.value!).set('date', 1).add(1, 'month'))) { + // If dt is the end of a calendar month, then fix each prior dt to be the end of the calendar month + thisReportDt = dayjs(dt.value!).subtract(i, 'month').set('date', 1).add(1, 'month').subtract(1, 'day').format('YYYY-MM-DD'); + thisReportDtStart = dayjs(dtStart.value!).subtract(i, 'month').format('YYYY-MM-DD'); + } else { + thisReportDt = dayjs(dt.value!).subtract(i, 'month').format('YYYY-MM-DD'); + thisReportDtStart = dayjs(dtStart.value!).subtract(i, 'month').format('YYYY-MM-DD'); + } thisReportLabel = dayjs(dt.value!).subtract(i, 'month').format('YYYY-MM'); } else { throw new Error('Unexpected compareUnit');