JezK
Edit File: collections.php
<?php require_once __DIR__ . '/../config/auth.php'; require_role('accountant', 'admin'); $pdo = db(); $lab_id = current_user()['lab_id']; $date_filter = $_GET['date'] ?? date('Y-m-d'); // Fetch all collections (installments) for a specific date $stmt = $pdo->prepare(" SELECT i.*, b.total_amount, p.name as patient_name, p.patient_code, pr.name as proc_name FROM installments i JOIN billings b ON i.billing_id = b.id JOIN patients p ON b.patient_id = p.id JOIN test_orders tp ON b.plan_id = tp.id JOIN procedures pr ON tp.test_id = pr.id WHERE p.lab_id = ? AND DATE(i.paid_on) = ? ORDER BY i.paid_on DESC "); $stmt->execute([$lab_id, $date_filter]); $collections = $stmt->fetchAll(); $total_collected = 0; foreach($collections as $c) { $total_collected += $c['amount']; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Daily Collections - X-Ray Lab</title> <link rel="stylesheet" href="../assets/css/style.css"> <script src="https://unpkg.com/lucide@latest/dist/umd/lucide.min.js"></script> </head> <body> <div class="app-layout"> <?php include '../layouts/sidebar_accountant.php'; ?> <header class="topbar"><div class="topbar-title">Daily Collections</div></header> <main class="main-content"> <div class="card" style="margin-bottom:20px;"> <div class="card-body"> <form method="GET" style="display:flex; gap:15px; align-items:flex-end;"> <div style="flex:1;"> <label style="display:block;margin-bottom:5px;">Filter by Date</label> <input type="date" name="date" value="<?= htmlspecialchars($date_filter) ?>" style="width:100%;padding:10px;border:1px solid #ccc;border-radius:6px;box-sizing:border-box;"> </div> <button type="submit" class="btn" style="background:var(--primary);color:#fff;padding:10px 20px;border-radius:6px;border:none;cursor:pointer;">View Collections</button> </form> </div> </div> <div class="card"> <div class="card-header" style="display:flex; justify-content:space-between; align-items:center;"> <div class="card-title">Receipts for <?= date('d M Y', strtotime($date_filter)) ?></div> <div style="font-size:18px; font-weight:bold; color:#16a34a;">Total: <?= format_currency($total_collected) ?></div> </div> <div class="table-wrap"> <table class="data-table"> <thead> <tr> <th>Time</th> <th>Patient</th> <th>X-Ray Test</th> <th>Mode</th> <th>Amount Received</th> </tr> </thead> <tbody> <?php foreach($collections as $c): ?> <tr> <td><?= date('h:i A', strtotime($c['paid_on'])) ?></td> <td><strong><?= htmlspecialchars($c['patient_name']) ?></strong><br><span style="font-size:11px;color:#64748b"><?= $c['patient_code'] ?></span></td> <td><?= htmlspecialchars($c['proc_name']) ?></td> <td> <span style="background:#f1f5f9;padding:3px 6px;border-radius:4px;font-size:12px;text-transform:uppercase;"><?= htmlspecialchars($c['payment_mode']) ?></span> <?php if ($c['status'] === 'pending' && $c['payment_mode'] === 'cash'): ?> <span style="margin-left:5px;background:#fef3c7;color:#d97706;padding:2px 6px;border-radius:4px;font-size:10px;font-weight:bold;">PENDING VERIFICATION</span> <?php elseif ($c['status'] === 'verified'): ?> <span style="margin-left:5px;background:#dcfce7;color:#166534;padding:2px 6px;border-radius:4px;font-size:10px;font-weight:bold;">VERIFIED</span> <?php endif; ?> </td> <td><strong style="color:#16a34a"><?= format_currency($c['amount']) ?></strong></td> </tr> <?php endforeach; ?> <?php if(empty($collections)): ?> <tr><td colspan="5" style="text-align:center;color:#64748b;">No collections recorded on this date.</td></tr> <?php endif; ?> </tbody> </table> </div> </div> </main> </div> <script>lucide.createIcons();</script> </body> </html>