prepare("UPDATE orders SET status = ? WHERE id = ?"); $stmt->execute([$new_status, $order_id]); header("Location: orders.php?" . http_build_query($_GET)); // Keep filters exit; } // Fetch Outlets for Filter $outlets = $pdo->query("SELECT id, name FROM outlets ORDER BY name")->fetchAll(PDO::FETCH_ASSOC); // Build Query with Filters $params = []; $where = []; // Filter: Outlet if (!empty($_GET['outlet_id'])) { $where[] = "o.outlet_id = :outlet_id"; $params[':outlet_id'] = $_GET['outlet_id']; } // Filter: Date Range if (!empty($_GET['start_date'])) { $where[] = "DATE(o.created_at) >= :start_date"; $params[':start_date'] = $_GET['start_date']; } if (!empty($_GET['end_date'])) { $where[] = "DATE(o.created_at) <= :end_date"; $params[':end_date'] = $_GET['end_date']; } // Filter: Search (Order No) if (!empty($_GET['search'])) { // Exact match for ID usually, but LIKE might be more user friendly if they type partial? // "search by order no" usually implies ID. Let's stick to ID or simple LIKE. // If numeric, assume ID. if (is_numeric($_GET['search'])) { $where[] = "o.id = :search"; $params[':search'] = $_GET['search']; } } $where_clause = !empty($where) ? 'WHERE ' . implode(' AND ', $where) : ''; // Changed alias 'out' to 'ot' to avoid reserved keyword conflict // Added join to payment_types to get payment name $query = "SELECT o.*, ot.name as outlet_name, pt.name as payment_type_name, (SELECT GROUP_CONCAT(CONCAT(p.name, ' x', oi.quantity) SEPARATOR ', ') FROM order_items oi JOIN products p ON oi.product_id = p.id WHERE oi.order_id = o.id) as items_summary FROM orders o LEFT JOIN outlets ot ON o.outlet_id = ot.id LEFT JOIN payment_types pt ON o.payment_type_id = pt.id $where_clause ORDER BY o.created_at DESC"; $orders_pagination = paginate_query($pdo, $query, $params); $orders = $orders_pagination['data']; include 'includes/header.php'; ?>
| ID | Outlet | Customer | Type | Source | Items | Total | Payment | Status | Time | Action |
|---|---|---|---|---|---|---|---|---|---|---|
| #= $order['id'] ?> | = htmlspecialchars($order['outlet_name'] ?? 'Unknown') ?> |
= htmlspecialchars($order['customer_name']) ?>
= htmlspecialchars($order['customer_phone']) ?>
Guest
|
'bg-info', 'takeaway' => 'bg-success', 'delivery' => 'bg-warning', 'drive-thru' => 'bg-primary', default => 'bg-secondary' }; ?> = ucfirst($order['order_type']) ?> | Table = htmlspecialchars($order['table_number']) ?> = ucfirst($order['order_type']) ?> | = htmlspecialchars($order['items_summary']) ?> | = format_currency($order['total_amount']) ?> | 'bg-success', 'credit card' => 'bg-primary', 'loyalty redeem' => 'bg-warning', 'unpaid' => 'bg-secondary', default => 'bg-secondary' }; ?> = htmlspecialchars($payment_name) ?> | = ucfirst($order['status']) ?> |
= date('M d', strtotime($order['created_at'])) ?>
= date('H:i', strtotime($order['created_at'])) ?>
|
|
| No active orders found matching your criteria. | ||||||||||