Lokasi:
/
home
/
u847703118
/
domains
/
alphamed.cloud
/
public_html
/
Ubah: debug_pending.php
<?php require_once 'db_connect.php'; echo "<h2>Debug Pending Invoices</h2>"; // 1. List all invoices that have a balance > 0 $sql = "SELECT id, patient_id, total_amount, paid_amount, status, (total_amount - paid_amount) as pending FROM invoices WHERE (total_amount - paid_amount) > 0"; $stmt = $pdo->query($sql); $invoices = $stmt->fetchAll(PDO::FETCH_ASSOC); echo "<h3>Invoices with Pending Balance > 0</h3>"; if (empty($invoices)) { echo "No invoices found with pending balance.<br>"; } else { echo "<table border='1'><tr><th>ID</th><th>Patient ID</th><th>Total</th><th>Paid</th><th>Status</th><th>Pending</th></tr>"; foreach ($invoices as $inv) { echo "<tr>"; echo "<td>{$inv['id']}</td>"; echo "<td>{$inv['patient_id']}</td>"; echo "<td>{$inv['total_amount']}</td>"; echo "<td>{$inv['paid_amount']}</td>"; echo "<td>{$inv['status']}</td>"; echo "<td>{$inv['pending']}</td>"; echo "</tr>"; } echo "</table>"; } // 2. Run the main query logic without the HAVING clause to see what it calculates echo "<h3>Main Query Result (Without HAVING > 0)</h3>"; $sql2 = "SELECT p.id, p.first_name, p.last_name, SUM(CASE WHEN i.status != 'Void' THEN (i.total_amount - i.paid_amount) ELSE 0 END) as total_pending FROM patients p JOIN invoices i ON p.id = i.patient_id GROUP BY p.id, p.first_name, p.last_name"; $stmt2 = $pdo->query($sql2); $results = $stmt2->fetchAll(PDO::FETCH_ASSOC); echo "<table border='1'><tr><th>Patient ID</th><th>Name</th><th>Total Pending</th></tr>"; foreach ($results as $row) { echo "<tr>"; echo "<td>{$row['id']}</td>"; echo "<td>{$row['first_name']} {$row['last_name']}</td>"; echo "<td>{$row['total_pending']}</td>"; echo "</tr>"; } echo "</table>"; // 3. Check for Void Status Columns echo "<h3>Invoice Void Columns Check</h3>"; $cols = $pdo->query("SHOW COLUMNS FROM invoices LIKE '%void%'")->fetchAll(); foreach ($cols as $col) { echo $col['Field'] . "<br>"; } ?>
Batal