WebOrbiton
v1.0.0.0

StocketBase

71 lines · 2.6 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (count(get_included_files()) === 1) {
  6. http_response_code(403);
  7. exit;
  8. }
  9. ​
  10. require_once __DIR__ . '/../includes/currency.php';
  11. ​
  12. if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)) {
  13. echo '<p>You do not have permission to manage orders.</p>';
  14. return;
  15. }
  16. ​
  17. $usersDb = Database::users();
  18. ​
  19. $statusFilter = (string) ($_GET['status'] ?? '');
  20. $allowedStatuses = ['pending', 'paid', 'processing', 'fulfilled', 'shipped', 'completed', 'canceled', 'refunded', 'failed'];
  21. ​
  22. $baseQuery = 'SELECT o.*, u.email AS account_email FROM orders o LEFT JOIN user_accounts u ON u.id = o.user_account_id';
  23. ​
  24. if (in_array($statusFilter, $allowedStatuses, true)) {
  25. $statement = $usersDb->prepare($baseQuery . ' WHERE o.status = :status ORDER BY o.created_at DESC LIMIT 200');
  26. $statement->execute(['status' => $statusFilter]);
  27. } else {
  28. $statement = $usersDb->query($baseQuery . ' ORDER BY o.created_at DESC LIMIT 200');
  29. }
  30. $orders = $statement->fetchAll();
  31. ​
  32. ?>
  33. <div class="dash-header-row">
  34. <h1 class="dash-title"><?= Icons::icon('checklist', 'icon icon-lg') ?>Orders</h1>
  35. </div>
  36. ​
  37. <div class="settings-tabs">
  38. <a href="dashboard.php?view=orders" class="<?= $statusFilter === '' ? 'active' : '' ?>">All</a>
  39. <?php foreach ($allowedStatuses as $status): ?>
  40. <a href="dashboard.php?view=orders&status=<?= urlencode($status) ?>" class="<?= $statusFilter === $status ? 'active' : '' ?>"><?= htmlspecialchars(ucfirst($status)) ?></a>
  41. <?php endforeach; ?>
  42. </div>
  43. ​
  44. <table class="dash-table">
  45. <thead>
  46. <tr>
  47. <th><?= Icons::icon('hash', 'icon icon-sm') ?>Order</th>
  48. <th><?= Icons::icon('user', 'icon icon-sm') ?>Customer</th>
  49. <th><?= Icons::icon('dollar', 'icon icon-sm') ?>Total</th>
  50. <th><?= Icons::icon('flag', 'icon icon-sm') ?>Status</th>
  51. <th><?= Icons::icon('clock', 'icon icon-sm') ?>Placed</th>
  52. <th></th>
  53. </tr>
  54. </thead>
  55. <tbody>
  56. <?php foreach ($orders as $order): ?>
  57. <tr>
  58. <td><?= htmlspecialchars($order['order_number']) ?></td>
  59. <td><?= htmlspecialchars((string) ($order['account_email'] ?: $order['guest_email'] ?: '—')) ?></td>
  60. <td><?= htmlspecialchars(Currency::format((int) $order['total_cents'], $order['currency'])) ?></td>
  61. <td><span class="status-pill status-<?= htmlspecialchars($order['status']) ?>"><?= htmlspecialchars($order['status']) ?></span></td>
  62. <td><?= htmlspecialchars($order['created_at']) ?></td>
  63. <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>
  64. </tr>
  65. <?php endforeach; ?>
  66. <?php if (empty($orders)): ?>
  67. <tr><td colspan="6">No orders found.</td></tr>
  68. <?php endif; ?>
  69. </tbody>
  70. </table>
  71. ​