145 lines
6.5 KiB
PHP
145 lines
6.5 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_role('receptionist');
|
|
require_once 'db/config.php';
|
|
|
|
// Handle status update
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'mark_paid') {
|
|
$patient_id_to_update = $_POST['patient_id'] ?? null;
|
|
if ($patient_id_to_update) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("UPDATE patients SET payment_status = 'paid' WHERE id = ?");
|
|
$stmt->execute([$patient_id_to_update]);
|
|
// Redirect to avoid form resubmission
|
|
header("Location: billing.php");
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
// Log error
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch unpaid patients
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT p.*, u.username as doctor_name FROM patients p JOIN users u ON p.doctor_id = u.id WHERE p.status = 'Completed' AND p.payment_status = 'unpaid' ORDER BY p.updated_at DESC");
|
|
$stmt->execute();
|
|
$unpaid_patients = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$unpaid_patients = [];
|
|
// Log error
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Billing Management</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">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="page-wrapper">
|
|
<!-- Sidebar -->
|
|
<aside class="sidebar">
|
|
<div class="sidebar-header">
|
|
<a href="index.php" class="sidebar-brand">
|
|
<i class="bi bi-heart-pulse-fill"></i>
|
|
<span>ClinicFlow</span>
|
|
</a>
|
|
</div>
|
|
<nav class="sidebar-nav">
|
|
<a href="reception.php" class="nav-link">
|
|
<i class="bi bi-people-fill"></i>
|
|
<span>Reception</span>
|
|
</a>
|
|
<a href="billing.php" class="nav-link active">
|
|
<i class="bi bi-receipt"></i>
|
|
<span>Billing</span>
|
|
</a>
|
|
<a href="doctor_dashboard.php" class="nav-link">
|
|
<i class="bi bi-person-fill"></i>
|
|
<span>Doctor</span>
|
|
</a>
|
|
</nav>
|
|
<div class="sidebar-footer">
|
|
<div class="dropdown">
|
|
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle me-2"></i>
|
|
<strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<!-- Main Content -->
|
|
<main class="main-content">
|
|
<div class="container-fluid">
|
|
<div class="header">
|
|
<h1 class="header-title">Billing</h1>
|
|
<p class="header-subtitle">Manage outstanding payments.</p>
|
|
</div>
|
|
|
|
<div class="card content-card">
|
|
<div class="card-header">
|
|
<h5 class="card-title-text"><i class="bi bi-hourglass-split me-2"></i>Pending Payments</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Patient Name</th>
|
|
<th>Doctor</th>
|
|
<th>Service Rendered</th>
|
|
<th>Cost</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($unpaid_patients)):
|
|
foreach ($unpaid_patients as $patient):
|
|
?>
|
|
<tr>
|
|
<td><a href="patient_profile.php?id=<?php echo $patient['id']; ?>"><?php echo htmlspecialchars($patient['patient_name']); ?></a></td>
|
|
<td>Dr. <?php echo htmlspecialchars($patient['doctor_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($patient['service_rendered']); ?></td>
|
|
<td>$<?php echo htmlspecialchars(number_format($patient['cost'], 2)); ?></td>
|
|
<td>
|
|
<form method="POST" action="billing.php" style="display:inline;">
|
|
<input type="hidden" name="patient_id" value="<?php echo $patient['id']; ?>">
|
|
<input type="hidden" name="action" value="mark_paid">
|
|
<button type="submit" class="btn btn-sm btn-success"><i class="bi bi-check-lg"></i> Mark as Paid</button>
|
|
</form>
|
|
<a href="invoice.php?id=<?php echo $patient['id']; ?>" class="btn btn-sm btn-info" target="_blank"><i class="bi bi-printer"></i> Invoice</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php else:
|
|
?>
|
|
<tr>
|
|
<td colspan="5" class="text-center text-muted">No pending payments.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|