Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 3, 20:45 UTC
source-data-cleanup
ADR-022 — Reviewable statement outputs (Phase 6)
- Status: Accepted (Phase 6)
- Date: 2026-12-03
- Booklet: §15 Phase 6 (reviewable output), D2/D3 (drill-down lineage)
Context
Phases 1–5 persist audited, versioned statements (BS/IS/CF/EQ) with exact integer-rial totals and a live drill-down chain to the source file/sheet/row, and provide an RTL workbench to build and inspect them. The product still needs a portable, independently reviewable artifact: an output a reviewer can open without the application and audit rial-for-rial against the source and the official statements.
Decision
services/statement_export.py produces two artifacts from the latest statement
version per type for a year:
- XLSX workbook (
export_statements_workbook):Summary: year, company, status, generation timestamp, per-statement version, lineage row count.- One sheet per statement (
BS/IS/CF/EQ): ordered lines with the exactmapped_total_rial(text, never rounded) and amapped_total_milliondisplay column (half-up, ADR-012) for readability only. - One sheet per evaluated note (
Note {number}): row order, label, formula, exactvalue_rial, and referenced accounts. Lineage: every statement line traced to account, effective balance, source filename, SHA-256, sheet and row (D2/D3).- Sheets are RTL (
rightToLeft, reading order 2) with frozen header rows.
- Structured JSON (
export_statements_json/_bytes): the same payload for machine review and diffing; all money is exact integer-rial strings (no float/Decimal leakage).
API: GET /api/v1/years/{id}/statements/export?format=xlsx|json streams the
artifact as an attachment. The workbench exposes both as download buttons.
Consequences
- The exact rial is always preserved; the million-rial column is display-only and never replaces it (P-02, ADR-012).
- Every output figure is independently traceable to its source row (D2/D3).
- No new dependency: openpyxl is already required (ADR-017). PDF output is deliberately deferred — it would need a new rendering dependency and a separate ADR; XLSX + JSON already satisfy reviewable, auditable output.
- Export reads the latest persisted version; it never mutates statements or source data and works on Approved/Locked years (read-only).
Rejected alternatives
- Rendering PDF directly: adds a dependency (reportlab/weasyprint) without a present need; XLSX matches the official workbook format reviewers already use.
- Exporting rounded million-rial as the primary figure: violates exact-rial preservation (P-02); rounding is display-only.
- Recomputing totals at export time: would diverge from the persisted, audited statement version; export must reflect the system of record exactly.