diff --git a/api/auth/sendLoginOTP.cfm b/api/auth/sendLoginOTP.cfm index 15db679..5902b54 100644 --- a/api/auth/sendLoginOTP.cfm +++ b/api/auth/sendLoginOTP.cfm @@ -136,8 +136,8 @@ try { // Send via SMS try { if (structKeyExists(application, "twilioObj")) { - smsMessage = "Your Payfrit code is: " & code; - application.twilioObj.sendSMS(to=qUser.ContactNumber, message=smsMessage); + smsMessage = "Your Payfrit login code is: " & code & ". It expires in 10 minutes."; + application.twilioObj.sendSMS(recipientNumber="+1" & qUser.ContactNumber, messageBody=smsMessage); } } catch (any smsErr) { writeLog(file="otp_errors", text="SMS send failed for user #userId#: #smsErr.message#"); diff --git a/api/orders/getCart.cfm b/api/orders/getCart.cfm index 5ec51f9..4e56fa9 100644 --- a/api/orders/getCart.cfm +++ b/api/orders/getCart.cfm @@ -37,24 +37,26 @@ diff --git a/api/orders/getOrCreateCart.cfm b/api/orders/getOrCreateCart.cfm index aa8feeb..08da5ae 100644 --- a/api/orders/getOrCreateCart.cfm +++ b/api/orders/getOrCreateCart.cfm @@ -33,28 +33,30 @@ + + + + + diff --git a/api/orders/setOrderType.cfm b/api/orders/setOrderType.cfm index c6a3de4..f3c1339 100644 --- a/api/orders/setOrderType.cfm +++ b/api/orders/setOrderType.cfm @@ -33,23 +33,25 @@ 0) { // Update order status to paid/submitted (status 1) - // Note: Task is created later when order status changes to Ready (3) in updateStatus.cfm queryTimed(" UPDATE Orders SET PaymentStatus = 'paid', @@ -134,6 +133,34 @@ try { ", { amount: val(qBalOrder.BalanceApplied), userID: val(qBalOrder.UserID) }); writeLog(file="stripe_webhooks", text="Order #orderID# balance deducted: $#qBalOrder.BalanceApplied#"); } + + // Create kitchen task for the order + qOrder = queryTimed(" + SELECT o.BusinessID, o.ServicePointID, sp.Name AS ServicePointName + FROM Orders o + LEFT JOIN ServicePoints sp ON sp.ID = o.ServicePointID + WHERE o.ID = :orderID + ", { orderID: orderID }); + + if (qOrder.recordCount > 0) { + tableName = len(trim(qOrder.ServicePointName)) ? qOrder.ServicePointName : "Table"; + taskTitle = "Prepare Order ##" & orderID & " for " & tableName; + + queryTimed(" + INSERT INTO Tasks ( + BusinessID, OrderID, ServicePointID, Title, CreatedOn, ClaimedByUserID + ) VALUES ( + :businessID, :orderID, :servicePointID, :title, NOW(), 0 + ) + ", { + businessID: qOrder.BusinessID, + orderID: orderID, + servicePointID: val(qOrder.ServicePointID), + title: taskTitle + }); + + writeLog(file="stripe_webhooks", text="Kitchen task created for order #orderID#"); + } } // === WORKER PAYOUT TRANSFER === diff --git a/api/tasks/callServer.cfm b/api/tasks/callServer.cfm index f29fb04..7cd7de3 100644 --- a/api/tasks/callServer.cfm +++ b/api/tasks/callServer.cfm @@ -36,6 +36,16 @@ try { apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "BusinessID is required" }); } + // If servicePointID not provided but orderID is, look it up from the order + if (servicePointID == 0 && orderID > 0) { + qOrderSP = queryExecute(" + SELECT ServicePointID FROM Orders WHERE ID = :orderID + ", { orderID: { value: orderID, cfsqltype: "cf_sql_integer" } }, { datasource: "payfrit" }); + if (qOrderSP.recordCount && val(qOrderSP.ServicePointID) > 0) { + servicePointID = val(qOrderSP.ServicePointID); + } + } + if (servicePointID == 0) { apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "ServicePointID is required" }); } diff --git a/api/tasks/complete.cfm b/api/tasks/complete.cfm index bef643e..c9f7834 100644 --- a/api/tasks/complete.cfm +++ b/api/tasks/complete.cfm @@ -297,6 +297,26 @@ + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + @@ -345,7 +391,7 @@ :sentBy, :receivedBy, :orderID, 0, 0, :cashAmount, :payfritCut, 0, :bizFee, - 'Cash payment', NOW() + :remark, NOW() ) ", { sentBy: customerUserID, @@ -353,7 +399,8 @@ orderID: qTask.OrderID, cashAmount: CashReceivedCents / 100, payfritCut: payfritRevenueCents / 100, - bizFee: round(businessFeeDollars * 100) / 100 + bizFee: round(businessFeeDollars * 100) / 100, + remark: isAdmin ? "Cash payment (collected by manager)" : "Cash payment" }, { datasource = "payfrit" })> @@ -430,6 +477,8 @@ + + diff --git a/api/tasks/createChat.cfm b/api/tasks/createChat.cfm index ef78839..1a7a06a 100644 --- a/api/tasks/createChat.cfm +++ b/api/tasks/createChat.cfm @@ -35,6 +35,16 @@ try { apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "BusinessID is required" }); } + // If servicePointID not provided but orderID is, look it up from the order + if (servicePointID == 0 && orderID > 0) { + qOrderSP = queryTimed(" + SELECT ServicePointID FROM Orders WHERE ID = :orderID + ", { orderID: { value: orderID, cfsqltype: "cf_sql_integer" } }, { datasource: "payfrit" }); + if (qOrderSP.recordCount && val(qOrderSP.ServicePointID) > 0) { + servicePointID = val(qOrderSP.ServicePointID); + } + } + // Look up "Chat With Staff" task type for this business ttQuery = queryTimed(" SELECT ID FROM tt_TaskTypes diff --git a/api/workers/myBusinesses.cfm b/api/workers/myBusinesses.cfm index af0d866..d751373 100644 --- a/api/workers/myBusinesses.cfm +++ b/api/workers/myBusinesses.cfm @@ -40,7 +40,7 @@ e.BusinessID, MIN(e.StatusID) AS StatusID, MAX(e.IsActive) AS IsActive, - MAX(e.RoleID) AS RoleID, + MAX(COALESCE(e.RoleID, 1)) AS RoleID, b.Name AS Name, (SELECT COUNT(*) FROM Tasks t WHERE t.BusinessID = e.BusinessID AND t.ClaimedByUserID = 0 AND t.CompletedOn IS NULL) AS PendingTaskCount, (SELECT COUNT(*) FROM Tasks t WHERE t.BusinessID = e.BusinessID AND t.ClaimedByUserID = ? AND t.CompletedOn IS NULL) AS ActiveTaskCount