97 lines
4.5 KiB
PHP
97 lines
4.5 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/header.php';
|
|
|
|
$msp_id = $_SESSION['msp_id'];
|
|
$customers = [];
|
|
try {
|
|
$stmt = db()->prepare("SELECT * FROM customers WHERE msp_id = ? ORDER BY name ASC");
|
|
$stmt->execute([$msp_id]);
|
|
$customers = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
// Handle error
|
|
}
|
|
?>
|
|
|
|
<div class="container py-5">
|
|
<div class="d-flex justify-content-between align-items-end mb-4">
|
|
<div>
|
|
<h1>Managed Customers</h1>
|
|
<p class="text-muted">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"></i> Add Customer
|
|
</a>
|
|
</div>
|
|
|
|
<div class="card shadow-sm border-0">
|
|
<div class="card-body p-0">
|
|
<table class="table mb-0">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th class="ps-4 py-3">Customer Name</th>
|
|
<th class="py-3">Email</th>
|
|
<th class="py-3">Status</th>
|
|
<th class="py-3">Onboarding Progress</th>
|
|
<th class="pe-4 py-3">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($customers)): ?>
|
|
<tr>
|
|
<td colspan="5" class="text-center text-muted py-5">
|
|
No customers found. <a href="add_customer.php" class="text-primary fw-bold">Add your first customer.</a>
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($customers as $customer): ?>
|
|
<tr>
|
|
<td class="ps-4 fw-bold"><?php echo htmlspecialchars($customer['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($customer['contact_email'] ?? 'N/A'); ?></td>
|
|
<td>
|
|
<span class="badge <?php echo $customer['status'] == 'active' ? 'bg-success-subtle text-success' : 'bg-primary-subtle text-primary'; ?> rounded-pill">
|
|
<?php echo ucfirst($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 class="progress" style="height: 8px; width: 120px; display: inline-flex;">
|
|
<div class="progress-bar bg-success" role="progressbar" style="width: <?php echo (int)$progress; ?>%;"></div>
|
|
</div>
|
|
<span class="small ms-2 fw-bold text-muted"><?php echo (int)$progress; ?>%</span>
|
|
</td>
|
|
<td class="pe-4">
|
|
<div class="btn-group">
|
|
<a href="onboarding.php?id=<?php echo $customer['id']; ?>" class="btn btn-outline-primary btn-sm" title="View Onboarding">
|
|
<i class="bi bi-list-check"></i>
|
|
</a>
|
|
<a href="#" class="btn btn-outline-secondary btn-sm" title="Edit Details">
|
|
<i class="bi bi-pencil-square"></i>
|
|
</a>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/footer.php'; ?>
|