backend phase 11

This commit is contained in:
hamid
2026-07-09 02:13:30 +03:30
parent 23605591eb
commit 465f75c29e
78 changed files with 9555 additions and 27 deletions
@@ -118,3 +118,19 @@ This is the most-changed domain. The previous model **inferred** money state fro
| `issued_at` | DATETIME2 | |
**Relations:** 1:1 → `bookings`; N:1 → `partner_centers` (when issuer).
### As built (backend-phase-11)
- **`refunds.refund_channel` canonical code is `manual`** (not `manual_bank`) for the out-of-band bank refund —
the two are the same channel; `manual` is the value stored and served. Set: `psp_card` | `bnpl_revert` | `manual`.
- **`refunds.ticket_id`** ships as a **nullable column with no FK** (the `tickets` table arrives in b15); the
"ticket required" rule is gated by the `refund_ticket_required` config flag (default off).
**`nurse_clawbacks.original_payout_id` / `recovered_in_payout_id`** and **`invoices.partner_center_id`** are
likewise nullable, FK-less join points that b13 / b15 fill.
- **`invoices.vat_irr = round(platform_commission_irr × vat_rate)`**, integer-only, on the commission line only; a
`vat_rate = 0` exemption yields `vat_irr = 0`.
- **`invoices.invoice_number`** is drawn from a single-row **counter table** (`invoice_number_sequences`), locked
and committed with the invoice insert — gap-free, unique, portable across SQL Server / SQLite (no DB sequence),
never random/timestamp-derived. One issued invoice per booking (idempotent).
- The refund posts the balanced reversal via the b10 ledger helper; the **`refund_payable ↔ escrow_held` clearing**
posts immediately for a succeeded card refund and is deferred to reconciliation for a `processing` BNPL/manual
refund. Card and BNPL post the **same** reversal legs.