Add CancelOrder option for cash tasks

When worker passes CancelOrder: true to complete.cfm:
- Skips all cash validation and financial processing
- Sets order status to 6 (cancelled)
- Completes the task normally
- Returns OrderCancelled: true in response

For when customer changes their mind about paying with cash.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John Mizerek 2026-02-17 09:39:35 -08:00
parent eb92042de5
commit 7f4af8b910

View file

@ -38,6 +38,7 @@
<!--- Optional: Worker rating of customer (when required or voluntary) ---> <!--- Optional: Worker rating of customer (when required or voluntary) --->
<cfset workerRating = structKeyExists(data,"workerRating") ? data.workerRating : {}> <cfset workerRating = structKeyExists(data,"workerRating") ? data.workerRating : {}>
<cfset CashReceivedCents = val( structKeyExists(data,"CashReceivedCents") ? data.CashReceivedCents : 0 )> <cfset CashReceivedCents = val( structKeyExists(data,"CashReceivedCents") ? data.CashReceivedCents : 0 )>
<cfset CancelOrder = structKeyExists(data,"CancelOrder") AND data.CancelOrder EQ true>
<cfif TaskID LTE 0> <cfif TaskID LTE 0>
<cfset apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "TaskID is required." })> <cfset apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "TaskID is required." })>
@ -110,8 +111,9 @@
<!--- === CASH TASK VALIDATION === ---> <!--- === CASH TASK VALIDATION === --->
<cfset cashResult = {}> <cfset cashResult = {}>
<!--- Skip cash processing for orphaned tasks (no order linked) ---> <cfset orderCancelled = false>
<cfif isCashTask AND qTask.OrderID GT 0> <!--- Skip cash processing for orphaned tasks (no order linked) OR if cancelling --->
<cfif isCashTask AND qTask.OrderID GT 0 AND NOT CancelOrder>
<cfif CashReceivedCents LTE 0> <cfif CashReceivedCents LTE 0>
<cfset apiAbort({ "OK": false, "ERROR": "cash_required", "MESSAGE": "Cash amount is required for cash tasks." })> <cfset apiAbort({ "OK": false, "ERROR": "cash_required", "MESSAGE": "Cash amount is required for cash tasks." })>
</cfif> </cfif>
@ -191,7 +193,17 @@
<!--- Update order status based on task type ---> <!--- Update order status based on task type --->
<cfset orderUpdated = false> <cfset orderUpdated = false>
<cfif qTask.OrderID GT 0> <cfif qTask.OrderID GT 0>
<cfif isCashTask> <cfif CancelOrder>
<!--- Cancel order: Set status to 6 (Cancelled), no financial processing --->
<cfset queryTimed("
UPDATE Orders
SET StatusID = 6,
PaymentStatus = 'cancelled',
LastEditedOn = NOW()
WHERE ID = ?
", [ { value = qTask.OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
<cfset orderCancelled = true>
<cfelseif isCashTask>
<!--- Cash task: Set to status 1 (Submitted/Paid) to trigger kitchen flow ---> <!--- Cash task: Set to status 1 (Submitted/Paid) to trigger kitchen flow --->
<!--- Kitchen will then move to 2, then 3 (which creates delivery task) ---> <!--- Kitchen will then move to 2, then 3 (which creates delivery task) --->
<cfset queryTimed(" <cfset queryTimed("
@ -275,7 +287,7 @@
<!--- === CASH TRANSACTION PROCESSING === ---> <!--- === CASH TRANSACTION PROCESSING === --->
<cfset cashProcessed = false> <cfset cashProcessed = false>
<cfif isCashTask AND CashReceivedCents GT 0 AND qTask.OrderID GT 0> <cfif isCashTask AND CashReceivedCents GT 0 AND qTask.OrderID GT 0 AND NOT CancelOrder>
<!--- Credit customer change to their balance ---> <!--- Credit customer change to their balance --->
<cfif changeCents GT 0 AND customerUserID GT 0> <cfif changeCents GT 0 AND customerUserID GT 0>
<cfset queryTimed(" <cfset queryTimed("
@ -384,9 +396,10 @@
<cfset response = { <cfset response = {
"OK": true, "OK": true,
"ERROR": "", "ERROR": "",
"MESSAGE": "Task completed successfully.", "MESSAGE": orderCancelled ? "Order cancelled." : "Task completed successfully.",
"TaskID": TaskID, "TaskID": TaskID,
"OrderUpdated": orderUpdated, "OrderUpdated": orderUpdated,
"OrderCancelled": orderCancelled,
"RatingsCreated": ratingsCreated, "RatingsCreated": ratingsCreated,
"LedgerCreated": ledgerCreated, "LedgerCreated": ledgerCreated,
"CashProcessed": cashProcessed "CashProcessed": cashProcessed