124 lines
4.1 KiB
PHP
124 lines
4.1 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$title = 'View Invoice - Billing';
|
|
$page = 'invoices';
|
|
require_once 'templates/header.php';
|
|
|
|
$invoice_id = $_GET['id'] ?? null;
|
|
$invoice = null;
|
|
|
|
if (!$invoice_id) {
|
|
header('Location: invoices.php');
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare('
|
|
SELECT
|
|
i.*,
|
|
c.name AS customer_name, c.email AS customer_email,
|
|
p.name AS plan_name
|
|
FROM invoices i
|
|
JOIN customers c ON i.customer_id = c.id
|
|
JOIN plans p ON i.plan_id = p.id
|
|
WHERE i.id = ?
|
|
');
|
|
$stmt->execute([$invoice_id]);
|
|
$invoice = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$invoice) {
|
|
header('Location: invoices.php');
|
|
exit;
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error_message = 'Database error: ' . $e->getMessage();
|
|
}
|
|
|
|
$status_colors = [
|
|
'Paid' => 'success',
|
|
'Pending' => 'warning',
|
|
'Overdue' => 'danger',
|
|
];
|
|
|
|
?>
|
|
|
|
<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">Invoice #<?php echo htmlspecialchars($invoice['id']); ?></h1>
|
|
<div class="btn-toolbar mb-2 mb-md-0">
|
|
<a href="edit_invoice.php?id=<?php echo $invoice['id']; ?>" class="btn btn-sm btn-outline-secondary me-2">
|
|
<i class="bi bi-pencil"></i> Edit
|
|
</a>
|
|
<button class="btn btn-sm btn-outline-primary" onclick="window.print();">
|
|
<i class="bi bi-printer"></i> Print
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (isset($error_message)): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
|
<?php else: ?>
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<div class="row align-items-center">
|
|
<div class="col-6">
|
|
<h5 class="mb-0">Invoice Details</h5>
|
|
</div>
|
|
<div class="col-6 text-end">
|
|
Status:
|
|
<span class="badge bg-<?php echo $status_colors[$invoice['status']] ?? 'secondary'; ?>">
|
|
<?php echo htmlspecialchars($invoice['status']); ?>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row mb-4">
|
|
<div class="col-md-6">
|
|
<h6>Billed To:</h6>
|
|
<p class="mb-1"><?php echo htmlspecialchars($invoice['customer_name']); ?></p>
|
|
<p class="mb-0"><?php echo htmlspecialchars($invoice['customer_email']); ?></p>
|
|
</div>
|
|
<div class="col-md-6 text-md-end mt-3 mt-md-0">
|
|
<h6>Invoice Info:</h6>
|
|
<p class="mb-1"><strong>Invoice #:</strong> <?php echo htmlspecialchars($invoice['id']); ?></p>
|
|
<p class="mb-1"><strong>Created Date:</strong> <?php echo date('M d, Y', strtotime($invoice['created_at'])); ?></p>
|
|
<p class="mb-0"><strong>Due Date:</strong> <?php echo date('M d, Y', strtotime($invoice['due_date'])); ?></p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th scope="col">Description</th>
|
|
<th scope="col" class="text-end">Amount</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>Subscription: <?php echo htmlspecialchars($invoice['plan_name']); ?></td>
|
|
<td class="text-end">$<?php echo number_format($invoice['amount'], 2); ?></td>
|
|
</tr>
|
|
</tbody>
|
|
<tfoot class="table-light">
|
|
<tr>
|
|
<th scope="row" class="text-end">Total:</th>
|
|
<th class="text-end">$<?php echo number_format($invoice['amount'], 2); ?></th>
|
|
</tr>
|
|
</tfoot>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="text-center mt-4">
|
|
<a href="invoices.php" class="btn btn-secondary">Back to Invoices</a>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
require_once 'templates/footer.php';
|
|
?>
|