fix: prevent tab cancel when approved orders exist
cancel.cfm previously only blocked cancel if orders had StatusID >= 1 (submitted to kitchen). If submitOrder() failed after addOrderToTab() succeeded, the order stayed at StatusID 0 but was linked to the tab with ApprovalStatus='approved'. This allowed cancelling the tab free. Now checks TabOrders directly — any approved orders with non-zero subtotals block the cancel, regardless of kitchen submission status. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c40e5c0181
commit
496ef74c4c
1 changed files with 8 additions and 8 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
<cfscript>
|
<cfscript>
|
||||||
/**
|
/**
|
||||||
* Cancel Tab
|
* Cancel Tab
|
||||||
* Only allowed if no orders have been submitted to kitchen (StatusID >= 1).
|
* Only allowed if no approved orders with non-zero subtotals exist.
|
||||||
* Releases the Stripe hold.
|
* Releases the Stripe hold.
|
||||||
*
|
*
|
||||||
* POST: { TabID: int, UserID: int }
|
* POST: { TabID: int, UserID: int }
|
||||||
|
|
@ -29,15 +29,15 @@ try {
|
||||||
if (qTab.StatusID != 1) apiAbort({ "OK": false, "ERROR": "tab_not_open" });
|
if (qTab.StatusID != 1) apiAbort({ "OK": false, "ERROR": "tab_not_open" });
|
||||||
if (qTab.OwnerUserID != userID) apiAbort({ "OK": false, "ERROR": "not_owner" });
|
if (qTab.OwnerUserID != userID) apiAbort({ "OK": false, "ERROR": "not_owner" });
|
||||||
|
|
||||||
// Check for submitted orders
|
// Check for any approved orders (regardless of kitchen status)
|
||||||
qSubmitted = queryTimed("
|
qApproved = queryTimed("
|
||||||
SELECT COUNT(*) AS Cnt FROM TabOrders tbo
|
SELECT COUNT(*) AS Cnt, COALESCE(SUM(SubtotalCents), 0) AS TotalCents
|
||||||
JOIN Orders o ON o.ID = tbo.OrderID
|
FROM TabOrders
|
||||||
WHERE tbo.TabID = :tabID AND tbo.ApprovalStatus = 'approved' AND o.StatusID >= 1
|
WHERE TabID = :tabID AND ApprovalStatus = 'approved'
|
||||||
", { tabID: { value: tabID, cfsqltype: "cf_sql_integer" } });
|
", { tabID: { value: tabID, cfsqltype: "cf_sql_integer" } });
|
||||||
|
|
||||||
if (qSubmitted.Cnt > 0) {
|
if (qApproved.Cnt > 0 && val(qApproved.TotalCents) > 0) {
|
||||||
apiAbort({ "OK": false, "ERROR": "has_submitted_orders", "MESSAGE": "Tab has orders in progress. Close the tab instead of cancelling." });
|
apiAbort({ "OK": false, "ERROR": "has_orders", "MESSAGE": "Tab has approved orders. Close the tab instead of cancelling." });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel Stripe PI
|
// Cancel Stripe PI
|
||||||
|
|
|
||||||
Reference in a new issue