160 lines
7.4 KiB
PHP
160 lines
7.4 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') {
|
|
$visit_id_to_update = $_POST['visit_id'] ?? null;
|
|
if ($visit_id_to_update) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("UPDATE patient_visits SET payment_status = 'paid' WHERE visit_id = ?");
|
|
$stmt->execute([$visit_id_to_update]);
|
|
header("Location: billing.php");
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
// Log error
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch unpaid visits and calculate total cost
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare(
|
|
"SELECT
|
|
pv.visit_id,
|
|
pv.cost as consultation_fee,
|
|
p.patient_name,
|
|
p.id as patient_id,
|
|
u.username as doctor_name,
|
|
pv.service_rendered,
|
|
COALESCE((SELECT SUM(lt.cost) FROM ordered_tests ot JOIN lab_tests lt ON ot.test_id = lt.test_id WHERE ot.visit_id = pv.visit_id AND ot.test_type = 'lab'), 0) as lab_tests_cost,
|
|
COALESCE((SELECT SUM(it.cost) FROM ordered_tests ot JOIN imaging_tests it ON ot.test_id = it.test_id WHERE ot.visit_id = pv.visit_id AND ot.test_type = 'imaging'), 0) as imaging_tests_cost
|
|
FROM patient_visits pv
|
|
JOIN patients p ON pv.patient_id = p.id
|
|
JOIN users u ON pv.doctor_id = u.id
|
|
WHERE pv.status = 'Completed' AND pv.payment_status = 'unpaid'
|
|
ORDER BY pv.visit_time DESC"
|
|
);
|
|
$stmt->execute();
|
|
$unpaid_visits = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$unpaid_visits = [];
|
|
// You should log the error in a real application
|
|
// error_log($e->getMessage());
|
|
}
|
|
|
|
?>
|
|
<!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>Total Bill</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($unpaid_visits)):
|
|
foreach ($unpaid_visits as $visit):
|
|
$total_bill = $visit['consultation_fee'] + $visit['lab_tests_cost'] + $visit['imaging_tests_cost'];
|
|
?>
|
|
<tr>
|
|
<td><a href="patient_profile.php?id=<?php echo $visit['patient_id']; ?>"><?php echo htmlspecialchars($visit['patient_name']); ?></a></td>
|
|
<td>Dr. <?php echo htmlspecialchars($visit['doctor_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($visit['service_rendered']); ?></td>
|
|
<td>$<?php echo htmlspecialchars(number_format($total_bill, 2)); ?></td>
|
|
<td>
|
|
<form method="POST" action="billing.php" style="display:inline;">
|
|
<input type="hidden" name="visit_id" value="<?php echo $visit['visit_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?visit_id=<?php echo $visit['visit_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>
|