Each station can mark their items done independently. When all stations are done, the order auto-promotes to Ready (status 3) and delivery/pickup tasks are created automatically. - New markStationDone.cfm endpoint for per-station completion - Extract task creation into shared _createOrderTasks.cfm include - Add line item StatusID to listForKDS.cfm response - KDS shows per-station "Mark Station Done" button when filtered - Done items display with strikethrough and checkmark - Manager view retains full manual control (no station selected) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
171 lines
6.4 KiB
Text
171 lines
6.4 KiB
Text
<!---
|
|
Shared task creation logic for orders moving to status 3 (Ready).
|
|
Expects these variables in calling scope:
|
|
- OrderID (integer)
|
|
- qOrder (query with BusinessID, ServicePointID, Name)
|
|
- NewStatusID (integer)
|
|
- oldStatusID (integer)
|
|
Sets:
|
|
- taskCreated (boolean)
|
|
- cashTaskCreated (boolean)
|
|
--->
|
|
|
|
<cfset taskCreated = false>
|
|
<cfset cashTaskCreated = false>
|
|
<cfif NewStatusID EQ 3 AND oldStatusID NEQ 3>
|
|
<cftry>
|
|
<!--- Get order type --->
|
|
<cfset qOrderDetails = queryExecute("
|
|
SELECT o.OrderTypeID
|
|
FROM Orders o
|
|
WHERE o.ID = ?
|
|
", [ { value = OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
|
|
|
<cfset orderTypeID = qOrderDetails.recordCount GT 0 ? val(qOrderDetails.OrderTypeID) : 1>
|
|
|
|
<!--- Look up task type for this business based on order type --->
|
|
<!--- OrderTypeID: 1=dine-in, 2=takeaway, 3=delivery --->
|
|
<cfif orderTypeID EQ 1>
|
|
<cfset taskTypeName = "Deliver to Table">
|
|
<cfelseif orderTypeID EQ 2>
|
|
<cfset taskTypeName = "Order Ready for Pickup">
|
|
<cfelseif orderTypeID EQ 3>
|
|
<cfset taskTypeName = "Deliver to Address">
|
|
<cfelse>
|
|
<cfset taskTypeName = "">
|
|
</cfif>
|
|
|
|
<cfset taskTypeID = 0>
|
|
<cfif len(taskTypeName)>
|
|
<cfset qTaskType = queryExecute("
|
|
SELECT ID FROM tt_TaskTypes WHERE BusinessID = ? AND Name = ? LIMIT 1
|
|
", [
|
|
{ value = qOrder.BusinessID, cfsqltype = "cf_sql_integer" },
|
|
{ value = taskTypeName, cfsqltype = "cf_sql_varchar" }
|
|
], { datasource = "payfrit" })>
|
|
<cfset taskTypeID = qTaskType.recordCount GT 0 ? qTaskType.ID : 0>
|
|
</cfif>
|
|
|
|
<!--- Check if this type of task already exists for this order to prevent duplicates --->
|
|
<cfset qExisting = queryExecute("
|
|
SELECT ID FROM Tasks WHERE OrderID = ? AND TaskTypeID = ? LIMIT 1
|
|
", [
|
|
{ value = OrderID, cfsqltype = "cf_sql_integer" },
|
|
{ value = taskTypeID, cfsqltype = "cf_sql_integer" }
|
|
], { datasource = "payfrit" })>
|
|
|
|
<cfif qExisting.recordCount EQ 0 AND taskTypeID GT 0>
|
|
<!--- Build task title based on order type --->
|
|
<cfif orderTypeID EQ 1>
|
|
<!--- Dine-in: Server delivers to service point --->
|
|
<cfset tableName = len(qOrder.Name) ? qOrder.Name : "Table">
|
|
<cfset taskTitle = "Deliver Order ###OrderID# to " & tableName>
|
|
<cfset taskCategoryID = 3>
|
|
<cfelseif orderTypeID EQ 2>
|
|
<!--- Takeaway: Expo task to notify customer order is ready --->
|
|
<cfset taskTitle = "Order ###OrderID# Ready for Pickup">
|
|
<cfset taskCategoryID = 4>
|
|
<cfelseif orderTypeID EQ 3>
|
|
<!--- Delivery: Hand off to delivery driver --->
|
|
<cfset taskTitle = "Deliver Order ###OrderID# to Address">
|
|
<cfset taskCategoryID = 5>
|
|
<cfelse>
|
|
<cfset taskTitle = "">
|
|
</cfif>
|
|
|
|
<cfif len(taskTitle)>
|
|
<cfset queryExecute("
|
|
INSERT INTO Tasks (
|
|
BusinessID,
|
|
OrderID,
|
|
ServicePointID,
|
|
TaskTypeID,
|
|
CategoryID,
|
|
Title,
|
|
ClaimedByUserID,
|
|
CreatedOn
|
|
) VALUES (
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
0,
|
|
NOW()
|
|
)
|
|
", [
|
|
{ value = qOrder.BusinessID, cfsqltype = "cf_sql_integer" },
|
|
{ value = OrderID, cfsqltype = "cf_sql_integer" },
|
|
{ value = qOrder.ServicePointID, cfsqltype = "cf_sql_integer", null = isNull(qOrder.ServicePointID) OR val(qOrder.ServicePointID) EQ 0 },
|
|
{ value = taskTypeID, cfsqltype = "cf_sql_integer" },
|
|
{ value = taskCategoryID, cfsqltype = "cf_sql_integer" },
|
|
{ value = taskTitle, cfsqltype = "cf_sql_varchar" }
|
|
], { datasource = "payfrit" })>
|
|
<cfset taskCreated = true>
|
|
</cfif>
|
|
</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">
|
|
<!--- 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 --->
|
|
<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 --->
|
|
</cfcatch>
|
|
</cftry>
|
|
</cfif>
|