update orders types

This commit is contained in:
Flatlogic Bot 2026-04-03 10:00:15 +00:00
parent 44b7842f7d
commit 8f58dec2a3
10 changed files with 61 additions and 23 deletions

View File

@ -131,7 +131,8 @@ $vat_rate = (float)($company_settings['vat_rate'] ?? 0);
<div><strong>Date:</strong> <?= date('M d, Y H:i', strtotime($order['created_at'])) ?></div>
<div><strong>Status:</strong> <?= ucfirst($order['status']) ?></div>
<div><strong>Payment:</strong> <?= htmlspecialchars($order['payment_type_name'] ?? 'N/A') ?></div>
<div><strong>Type:</strong> <?= ucfirst($order['order_type']) ?></div>
<div><strong>Type:</strong> <?= ucfirst($order["order_type"]) ?></div>
<div><strong>Source:</strong> <?= match($order["source"] ?? "pos") { "online" => "Online", "qr" => "QR Order", default => "POS" } ?></div>
</div>
</div>
</div>
@ -261,10 +262,14 @@ $vat_rate = (float)($company_settings['vat_rate'] ?? 0);
<div class="mb-3">
<label class="text-muted small d-block">Outlet</label>
<div class="fw-bold"><?= htmlspecialchars($order['outlet_name'] ?? 'N/A') ?></div>
</div>
<div class="mb-3">
<label class="text-muted small d-block">Order Source</label>
<div class="fw-bold"><?= match($order["source"] ?? "pos") { "online" => "Online", "qr" => "QR Order", default => "POS" } ?></div>
</div>
<div class="mb-3">
<label class="text-muted small d-block">Order Type</label>
<div class="fw-bold"><?= ucfirst($order['order_type']) ?></div>
<div class="fw-bold"><?= ucfirst($order["order_type"]) ?></div>
</div>
<?php if ($order['order_type'] === 'dine-in'): ?>
<div class="mb-3">
@ -362,6 +367,7 @@ function printThermalReceipt() {
vat: <?= (float)$order['vat'] ?>,
discount: <?= (float)$order['discount'] ?>,
orderType: '<?= $order['order_type'] ?>',
source: '<?= $order['source'] ?? 'pos' ?>',
tableNumber: '<?= $order['table_number'] ?>',
date: '<?= date('M d, Y H:i', strtotime($order['created_at'])) ?>',
paymentMethod: '<?= $order['payment_type_name'] ?? 'Unpaid' ?>',
@ -492,10 +498,15 @@ function printThermalReceipt() {
<span><strong>Order:</strong> #${data.orderId}</span>
<span><strong>${tr['Order']}:</strong> #${data.orderId}</span>
</div>
<div class="order-info-row">
<div class="order-info-row">
<span><strong>Type:</strong> ${data.orderType.toUpperCase()}</span>
<span><strong>${tr['Type']}:</strong> ${tr[data.orderType] || data.orderType}</span>
</div>
${data.source ? \`
<div class="order-info-row">
<span><strong>Source:</strong> ${data.source.toUpperCase()}</span>
<span><strong>${tr['Source'] || "Source"}:</strong> ${data.source.toUpperCase()}</span>
</div>\` : ""}
<div class="order-info-row">
<span><strong>Date:</strong> ${data.date}</span>
<span><strong>${tr['Date']}:</strong> ${data.date}</span>

View File

@ -321,16 +321,27 @@ include 'includes/header.php';
<?php endif; ?>
</td>
<td>
<?php
$badge = match($order['order_type']) {
'dine-in' => 'bg-info',
'takeaway' => 'bg-success',
'delivery' => 'bg-warning',
'drive-thru' => 'bg-primary',
default => 'bg-secondary'
<?php
$badge = match($order["order_type"]) {
"dine-in" => "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"
};
?>
<span class="badge <?= $badge ?> text-dark bg-opacity-25 border border-<?= str_replace('bg-', '', $badge) ?>"><?= ucfirst($order['order_type']) ?></span>
<span class="badge <?= $badge ?> text-dark bg-opacity-25 border border-<?= str_replace("bg-", "", $badge) ?> mb-1"><?= ucfirst($order["order_type"]) ?></span><br>
<span class="badge <?= $source_badge ?> text-white"><?= $source_name ?></span>
</td>
<td>
<span class="text-muted small"><?= format_currency($order['vat']) ?></span>

View File

@ -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

View File

@ -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 = [];

View File

@ -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', () => {
<div class="divider"></div>
<div class="order-info">
<div class="order-info-row"><span><strong>Order:</strong> #${data.orderId}</span><span><strong>${tr['Order']}:</strong> #${data.orderId}</span></div>
<div class="order-info-row"><span><strong>Type:</strong> ${data.orderType.toUpperCase()}</span><span><strong>${tr['Type']}:</strong> ${tr[data.orderType] || data.orderType}</span></div>
<div class="order-info-row"><span><strong>Type:</strong> ${data.orderType.toUpperCase()}</span><span><strong>${tr['Type']}:</strong> ${tr[data.orderType] || data.orderType}</span></div>
${data.source ? \`<div class="order-info-row"><span><strong>Source:</strong> ${data.source.toUpperCase()}</span><span><strong>${tr['Source'] || "Source"}:</strong> ${data.source.toUpperCase()}</span></div>\` : ""}
<div class="order-info-row"><span><strong>Date:</strong> ${data.date}</span><span><strong>${tr['Date']}:</strong> ${data.date}</span></div>
<div class="order-info-row"><span><strong>Staff:</strong> ${CURRENT_USER.name}</span><span><strong>${tr['Staff']}:</strong> ${CURRENT_USER.name}</span></div>
</div>

View File

@ -0,0 +1 @@
ALTER TABLE orders ADD COLUMN source VARCHAR(50) DEFAULT 'pos';

View File

@ -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";

View File

@ -282,7 +282,8 @@ function renderOrders(orders) {
</div>
<div class="card-body">
<h5 class="card-title mb-3">
${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()}
<br><small class="text-white badge bg-dark opacity-75">${order.source ? order.source.toUpperCase() : "POS"}</small>
${order.customer_name ? `<br><small class="text-muted">${order.customer_name}</small>` : ''}
${order.car_plate ? `<br><small class="text-muted"><i class="bi bi-car-front"></i> ${order.car_plate}</small>` : ''}
${order.ready_time ? `<br><small class="text-danger fw-bold countdown-timer" data-ready-time="${new Date(order.ready_time).getTime()}"><i class="bi bi-clock-history"></i> <span></span></small>` : ''}
@ -348,7 +349,8 @@ function printKitchenTicket(orderId) {
<div style="font-size: 24px; font-weight: bold;">#${order.id}</div>
</div>
<div class="info">
<div><strong>Type:</strong> ${order.order_type.toUpperCase()}</div>
<div><strong>Type:</strong> ${order.order_type.toUpperCase()}</div>
<div><strong>Source:</strong> ${order.source ? order.source.toUpperCase() : "POS"}</div>
${order.order_type === 'dine-in' ? `<div><strong>Table:</strong> ${order.table_number}</div>` : ''}
<div><strong>Time:</strong> ${new Date(order.created_at).toLocaleString()}</div>
${order.customer_name ? `<div><strong>Cust:</strong> ${order.customer_name}</div>` : ''}

View File

@ -871,6 +871,7 @@ foreach ($variants_by_product as $pid => $vars) {
}
const orderData = {
source: 'online',
table_id: <?= $table_id ?>,
outlet_id: <?= $outlet_id ?>,
items: cart.map(item => ({

View File

@ -698,6 +698,7 @@ foreach ($variants_raw as $v) {
if (cart.length === 0) return;
const orderData = {
source: 'qr',
table_id: <?= $table_id ?>,
outlet_id: <?= $outlet_id ?>,
items: cart.map(item => ({