feat(reports): sales summary, transaction report and finance exports (#38 slice 1) #109

Merged
amiryahaya merged 13 commits from feat/38-reporting into main 2026-10-27 16:44:44 +01:00
Owner

Slice 1 of #38 (reporting). Issue stays open for slices 2 and 3.

What

  • GET /v1/admin/reports/sales-summary (day/week/month buckets, per-currency totals, per-park net, waived/collected)
  • GET /v1/admin/reports/transactions (keyset paging) and /transactions/export (XLSX)
  • GET /v1/admin/reports/finance/daily-sales/export (XLSX: lines + summary sheet)
  • Platform-scope only (reports.view; finance export needs finance.manage). Read-only RepeatableRead snapshots with statement timeouts, no locks.
  • Stdlib XLSX writer (no new dependency); cells starting with = + - @ TAB CR are quote-prefixed.
  • Migration 0027 (two report indexes); OpenAPI + live contract test; ADR 0022 (time and time zone), ADR 0023 (reporting); CLAUDE.md sections.

Rules worth a look

  • Business day = Africa/Nairobi calendar day, computed in SQL; no zone declared in Go (ADR 0022).
  • A sale counts once at its own grand_total on the day of completed_at; never purchase_price. Per currency, no KES conversion.
  • Line net = quantity * unit_sub_total (checkout stores it after promo). The plan text said minus discount; that was wrong and a test pins it.
  • refund_amount sums refund_due + refunded payments in the sale's currency only.
  • Exports: counted first, 422 over 100,000 rows/lines; 2 concurrent per node, else 503 + Retry-After.

Verification

  • Coverage (make cover): 90.9% total (minimum 80%). make lint 0 issues, make contract ok, go test -race ./... ok.
  • Review: dual-pass (Pass 1 ponytail, Pass 2 correctness) plus per-task reviews; all Must/Important findings fixed, Pass 1 re-check of the fix commit clean.

Owner follow-ups ([verify])

  • Open one export in Excel before go-live (only openpyxl validated the file).
  • Confirm: Monday-start weeks, fiscal period YYYY/0MM (July start), D/C = C for wallet, payment reference = Daraja CheckoutRequestID, hand-written XLSX writer acceptable.
  • Numbers will not match legacy (UTC/EAT mixing, 7.3% fee stripping, KES conversion).
  • Exports hold up to 100k rows in memory (~40 MB). The API server has no WriteTimeout; a reverse proxy may impose one.
  • Not in this slice: daily invoice, QR income, partner report (#51), check-in/ticket activity reports. internal/kenyatime consolidation of six FixedZone copies is a separate follow-up.

🤖 Generated with Claude Code

Slice 1 of #38 (reporting). Issue stays open for slices 2 and 3. ## What - `GET /v1/admin/reports/sales-summary` (day/week/month buckets, per-currency totals, per-park net, waived/collected) - `GET /v1/admin/reports/transactions` (keyset paging) and `/transactions/export` (XLSX) - `GET /v1/admin/reports/finance/daily-sales/export` (XLSX: lines + summary sheet) - Platform-scope only (`reports.view`; finance export needs `finance.manage`). Read-only RepeatableRead snapshots with statement timeouts, no locks. - Stdlib XLSX writer (no new dependency); cells starting with `= + - @ TAB CR` are quote-prefixed. - Migration 0027 (two report indexes); OpenAPI + live contract test; ADR 0022 (time and time zone), ADR 0023 (reporting); CLAUDE.md sections. ## Rules worth a look - Business day = `Africa/Nairobi` calendar day, computed in SQL; no zone declared in Go (ADR 0022). - A sale counts once at its own `grand_total` on the day of `completed_at`; never `purchase_price`. Per currency, no KES conversion. - Line net = `quantity * unit_sub_total` (checkout stores it after promo). The plan text said minus discount; that was wrong and a test pins it. - `refund_amount` sums refund_due + refunded payments in the sale's currency only. - Exports: counted first, 422 over 100,000 rows/lines; 2 concurrent per node, else 503 + Retry-After. ## Verification - Coverage (`make cover`): **90.9%** total (minimum 80%). `make lint` 0 issues, `make contract` ok, `go test -race ./...` ok. - Review: dual-pass (Pass 1 ponytail, Pass 2 correctness) plus per-task reviews; all Must/Important findings fixed, Pass 1 re-check of the fix commit clean. ## Owner follow-ups ([verify]) - Open one export in Excel before go-live (only openpyxl validated the file). - Confirm: Monday-start weeks, fiscal period `YYYY/0MM` (July start), D/C = C for wallet, payment reference = Daraja CheckoutRequestID, hand-written XLSX writer acceptable. - Numbers will not match legacy (UTC/EAT mixing, 7.3% fee stripping, KES conversion). - Exports hold up to 100k rows in memory (~40 MB). The API server has no WriteTimeout; a reverse proxy may impose one. - Not in this slice: daily invoice, QR income, partner report (#51), check-in/ticket activity reports. `internal/kenyatime` consolidation of six FixedZone copies is a separate follow-up. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ParseRange and FiscalPeriod, a read-only snapshot with a statement timeout
(57014 is ErrTooSlow, a cancelled request is not), and the sales summary:
completed sales per Nairobi day/week/month and currency with waived and
collected, and per-park line nets. A line's net is quantity * unit_sub_total:
checkout stores the per-person price after the promo and a per-person
discount, so the plan's "- discount" would subtract it twice.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(reports): review fixes (#38)
All checks were successful
ci / changes (pull_request) Successful in 14s
ci / clients (pull_request) Successful in 1m22s
ci / api (pull_request) Successful in 20m3s
ci / ci-gate (pull_request) Successful in 6s
932dbba447
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!109
No description provided.