feat(reports): prior-period comparison toggle on the Sales report

Adds a "Compare to prior period" toggle to the Sales report header.
When on, the API recomputes the KPI window for the equal-length window
immediately preceding the selected range (previousPeriodBounds) behind
`?compare=1`, and the five window-derived KPI tiles (Won, Lost, Win
rate, Avg time-to-close, New leads) render colour-correct "vs prior"
deltas. Point-in-time tiles (Active interests, Pipeline value) have no
prior-window analogue and intentionally show no delta. The prior-window
query runs in parallel with the main batch and resolves to null when the
toggle is off (zero cost). Toggle state persists in the saved-template
config.

Closes the spec's "period comparison on every report" gap for Sales;
Operational already rendered period-start deltas.

Pure helpers TDD'd: previousPeriodBounds (range.ts) +
computeSalesKpiComparison (sales-comparison.ts), 7 unit tests. tsc +
lint clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 18:49:35 +02:00
parent 172af02f81
commit 681b94a8ef
7 changed files with 333 additions and 9 deletions

View File

@@ -77,8 +77,20 @@ everything else is post-launch polish unless promoted.
#### Cross-cutting capabilities (apply to every report)
- **Period comparison toggle** — "this period vs prior period" delta
arrows on KPI cards. Spec calls for it on every report. Not on any.
- ⚠️ **Period comparison toggle** — "this period vs prior period" delta
arrows on KPI cards. **Sales: SHIPPED locally (2026-05-31)** — a
"Compare to prior period" toggle in the header computes an
equal-length preceding window (`previousPeriodBounds`), the API
recomputes KPIs for that window behind `?compare=1`, and the five
window-derived tiles (Won, Lost, Win rate, Avg time-to-close, New
leads) render colour-correct "vs prior" deltas. Point-in-time tiles
(Active interests, Pipeline value) intentionally have no delta.
Persisted in the saved-template config. TDD'd:
`previousPeriodBounds` + `computeSalesKpiComparison` unit tests.
Operational already rendered period-start deltas. **Still open:** the
spec's "on every report" — Operational uses a different
"vs period start" baseline; reconcile the two semantics if a single
consistent comparison is wanted.
-**Rep multi-select filter** — exists implicitly via the single-rep
leaderboard collapse, but no explicit multi-select dropdown.
-**Source multi-select filter** — Sales has lead-category + outcome