Objective
- Ensure the invoice total correctly reflects the full applied discount when a fixed discount code is combined with a bundle on the same order.
- A $3 shortfall on invoice #TCI3667 (Axium Colorado, 7428 Coral Ridge Dr, 7/1/26) confirmed the bug is live and affecting real orders.
Background
- Neil Chini (Axium/Colorado) identified a $3 discrepancy on invoice #TCI3667: the Military Discount ($30 fixed, applied to all 5 services) shows $102 in total savings rather than the expected $105.
- The order contains the VA Loan Complete bundle, which applies fixed per-service discounts to 3 of the 5 services (Radon, Sewer, Mold: -$25 each). The primary service (Home Inspection - VA Loan) receives a separate primary service bundle discount.
- Tracing the invoice line items: Radon (-$31), Sewer (-$31), Mold (-$31), WDI (-$6), and Home Inspection (-$3). The Military Discount's $6-per-service share is correctly applied to 4 of 5 services but produces only $3 on the Home Inspection — the primary service.
- The bug lives in
calculateServicePrices.ts. For fixed discount codes, the function splits the total evenly (perService = round2(totalDiscount / eligibleServices.length)) and uses a "last eligible service gets the remainder" pattern to prevent cumulative rounding drift. However, the primary service also has aprimaryDiscountAmountapplied in an earlier pass, which modifies itspreTaxAmountbefore the discount code pass runs. The combination of prior-pass price modification and the fixed-split rounding correction appears to produce an off-by-one allocation on the primary service. - The result is a real invoice discrepancy: the client is billed $3 more than intended.
Product Decisions
Locked
- Correct behavior — The full fixed discount amount ($30) must be distributed across all eligible services such that the invoice total reflects the full discount. No rounding residual should result in under-discounting any service.
- Invoice accuracy is authoritative — The discrepancy is present in the invoice total ($1,083 instead of $1,080), not just the display; this is a billing accuracy bug, not a cosmetic one.
Open
- Allocation method — The current even-split with last-service remainder correction is conceptually sound, but the interaction with pre-modified
preTaxAmounton bundle+primary service combinations needs investigation. Should the fixed split useoriginalPreTaxAmountas the denominator base instead of the already-reducedpreTaxAmount? Engineering should confirm whether the fix is isolated to the allocation order or requires a deeper change to how sequential discount passes interact.
Scope
Monorepo (attik) — Frontend
- Primary file:
apps/frontend/src/util/functions/schedulingHelpers/calculateServicePrices.ts - The fixed discount distribution block is the primary suspect. Focus on the interaction between the
primaryDiscountpass (which modifiespreTaxAmounton the primary service) and the subsequent fixed-code split, which usespreTaxAmountas the basis for even distribution. - The
isLastremainder logic usesfindLastIndexoverprocessedServices— verify that index is resolving correctly when the primary service is the first in the array and the last eligible service has already absorbed prior discount passes. - Related:
apps/frontend/src/components/scheduling/DiscountModel.tsx— UI for discount code application; not the source of the bug but relevant for confirming which service IDs are passed as eligible.
References
- Invoice screenshot: #TCI3667 (attached)
- Reported by: Neil Chini, Axium/Colorado (neil@axiuminspections.com), July 1, 2026
- Related: ATT-1923 (discount strikethrough display on primary lines — different symptom, same pricing surface)
- Codebase entry point:
apps/frontend/src/util/functions/schedulingHelpers/calculateServicePrices.ts
Repro Steps
- Create an order with 5 services: one primary service (e.g. Home Inspection - VA Loan) + 4 add-ons.
- Apply a bundle that discounts 3 of the 5 services (not the primary) with fixed per-service amounts, plus a separate primary service discount.
- Apply a fixed-amount discount code (e.g. $30) scoped to all services.
- View the invoice and compare total discount savings to expected (bundle total + code total).
- Confirm whether the primary service line receives the correct pro-rata share of the code discount.