ADR-0005: One payout spine for every source of money
Status
Accepted. The tables are in 51-settlement.prisma, 53-receivable.prisma, 54-reconciliation-ops.prisma and 56-journal.prisma, created by migration 20261004120000_settlement_money_spine on a reset database.
Context
Marketplace settlements, courier COD remittances and gateway payouts each had their own header, line, bank allocation and journal tables. Every cross-source feature (bank matching, the dashboard, ERP push, the exception queue) had to know three shapes, and a bank allocation had three nullable foreign keys. Reconciliation rows existed only for marketplace order lines, keyed by order item, so COD and gateway money had no "owed vs paid" record, and orders shipped outside PointNXT (Easy Ship from Seller Central, FBA) or paid for orders PointNXT never imported had nowhere to go. Settlement lines were updated in place when an order was linked, which lost what the partner originally reported.
Decision
- One
Payoutper partner transfer, withsource(MARKETPLACE,COURIER_COD,PAYMENT_GATEWAY) and exactly one partner id. Source-specific figures live in one-to-one detail tables. PayoutLineis insert-only (trigger enforced) and partitioned byvalueDate. Corrections are new lines that supersede old ones byidentityKey. The interpretation (which order, which category) is a separatePayoutLineResolution.Receivablerecords what a payer owes for an order line, a COD shipment, a gateway-paid order, an FBA loss, or a payout line with no order, andReceivableMatchrecords which lines paid it. Recognition is driven by PointNXT'sOrder.orderStatus, never the channel's raw status.- Bank credits are allocated to payouts (
BankAllocation.payoutId), whatever their source. - Journals are
JournalVoucher/JournalLineagainst a per-tenantLedgerAccountchart. Posted vouchers are reversed, never edited; ERP sync is one log row per voucher per system.
Alternatives
Keeping the three per-source models and adding a union view for cross-source screens. Not recorded beyond the proposal; the database reset made the breaking change cheap.
Consequences
- A loader writes through
PayoutRepository.writeand never updates a line. To change how a line reads, write a resolution or a category override. - Every foreign key to
PayoutLineorJournalLineincludes the partition key (valueDate/voucherDate). - New money sources add a
PayoutSourcevalue and a detail table, not new header and line tables. - A
Shipmentrow always means PointNXT shipped it. Orders shipped outside PointNXT are recognised from their order status and get no shipment row, so nothing that branches on a shipment existing is misled.