From 49decf9b9fa2ac1a82ce501d52aa1e466439e7fa Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Wed, 28 Jan 2026 09:11:13 +0100 Subject: [PATCH] Fix: Corrected ForecastView data structure and missing aggregated properties --- services/dataProcessor.ts | 28 ++++++++++++++++++++++------ types.ts | 5 ++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/services/dataProcessor.ts b/services/dataProcessor.ts index dfaf31c..4739520 100644 --- a/services/dataProcessor.ts +++ b/services/dataProcessor.ts @@ -1656,23 +1656,39 @@ export const calculateForecastViewData = ( } } - // 3. Build monthly points - const monthlyData: MonthlyForecastPoint[] = MONTH_ORDER.map((m, idx) => { + // 3. Build monthly points and aggregate + const monthlyData: Record = {}; + let totalActualUnits = 0; + let totalForecastUnits = 0; + + MONTH_ORDER.forEach((m, idx) => { const forecastUnits = Math.round(fc.annualForecast * productWeights[idx]); const actualUnits = actuals2026.get(identifier)?.get(m) || 0; - return { + + monthlyData[m] = { month: m, forecastUnits, - actualUnits - }; + actualUnits, + units: actualUnits // Added for chart compatibility + } as any; + + totalActualUnits += actualUnits; + totalForecastUnits += forecastUnits; }); + const accuracy = totalForecastUnits > 0 + ? Math.min(100, Math.round((1 - Math.abs(totalActualUnits - totalForecastUnits) / totalForecastUnits) * 100)) + : 0; + return { asin: identifier, sku: meta?.sku || fc.sku || identifier, title: meta?.title || fc.title || identifier, - line: meta?.line || fc.line || "", + line: meta?.line || fc.line || "Unassigned", annualForecast: fc.annualForecast, + actualUnits: totalActualUnits, + forecastUnits: totalForecastUnits, + accuracy: Math.max(0, accuracy), monthlyData }; }); diff --git a/types.ts b/types.ts index 5910894..2b76f8d 100644 --- a/types.ts +++ b/types.ts @@ -216,5 +216,8 @@ export interface ProductForecastData { title: string; line: string; annualForecast: number; - monthlyData: MonthlyForecastPoint[]; + actualUnits: number; + forecastUnits: number; + accuracy: number; + monthlyData: Record; }