Date: 2026-08-27
Scope: wpos_CheckPCoupon, wpos_TicketCouponUse, wpos_TicketCouponUseSum, and the normal-sales caller
The ticket coupon is accepted only provisionally when scanned. If a later product coupon with PRODUCTCOUPON.CPN_TYPE = 'C' lowers the eligible product value below the ticket coupon's TCINMASTER.MIN_PURCHASE_AMT, wpos_TicketCouponUseSum re-evaluates the receipt and rejects the ticket coupon for that sale.
The exact outcome is:
SCANTC.wpos_TicketCouponUseSum does not create a corresponding TCIN usage row.wpos_TicketCouponUseSum, not a RAISERROR from the final conclude procedure.The initial premise is therefore partly right: wpos_TicketCouponUseSum uses promotion-adjusted eligible value, but the earlier scan-time check in wpos_TicketCouponUse does not use the same calculation.
| Question | Answer |
|---|---|
Does the later C product coupon count against ticket-coupon minimum spend? |
Yes. Its item discount is included in the FDS deducted from eligible gross product amount. |
| Is the already-scanned ticket coupon removed? | No, not from SCANTC on this path. |
| Is it still usable? | No, not while the recalculated eligible value remains below the minimum. No valid TCIN usage row is produced. |
Does wpos_TicketCouponUseSum fail? |
It fails the business condition, skips the coupon, and returns an “unusable coupon” diagnostic. It does not throw a SQL exception for this condition. |
sequenceDiagram
participant POS as NormalSales
participant Check as wpos_CheckPCoupon
participant Use as wpos_TicketCouponUse
participant Sum as wpos_TicketCouponUseSum
participant DB as Coupon state
POS->>Check: Scan ticket coupon first
Check->>Use: Route ticket coupon
Use->>Use: Compare SUM(TEMPDLYPTRANS.AMT) to MIN_PURCHASE_AMT
Use->>DB: Stage accepted scan in SCANTC
POS->>Check: Add product coupon C
Check->>DB: Add item discount, DISCID=100
POS->>Sum: Enter payment/tender processing
Sum->>Sum: Rebuild eligible amount as gross AMT - FDS
alt eligible net >= minimum
Sum->>DB: Insert TCIN usage row
Sum-->>POS: Ticket coupon is usable
else eligible net < minimum
Sum->>Sum: GOTO Ext; skip TCIN insertion
Note over DB: SCANTC remains; TCIN is absent
Sum-->>POS: Return coupon-not-usable diagnostic rows
end
CPN_TYPE = 'C' is the product-discount casewpos_CalculatePRCPN creates DISCTRANS rows only for scanned product coupons whose CPN_TYPE='C', calculating the discount as the smaller of coupon value and item amount. It handles CPN_TYPE='P' separately as product-coupon payment.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_CalculatePRCPN.StoredProcedure.sql:116-121POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_CalculatePRCPN.StoredProcedure.sql:134-138wpos_CheckPCoupon reads the product coupon's CPN_TYPE, calculates the eligible item price after existing discounts, and inserts a new SCANPRODUCT_ITEM row with DISCID=100, DISC=CPN_VAL, and the coupon series in EVNUM.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_CheckPCoupon.StoredProcedure.sql:395-397POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_CheckPCoupon.StoredProcedure.sql:451-485POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_CheckPCoupon.StoredProcedure.sql:575-579There is no branch here that revisits existing SCANTC ticket scans. Ticket-coupon input is routed separately to wpos_TicketCouponUse.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_CheckPCoupon.StoredProcedure.sql:652-715wpos_TicketCouponUse reads MIN_PURCHASE_AMT, but its early check compares that minimum to SUM(TEMPDLYPTRANS.AMT) for sale-item rows. It does not subtract FDS in this check.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUse.StoredProcedure.sql:1335-1357POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUse.StoredProcedure.sql:1365-1379On acceptance, it stages the ticket in SCANTC; this is not yet the final TCIN redemption.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUse.StoredProcedure.sql:4071-4086This is why a ticket can pass when scanned first, even though a later discount causes it to fail at payment summary.
wpos_TicketCouponUseSum counts the later C discountThe summary procedure aggregates SCANPRODUCT_ITEM.DISC for item-discount rows. It excludes discount IDs 0, 1, and 2, and it excludes coupon discount rows only when their product coupon has CPN_TYPE='P'. A CPN_TYPE='C' row is therefore retained.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:788-806It then builds the eligible-product working set with:
AMT = SUM(QUANT * PRICE)
FDS = SUM(DISC)
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:1907-1911
For amount-based ticket criteria, it calculates @saleamtpromo = SUM(amt - fds) over the eligible product group.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:2003-2010POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:2126-2134For each ticket coupon, the summary procedure reloads TCINMASTER.MIN_PURCHASE_AMT, then performs the decisive check:
if @saleamtpromo < @MIN_AMOUNT
begin
goto Ext
end
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:1451-1457POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:2685-2688Ext advances to the next coupon. It bypasses the success path that inserts the TCIN usage record.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:2693-2709POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:2853-2891POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:3149-3153Before recalculation, normal local processing deletes prior TCIN, TCINPRODUCT, and TCTRANS results and rebuilds them. A prior summary result therefore does not “lock in” ticket eligibility.
POS_SQL_Exports/ESTORE_stored_procedures/dbo.wpos_TicketCouponUseSum.StoredProcedure.sql:815-844At the end, the procedure detects positive-quantity SCANTC records that have no matching TCIN usage. It returns the Thai heading:
*** เลขที่คูปองที่ไม่สามารถใช้ร่วมรายการขายได้ ***