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 view customers.</p>';
- return;
- }
-
- $usersDb = Database::users();
-
- $customers = $usersDb->query(
- "SELECT u.*, COUNT(o.id) AS order_count, COALESCE(SUM(CASE WHEN o.status IN ('paid','processing','fulfilled','shipped','completed') THEN o.total_cents ELSE 0 END), 0) AS lifetime_value
- FROM user_accounts u LEFT JOIN orders o ON o.user_account_id = u.id
- GROUP BY u.id ORDER BY u.created_at DESC"
- )->fetchAll();
-
- $storeCurrency = SiteFront::settings()['store_currency'] ?? 'USD';
-
- ?>
- <h1 class="dash-title"><?= Icons::icon("users", "icon icon-lg") ?>Customers</h1>
-
- <table class="dash-table">
- <thead>
- <tr>
- <th><?= Icons::icon('heading', 'icon icon-sm') ?>Name</th>
- <th><?= Icons::icon('user', 'icon icon-sm') ?>Email</th>
- <th><?= Icons::icon('checklist', 'icon icon-sm') ?>Orders</th>
- <th><?= Icons::icon('dollar', 'icon icon-sm') ?>Lifetime value</th>
- <th><?= Icons::icon('flag', 'icon icon-sm') ?>Status</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($customers as $customer): ?>
- <tr>
- <td><?= htmlspecialchars((string) ($customer['display_name'] ?? '—')) ?></td>
- <td><?= htmlspecialchars($customer['email']) ?></td>
- <td><?= (int) $customer['order_count'] ?></td>
- <td><?= htmlspecialchars(Currency::format((int) $customer['lifetime_value'], $storeCurrency)) ?></td>
- <td><span class="status-pill status-<?= $customer['status'] === 'active' ? 'published' : 'rejected' ?>"><?= htmlspecialchars($customer['status']) ?></span></td>
- <td class="dash-table-actions"><a href="dashboard.php?view=customer-detail&id=<?= (int) $customer['id'] ?>" class="dash-btn-small"><?= Icons::icon('eye', 'icon icon-sm') ?>View</a></td>
- </tr>
- <?php endforeach; ?>
- <?php if (empty($customers)): ?>
- <tr><td colspan="6">No customers yet.</td></tr>
- <?php endif; ?>
- </tbody>
- </table>
- <?php if (Auth::hasRoleAtLeast(Auth::ROLE_SUPER_ADMIN)): ?>
- <p style="font-size:12.5px;color:var(--muted);margin-top:12px;">To suspend or reactivate a customer account, use <a href="admin.php?tab=customers">Team accounts → Customer accounts</a>.</p>
- <?php endif; ?>
-