Dashboard's week/month tiles were only computed on initial load; the 5-minute
timer refreshed the AI insight but not the tiles, so an installed PWA left
open would keep showing stale forecast numbers indefinitely. Monthly's forecast
had no refresh at all. Both now recompute every 5 minutes while viewing the
current month.
iOS Safari has no beforeinstallprompt API, so the portal's Install
button (?install=1) silently did nothing there. IosInstallHint now
shows Share -> Add to Home Screen steps on Safari, or a prompt to
switch to Safari first if opened in another iOS browser/in-app
webview (those can't install PWAs on iOS at all).
Also added apple-mobile-web-app-title + apple-touch-icon so the
home screen icon isn't a page screenshot, and added the
beforeinstallprompt handler that was missing entirely (Android
Install button did nothing either).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The "Prev wk" figure shown under Forecast Full Week was reusing
prevCost, which is deliberately scoped to "same elapsed days as WTD"
(e.g. only Mon-Wed of last week if today's Wednesday) — correct for
the per-department table's WTD-vs-WTD "vs Prev Wk" column, but wrong
paired with totalForecast, which projects a full 7 days. Comparing a
full-week projection against a few days of last week made prev week
look artificially low and the delta look inflated.
Added prevFullCost (full Mon-Sun of the prior week — already present
in the 14-day actuals fetch) for the full-week comparison specifically;
left prevCost/totalPrev untouched for the table's WTD comparisons.
Monthly.tsx and Dashboard.tsx only ever fetched actuals for the current
period (month-start..month-end, or a 7-day lookback for the week view),
but forecastDayCost's same-weekday fallback hops back up to 42 days
looking for a match. For any early-period date whose hop landed before
the fetch window started, that data was never in memory at all — it
silently fell through to the 'none' tier (£0) once published rota ran
out, rather than finding a real historical match.
ai-insights.js's gatherForecastData already fetched a proper 42-day
lookback; these two pages didn't. Widened both fetches to match, with
explicit >= period-start filters on the actual-sum calculations so the
extra history is only ever used by the hop fallback, never counted
twice into "actual".
wage_actuals rows for the current day exist with real shift_count but
£0 cost until Workforce finishes costing the shift (clock-out/approval
pending). forecastDayCost was treating that as a legitimate zero-cost
actual, both zeroing today's own forecast contribution and poisoning
every future date whose 7-day hop-back chain lands on today — e.g.
every remaining same-weekday this month resolved straight to £0
instead of falling through to published rota or older actuals.
Manifest referenced icon-192.png/icon-512.png but the icons directory
didn't exist, so Chrome failed installability and only offered a
home-screen shortcut instead of a full installable PWA.
Previously showed a false "all departments within budget" message even
when Settings has no per-department split defined, since every share
was 0/undefined and nothing was actually being evaluated.
Dashboard now shows Actual/Forecast, % vs budget, and % net sales for both
the current week and current month, plus a budget-watch callout listing any
departments forecast to finish the month over their budget share.
Split the system prompt into an editable part (persona/focus/tone/
format — what the briefing prioritises and how strict its length is)
and a fixed structural appendix (how the Manual Context and Recent
Previous Insights sections get interpreted, which map directly to
conditional data the code assembles, not just prose — kept safe from
being accidentally edited away).
New ai_insights_prompt_instructions config key, a
GET /api/ai-insights/default-prompt endpoint so the Settings UI can
pre-fill/reset to the built-in default, and a textarea in the AI
Insights settings card.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Now that the sync uses /api/v2/rosters/on/{date} (2026-07-25) instead
of /api/v2/schedules, real employer-oncost figures are available for
rota data, so gatherRotaVsActualData() no longer needs the base-cost-
only workaround — it respects show_oncosts like the rest of the app
again. Also removes the now-inaccurate Monthly.tsx footnote claiming
rota-based forecasts exclude NI, and the now-obsolete methodology note
that told the model to expect a swing from the base-cost fix (moot —
insight history is being cleared, so there's nothing to compare
against).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Free-text setting fed directly into every briefing's prompt as ground
truth (e.g. "Joseph Trice-Rolph is on a flexi rota, has no fixed rota
shifts — account for that in overspend"), so known context the data
itself can't show doesn't get flagged as an anomaly. New
ai_insights_manual_context config key, a textarea in Settings, and a
top-of-prompt section in the job with an explicit instruction to treat
it as ground truth.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Dashboard now shows a collapsible history of past AI insights (reusing
the existing /history endpoint), and generation now includes the last
3 insights in the prompt so the model can reference what it already
said instead of repeating the same points every day.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
runRollingSync only ever syncs wage_scheduled 14 days forward, so the AI
insight's 28-day rota-vs-actual comparison had no historical rota to compare
against for a freshly-scaffolded app. Adds a dedicated backfill action that
pulls past schedules via the same throttled weekly-batch pattern as the
existing actuals backfill.
AI Insights: a daily Claude-generated wage cost briefing covering
month-to-date pace vs budget, prior-month/prior-year comparison,
rota-vs-actual variance by department, a rota-informed forecast to
month-end, employee-level anomalies, and wage cost as a % of revenue.
Runs on a configurable daily schedule or on demand, gated by a manual
5-minute rate limit and a daily token budget. Uses the Anthropic key
configured centrally in Portal → Settings → Integrations.
Also includes the rota-vs-repeat-pattern forecast method (published/
draft rota tiers with same-weekday fallback) already built into the
Weekly/Monthly views, and adds a .gitignore for node_modules/dist.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Same fix as maintenance/reports/room-planner: manifest scope was the
app's own base path instead of "/", and AuthGate unconditionally
hard-navigated window.top to the central /login on session expiry
even when not embedded in the portal iframe — together these dropped
an installed/standalone wages PWA into the portal's framed browser
view instead of staying in its own window.
AuthGate now only bounces to central login when actually embedded
(passing ?from= so it returns here afterwards); standalone or
directly-opened tabs get an in-app login form and never navigate
away. Also wired up the previously-dead inactivity auto-logout timer.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sidebar was missing the account info + sign-out control that every
other app's sidebar has; it showed a static hotel-name label instead.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Legend was sorted to mirror bar stack order, making it hard to tell
segments apart at a glance; reverse it. Tooltip also rendered behind
the legend div when they overlapped — raise its z-index above it.
Rolling12Months: current month's budget wasn't prorated at all, so
%Budget compared MTD actual against the FULL monthly budget — always
looked artificially favorable. Now prorates by elapsed PY DOW-matched
sales share (flat day-count fallback), reusing already-fetched data.
Rolling12Weeks: budget was prorated, but the elapsed-day count mixed a
real timestamp with Math.ceil(...)+1, always overstating elapsed days
by one and inflating the budget denominator. Rewrote to sum per-day
budgets by date string (no fractional-time bug), and applied the same
PY DOW-weighting as the Weekly page, sourcing each day from its own
calendar month so weeks spanning a month boundary split correctly.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Distributes the monthly wage budget across days proportionally to each
day's share of last year's same-day-of-week sales, so pacing on Weekly/
Monthly views reflects real demand shape (e.g. weekend-heavy) rather than
an even calendar split. Falls back to the old flat day-count split when
PY sales data is unavailable. Weekly also now sources each day's budget
from its own calendar month, so weeks spanning a month boundary split
correctly across both months' budgets.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The forecasting API's total.otb is booked-to-date only; total.forecast adds
expected pickup and equals otb for past dates anyway. Using otb-only for
future days understated expected net sales in the current-week/month
forecast sections. Relabelled "(OTB)" cards to "(Forecast)" to match.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both views already showed % Net Sales with a PY % sub-line, but lacked a
raw-£ Net Sales card with PY value + delta% — the style already used for
past weeks/months. Adds it consistently across current-period, forecast,
and past-period sections in both views.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes an edge case where days more than 7 days past the actual cutoff had no
valid prior-week source day (itself a forecast day), silently contributing
£0. Now walks back in 7-day steps until landing on an actual day, so the
last complete actual week tiles forward for the rest of the month.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Monthly: fetches previous month actuals; adds % delta vs prior month full
alongside existing vs PY column in the dept breakdown table.
Weekly: expanded 14-day actuals fetch (prev+current week) so prior-week
per-dept data is available for both forecast and comparison. Two-row summary
cards for current week (WTD actuals + full-week forecast). Past weeks keep
single-row layout. Dept table gains vs PY and vs Prev Wk delta columns;
budget columns use WTD pro-rata for current week, 7-day proportion for past.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Shows (actual_mtd - PY_MTD) / PY_MTD for current month rows,
(actual - PY_full) / PY_full for past months. Red if wages up vs PY,
green if down. Total row uses same basis. Matches department by ID
against pyDepts so departments with no PY data show —.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both Weekly and Monthly now cut off actuals at yesterday (not today) to avoid
partial clockins and open timesheets skewing the WTD/MTD figures and % net sales.
PY comparison periods also cap at the equivalent yesterday for fair comparison.
Monthly rota forecast removed — all future days use prior-week same-day actuals
from yesterday back, which is more reliable than partially-published future rotas.
Monthly summary cards split into two rows for current month:
Row 1 (MTD to yesterday): Actual MTD · Budget pro-rata · % Budget MTD · % Net Sales MTD
Row 2 (Full month): Forecast EOM · Monthly Budget · % Budget (Forecast) · % Net Sales (OTB)
Net sales fetched for full month so row 2 % net sales uses OTB forecast revenue.
Past months show one row (full month actuals only).
Weekly: budget pro-rata now counts days Monday to yesterday for current week;
dept totals filtered to yesterday for current week.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rota forecasting: only trust Workforce rota for the current Mon–Sun week —
beyond that use prior-week actuals to avoid incomplete next-week rotas
deflating the EOM forecast.
% vs Budget cards (Weekly + Monthly): show as coloured headline number
(green/amber/red) instead of small pct-badge chip, matching other cards.
Forecast EOM: PY sub-label shows full prior-year month total + % delta,
replacing the static "rota + prior-week actual" note once PY data exists.
Achieves this by fetching the full PY month rather than MTD-capped range,
then deriving both MTD (for Actual MTD card) and full-month (for EOM card).
Backfill depth: 13 → 25 months so past months in Rolling 12 have PY wage
data available (viewing Dec 2024 needs Dec 2023 = 19 months ago).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Hide sidebar on mobile (≤640px), show fixed bottom nav bar instead
- Cards get overflow-x: auto so wide tables scroll horizontally
- Summary grid forces 2-column on mobile
- Reduce content padding to 12px, clear 68px for bottom nav
- Summary card values shrink to 18px on mobile
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Stores per-employee shift costs in wage_actuals_detail (APPROVED shifts
only). Sync fetches employee name map from /api/v2/users alongside dept
names. Clicking any dept row in Weekly or Monthly opens a modal showing
Employee · Shifts · Cost · % of Dept, fetched on demand.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Stores full PY department breakdown from already-fetched pyActRes.
A toggle button (collapsed by default) expands an inline table showing
PY wages per dept, % of PY total, and % of PY net sales. Label adapts
to PY WTD / PY MTD for current partial periods.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Shows prior year equivalent % (wages/net sales) as a sub-label under the
current period value — labelled PY WTD/MTD for current partial periods,
PY for complete past periods.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Weekly: cap pyToStr at elapsed days (not full Mon-Sun), and filter
py_sales to past days only — both give WTD vs WTD. Labels show
'PY WTD' for current week, 'PY' for complete past weeks.
Monthly: pyToStr already capped at same day-of-month; salesTo already
capped at today. Labels now show 'PY MTD' for current month, 'PY' for
complete past months.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Show PY value + % change as a subtitle line under the period card,
same pattern as the original PY sales sub-label.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Weekly/Monthly: PY Wages summary card (fetches equivalent week/month last year)
- Weekly/Monthly: PY Net Sales as its own card (was a sub-label, now prominent)
- Weekly/Monthly: dept table gains '% of Total' column
- Monthly: PY comparison caps at same day-of-month for fair PYTD comparison
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
toISOString() returns UTC — in BST (UTC+1) dates computed from new Date()
land one day early. Replace with local date components via fmt()/localStr().
Affects Weekly, Monthly, Rolling12Weeks, Rolling12Months.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Full wage cost reporting app — weekly/monthly views, rolling 12-week/12-month
history, budget management, Workforce API sync with SSE backfill, net sales
via forecasting public API, department filter, CSV export.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>