diff --git a/frontend/src/pages/Monthly.tsx b/frontend/src/pages/Monthly.tsx index fed2556..e6b7d64 100644 --- a/frontend/src/pages/Monthly.tsx +++ b/frontend/src/pages/Monthly.tsx @@ -192,7 +192,7 @@ export default function Monthly() {
{isCurrentMonth ? 'Actual MTD' : 'Actual'}
{fmtMoney(totalActual)}
- {pyWages != null &&
PY {fmtMoney(pyWages)}{pyPct(totalActual, pyWages)}
} + {pyWages != null &&
{isCurrentMonth ? 'PY MTD' : 'PY'} {fmtMoney(pyWages)}{pyPct(totalActual, pyWages)}
}
{isCurrentMonth && (
@@ -221,7 +221,7 @@ export default function Monthly() {
{isCurrentMonth ? 'Net Sales MTD' : 'Net Sales'}
{fmtMoney(netSales)}
- {pySales > 0 &&
PY {fmtMoney(pySales)}{pyPct(netSales, pySales)}
} + {pySales > 0 &&
{isCurrentMonth ? 'PY MTD' : 'PY'} {fmtMoney(pySales)}{pyPct(netSales, pySales)}
}
% Net Sales
diff --git a/frontend/src/pages/Weekly.tsx b/frontend/src/pages/Weekly.tsx index 47980a7..0ba1211 100644 --- a/frontend/src/pages/Weekly.tsx +++ b/frontend/src/pages/Weekly.tsx @@ -44,11 +44,15 @@ function pctClass(pct: number | null): string { export default function Weekly() { const [fromStr, setFromStr] = useState(() => mondayOf(new Date())) - const toStr = addDaysStr(fromStr, 6) - const todayStr = localStr(new Date()) - // Prior-year equivalent week (52 weeks back) - const pyFromStr = addDaysStr(fromStr, -364) - const pyToStr = addDaysStr(toStr, -364) + const toStr = addDaysStr(fromStr, 6) + const todayStr = localStr(new Date()) + const isCurrentWeek = fromStr === mondayOf(new Date()) + const pyFromStr = addDaysStr(fromStr, -364) + // For current (partial) week cap PY at equivalent elapsed day — fair WTD comparison + const daysElapsed = isCurrentWeek + ? Math.round((new Date(todayStr + 'T00:00:00').getTime() - new Date(fromStr + 'T00:00:00').getTime()) / 86_400_000) + : 6 + const pyToStr = addDaysStr(fromStr, -364 + daysElapsed) const [depts, setDepts] = useState([]) const [netSales, setNetSales] = useState(0) @@ -74,7 +78,13 @@ export default function Weekly() { setShowOncosts(actRes.show_oncosts) setDeptPcts(actRes.dept_pcts) setNetSales(salesRes.days.reduce((s, d) => s + d.net_sales, 0)) - setPySales(salesRes.days.reduce((s, d) => s + d.py_sales, 0)) + // For current week only sum PY sales for elapsed days (WTD = apples to apples) + const isCurrentWk = fromStr === mondayOf(new Date()) + setPySales( + isCurrentWk + ? salesRes.days.filter(d => d.date <= todayStr).reduce((s, d) => s + d.py_sales, 0) + : salesRes.days.reduce((s, d) => s + d.py_sales, 0) + ) const pyTotal = pyActRes.departments.reduce( (s, dep) => s + Object.values(dep.days).reduce((ds, d) => ds + d.cost, 0), 0 @@ -109,7 +119,6 @@ export default function Weekly() { const prev = () => setFromStr(s => addDaysStr(s, -7)) const next = () => setFromStr(s => addDaysStr(s, 7)) - const isCurrentWeek = fromStr === mondayOf(new Date()) const deptWeekBudget = (deptId: string) => budget != null && monthlyBudg != null && (deptPcts[deptId] ?? 0) > 0 @@ -154,7 +163,7 @@ export default function Weekly() {
Total Wages
{fmtMoney(totalWages)}
{pyWages != null - ?
PY {fmtMoney(pyWages)}{pyPct(totalWages, pyWages)}
+ ?
{isCurrentWeek ? 'PY WTD' : 'PY'} {fmtMoney(pyWages)}{pyPct(totalWages, pyWages)}
:
{showOncosts ? 'incl. on-costs' : 'base cost'}
}
@@ -173,7 +182,7 @@ export default function Weekly() {
Net Sales
{fmtMoney(netSales)}
- {pySales > 0 &&
PY {fmtMoney(pySales)}{pyPct(netSales, pySales)}
} + {pySales > 0 &&
{isCurrentWeek ? 'PY WTD' : 'PY'} {fmtMoney(pySales)}{pyPct(netSales, pySales)}
}
% of Net Sales