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:
parent
7f4af8b910
commit
43afe9ae8c
1 changed files with 22 additions and 12 deletions
|
|
@ -192,19 +192,28 @@
|
||||||
", [ { 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">
|
||||||
<!--- Get "Pay With Cash" task type ID for this business --->
|
<!--- Check if there's already an active cash task for this order --->
|
||||||
<cfset qCashTaskType = queryExecute("
|
<cfset qExistingCashTask = queryExecute("
|
||||||
SELECT ID FROM tt_TaskTypes WHERE BusinessID = ? AND Name LIKE '%Cash%' LIMIT 1
|
SELECT t.ID FROM Tasks t
|
||||||
", [ { value = qOrder.BusinessID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
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" })>
|
||||||
|
|
||||||
<cfset cashTaskTypeID = qCashTaskType.recordCount GT 0 ? qCashTaskType.ID : 0>
|
<cfif qExistingCashTask.recordCount EQ 0>
|
||||||
<cfset cashTaskTitle = "Pay With Cash - Order ###OrderID#">
|
<!--- Get "Pay With Cash" task type ID for this business --->
|
||||||
<cfif len(qCashPayment.ServicePointName)>
|
<cfset qCashTaskType = queryExecute("
|
||||||
<cfset cashTaskTitle = cashTaskTitle & " (" & qCashPayment.ServicePointName & ")">
|
SELECT ID FROM tt_TaskTypes WHERE BusinessID = ? AND Name LIKE '%Cash%' LIMIT 1
|
||||||
</cfif>
|
", [ { value = qOrder.BusinessID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
||||||
|
|
||||||
<cfset queryExecute("
|
<cfset cashTaskTypeID = qCashTaskType.recordCount GT 0 ? qCashTaskType.ID : 0>
|
||||||
INSERT INTO Tasks (
|
<cfset cashTaskTitle = "Pay With Cash - Order ###OrderID#">
|
||||||
|
<cfif len(qCashPayment.ServicePointName)>
|
||||||
|
<cfset cashTaskTitle = cashTaskTitle & " (" & qCashPayment.ServicePointName & ")">
|
||||||
|
</cfif>
|
||||||
|
|
||||||
|
<cfset queryExecute("
|
||||||
|
INSERT INTO Tasks (
|
||||||
BusinessID,
|
BusinessID,
|
||||||
OrderID,
|
OrderID,
|
||||||
TaskTypeID,
|
TaskTypeID,
|
||||||
|
|
@ -228,7 +237,8 @@
|
||||||
{ value = cashTaskTitle, cfsqltype = "cf_sql_varchar" },
|
{ value = cashTaskTitle, cfsqltype = "cf_sql_varchar" },
|
||||||
{ 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>
|
||||||
|
|
|
||||||
Reference in a new issue