diff --git a/App.tsx b/App.tsx index 7ceec39..7c35423 100644 --- a/App.tsx +++ b/App.tsx @@ -90,7 +90,7 @@ const App: React.FC = () => { console.log('[App] Successfully loaded', data.length, 'rows'); // Refresh forecast too - handleForecastFetch(data); + handleForecastFetch(data, filters.customer); } catch (error) { console.error("Failed to fetch/parse CSV", error); alert("Error loading data. Please refresh the page."); @@ -143,11 +143,14 @@ const App: React.FC = () => { } }, []); - const handleForecastFetch = useCallback(async (sales: SalesRecord[]) => { + const handleForecastFetch = useCallback(async (sales: SalesRecord[], customerFilters: string[] = []) => { try { - console.log('[App] Fetching forecast from /forecast.xlsx...'); - const response = await fetch('/forecast.xlsx'); - if (!response.ok) throw new Error("Forecast file not found"); + const isUK = customerFilters.includes('Amazon UK'); + const filename = isUK ? '/fc UK 26.xlsx' : '/fc 26.xlsx'; + + console.log(`[App] Fetching forecast from ${filename}...`); + const response = await fetch(filename); + if (!response.ok) throw new Error(`Forecast file ${filename} not found`); const buffer = await response.arrayBuffer(); const fcRecords = await processForecastExcel(buffer); @@ -166,10 +169,17 @@ const App: React.FC = () => { setForecastData(viewData); console.log('[App] Forecast loaded:', viewData.length, 'records'); } catch (error) { - console.warn("Forecast fetch failed (expected if local file not set up yet):", error); + console.warn("Forecast fetch failed:", error); } }, []); + // Update forecast when customer filter changes + useEffect(() => { + if (rawData.length > 0) { + handleForecastFetch(rawData, filters.customer); + } + }, [filters.customer, rawData, handleForecastFetch]); + const initializeData = (data: SalesRecord[]) => { setRawData(data); setFilters({ @@ -245,7 +255,7 @@ const App: React.FC = () => { handleTrafficFetch(); // 1d. Fetch Forecast data - handleForecastFetch(cachedData || []); + handleForecastFetch(cachedData || [], filters.customer); }; initApp(); }, [handleDataFetch]); diff --git a/components/ForecastView.tsx b/components/ForecastView.tsx index 250e375..413eba1 100644 --- a/components/ForecastView.tsx +++ b/components/ForecastView.tsx @@ -135,33 +135,33 @@ const ForecastView: React.FC = ({ data, filters, top50Ranking
{/* Summary Cards */} -
-
+
+
-

Total Forecast 2026

-
- {globalSummary.totalForecast.toLocaleString('de-DE')} Units +

Total Forecast 2026

+
+ {globalSummary.totalForecast.toLocaleString('de-DE')} Units
-
+
-

Total Actual Sales 2026

-
- {globalSummary.totalActual.toLocaleString('de-DE')} Units +

Total Actual Sales 2026

+
+ {globalSummary.totalActual.toLocaleString('de-DE')} Units
-
+
-

Global Fulfillment

+

Global Fulfillment

-
= 100 ? 'text-emerald-400' : 'text-indigo-400'}`}> +
= 100 ? 'text-emerald-400' : 'text-indigo-400'}`}> {globalSummary.fulfillment.toFixed(1)}%
{/* Fulfillment Progress Bar */} -
+