v1.0.0.0
StocketBase
- <?php
-
- declare(strict_types=1);
-
- if (count(get_included_files()) === 1) {
- http_response_code(403);
- exit;
- }
-
- require_once __DIR__ . '/../includes/currency.php';
-
- if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)) {
- echo '<p>You do not have permission to manage orders.</p>';
- return;
- }
-
- $usersDb = Database::users();
-
- $statusFilter = (string) ($_GET['status'] ?? '');
- $allowedStatuses = ['pending', 'paid', 'processing', 'fulfilled', 'shipped', 'completed', 'canceled', 'refunded', 'failed'];
-
- $baseQuery = 'SELECT o.*, u.email AS account_email FROM orders o LEFT JOIN user_accounts u ON u.id = o.user_account_id';
-
- if (in_array($statusFilter, $allowedStatuses, true)) {
- $statement = $usersDb->prepare($baseQuery . ' WHERE o.status = :status ORDER BY o.created_at DESC LIMIT 200');
- $statement->execute(['status' => $statusFilter]);
- } else {
- $statement = $usersDb->query($baseQuery . ' ORDER BY o.created_at DESC LIMIT 200');
- }
- $orders = $statement->fetchAll();
-
- ?>
- <div class="dash-header-row">
- <h1 class="dash-title"><?= Icons::icon('checklist', 'icon icon-lg') ?>Orders</h1>
- </div>
-
- <div class="settings-tabs">
- <a href="dashboard.php?view=orders" class="<?= $statusFilter === '' ? 'active' : '' ?>">All</a>
- <?php foreach ($allowedStatuses as $status): ?>
- <a href="dashboard.php?view=orders&status=<?= urlencode($status) ?>" class="<?= $statusFilter === $status ? 'active' : '' ?>"><?= htmlspecialchars(ucfirst($status)) ?></a>
- <?php endforeach; ?>
- </div>
-
- <table class="dash-table">
- <thead>
- <tr>
- <th><?= Icons::icon('hash', 'icon icon-sm') ?>Order</th>
- <th><?= Icons::icon('user', 'icon icon-sm') ?>Customer</th>
- <th><?= Icons::icon('dollar', 'icon icon-sm') ?>Total</th>
- <th><?= Icons::icon('flag', 'icon icon-sm') ?>Status</th>
- <th><?= Icons::icon('clock', 'icon icon-sm') ?>Placed</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($orders as $order): ?>
- <tr>
- <td><?= htmlspecialchars($order['order_number']) ?></td>
- <td><?= htmlspecialchars((string) ($order['account_email'] ?: $order['guest_email'] ?: '—')) ?></td>
- <td><?= htmlspecialchars(Currency::format((int) $order['total_cents'], $order['currency'])) ?></td>
- <td><span class="status-pill status-<?= htmlspecialchars($order['status']) ?>"><?= htmlspecialchars($order['status']) ?></span></td>
- <td><?= htmlspecialchars($order['created_at']) ?></td>
- <td class="dash-table-actions"><a href="dashboard.php?view=order-detail&id=<?= (int) $order['id'] ?>" class="dash-btn-small"><?= Icons::icon('eye', 'icon icon-sm') ?>View</a></td>
- </tr>
- <?php endforeach; ?>
- <?php if (empty($orders)): ?>
- <tr><td colspan="6">No orders found.</td></tr>
- <?php endif; ?>
- </tbody>
- </table>
-