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]) => ({