| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/thelittlebigshow/self-hosted/ |
Upload File : |
<?php
include 'protect.php';
include 'db.php';
include 'store_settings.php';
require_once __DIR__ . '/brand_header.php';
$tax_rate = getStoreTaxRate($conn);
$credit_customers = [];
$customers = $conn->query("SELECT id, first_name, last_name FROM customers ORDER BY last_name, first_name");
while ($customer = $customers->fetch_assoc()) {
$id = $customer['id'];
$name = $customer['first_name'] . ' ' . $customer['last_name'];
$total = 0;
$stmt = $conn->prepare("SELECT quantity, price, taxable FROM transactions WHERE customer_id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$line = $row['quantity'] * $row['price'];
if ($row['taxable']) {
$line += $line * $tax_rate;
}
$total += $line;
}
$stmt->close();
if ($total < 0) {
$credit_customers[] = [
'id' => $id,
'name' => $name,
'credit' => $total
];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Customers with Credit</title>
<style>
body { font-family: 'Segoe UI', sans-serif; padding: 30px; background: #f7f7f7; }
.container { background: #fff; padding: 30px; max-width: 800px; margin: auto; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
h2 { margin-top: 0; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { padding: 12px; border: 1px solid #ccc; text-align: left; }
th { background: #eee; }
.red { color: red; }
.back-link { display: inline-block; margin-top: 20px; text-decoration: none; color: #2196F3; }
.back-link:hover { text-decoration: underline; }
</style>
<?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
<?php renderAppBrandHeader(); ?>
<h2>Customers with Credit (Negative Balance)</h2>
<?php if (!empty($credit_customers)): ?>
<table>
<thead>
<tr>
<th>Customer</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php foreach ($credit_customers as $row): ?>
<tr>
<td>
<a href="view_account.php?customer_id=<?= $row['id'] ?>">
<?= htmlspecialchars($row['name']) ?>
</a>
</td>
<td class="red">- $<?= number_format(abs($row['credit']), 2) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p><em>No customers currently have a credit.</em></p>
<?php endif; ?>
<a class="back-link" href="index.php">← Back to Dashboard</a>
</div>
</body>
</html>