Two bugs inflating the rota variance figures in AI insights:
1. Actual cost (incl. NI oncosts) was compared against rota cost that
silently falls back to base pay — Workforce's schedules API never
actually supplies oncosts (confirmed: published_total_cost equals
published_base_cost on every synced row), so every variance was
inflated by ~14-20% for reasons unrelated to real overspend. Now
always compares base cost on both sides, with a note in the prompt
that this is a base-pay-only comparison.
2. Variance was summed over the full window using actual cost, but
only over covered days using rota cost, understating rota further
whenever coverage was incomplete. Now restricts the actual-cost side
to the same days rota data exists for, and reports coverage (days
w/ rota vs total) explicitly so partial coverage isn't presented as
a confirmed figure.
Also: the employee anomalies section only had department_id (a raw
Workforce code), not department_name, since wage_actuals_detail doesn't
store it — resolved via wage_actuals so the model can say "Chef"
instead of guessing from a numeric code.
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>
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>