Prevent duplicate cash tasks for same order

Check for existing active (uncompleted) cash task before creating
a new one. Prevents duplicate "Pay With Cash" tasks if order status
changes are triggered multiple times.

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

View file

@ -192,6 +192,15 @@
", [ { value = OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })> ", [ { value = OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
<cfif qCashPayment.recordCount GT 0 AND val(qCashPayment.PaymentPaidInCash) GT 0 AND qCashPayment.PaymentStatus EQ "pending"> <cfif qCashPayment.recordCount GT 0 AND val(qCashPayment.PaymentPaidInCash) GT 0 AND qCashPayment.PaymentStatus EQ "pending">
<!--- Check if there's already an active cash task for this order --->
<cfset qExistingCashTask = queryExecute("
SELECT t.ID FROM Tasks t
INNER JOIN tt_TaskTypes tt ON tt.ID = t.TaskTypeID
WHERE t.OrderID = ? AND tt.Name LIKE '%Cash%' AND t.CompletedOn IS NULL
LIMIT 1
", [ { value = OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
<cfif qExistingCashTask.recordCount EQ 0>
<!--- Get "Pay With Cash" task type ID for this business ---> <!--- Get "Pay With Cash" task type ID for this business --->
<cfset qCashTaskType = queryExecute(" <cfset qCashTaskType = queryExecute("
SELECT ID FROM tt_TaskTypes WHERE BusinessID = ? AND Name LIKE '%Cash%' LIMIT 1 SELECT ID FROM tt_TaskTypes WHERE BusinessID = ? AND Name LIKE '%Cash%' LIMIT 1
@ -229,6 +238,7 @@
{ value = qCashPayment.ServicePointID, cfsqltype = "cf_sql_integer", null = isNull(qCashPayment.ServicePointID) OR val(qCashPayment.ServicePointID) EQ 0 } { value = qCashPayment.ServicePointID, cfsqltype = "cf_sql_integer", null = isNull(qCashPayment.ServicePointID) OR val(qCashPayment.ServicePointID) EQ 0 }
], { datasource = "payfrit" })> ], { datasource = "payfrit" })>
<cfset cashTaskCreated = true> <cfset cashTaskCreated = true>
</cfif><!--- qExistingCashTask.recordCount EQ 0 --->
</cfif> </cfif>
</cfif> </cfif>
<cfcatch> <cfcatch>