This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/api/tasks/getDetails.cfm
John Mizerek 1210249f54 Normalize database column and table names across entire codebase
Update all SQL queries, query result references, and ColdFusion code to match
the renamed database schema. Tables use plural CamelCase, PKs are all `ID`,
column prefixes stripped (e.g. BusinessName→Name, UserFirstName→FirstName).

Key changes:
- Strip table-name prefixes from all column references (Businesses, Users,
  Addresses, Hours, Menus, Categories, Items, Stations, Orders,
  OrderLineItems, Tasks, TaskCategories, TaskRatings, QuickTaskTemplates,
  ScheduledTaskDefinitions, ChatMessages, Beacons, ServicePoints, Employees,
  VisitorTrackings, ApiPerfLogs, tt_States, tt_Days, tt_AddressTypes,
  tt_OrderTypes, tt_TaskTypes)
- Rename PK references from {TableName}ID to ID in all queries
- Rewrite 7 admin beacon files to use ServicePoints.BeaconID instead of
  dropped lt_Beacon_Businesses_ServicePoints link table
- Rewrite beacon assignment files (list, save, delete) for new schema
- Fix FK references incorrectly changed to ID (OrderLineItems.OrderID,
  Categories.MenuID, Tasks.CategoryID, ServicePoints.BeaconID)
- Update Addresses: AddressLat→Latitude, AddressLng→Longitude
- Update Users: UserPassword→Password, UserIsEmailVerified→IsEmailVerified,
  UserIsActive→IsActive, UserBalance→Balance, etc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 15:39:12 -08:00

