From 8f58dec2a3376ebebafc7261bdbc8180dd361941 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 3 Apr 2026 10:00:15 +0000 Subject: [PATCH] update orders types --- admin/order_view.php | 17 +++++++++++--- admin/orders.php | 27 +++++++++++++++------- api/kitchen.php | 2 +- api/order.php | 20 +++++++++------- assets/js/main.js | 4 +++- db/migrations/050_add_source_to_orders.sql | 1 + includes/PrinterService.php | 5 ++++ kitchen.php | 6 +++-- online_order.php | 1 + qorder.php | 1 + 10 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 db/migrations/050_add_source_to_orders.sql diff --git a/admin/order_view.php b/admin/order_view.php index debcb03..f747b8e 100644 --- a/admin/order_view.php +++ b/admin/order_view.php @@ -131,7 +131,8 @@ $vat_rate = (float)($company_settings['vat_rate'] ?? 0);
Date:
Status:
Payment:
-
Type:
+
Type:
+
Source: "Online", "qr" => "QR Order", default => "POS" } ?>
@@ -261,10 +262,14 @@ $vat_rate = (float)($company_settings['vat_rate'] ?? 0);
+
+
+ +
"Online", "qr" => "QR Order", default => "POS" } ?>
-
+
@@ -362,6 +367,7 @@ function printThermalReceipt() { vat: , discount: , orderType: '', + source: '', tableNumber: '', date: '', paymentMethod: '', @@ -492,10 +498,15 @@ function printThermalReceipt() { Order: #${data.orderId} ${tr['Order']}: #${data.orderId}
-
+
Type: ${data.orderType.toUpperCase()} ${tr['Type']}: ${tr[data.orderType] || data.orderType}
+ ${data.source ? \` +
+ Source: ${data.source.toUpperCase()} + ${tr['Source'] || "Source"}: ${data.source.toUpperCase()} +
\` : ""}
Date: ${data.date} ${tr['Date']}: ${data.date} diff --git a/admin/orders.php b/admin/orders.php index 9422f25..3929f05 100644 --- a/admin/orders.php +++ b/admin/orders.php @@ -321,16 +321,27 @@ include 'includes/header.php'; - 'bg-info', - 'takeaway' => 'bg-success', - 'delivery' => 'bg-warning', - 'drive-thru' => 'bg-primary', - default => 'bg-secondary' + "bg-info", + "takeaway" => "bg-success", + "delivery" => "bg-warning", + "drive-thru" => "bg-primary", + default => "bg-secondary" + }; + $source_name = match($order["source"] ?? "pos") { + "online" => "Online", + "qr" => "QR Order", + default => "POS" + }; + $source_badge = match($order["source"] ?? "pos") { + "online" => "bg-success", + "qr" => "bg-info", + default => "bg-secondary" }; ?> - + mb-1">
+ diff --git a/api/kitchen.php b/api/kitchen.php index 19a2acb..617693b 100644 --- a/api/kitchen.php +++ b/api/kitchen.php @@ -14,7 +14,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { // Kitchen sees: pending, preparing, ready $stmt = $pdo->prepare(" SELECT - o.id, o.table_number, o.order_type, o.status, o.created_at, o.ready_time, o.customer_name, o.car_plate, o.user_id, + o.id, o.table_number, o.order_type, o.source, o.status, o.created_at, o.ready_time, o.customer_name, o.car_plate, o.user_id, oi.quantity, COALESCE(p.name, oi.product_name) as product_name, COALESCE(v.name, oi.variant_name) as variant_name FROM orders o JOIN order_items oi ON o.id = oi.order_id diff --git a/api/order.php b/api/order.php index 7f47608..94f22e6 100644 --- a/api/order.php +++ b/api/order.php @@ -26,6 +26,9 @@ try { : 'dine-in'; // Get outlet_id from input, default to 1 if missing + $allowed_sources = ['pos', 'online', 'qr']; + $source = isset($data['source']) && in_array($data['source'], $allowed_sources) ? $data['source'] : 'pos'; + $outlet_id = !empty($data['outlet_id']) ? intval($data['outlet_id']) : 1; $table_id = null; @@ -89,7 +92,7 @@ try { if ($existing) { $customer_id = $existing['id']; } else { - $stmt = $pdo->prepare("INSERT INTO customers (name, phone) VALUES (?, ?)"); + $stmt = $pdo->prepare("INSERT INTO customers (name, phone) VALUES (?, ?, ?)"); $stmt->execute([$customer_name, $customer_phone]); $customer_id = $pdo->lastInsertId(); } @@ -251,7 +254,7 @@ try { ->execute([$redemptions_done, $customer_id]); // Record Loyalty History (Deduction) - $historyStmt = $pdo->prepare("INSERT INTO loyalty_points_history (customer_id, points_change, reason) VALUES (?, ?, 'Redeemed Free Product(s)')"); + $historyStmt = $pdo->prepare("INSERT INTO loyalty_points_history (customer_id, points_change, reason) VALUES (?, ?, ?, 'Redeemed Free Product(s)')"); $historyStmt->execute([$customer_id, -$points_deducted]); $redeem_history_id = $pdo->lastInsertId(); @@ -290,7 +293,7 @@ try { $awardStmt->execute([$points_awarded, $customer_id]); // Record Loyalty History (Award) - $historyStmt = $pdo->prepare("INSERT INTO loyalty_points_history (customer_id, points_change, reason) VALUES (?, ?, 'Earned from Products')"); + $historyStmt = $pdo->prepare("INSERT INTO loyalty_points_history (customer_id, points_change, reason) VALUES (?, ?, ?, 'Earned from Products')"); $historyStmt->execute([$customer_id, $points_awarded]); $award_history_id = $pdo->lastInsertId(); } @@ -335,14 +338,15 @@ try { } if ($is_update) { - $stmt = $pdo->prepare("UPDATE orders SET + $stmt = $pdo->prepare("UPDATE orders SET + source = ?, outlet_id = ?, table_id = ?, table_number = ?, order_type = ?, customer_id = ?, customer_name = ?, customer_phone = ?, car_plate = ?, ready_time = ?, payment_type_id = ?, total_amount = ?, discount = ?, vat = ?, user_id = ?, commission_amount = ?, status = 'pending' WHERE id = ?"); $stmt->execute([ - $outlet_id, $table_id, $table_number, $order_type, + $source, $outlet_id, $table_id, $table_number, $order_type, $customer_id, $customer_name, $customer_phone, $car_plate, $ready_time, $payment_type_id, $final_total, 0, $calculated_vat, $user_id, $commission_amount, $order_id @@ -351,8 +355,8 @@ try { $delStmt = $pdo->prepare("DELETE FROM order_items WHERE order_id = ?"); $delStmt->execute([$order_id]); } else { - $stmt = $pdo->prepare("INSERT INTO orders (outlet_id, table_id, table_number, order_type, customer_id, customer_name, customer_phone, car_plate, ready_time, payment_type_id, total_amount, discount, vat, user_id, commission_amount, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending')"); - $stmt->execute([$outlet_id, $table_id, $table_number, $order_type, $customer_id, $customer_name, $customer_phone, $car_plate, $ready_time, $payment_type_id, $final_total, 0, $calculated_vat, $user_id, $commission_amount]); + $stmt = $pdo->prepare("INSERT INTO orders (source, outlet_id, table_id, table_number, order_type, customer_id, customer_name, customer_phone, car_plate, ready_time, payment_type_id, total_amount, discount, vat, user_id, commission_amount, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending')"); + $stmt->execute([$source, $outlet_id, $table_id, $table_number, $order_type, $customer_id, $customer_name, $customer_phone, $car_plate, $ready_time, $payment_type_id, $final_total, 0, $calculated_vat, $user_id, $commission_amount]); $order_id = $pdo->lastInsertId(); } @@ -367,7 +371,7 @@ try { } // Insert Items and Update Stock - $item_stmt = $pdo->prepare("INSERT INTO order_items (order_id, product_id, product_name, variant_id, variant_name, quantity, unit_price, vat_percent, vat_amount) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $item_stmt = $pdo->prepare("INSERT INTO order_items (order_id, product_id, product_name, variant_id, variant_name, quantity, unit_price, vat_percent, vat_amount) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stock_stmt = $pdo->prepare("UPDATE products SET stock_quantity = stock_quantity - ? WHERE id = ?"); $order_items_list = []; diff --git a/assets/js/main.js b/assets/js/main.js index 5f0b592..b4aae23 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -769,6 +769,7 @@ document.addEventListener('DOMContentLoaded', () => { total: isLoyaltyRedemption ? 0 : (subtotal + totalVat), vat: isLoyaltyRedemption ? 0 : totalVat, orderType: orderType, + source: 'pos', tableNumber: (orderType === 'dine-in') ? currentTableName : null, date: new Date().toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }), paymentMethod: paymentTypeName || (isLoyaltyRedemption ? 'Loyalty Redeem' : 'Unpaid'), @@ -939,7 +940,8 @@ document.addEventListener('DOMContentLoaded', () => {
Order: #${data.orderId}${tr['Order']}: #${data.orderId}
-
Type: ${data.orderType.toUpperCase()}${tr['Type']}: ${tr[data.orderType] || data.orderType}
+
Type: ${data.orderType.toUpperCase()}${tr['Type']}: ${tr[data.orderType] || data.orderType}
+ ${data.source ? \`
Source: ${data.source.toUpperCase()}${tr['Source'] || "Source"}: ${data.source.toUpperCase()}
\` : ""}
Date: ${data.date}${tr['Date']}: ${data.date}
Staff: ${CURRENT_USER.name}${tr['Staff']}: ${CURRENT_USER.name}
diff --git a/db/migrations/050_add_source_to_orders.sql b/db/migrations/050_add_source_to_orders.sql new file mode 100644 index 0000000..ba34ae0 --- /dev/null +++ b/db/migrations/050_add_source_to_orders.sql @@ -0,0 +1 @@ +ALTER TABLE orders ADD COLUMN source VARCHAR(50) DEFAULT 'pos'; diff --git a/includes/PrinterService.php b/includes/PrinterService.php index 9707195..63a0d2f 100644 --- a/includes/PrinterService.php +++ b/includes/PrinterService.php @@ -58,6 +58,11 @@ class PrinterService { $out .= $esc . "a" . "\x00"; // Left align $out .= "Order ID: #" . $order['id'] . "\n"; + $out .= "Type: " . strtoupper($order['order_type'] ?? '') . "\n"; + if (!empty($order['table_number'])) { + $out .= "Table: " . $order['table_number'] . "\n"; + } + $out .= "Source: " . strtoupper($order['source'] ?? 'POS') . "\n"; $out .= "Date: " . ($order['created_at'] ?? date('Y-m-d H:i:s')) . "\n"; if (!empty($order['customer_name'])) { $out .= "Customer: " . $order['customer_name'] . "\n"; diff --git a/kitchen.php b/kitchen.php index fa2ed5c..77d83cb 100644 --- a/kitchen.php +++ b/kitchen.php @@ -282,7 +282,8 @@ function renderOrders(orders) {
- ${order.order_type === 'dine-in' ? `Table ${order.table_number}` : order.order_type.toUpperCase()} + ${order.order_type === 'dine-in' ? \`Table ${order.table_number}\` : order.order_type.toUpperCase()} +
${order.source ? order.source.toUpperCase() : "POS"} ${order.customer_name ? `
${order.customer_name}` : ''} ${order.car_plate ? `
${order.car_plate}` : ''} ${order.ready_time ? `
` : ''} @@ -348,7 +349,8 @@ function printKitchenTicket(orderId) {
#${order.id}
-
Type: ${order.order_type.toUpperCase()}
+
Type: ${order.order_type.toUpperCase()}
+
Source: ${order.source ? order.source.toUpperCase() : "POS"}
${order.order_type === 'dine-in' ? `
Table: ${order.table_number}
` : ''}
Time: ${new Date(order.created_at).toLocaleString()}
${order.customer_name ? `
Cust: ${order.customer_name}
` : ''} diff --git a/online_order.php b/online_order.php index 174d6d6..6c746da 100644 --- a/online_order.php +++ b/online_order.php @@ -871,6 +871,7 @@ foreach ($variants_by_product as $pid => $vars) { } const orderData = { + source: 'online', table_id: , outlet_id: , items: cart.map(item => ({ diff --git a/qorder.php b/qorder.php index 3911a9a..56f35ea 100644 --- a/qorder.php +++ b/qorder.php @@ -698,6 +698,7 @@ foreach ($variants_raw as $v) { if (cart.length === 0) return; const orderData = { + source: 'qr', table_id: , outlet_id: , items: cart.map(item => ({