35251-vm/customers.php
2025-10-26 16:53:16 +00:00

81 lines
3.2 KiB
PHP

<?php
require_once 'db/config.php';
$title = 'Customers - Billing';
$page = 'customers';
require_once 'templates/header.php';
try {
$pdo = db();
$stmt = $pdo->query('SELECT id, name, email, status, created_at FROM customers ORDER BY created_at DESC');
$customers = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$customers = [];
$error_message = "Error: Could not fetch customer data.";
}
?>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Customers</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<a href="create_customer.php" class="btn btn-sm btn-primary">
<i class="bi bi-plus-circle"></i>
Add New Customer
</a>
</div>
</div>
<?php if (isset($error_message)): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Status</th>
<th scope="col">Registered</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($customers)): ?>
<tr>
<td colspan="6" class="text-center">No customers found.</td>
</tr>
<?php else: ?>
<?php foreach ($customers as $customer): ?>
<tr>
<td><?php echo htmlspecialchars($customer['id']); ?></td>
<td><?php echo htmlspecialchars($customer['name']); ?></td>
<td><?php echo htmlspecialchars($customer['email']); ?></td>
<td>
<?php
$status = htmlspecialchars($customer['status']);
$badge_class = 'bg-secondary';
if ($status === 'active') {
$badge_class = 'bg-success';
} elseif ($status === 'inactive') {
$badge_class = 'bg-danger';
}
?>
<span class="badge <?php echo $badge_class; ?>"><?php echo ucfirst($status); ?></span>
</td>
<td><?php echo htmlspecialchars(date('M d, Y', strtotime($customer['created_at']))); ?></td>
<td>
<a href="edit_customer.php?id=<?php echo $customer['id']; ?>" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></a>
<a href="delete_customer.php?id=<?php echo $customer['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this customer?');"><i class="bi bi-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<?php
require_once 'templates/footer.php';
?>