From 07abcee2fdc49116b272f20a072b3b4845d72b96 Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Mon, 16 Mar 2026 20:02:02 -0700 Subject: [PATCH] Create kitchen task on order submission for KDS display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit submitCash.php had no task creation — cash orders were invisible to KDS. submit.php also lacked it (tab orders never hit webhook.php). Both now create "Prepare Order #X for Table" task at StatusID=1. submit.php includes duplicate guard since webhook.php also creates tasks for card payments. Co-Authored-By: Claude Opus 4.6 (1M context) --- api/orders/submit.php | 21 +++++++++++++++++++++ api/orders/submitCash.php | 16 ++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/api/orders/submit.php b/api/orders/submit.php index a24e5a3..23d9dfd 100644 --- a/api/orders/submit.php +++ b/api/orders/submit.php @@ -191,6 +191,27 @@ try { [$OrderID] ); + // Create kitchen task for KDS display + $spID = (int) ($qOrder['ServicePointID'] ?? 0); + $spName = 'Table'; + if ($spID > 0) { + $qSP = queryOne("SELECT Name FROM ServicePoints WHERE ID = ?", [$spID]); + $spName = !empty(trim($qSP['Name'] ?? '')) ? $qSP['Name'] : 'Table'; + } + $taskTitle = "Prepare Order #{$OrderID} for {$spName}"; + + // Prevent duplicates (webhook.php also creates a task for card payments) + $qExistingTask = queryOne( + "SELECT ID FROM Tasks WHERE OrderID = ? AND Title LIKE 'Prepare Order%' LIMIT 1", + [$OrderID] + ); + if (!$qExistingTask) { + queryTimed(" + INSERT INTO Tasks (BusinessID, OrderID, ServicePointID, Title, CreatedOn, ClaimedByUserID) + VALUES (?, ?, ?, ?, NOW(), 0) + ", [$qOrder['BusinessID'], $OrderID, $spID > 0 ? $spID : null, $taskTitle]); + } + // Tab running total update if ($tabID > 0) { queryTimed("UPDATE Tabs SET LastActivityOn = NOW() WHERE ID = ?", [$tabID]); diff --git a/api/orders/submitCash.php b/api/orders/submitCash.php index c541b72..508025e 100644 --- a/api/orders/submitCash.php +++ b/api/orders/submitCash.php @@ -98,6 +98,22 @@ try { WHERE ID = ? ", [$PaymentID, $paymentStatus, $platformFee, $Tip, $balanceApplied, $fullyPaidByBalance ? 1 : 0, $OrderID]); + // Create kitchen task for KDS display (same as webhook.php does for card payments) + $spName = ''; + $spID = (int) ($qOrder['ServicePointID'] ?? 0); + if ($spID > 0) { + $qSP = queryOne("SELECT Name FROM ServicePoints WHERE ID = ?", [$spID]); + $spName = !empty(trim($qSP['Name'] ?? '')) ? $qSP['Name'] : 'Table'; + } else { + $spName = 'Table'; + } + $taskTitle = "Prepare Order #{$OrderID} for {$spName}"; + + queryTimed(" + INSERT INTO Tasks (BusinessID, OrderID, ServicePointID, Title, CreatedOn, ClaimedByUserID) + VALUES (?, ?, ?, ?, NOW(), 0) + ", [$qOrder['BusinessID'], $OrderID, $spID > 0 ? $spID : null, $taskTitle]); + $response = [ 'OK' => true, 'OrderID' => $OrderID,