130 lines
6.4 KiB
PHP
130 lines
6.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
if (isset($_POST['action']) && $_POST['action'] === 'update_status') {
|
|
$order_id = $_POST['order_id'];
|
|
$new_status = $_POST['status'];
|
|
$stmt = $pdo->prepare("UPDATE orders SET status = ? WHERE id = ?");
|
|
$stmt->execute([$new_status, $order_id]);
|
|
header("Location: orders.php");
|
|
exit;
|
|
}
|
|
|
|
$query = "SELECT o.*,
|
|
(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
|
|
ORDER BY o.created_at DESC";
|
|
|
|
$orders_pagination = paginate_query($pdo, $query);
|
|
$orders = $orders_pagination['data'];
|
|
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="fw-bold mb-0">Order Management</h2>
|
|
<span class="badge bg-success bg-opacity-10 text-success border border-success px-3 py-2 rounded-pill">
|
|
<i class="bi bi-circle-fill small me-1"></i> Live
|
|
</span>
|
|
</div>
|
|
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body p-0">
|
|
<!-- Pagination Controls -->
|
|
<div class="p-3 border-bottom bg-light">
|
|
<?php render_pagination_controls($orders_pagination); ?>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th class="ps-4">ID</th>
|
|
<th>Type</th>
|
|
<th>Source</th>
|
|
<th>Items</th>
|
|
<th>Total</th>
|
|
<th>Status</th>
|
|
<th>Time</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($orders as $order): ?>
|
|
<tr>
|
|
<td class="ps-4 fw-medium">#<?= $order['id'] ?></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'
|
|
};
|
|
?>
|
|
<span class="badge <?= $badge ?> text-dark bg-opacity-25 border border-<?= str_replace('bg-', '', $badge) ?>"><?= ucfirst($order['order_type']) ?></span>
|
|
</td>
|
|
<td>
|
|
<?php if ($order['order_type'] === 'dine-in' && $order['table_number']): ?>
|
|
<span class="badge bg-secondary">Table <?= htmlspecialchars($order['table_number']) ?></span>
|
|
<?php else: ?>
|
|
<span class="badge bg-light text-dark border"><?= ucfirst($order['order_type']) ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><small class="text-muted"><?= htmlspecialchars($order['items_summary']) ?></small></td>
|
|
<td class="fw-bold"><?= format_currency($order['total_amount']) ?></td>
|
|
<td>
|
|
<span class="badge rounded-pill status-<?= $order['status'] ?>">
|
|
<?= ucfirst($order['status']) ?>
|
|
</span>
|
|
</td>
|
|
<td class="text-muted small"><?= date('H:i', strtotime($order['created_at'])) ?></td>
|
|
<td>
|
|
<form method="POST" class="d-flex gap-2">
|
|
<input type="hidden" name="order_id" value="<?= $order['id'] ?>">
|
|
<input type="hidden" name="action" value="update_status">
|
|
|
|
<?php if ($order['status'] === 'pending'): ?>
|
|
<button type="submit" name="status" value="preparing" class="btn btn-sm btn-primary">
|
|
<i class="bi bi-play-fill"></i> Start
|
|
</button>
|
|
<button type="submit" name="status" value="cancelled" class="btn btn-sm btn-outline-danger">
|
|
<i class="bi bi-x"></i>
|
|
</button>
|
|
<?php elseif ($order['status'] === 'preparing'): ?>
|
|
<button type="submit" name="status" value="ready" class="btn btn-sm btn-warning text-dark">
|
|
<i class="bi bi-check-circle"></i> Ready
|
|
</button>
|
|
<?php elseif ($order['status'] === 'ready'): ?>
|
|
<button type="submit" name="status" value="completed" class="btn btn-sm btn-success">
|
|
<i class="bi bi-check-all"></i> Complete
|
|
</button>
|
|
<?php else: ?>
|
|
<span class="text-muted small">-</span>
|
|
<?php endif; ?>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($orders)): ?>
|
|
<tr>
|
|
<td colspan="8" class="text-center py-5 text-muted">
|
|
<i class="bi bi-inbox fs-1 d-block mb-2"></i>
|
|
No active orders.
|
|
</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- Bottom Pagination -->
|
|
<div class="p-3 border-top bg-light">
|
|
<?php render_pagination_controls($orders_pagination); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|