feat(reports): Purchasing spend analytics (Cost Centres + Accounting Codes) #117
No reviewers
Labels
No labels
bug
claude-failed
claude-pr
claude-queue
claude-working
epic
feature
interactive
portal
triaged
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: shad0w/pelagia-portal#117
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/reports"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements the wiki Reports Mockup as a Reports → Purchasing sidebar section, wired to real approved-PO spend.
What's included
Two report families, each an index → drill/detail pair:
/reports/cost-centres) — approved spend compared across vessels (the PO cost centre). A row opens/reports/cost-centres/[id]: KPIs, spend trend, and a Top accounting codes breakdown re-pivotable by tier (Heading / Sub-heading / Leaf) and Top-N./reports/accounting-codes) — drills theAccounttree (headings → sub-headings → leaves) via?parent=. A leaf opens/reports/accounting-codes/[id]: trend + breakdown by cost centre (or, for a non-leaf, by sub-account).Shared filter toolbar (Granularity Monthly/Yearly · Financial Year · Show Top 5/Top 10/Bottom 5/All) — values live in the URL query so the server component re-renders (no client fetching; views are shareable). KPI tiles, recharts comparison/trend/breakdown charts, per-row trend sparklines, and CSV export (
/api/reports/spend).How it works
lib/reports.ts— the pure, unit-tested aggregation core. Spend = a PO once it reachesPOST_APPROVAL_STATUSES, dated byapprovedAt, valued attotalAmount(the dashboard's basis). Indian Apr–Mar FY; each PO's leafaccountIdrolled up to parents. One query ingetReportDataset(); everything else is pure functions.Sectionmodel). Gated byview_analytics(Manager / SuperUser / Auditor / Admin); export by the same.Scope / deferred
Documented in the mockup: synthetic Weekly granularity, the "Add to graph" custom multi-select comparison, and line-item-level account allocation (v1 attributes a PO's whole amount to its PO-level accounting code). Sites are not cost centres — only vessels.
Verification
pnpm test303 passed;tsc --noEmitclean.view_analyticsrole gets 307 → /dashboard (page) and 403 (export).Wiki
/reports/*routes + the Reports section.🤖 Generated with Claude Code