false, 'ERROR' => 'missing_params', 'MESSAGE' => 'OrderID and StatusID are required.']); } try { $qOrder = queryOne(" 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 ", [$OrderID]); if (!$qOrder) { apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Order not found.']); } $oldStatusID = (int) $qOrder['StatusID']; queryTimed("UPDATE Orders SET StatusID = ?, LastEditedOn = NOW() WHERE ID = ?", [$NewStatusID, $OrderID]); // Create tasks when order moves to status 3 require __DIR__ . '/_createOrderTasks.php'; jsonResponse([ 'OK' => true, 'ERROR' => '', 'MESSAGE' => 'Order status updated successfully.', 'OrderID' => $OrderID, 'StatusID' => $NewStatusID, 'TaskCreated' => $taskCreated, ]); } catch (Exception $e) { jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => 'DB error updating order status', 'DETAIL' => $e->getMessage()]); }