35251-vm/invoices.php
2025-10-26 16:46:07 +00:00

81 lines
2.9 KiB
PHP

<?php
$title = 'Invoices - Billing';
$page = 'invoices';
require_once 'templates/header.php';
?>
<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">Invoices</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<button type="button" class="btn btn-sm btn-primary">
<i class="bi bi-plus-circle"></i>
Create New Invoice
</button>
</div>
</div>
<?php
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->query('SELECT invoices.*, customers.name AS customer_name FROM invoices LEFT JOIN customers ON invoices.customer_id = customers.id ORDER BY invoices.created_at DESC');
$invoices = $stmt->fetchAll(PDO::FETCH_ASSOC);
$status_colors = [
'Paid' => 'success',
'Pending' => 'warning',
'Overdue' => 'danger',
];
?>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>Invoice #</th>
<th>Customer</th>
<th>Amount</th>
<th>Status</th>
<th>Due Date</th>
<th>Created</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (empty($invoices)): ?>
<tr>
<td colspan="7" class="text-center py-5">
<i class="bi bi-journal-text" style="font-size: 3rem; color: #ccc;"></i>
<h2 class="mt-3">No Invoices Found</h2>
<p class="text-muted">There are no invoices to display yet.</p>
</td>
</tr>
<?php else: ?>
<?php foreach ($invoices as $invoice): ?>
<tr>
<td>#<?php echo htmlspecialchars($invoice['id']); ?></td>
<td><?php echo htmlspecialchars($invoice['customer_name']); ?></td>
<td>$<?php echo number_format($invoice['amount'], 2); ?></td>
<td>
<span class="badge bg-<?php echo $status_colors[$invoice['status']] ?? 'secondary'; ?>">
<?php echo htmlspecialchars($invoice['status']); ?>
</span>
</td>
<td><?php echo date('M d, Y', strtotime($invoice['due_date'])); ?></td>
<td><?php echo date('M d, Y', strtotime($invoice['created_at'])); ?></td>
<td>
<button class="btn btn-sm btn-outline-secondary"><i class="bi bi-eye"></i></button>
<button class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></button>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<?php
require_once 'templates/footer.php';
?>