01Every counter has to reconcile with the books
- Problem
- OPD fees, admission fees, lab and radiology orders, pharmacy sales, IPD deposits, refunds and purchases were each collected in their own module, and the accountant needed a day book, trial balance and P&L they could trust.
- Approach
- One posting path for every module: it builds the voucher with Decimal arithmetic, rejects negative lines and refuses to save unless debits equal credits, against a chart of accounts with fixed ledger codes. The voucher table has a nullable unique foreign key per source document, so idempotency lives in the database.
- Why it was hard
- Every module had to move onto the same path without breaking live behaviour, a retried request must never post twice, and rounding on a multi-line reversal can leave a voucher a fraction out of balance.
- Result
- Each collection posts debit cash or bank and credit the right revenue or receivable ledger, a duplicate posting fails on a unique constraint, reversal lines are rounded to the paisa so they always balance, and the reports read straight from posted entries.