189 lines
5.9 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 TaskID = val( structKeyExists(data,"TaskID") ? data.TaskID : 0 )>
<cfif TaskID LTE 0>
<cfset apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "TaskID is required." })>
</cfif>
<cftry>
<!--- Get the task and linked order details --->
<cfset qTask = queryExecute("
SELECT
t.ID,
t.BusinessID,
t.CategoryID,
t.OrderID,
t.TaskTypeID,
t.CreatedOn,
t.ClaimedByUserID,
tc.Name,
tc.Color,
o.ID,
o.UUID,
o.UserID,
o.OrderTypeID,
o.StatusID,
o.ServicePointID,
o.Remarks,
o.SubmittedOn,
sp.Name,
sp.TypeID,
u.ID as CustomerUserID,
u.FirstName,
u.LastName,
u.ContactNumber
FROM Tasks t
LEFT JOIN TaskCategories tc ON tc.ID = t.CategoryID
LEFT JOIN Orders o ON o.ID = t.OrderID
LEFT JOIN ServicePoints sp ON sp.ID = o.ServicePointID
LEFT JOIN Users u ON u.ID = o.UserID
WHERE t.ID = ?
", [ { value = TaskID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
<cfif qTask.recordCount EQ 0>
<cfset apiAbort({ "OK": false, "ERROR": "not_found", "MESSAGE": "Task not found." })>
</cfif>
<!--- Build basic task info --->
<cfset taskTitle = "Task ##" & qTask.ID>
<cfif qTask.OrderID GT 0>
<cfset taskTitle = "Order ##" & qTask.OrderID>
</cfif>
<!--- Check if user photo file exists (try both .jpg and .png) --->
<cfset customerPhotoUrl = "">
<cfif qTask.CustomerUserID GT 0>
<cfset uploadDir = expandPath("/uploads/users/")>
<cfset jpgPath = uploadDir & qTask.CustomerUserID & ".jpg">
<cfset pngPath = uploadDir & qTask.CustomerUserID & ".png">
<cfset pngPathUpper = uploadDir & qTask.CustomerUserID & ".PNG">
<cfif fileExists(jpgPath)>
<cfset customerPhotoUrl = "https://biz.payfrit.com/uploads/users/" & qTask.CustomerUserID & ".jpg">
<cfelseif fileExists(pngPath)>
<cfset customerPhotoUrl = "https://biz.payfrit.com/uploads/users/" & qTask.CustomerUserID & ".png">
<cfelseif fileExists(pngPathUpper)>
<cfset customerPhotoUrl = "https://biz.payfrit.com/uploads/users/" & qTask.CustomerUserID & ".PNG">
</cfif>
</cfif>
<cfset result = {
"TaskID": qTask.ID,
"BusinessID": qTask.BusinessID,
"TaskCategoryID": qTask.CategoryID,
"Title": taskTitle,
"CreatedOn": dateFormat(qTask.CreatedOn, "yyyy-mm-dd") & "T" & timeFormat(qTask.CreatedOn, "HH:mm:ss"),
"StatusID": qTask.ClaimedByUserID GT 0 ? 1 : 0,
"Name": len(trim(qTask.Name)) ? qTask.Name : "General",
"Color": len(trim(qTask.Color)) ? qTask.Color : "##888888",
"OrderID": qTask.OrderID ?: 0,
"Remarks": qTask.Remarks ?: "",
"SubmittedOn": isDate(qTask.SubmittedOn) ? (dateFormat(qTask.SubmittedOn, "yyyy-mm-dd") & "T" & timeFormat(qTask.SubmittedOn, "HH:mm:ss")) : "",
"ServicePointID": qTask.ServicePointID ?: 0,
"Name": qTask.Name ?: "",
"TypeID": qTask.TypeID ?: 0,
"DeliveryAddress": "",
"DeliveryLat": 0,
"DeliveryLng": 0,
"CustomerUserID": qTask.CustomerUserID ?: 0,
"CustomerFirstName": qTask.FirstName ?: "",
"CustomerLastName": qTask.LastName ?: "",
"CustomerPhone": qTask.ContactNumber ?: "",
"CustomerPhotoUrl": customerPhotoUrl,
"UUID": "",
"LineItems": []
}>
<!--- Get beacon UUID for the service point (for auto-completion on Works app) --->
<cfif val(qTask.ServicePointID) GT 0>
<cfset qBeacon = queryExecute("
SELECT b.UUID
FROM ServicePoints sp_link
INNER JOIN Beacons b ON b.ID = sp_link.BeaconID
WHERE sp_link.ID = ?
AND b.IsActive = 1
LIMIT 1
", [ { value = qTask.ServicePointID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
<cfif qBeacon.recordCount GT 0>
<cfset result.UUID = qBeacon.UUID>
</cfif>
</cfif>
<!--- Get order line items if there's an order --->
<cfif qTask.OrderID GT 0>
<cfset qLineItems = queryExecute("
SELECT
oli.ID,
oli.ParentOrderLineItemID,
oli.ItemID,
oli.Price,
oli.Quantity,
oli.Remark,
i.ID,
i.Name,
i.ParentItemID,
i.Price,
i.IsCheckedByDefault
FROM OrderLineItems oli
INNER JOIN Items i ON i.ID = oli.ItemID
WHERE oli.OrderID = ?
AND oli.IsDeleted = b'0'
ORDER BY oli.ID
", [ { value = qTask.OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
<cfloop query="qLineItems">
<cfset arrayAppend(result.LineItems, {
"LineItemID": qLineItems.OrderLineItemID,
"ParentLineItemID": qLineItems.ParentOrderLineItemID,
"ItemID": qLineItems.ID,
"Name": qLineItems.Name,
"Price": qLineItems.Price,
"Quantity": qLineItems.Quantity,
"Remark": qLineItems.Remark,
"IsModifier": qLineItems.ParentOrderLineItemID GT 0
})>
</cfloop>
</cfif>
<cfset apiAbort({
"OK": true,
"ERROR": "",
"TASK": result
})>
<cfcatch>
<cfset apiAbort({
"OK": false,
"ERROR": "server_error",
"MESSAGE": "Error loading task details",
"DETAIL": cfcatch.message
})>
</cfcatch>
</cftry>