From 50e719e1a97633253052d96b8287991b351f0a74 Mon Sep 17 00:00:00 2001 From: Joel Brock Date: Wed, 10 Jun 2026 09:29:42 -0700 Subject: [PATCH] Staff report: fold Y1 Monthly Sales Target row into the M matrix The Y1 Monthly Sales Target fields don't match the Y1_M_ regex the monthly matrix collector uses to discover rows: M1 -> Y1_Monthly_Sales_Targets (no _M1 suffix; trailing 's') M2 -> Y1_Monthly_Sales_Targets_M2 (plural with _M2) M3 -> Y1_Monthly_Sales_Target_M2 (Civi name says _M2 but the value represents M3; pre-existing schema error) M4..M12 -> Y1_Monthly_Sales_Target_M Hardcode a period->civi-field-name map (Y1_MONTHLY_SALES_TARGET_FIELDS) so the monthly matrix can pick these up alongside the regex-matched Y1_M_Actual_Sales / Y1_M_Transactions rows. The M3->_M2 irregularity is called out inline so a future reader doesn't "fix" it into a regression. --- components/StaffReportView.tsx | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/components/StaffReportView.tsx b/components/StaffReportView.tsx index ca9953a..037110c 100644 --- a/components/StaffReportView.tsx +++ b/components/StaffReportView.tsx @@ -553,6 +553,28 @@ interface Y1MatrixData { periodLetter: "Q" | "M"; usedNames: Set; } +/** + * Y1 Monthly Sales Target Civi machine names — irregular. M1 dropped the + * trailing period from "Y1_Monthly_Sales_Targets", M3 lives in a field named + * "_M2" (Civi schema error captured in the original form mapping), and the + * rest follow "Y1_Monthly_Sales_Target_M". Hardcoded here so the staff + * report can fold these into the monthly Y1 matrix. + */ +const Y1_MONTHLY_SALES_TARGET_FIELDS: Record = { + 1: "Y1_Monthly_Sales_Targets", + 2: "Y1_Monthly_Sales_Targets_M2", + 3: "Y1_Monthly_Sales_Target_M2", // intentional: Civi name says M2, value is M3. + 4: "Y1_Monthly_Sales_Target_M4", + 5: "Y1_Monthly_Sales_Target_M5", + 6: "Y1_Monthly_Sales_Target_M6", + 7: "Y1_Monthly_Sales_Target_M7", + 8: "Y1_Monthly_Sales_Target_M8", + 9: "Y1_Monthly_Sales_Target_M9", + 10: "Y1_Monthly_Sales_Target_M10", + 11: "Y1_Monthly_Sales_Target_M11", + 12: "Y1_Monthly_Sales_Target_M12", +}; + function collectY1MatrixByPeriod( filled: StaffReportField[], periodLetter: "Q" | "M", @@ -563,6 +585,7 @@ function collectY1MatrixByPeriod( const byMetric = new Map>(); const periodsSet = new Set(); const metricLabel = new Map(); + const byName = new Map(filled.map((f) => [f.descriptor.name, f])); for (const f of filled) { const m = nameRe.exec(f.descriptor.name); @@ -583,6 +606,24 @@ function collectY1MatrixByPeriod( } } + // Y1 Monthly Sales Target — fold in the irregular fields that don't fit + // the Y1_M_ regex above. Only present in the monthly matrix. + if (periodLetter === "M") { + const byMonth = new Map(); + for (const [periodStr, fieldName] of Object.entries(Y1_MONTHLY_SALES_TARGET_FIELDS)) { + const f = byName.get(fieldName); + if (!f) continue; + const period = Number(periodStr); + byMonth.set(period, f); + used.add(fieldName); + periodsSet.add(period); + } + if (byMonth.size > 0) { + byMetric.set("Sales_Target", byMonth); + metricLabel.set("Sales_Target", "Sales Target"); + } + } + if (byMetric.size === 0) return null; const periods = Array.from(periodsSet).sort((a, b) => a - b); const rows: Y1MatrixRow[] = Array.from(byMetric.entries()).map(([metric, byPeriod]) => ({