Skip to main content

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 Payout per partner transfer, with source (MARKETPLACE, COURIER_COD, PAYMENT_GATEWAY) and exactly one partner id. Source-specific figures live in one-to-one detail tables.
  • PayoutLine is insert-only (trigger enforced) and partitioned by valueDate. Corrections are new lines that supersede old ones by identityKey. The interpretation (which order, which category) is a separate PayoutLineResolution.
  • Receivable records 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, and ReceivableMatch records which lines paid it. Recognition is driven by PointNXT's Order.orderStatus, never the channel's raw status.
  • Bank credits are allocated to payouts (BankAllocation.payoutId), whatever their source.
  • Journals are JournalVoucher / JournalLine against a per-tenant LedgerAccount chart. 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.write and never updates a line. To change how a line reads, write a resolution or a category override.
  • Every foreign key to PayoutLine or JournalLine includes the partition key (valueDate / voucherDate).
  • New money sources add a PayoutSource value and a detail table, not new header and line tables.
  • A Shipment row 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.