Milestone 13: Reporting
Purpose: Agents and admins see basic (and if entitled, advanced) reports; Reports page with date range, charts, and CSV export (advanced).
Exit state: Basic reporting (volume, response time, resolution time, by inbox/assignee); Reports page; advanced reporting (SLA compliance, tag distribution, workload, export) gated by entitlement.
Spec reference: §2.12 Reporting, §6.10 reports page.
Prerequisites: M12. SLA (M11) for SLA metrics; entitlements (M10) for advanced_reports.
13.1 Basic reporting
Tasks
-
Metrics (Section 2.12)
- Tickets created: count per day/week in date range; by tenant.
- Tickets resolved: count resolved/closed per period.
- Open ticket count: snapshot by status (open, in_progress, waiting, resolved, closed).
- First response time: avg(first_response_at - created_at) for tickets with first_response_at; filter by date range (created_at).
- Resolution time: avg(resolved_at - created_at) for resolved tickets in range.
- Tickets by inbox: count group by inbox_id.
- Tickets by assignee: count and resolution rate per assignee.
- tRPC or server procedures: input tenant_id, date_from, date_to; return aggregates. Optional: cache (e.g. 5 min) for heavy dashboards.
-
Reports page layout
- Route /app/[slug]/reports. Section 6.10. Date range picker (presets: 7d, 30d, 90d + custom). Sub-tabs or sections: Overview, By Inbox, By Agent, SLA (advanced), Export (advanced).
-
Overview
- Stat cards: tickets created (period), tickets resolved, open count, avg first response time, avg resolution time. Bar chart: tickets created/resolved per day. Line chart: avg response time over period (optional). Recharts. Section 6.10.
-
By Inbox / By Agent
- Tables or charts: volume per inbox; volume and resolution rate per agent. Filter by date range.
Acceptance criteria
| Criterion | Status |
|---|---|
| Reports page loads; date range applies to all metrics. | Pending |
| Basic metrics match manual count from DB; charts render (Recharts). | Pending |
| All roles can view (Viewer read-only); data tenant-scoped. | Pending |
| Report data refreshes when underlying tickets/messages change (SSE-driven invalidation or refetch so dashboard stays current; Section 4.11). | Pending |
13.2 Advanced reporting (Growth+)
Tasks
-
Entitlement gate
- Check tenant_entitlements for advanced_reports; if not entitled, hide or disable SLA and Export sections and show "Upgrade" prompt. Section 2.12.
-
SLA compliance
- SLA compliance rate: % of tickets (in range) that met first response and resolution targets (compare first_response_at and resolved_at to policy). SLA breach count per inbox or period. Section 2.12. Display in Reports → SLA section.
-
Tag distribution
- Ticket count per tag in date range; chart or table.
-
Agent workload
- Open + resolved count per agent in period; optional avg response time. Section 2.12.
-
CSV export
- Button "Export CSV": generate CSV server-side (stream or buffer) with columns id, subject, status, inbox, assignee, created_at, first_response_at, resolved_at, tags (or tag names). Date range and filters apply. Download as file. Section 2.12. Role: Agent + Admin per spec.
Acceptance criteria
| Criterion | Status |
|---|---|
| With advanced_reports entitlement: SLA section and Export visible; without, gated with upgrade prompt. | Pending |
| SLA compliance and breach counts correct; tag distribution and workload tables correct. | Pending |
| CSV export returns correct columns and rows for selected range; download works. | Pending |
| Export role: Agent and Admin can export; Viewer cannot (or can per product decision). | Pending |
Milestone 13 sign-off
| Criterion | Status |
|---|---|
| All tasks in 13.1–13.2 complete. | Pending |
| All acceptance criteria met. | Pending |
| Basic and advanced reporting functional; export gated by plan. | Pending |
| E2E: Reports page and at least one report render (see INDEX — Testing strategy). | Pending |
| Ready for M14 (Integrations). | Pending |