Skip to content

feat(finance): penalties & interest on arrears (#95)#99

Merged
ankitsejwal merged 1 commit into
mainfrom
feat/m3.5-interest
Jul 16, 2026
Merged

feat(finance): penalties & interest on arrears (#95)#99
ankitsejwal merged 1 commit into
mainfrom
feat/m3.5-interest

Conversation

@ankitsejwal

Copy link
Copy Markdown
Member

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.
  • Rate is always supplied by config, never hardcoded (Bye-law 71 cap — ≤21% legacy / ~12% revised MH).

Config (migration 0022)

bill_config gains interest_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: sets CANCELLED and posts a §6.9 reversing ledger entry (swapped legs, is_reversal).

Acceptance

  • ✅ Admin sets rate + grace; overdue bills accrue simple interest from due date after grace.
  • ✅ Interest is a distinct charge (its own bill line), waivable per flat with a reason.
  • ✅ Rate configurable, defaults sane, never hardcoded.

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.

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
ankitsejwal merged commit 4620240 into main Jul 16, 2026
1 check passed
@ankitsejwal
ankitsejwal deleted the feat/m3.5-interest branch July 16, 2026 11:13
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant