116 lines
4.5 KiB
PHP
116 lines
4.5 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_once 'db/config.php';
|
|
|
|
$patient_id = $_GET['id'] ?? null;
|
|
|
|
if (!$patient_id) {
|
|
die("Patient ID is required.");
|
|
}
|
|
|
|
// Fetch patient and latest completed visit details
|
|
try {
|
|
$pdo = db();
|
|
// This query fetches the most recent completed visit for the patient
|
|
$stmt = $pdo->prepare("
|
|
SELECT p.*, u.username as doctor_name
|
|
FROM patients p
|
|
JOIN users u ON p.doctor_id = u.id
|
|
WHERE p.id = ? AND p.status = 'Completed'
|
|
ORDER BY p.updated_at DESC
|
|
LIMIT 1
|
|
");
|
|
$stmt->execute([$patient_id]);
|
|
$visit = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$visit = null;
|
|
// Log error
|
|
}
|
|
|
|
if (!$visit) {
|
|
die("No completed visit found for this patient or an error occurred.");
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Invoice - <?php echo htmlspecialchars($visit['patient_id']); ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
|
|
<style>
|
|
body { font-family: 'Poppins', sans-serif; background-color: #f8f9fa; }
|
|
.invoice-container { max-width: 800px; margin: 40px auto; padding: 40px; background: #fff; border-radius: 15px; box-shadow: 0 4px 20px rgba(0,0,0,0.05); }
|
|
.invoice-header { text-align: center; margin-bottom: 40px; }
|
|
.invoice-header h1 { font-weight: 600; color: #343a40; }
|
|
.invoice-header .brand { font-size: 1.5rem; font-weight: 600; color: #0d6efd; }
|
|
.invoice-details, .billing-details { margin-bottom: 30px; }
|
|
.invoice-details h5, .billing-details h5 { font-weight: 600; margin-bottom: 15px; }
|
|
.invoice-details p, .billing-details p { margin-bottom: 5px; }
|
|
.table thead { background-color: #e9ecef; }
|
|
.total-section { text-align: right; margin-top: 30px; }
|
|
.total-section h4 { font-weight: 600; }
|
|
.print-btn { display: block; width: 150px; margin: 30px auto 0; }
|
|
@media print {
|
|
body { background-color: #fff; }
|
|
.invoice-container { margin: 0; box-shadow: none; border-radius: 0; }
|
|
.print-btn, .btn-back { display: none; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="invoice-container">
|
|
<div class="invoice-header">
|
|
<div class="brand"><i class="bi bi-heart-pulse-fill"></i> ClinicFlow</div>
|
|
<h1>Invoice</h1>
|
|
</div>
|
|
|
|
<div class="row justify-content-between invoice-details">
|
|
<div class="col-md-6">
|
|
<h5>Billed To:</h5>
|
|
<p><strong><?php echo htmlspecialchars($visit['patient_name']); ?></strong></p>
|
|
<p><?php echo htmlspecialchars($visit['address']); ?></p>
|
|
<p><?php echo htmlspecialchars($visit['phone']); ?></p>
|
|
</div>
|
|
<div class="col-md-5 text-md-end">
|
|
<p><strong>Invoice #:</strong> INV-<?php echo htmlspecialchars($visit['id']); ?></p>
|
|
<p><strong>Date:</strong> <?php echo date("F j, Y", strtotime($visit['updated_at'])); ?></p>
|
|
<p><strong>Status:</strong> <span class="badge bg-<?php echo $visit['payment_status'] === 'paid' ? 'success' : 'danger'; ?>"><?php echo ucfirst(htmlspecialchars($visit['payment_status'])); ?></span></p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="billing-details">
|
|
<h5>Consultation Details:</h5>
|
|
<p><strong>Consulting Doctor:</strong> Dr. <?php echo htmlspecialchars($visit['doctor_name']); ?></p>
|
|
</div>
|
|
|
|
<table class="table table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th>Service Rendered</th>
|
|
<th class="text-end">Cost</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($visit['service_rendered']); ?></td>
|
|
<td class="text-end">$<?php echo htmlspecialchars(number_format($visit['cost'], 2)); ?></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<div class="total-section">
|
|
<h4>Total: $<?php echo htmlspecialchars(number_format($visit['cost'], 2)); ?></h4>
|
|
</div>
|
|
|
|
<button onclick="window.print();" class="btn btn-primary print-btn"><i class="bi bi-printer"></i> Print Invoice</button>
|
|
<a href="billing.php" class="btn btn-secondary btn-back d-print-none" style="display: block; width: 150px; margin: 10px auto 0;">Back to Billing</a>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|