diff --git a/src/reports/IncomeStatementReport.vue b/src/reports/IncomeStatementReport.vue
index f4bb7a5..d3442cd 100644
--- a/src/reports/IncomeStatementReport.vue
+++ b/src/reports/IncomeStatementReport.vue
@@ -64,8 +64,15 @@
to
Compare
-
- months
+
+
+
+
+
+
@@ -86,7 +93,9 @@
const dt = ref(null as string | null);
const dtStart = ref(null as string | null);
- const compareMonths = ref(1);
+
+ const comparePeriods = ref(1);
+ const compareUnit = ref('years');
async function load() {
const session = await db.load();
@@ -98,7 +107,7 @@
// Update report when dates etc. changed
// We initialise the watcher here only after dt and dtStart are initialised above
- watch([dt, dtStart, compareMonths], async () => {
+ watch([dt, dtStart, comparePeriods, compareUnit], async () => {
const session = await db.load();
await updateReport(session);
});
@@ -107,9 +116,20 @@
async function updateReport(session: ExtendedDatabase) {
const newReportPromises = [];
const newReportLabels = [];
- for (let i = 0; i < compareMonths.value; i++) {
- const thisReportDt = dayjs(dt.value!).subtract(i, 'month').format('YYYY-MM-DD');
- const thisReportDtStart = dayjs(dtStart.value!).subtract(i, 'month').format('YYYY-MM-DD');
+ for (let i = 0; i < comparePeriods.value; i++) {
+ let thisReportDt, thisReportDtStart, thisReportLabel;
+
+ if (compareUnit.value === 'years') {
+ thisReportDt = dayjs(dt.value!).subtract(i, 'year').format('YYYY-MM-DD');
+ 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');
+ thisReportLabel = dayjs(dt.value!).subtract(i, 'month').format('YYYY-MM');
+ } else {
+ throw new Error('Unexpected compareUnit');
+ }
// Generate reports asynchronously
newReportPromises.push((async () => {
@@ -118,7 +138,12 @@
return reportingWorkflow.getReportAtStage(ReportingStage.InterimIncomeStatement, IncomeStatementReport) as IncomeStatementReport;
})());
- newReportLabels.push('$');
+ if (comparePeriods.value === 1) {
+ // If only 1 report, the heading is simply "$"
+ newReportLabels.push(db.metadata.reporting_commodity);
+ } else {
+ newReportLabels.push(thisReportLabel);
+ }
}
reports.value = await Promise.all(newReportPromises);