Task System: - Tasks auto-created when KDS marks order Ready (status 3) - Duplicate task prevention via TaskOrderID check - Task completion now marks associated order as Completed (status 4) - Fixed isNull() check for TaskCompletedOn (use len() instead) - Added TaskOrderID to task queries for order linking Worker APIs: - api/workers/myBusinesses.cfm with GROUP BY to prevent duplicates - api/tasks/listMine.cfm for worker's claimed tasks with filters - api/tasks/complete.cfm updates both task and order status - api/tasks/accept.cfm for claiming tasks KDS/Portal: - KDS only shows orders with status < 4 - Portal dashboard improvements Admin/Debug: - Debug endpoints for tasks and businesses - Test data reset endpoint 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
108 lines
3.3 KiB
Text
108 lines
3.3 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 BusinessID = val( structKeyExists(data,"BusinessID") ? data.BusinessID : 0 )>
|
|
<cfset CategoryID = val( structKeyExists(data,"CategoryID") ? data.CategoryID : 0 )>
|
|
|
|
<cfif BusinessID LTE 0>
|
|
<cfset apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "BusinessID is required." })>
|
|
</cfif>
|
|
|
|
<cftry>
|
|
<!--- Build WHERE clause - unclaimed tasks only --->
|
|
<cfset whereClauses = ["t.TaskBusinessID = ?", "t.TaskClaimedByUserID = 0"]>
|
|
<cfset params = [ { value = BusinessID, cfsqltype = "cf_sql_integer" } ]>
|
|
|
|
<!--- Filter by category if provided --->
|
|
<cfif CategoryID GT 0>
|
|
<cfset arrayAppend(whereClauses, "t.TaskCategoryID = ?")>
|
|
<cfset arrayAppend(params, { value = CategoryID, cfsqltype = "cf_sql_integer" })>
|
|
</cfif>
|
|
|
|
<cfset whereSQL = arrayToList(whereClauses, " AND ")>
|
|
|
|
<cfset qTasks = queryExecute("
|
|
SELECT
|
|
t.TaskID,
|
|
t.TaskBusinessID,
|
|
t.TaskCategoryID,
|
|
t.TaskOrderID,
|
|
t.TaskTypeID,
|
|
t.TaskAddedOn,
|
|
t.TaskClaimedByUserID,
|
|
tc.TaskCategoryName,
|
|
tc.TaskCategoryColor
|
|
FROM Tasks t
|
|
LEFT JOIN TaskCategories tc ON tc.TaskCategoryID = t.TaskCategoryID
|
|
WHERE #whereSQL#
|
|
ORDER BY t.TaskAddedOn ASC
|
|
", params, { datasource = "payfrit" })>
|
|
|
|
<cfset tasks = []>
|
|
|
|
<cfloop query="qTasks">
|
|
<!--- Build title based on task type --->
|
|
<cfset taskTitle = "Task ##" & qTasks.TaskID>
|
|
<cfset taskDetails = "">
|
|
|
|
<cfif qTasks.TaskOrderID GT 0>
|
|
<cfset taskTitle = "Order ##" & qTasks.TaskOrderID>
|
|
</cfif>
|
|
|
|
<cfset arrayAppend(tasks, {
|
|
"TaskID": qTasks.TaskID,
|
|
"TaskBusinessID": qTasks.TaskBusinessID,
|
|
"TaskCategoryID": qTasks.TaskCategoryID,
|
|
"TaskTitle": taskTitle,
|
|
"TaskDetails": taskDetails,
|
|
"TaskCreatedOn": dateFormat(qTasks.TaskAddedOn, "yyyy-mm-dd") & "T" & timeFormat(qTasks.TaskAddedOn, "HH:mm:ss"),
|
|
"TaskStatusID": qTasks.TaskClaimedByUserID GT 0 ? 1 : 0,
|
|
"TaskSourceType": "order",
|
|
"TaskSourceID": qTasks.TaskOrderID,
|
|
"TaskCategoryName": len(trim(qTasks.TaskCategoryName)) ? qTasks.TaskCategoryName : "General",
|
|
"TaskCategoryColor": len(trim(qTasks.TaskCategoryColor)) ? qTasks.TaskCategoryColor : "##888888"
|
|
})>
|
|
</cfloop>
|
|
|
|
<cfset apiAbort({
|
|
"OK": true,
|
|
"ERROR": "",
|
|
"TASKS": tasks,
|
|
"COUNT": arrayLen(tasks)
|
|
})>
|
|
|
|
<cfcatch>
|
|
<cfset apiAbort({
|
|
"OK": false,
|
|
"ERROR": "server_error",
|
|
"MESSAGE": "Error loading tasks",
|
|
"DETAIL": cfcatch.message
|
|
})>
|
|
</cfcatch>
|
|
</cftry>
|