| 03-operational-modules |
02 |
payments |
| prisma |
| postgresql |
| accounting |
| double-entry |
| collections |
| remittances |
| fifo |
| zone-enforcement |
|
| phase |
provides |
| 02-subscriber-and-billing-core |
Invoice model, AR account (1100), JournalEntryService, PaymentService FIFO pattern |
|
| phase |
provides |
| 03-01 |
Zone model, ZoneAssignment, getCollectorSubscribers zone scoping pattern |
|
|
| Collection model with FIFO invoice allocation and zone enforcement |
| CollectionAllocation model linking collections to invoices |
| Remittance model with two-party verification and variance tracking |
| Account 1030 Cash in Transit in ISP COA |
| CollectorService |
| recordCollection, voidCollection, getCollectionHistory |
|
| RemittanceService |
| createRemittance, verifyRemittance, listRemittances |
|
| CollectionReportService |
| getDailyCollectionSummary, getCollectorCollectionDetail |
|
| 6 API routes for collections, remittances, and collection reports |
| 26 integration tests (13 collector + 13 remittance) |
|
| 03-04 (inventory or financial reporting phases that use collection totals) |
| 03-05 (any future financial dashboard reading 1030/1010 account balances) |
| Phase 5 reporting (collection→remittance chain feeds cash flow reports) |
|
| added |
patterns |
|
|
| Two-phase cash tracking: 1030 (collector holds) → 1010 (office receives) |
| FIFO collection allocation: same pattern as PaymentService but DR 1030 (not 1010) |
| Variance-tolerant verification: non-blocking discrepancy recording |
| Zone enforcement throws on violation: same security boundary pattern as 03-01 |
|
|
| created |
modified |
| prisma/migrations/20260304234448_add_collections_remittances/migration.sql |
| src/lib/services/collector-service.ts |
| src/lib/services/remittance-service.ts |
| src/lib/services/collection-report-service.ts |
| src/app/api/collections/route.ts |
| src/app/api/collections/[id]/route.ts |
| src/app/api/collections/[id]/void/route.ts |
| src/app/api/remittances/route.ts |
| src/app/api/remittances/[id]/verify/route.ts |
| src/app/api/reports/collections/route.ts |
| src/lib/__tests__/collector-service.test.ts |
| src/lib/__tests__/remittance-service.test.ts |
|
| prisma/schema.prisma |
| src/lib/prisma-tenant.ts |
| src/lib/accounting/chart-of-accounts.ts |
|
|
| Collection JE uses 1030 Cash in Transit (not 1010 Cash on Hand) — cash is in collector's hands, not yet at office |
| Remittance verification JE: DR 1010 verifiedTotal, CR 1030 verifiedTotal — JE balanced using verifiedTotal on both sides; variance recorded on remittance record only (not in ledger) |
| Variance is non-blocking by design — any discrepancy is an audit record, not a system blocker |
| Collector balances derived from transactions — no stored balance field on collector or remittance |
| Zone enforcement throws (not empty return) on violation — matches 03-01 security boundary decision |
| Collection cleanup order: collectionAllocations → collections → invoiceLines → invoices → journalEntryLines → null reversesEntryId → journalEntries → zoneAssignments → subscribers → zones → servicePlans → accountingPeriods → accounts → users → tenant |
| withPermission HOF used for API routes (same pattern as ticket/zone routes — no direct getServerSession) |
|
| Cash flow chain: Subscriber pays Collector (1030 DR/1100 CR) → Collector remits to office (1010 DR/1030 CR) |
| Two-party verification: collector declares total (PENDING), office verifies with counted total (VERIFIED) |
| FIFO allocation for collections mirrors PaymentService FIFO — same pattern, different debit account |
|
11min |
2026-03-05 |