diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index f4765ed..55c40b4 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -71,6 +71,7 @@ export default function Dashboard() { const [week, setWeek] = useState(null) const [month, setMonth] = useState(null) const [overBudget, setOverBudget] = useState([]) + const [hasDeptSplit, setHasDeptSplit] = useState(false) const [weekLabel, setWeekLabel] = useState('') const [monthLabel, setMonthLabel] = useState('') const [statsLoading, setStatsLoading] = useState(true) @@ -169,8 +170,11 @@ export default function Dashboard() { const monthNetSalesFull = monthSalesRes.days.reduce((s, d) => s + d.net_sales, 0) // ── Budget-watch: departments forecast to finish the month over their budget share ── + // Only meaningful once a per-department split is actually configured (Settings) — + // otherwise every dept_pcts share is 0/undefined and there's nothing to evaluate. + const deptSplitConfigured = Object.values(monthActRes.dept_pcts).some(pct => pct > 0) const overBudgetList: DeptOverBudget[] = [] - if (monthBudgetFull != null) { + if (monthBudgetFull != null && deptSplitConfigured) { for (const dep of monthDeptRows) { const share = monthActRes.dept_pcts[dep.id] ?? 0 if (share <= 0) continue @@ -203,6 +207,7 @@ export default function Dashboard() { pctSalesForecast: monthNetSalesFull > 0 ? (monthForecast / monthNetSalesFull) * 100 : null, }) setOverBudget(overBudgetList.slice(0, 3)) + setHasDeptSplit(deptSplitConfigured) setWeekLabel(`${fmtDisplay(weekFrom)} – ${fmtDisplay(weekTo)}`) setMonthLabel(new Date(monthFrom + 'T00:00:00').toLocaleDateString('en-GB', { month: 'long', year: 'numeric' })) } catch (e: unknown) { @@ -284,7 +289,7 @@ export default function Dashboard() { {!statsLoading && !statsError && week && renderPeriodGrid(`This Week (${weekLabel})`, 'Actual WTD', 'Forecast Full Week', week)} {!statsLoading && !statsError && month && renderPeriodGrid(`This Month (${monthLabel})`, 'Actual MTD', 'Forecast EOM', month)} - {!statsLoading && !statsError && month?.budgetFull != null && ( + {!statsLoading && !statsError && month?.budgetFull != null && hasDeptSplit && (