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>
108 lines
3.4 KiB
Text
108 lines
3.4 KiB
Text
<cfsetting showdebugoutput="false">
|
|
<cfsetting enablecfoutputonly="true">
|
|
|
|
<cffunction name="apiAbort" access="public" returntype="void" output="true">
|
|
<cfargument name="payload" type="struct" required="true">
|
|
<cfcontent type="application/json; charset=utf-8">
|
|
<cfoutput>#serializeJSON(arguments.payload)#</cfoutput>
|
|
<cfabort>
|
|
</cffunction>
|
|
|
|
<cffunction name="readJsonBody" access="public" returntype="struct" output="false">
|
|
<cfset var raw = getHttpRequestData().content>
|
|
<cfif isNull(raw) OR len(trim(raw)) EQ 0>
|
|
<cfreturn {}>
|
|
</cfif>
|
|
<cftry>
|
|
<cfset var data = deserializeJSON(raw)>
|
|
<cfif isStruct(data)>
|
|
<cfreturn data>
|
|
<cfelse>
|
|
<cfreturn {}>
|
|
</cfif>
|
|
<cfcatch>
|
|
<cfreturn {}>
|
|
</cfcatch>
|
|
</cftry>
|
|
</cffunction>
|
|
|
|
<cfset data = readJsonBody()>
|
|
<cfset OrderID = val( structKeyExists(data,"OrderID") ? data.OrderID : 0 )>
|
|
<cfset NewStatusID = val( structKeyExists(data,"StatusID") ? data.StatusID : 0 )>
|
|
|
|
<cfif OrderID LTE 0 OR NewStatusID LTE 0>
|
|
<cfset apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "OrderID and StatusID are required.", "DETAIL": "" })>
|
|
</cfif>
|
|
|
|
<cftry>
|
|
<!--- Verify order exists and get details --->
|
|
<cfset qOrder = queryExecute("
|
|
SELECT o.ID, o.StatusID, o.BusinessID, o.ServicePointID,
|
|
sp.Name
|
|
FROM Orders o
|
|
LEFT JOIN ServicePoints sp ON sp.ID = o.ServicePointID
|
|
WHERE o.ID = ?
|
|
LIMIT 1
|
|
", [ { value = OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
|
|
|
<cfif qOrder.recordCount EQ 0>
|
|
<cfset apiAbort({ "OK": false, "ERROR": "not_found", "MESSAGE": "Order not found.", "DETAIL": "" })>
|
|
</cfif>
|
|
|
|
<cfset oldStatusID = qOrder.StatusID>
|
|
|
|
<!--- Update status --->
|
|
<cfset queryExecute("
|
|
UPDATE Orders
|
|
SET StatusID = ?,
|
|
LastEditedOn = ?
|
|
WHERE ID = ?
|
|
", [
|
|
{ value = NewStatusID, cfsqltype = "cf_sql_integer" },
|
|
{ value = now(), cfsqltype = "cf_sql_timestamp" },
|
|
{ value = OrderID, cfsqltype = "cf_sql_integer" }
|
|
], { datasource = "payfrit" })>
|
|
|
|
<!---
|
|
Order Status Flow:
|
|
0 = Cart
|
|
1 = Submitted (paid via Stripe/other payment, or added to tab)
|
|
2 = In Progress (Kitchen preparing)
|
|
3 = Order Complete, Final Prep (Kitchen done, create delivery/pickup task)
|
|
4 = Claimed (Worker claimed task - delivering to table, out for delivery, or notifying customer for pickup)
|
|
5 = Delivered/Complete
|
|
6 = Cancelled
|
|
7 = Deleted (user abandoned cart and started new one)
|
|
|
|
Task Types (auto-created at status 3):
|
|
- Dine-in: "Deliver Order #X to <Service Point>"
|
|
- Takeaway: "Prepare Order #X for customer pickup"
|
|
- Delivery: "Prepare Order #X for delivery worker pickup"
|
|
|
|
Other system tasks (manually created or scheduled):
|
|
- "Go to <Service Point>" (customer call server)
|
|
- "Customer Chat"
|
|
- Scheduled: "Clean Men's Washroom", "Clean Women's Restroom", "Silverware roll-ups", "Check Floor", "Check garbage cans", etc.
|
|
--->
|
|
|
|
<!--- Create delivery/pickup task when order moves to status 3 (Final Prep) --->
|
|
<cfinclude template="_createOrderTasks.cfm">
|
|
|
|
<cfset apiAbort({
|
|
"OK": true,
|
|
"ERROR": "",
|
|
"MESSAGE": "Order status updated successfully.",
|
|
"OrderID": OrderID,
|
|
"StatusID": NewStatusID,
|
|
"TaskCreated": taskCreated
|
|
})>
|
|
|
|
<cfcatch>
|
|
<cfset apiAbort({
|
|
"OK": false,
|
|
"ERROR": "server_error",
|
|
"MESSAGE": "DB error updating order status",
|
|
"DETAIL": cfcatch.message
|
|
})>
|
|
</cfcatch>
|
|
</cftry>
|