feat(finance): penalties & interest on arrears (#95)#99
Merged
Conversation
Simple (non-compound), opt-in, waivable interest on overdue dues. - computeInterest / sumApartmentInterest (shared): simple interest from due date + grace to as-of, at a configured annual rate. Rate always from config, never hardcoded (Bye-law 71 cap). - bill_config gains interest_enabled / interest_rate_pct / grace_period_days (migration 0022) + Zod + PUT wiring. - API: GET /bills/interest-preview (per-flat accrued, not charged), POST /bills/apply-interest (charges one-time interest bills per flat, mapped to Interest on Arrears Income, idempotent per period, posts to GL), and POST /bills/:id/cancel (waive with reason → status CANCELLED + §6.9 reversing ledger entry). Interest is excluded from its own base so it never compounds. - Ledger: JournalDraft carries reversal metadata; safeReverseBill posts the swapped-legs ADJUSTMENT for a cancelled bill. - Tests: computeInterest/grace/pro-rata units + interest route tests (auth, disabled-config, empty preview). Suite 333 green; web typechecks. Editable interest controls in the bill-config UI come with the consolidated M3.5 admin-UI pass; values are preserved on save meanwhile.
ankitsejwal
added a commit
that referenced
this pull request
Jul 16, 2026
The most-demanded treasurer feature: financial reports the society's CA can
consume. Dependency-free and Cloudflare-Workers-safe.
- lib/xlsx.ts: a from-scratch .xlsx writer — real OOXML SpreadsheetML zipped
with STORED entries + a hand-rolled CRC32, so no Node-only zip/xlsx lib is
needed on Workers. Validated with `unzip -t` (CRC OK) and openpyxl-shaped
structure.
- shared/export.ts (pure): report -> table (rows in rupees) for trial balance,
I&E, balance sheet, R&P, and dues; a CSV serializer; and a Tally-import XML
builder (ledger masters + vouchers, debit negative / credit positive).
- API: ?format=xlsx|csv on /reports/{trial-balance,income-expenditure,
balance-sheet,receipts-payments} and /bills/dues; GET /reports/tally-export
streams Tally XML (PAYMENT->Receipt, EXPENSE->Payment, else Journal).
- Tests: xlsx zip structure + inline-string/number/escaping, CSV escaping,
Tally envelope/signing/masters, table shaping. Suite 359 green.
Print-ready statement PDFs + the invoice ₹-glyph fix are the next export PR.
ankitsejwal
added a commit
that referenced
this pull request
Jul 16, 2026
- lib/statements-pdf.ts: a paginated A4 table renderer (pdf-lib) that turns any
report Table into a print-ready PDF — first column left-aligned, numeric
columns right-aligned, bold header rule. WinAnsi can't encode ₹ so amounts
render "Rs" (same limitation as the invoice PDF; documented).
- ?format=pdf on /reports/{trial-balance,income-expenditure,balance-sheet,
receipts-payments} alongside xlsx|csv.
- Smoke-tested: valid %PDF, reloads in pdf-lib; route tests assert the pdf/csv
content-types. Suite 361 green.
Completes #99 acceptance (3): Balance Sheet / I&E / R&P as print-ready PDF.
The invoice ₹-glyph fix needs a bundled Unicode TTF (fontkit) — left as a known
limitation, not attempted here.
ankitsejwal
added a commit
that referenced
this pull request
Jul 16, 2026
Surfaces the M3.5 accounting backend in the admin app (extends existing pages — no new routes). - admin/index.tsx: finance tiles — outstanding dues, collection rate, cash+bank. - admin/reports.tsx: statutory statements (Balance Sheet, I&E with mutual/ taxable split, Receipts & Payments, Trial Balance with balanced badges) each with PDF/Excel/CSV export buttons + a Tally XML export; and an aging section (0-30/31-60/61-90/90+ buckets + per-flat breakdown). - api.ts: getTrialBalance/getIncomeExpenditure/getBalanceSheet/ getReceiptsPayments/getAging + reportExportObjectUrl (auth-fetch downloads). - i18n: ~33 new keys (en + hi, parity test green). - Validated: web check-types, vite build, lint (0 errors), web tests 27 green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
M3.5 · Task #95 — Interest on arrears (backend)
Automates what treasurers do by hand in Excel: simple, opt-in, waivable interest on overdue maintenance dues.
Domain (shared, unit-tested)
computeInterest(outstanding, dueDateMs, asOfMs, ratePct, graceDays)— simple interest from due date + grace to as-of. Zero inside grace / for a cleared balance / when the rate is off.sumApartmentInterest(...)across a flat's overdue bills.Config (migration 0022)
bill_configgainsinterest_enabled(default off),interest_rate_pct(18),grace_period_days(15) + Zod + PUT wiring.API
GET /bills/interest-preview?asOf=— per-flat accrued interest (preview, not charged).POST /bills/apply-interest?asOf=— charges a one-time interest bill per flat (mapped to Interest on Arrears Income), idempotent per period, posts to the GL. Interest bills are excluded from the base → never compounds.POST /bills/:id/cancel— waive with a reason: setsCANCELLEDand posts a §6.9 reversing ledger entry (swapped legs,is_reversal).Acceptance
Tests / notes
computeInterest (grace, pro-rata, full-year) + interest route tests (auth, disabled-config, empty preview). Suite 333 green, web typechecks. The editable interest controls in the bill-config editor come with the M3.5 admin-UI pass (values preserved on save meanwhile). Migration 0022 committed, not applied here.