Repository navigation
Open
Labels
area:backendBackend (Express/SQLite)enhancementNew feature or requestpriority:highHigh priority against the backlogstate:needs-designNeeds a design/scope decision before work startstype:designArchitecture/design decision needed before implementation
Description
Problem
Order pricing, discounts, charges, split checks, and payment tender validation are currently distributed across main/routes/bills.ts, main/routes/orders.ts, shared/charges.ts, and main/services/tax.ts. Upcoming features - Promotion Engine (#359), Customer Types (#633), Combos (#366), Tipping (#364), Gift Cards (#363), and Payment-Method Surcharges - all intersect this boundary. Additionally, shared/charges.ts currently evaluates percentage fees independently against net or gross item subtotal only (no compound fee-on-fee ordering, Fork Audit TAX-002), and main/services/tax.ts only maps 3 hardcoded charge tax kinds (packaging, delivery, service_charge).
Codebase Anchor
main/routes/bills.ts:96-99,175,485-491,548-556,1753-2045(inline payment tender validation, rounding, split checkssplit_group_id, manual discount endpoints,payment_idempotency).shared/charges.ts:14-50,273-316(ChargeDefinition,calculateAppliedCharges- integer minor-unit math, currently onlynet | grossbasis) &main/services/charges.ts:90-140(resolveOrderChargesretaining applied snapshots).main/services/tax-engine.ts:209-236(already decoupled withDecimal.jsand tax-on-taxbaseRuleIds) &main/services/tax.ts:71-85,282-301(ChargeTaxKindlimited to 3 standard charge kinds).main/services/refund.ts(already decoupled refund ceiling &amount_centsminor units),main/routes/cash-sessions.ts&main/routes/cash-closures.ts.
Core Invariants & Constraints
- Backend authority (Core Invariant Add AppX tile assets to resolve Windows Store certification failure (10.1.1.11) #5): All order totals, adjustments, compound charges, taxes, and tender allocations remain strictly backend-authoritative.
- Applied charge snapshots (
docs/reference/product-invariants.md:186-216): Disabling or editing a charge/promotion definition must never mutate existing open or historical orders. - Zero regression on existing flows: Existing manual discounts, tax packs, split checks, and refund ceilings must pass all current suites untouched (
npm run test:charges-engine,npm run test:refunds, tax suites).
Scope / Acceptance Criteria
- Phase 1 - Payment Tender Extraction (absorbed from
#282): Extract payment tender validation, split allocation, rounding remainder distribution, and multi-tender reconciliation out ofmain/routes/bills.tsintomain/services/payment-tender.tswith unit/boundary tests independent of dining/table assumptions, plus tax-snapshot contract tests. - Phase 2 - Central Adjustment & Compound Fee Boundary (includes Fork
TAX-002): Introducemain/services/pricing.tsowning the single calculation pipeline (items -> order_adjustments snapshot -> charges [with optional ordered/compound fee-on-fee basis in shared/charges.ts] -> tax engine [supporting arbitrary custom charge tax categories in main/services/tax.ts] -> payable total) so#359,#633,#366,#364, and payment surcharges plug into one module. - Phase 3 - Financial Ledger Boundary: Define the clean write interface feeding payments, refunds (
#278), gift cards (#363), tips (#364), and cash sessions (#279) without four disconnected accounting tables. - All tests wired into
package.jsonand passing (npm test).
Concrete Design Decisions to Lock Before Coding
- Incremental rollout: Confirm Phase 1 (
payment-tender.tsextraction, zero schema change) ships first as a pure refactor PR before Phase 2 addsorder_adjustmentsand compound charge ordering. - Compound fee ordering (
TAX-002): Confirm whether compound charges use an explicitsort_order+calculation_basis: 'net' | 'gross' | 'post_charges'(preventing circular fee dependencies) and how receipts display compound basis clarity.
Out of Scope
- Replacing all existing
REALSQLite columns in one shot (tracked separately under#285persistence boundary). - Payment-gateway SDKs or card-surcharge UI/legal policy (tracked separately in Payment-Method Surcharges design issue, gated on Phase 1).
Metadata
Metadata
Assignees
Labels
area:backendBackend (Express/SQLite)enhancementNew feature or requestpriority:highHigh priority against the backlogstate:needs-designNeeds a design/scope decision before work startstype:designArchitecture/design decision needed before implementation
Activity