Create 'Pay With Cash' task when cash orders reach Final Prep
- Auto-create cash task when order status transitions to 3 (Final Prep) and has a pending cash payment (Payments.PaymentPaidInCash > 0) - Task includes OrderID so Android can display OrderTotal - Task title includes service point name when available - Fix duplicate task check: was WHERE ID = ?, now WHERE OrderID = ? Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c198b68ee0
commit
5912784772
1 changed files with 51 additions and 1 deletions
|
|
@ -87,11 +87,12 @@
|
|||
|
||||
<!--- Create delivery/pickup task when order moves to status 3 (Final Prep) --->
|
||||
<cfset taskCreated = false>
|
||||
<cfset cashTaskCreated = false>
|
||||
<cfif NewStatusID EQ 3 AND oldStatusID NEQ 3>
|
||||
<cftry>
|
||||
<!--- Check if task already exists for this order to prevent duplicates --->
|
||||
<cfset qExisting = queryExecute("
|
||||
SELECT ID FROM Tasks WHERE ID = ? LIMIT 1
|
||||
SELECT ID FROM Tasks WHERE OrderID = ? LIMIT 1
|
||||
", [ { value = OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
||||
|
||||
<cfif qExisting.recordCount EQ 0>
|
||||
|
|
@ -149,6 +150,55 @@
|
|||
], { datasource = "payfrit" })>
|
||||
<cfset taskCreated = true>
|
||||
</cfif>
|
||||
|
||||
<!--- Check for pending cash payment and create "Pay With Cash" task --->
|
||||
<cfset qCashPayment = queryExecute("
|
||||
SELECT p.PaymentPaidInCash, o.PaymentStatus, o.ServicePointID, sp.Name AS ServicePointName
|
||||
FROM Orders o
|
||||
LEFT JOIN Payments p ON p.PaymentID = o.PaymentID
|
||||
LEFT JOIN ServicePoints sp ON sp.ID = o.ServicePointID
|
||||
WHERE o.ID = ?
|
||||
", [ { value = OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
||||
|
||||
<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 --->
|
||||
<cfset qCashTaskType = queryExecute("
|
||||
SELECT ID FROM tt_TaskTypes WHERE BusinessID = ? AND Name LIKE '%Cash%' LIMIT 1
|
||||
", [ { value = qOrder.BusinessID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
||||
|
||||
<cfset cashTaskTypeID = qCashTaskType.recordCount GT 0 ? qCashTaskType.ID : 0>
|
||||
<cfset cashTaskTitle = "Pay With Cash - Order ###OrderID#">
|
||||
<cfif len(qCashPayment.ServicePointName)>
|
||||
<cfset cashTaskTitle = cashTaskTitle & " (" & qCashPayment.ServicePointName & ")">
|
||||
</cfif>
|
||||
|
||||
<cfset queryExecute("
|
||||
INSERT INTO Tasks (
|
||||
BusinessID,
|
||||
OrderID,
|
||||
TaskTypeID,
|
||||
Title,
|
||||
ClaimedByUserID,
|
||||
CreatedOn,
|
||||
ServicePointID
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
0,
|
||||
NOW(),
|
||||
?
|
||||
)
|
||||
", [
|
||||
{ value = qOrder.BusinessID, cfsqltype = "cf_sql_integer" },
|
||||
{ value = OrderID, cfsqltype = "cf_sql_integer" },
|
||||
{ value = cashTaskTypeID, cfsqltype = "cf_sql_integer" },
|
||||
{ value = cashTaskTitle, cfsqltype = "cf_sql_varchar" },
|
||||
{ value = qCashPayment.ServicePointID, cfsqltype = "cf_sql_integer", null = isNull(qCashPayment.ServicePointID) OR val(qCashPayment.ServicePointID) EQ 0 }
|
||||
], { datasource = "payfrit" })>
|
||||
<cfset cashTaskCreated = true>
|
||||
</cfif>
|
||||
</cfif>
|
||||
<cfcatch>
|
||||
<!--- Task creation failed, but don't fail the status update --->
|
||||
|
|
|
|||
Reference in a new issue