84 lines
4.0 KiB
PHP
84 lines
4.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/header.php';
|
|
|
|
$customers = [];
|
|
try {
|
|
$stmt = db()->query("SELECT * FROM customers ORDER BY name ASC");
|
|
$customers = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
// Handle error
|
|
}
|
|
?>
|
|
|
|
<div class="container">
|
|
<div style="display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 2rem;">
|
|
<div>
|
|
<h2 style="font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem;">Managed Customers</h2>
|
|
<p style="color: var(--text-muted); font-size: 0.875rem;">List of all customers and their current status.</p>
|
|
</div>
|
|
<a href="add_customer.php" class="btn btn-primary">
|
|
<i class="bi bi-person-plus" style="margin-right: 0.5rem;"></i> Add Customer
|
|
</a>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Customer Name</th>
|
|
<th>Email</th>
|
|
<th>Status</th>
|
|
<th>Onboarding Progress</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($customers)): ?>
|
|
<tr>
|
|
<td colspan="5" style="text-align: center; color: var(--text-muted); padding: 4rem;">
|
|
No customers found. <a href="add_customer.php" style="color: var(--primary);">Add your first customer.</a>
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($customers as $customer): ?>
|
|
<tr>
|
|
<td style="font-weight: 600;"><?php echo htmlspecialchars($customer['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($customer['contact_email'] ?? 'N/A'); ?></td>
|
|
<td><span class="badge badge-<?php echo $customer['status']; ?>"><?php echo $customer['status']; ?></span></td>
|
|
<td>
|
|
<?php
|
|
$progress = 0;
|
|
try {
|
|
$stmt = db()->prepare("SELECT COUNT(*) as total, SUM(CASE WHEN is_completed = 1 THEN 1 ELSE 0 END) as completed FROM onboarding_tasks WHERE customer_id = ?");
|
|
$stmt->execute([$customer['id']]);
|
|
$row = $stmt->fetch();
|
|
if ($row && $row['total'] > 0) {
|
|
$progress = round(($row['completed'] / $row['total']) * 100);
|
|
}
|
|
} catch (PDOException $e) {}
|
|
?>
|
|
<div style="width: 100px; height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle;">
|
|
<div style="width: <?php echo (int)$progress; ?>%; height: 100%; background: var(--success);"></div>
|
|
</div>
|
|
<span style="font-size: 0.75rem; margin-left: 0.5rem; font-weight: 600;"><?php echo (int)$progress; ?>%</span>
|
|
</td>
|
|
<td>
|
|
<div style="display: flex; gap: 0.5rem;">
|
|
<a href="onboarding.php?id=<?php echo $customer['id']; ?>" class="btn btn-outline" style="padding: 0.25rem 0.5rem;" title="View Onboarding">
|
|
<i class="bi bi-list-check"></i>
|
|
</a>
|
|
<a href="#" class="btn btn-outline" style="padding: 0.25rem 0.5rem;" title="Edit Details">
|
|
<i class="bi bi-pencil-square"></i>
|
|
</a>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/footer.php'; ?>
|