| 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/wcfs/tabs/Backups/ |
Upload File : |
<?php
include 'db.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$tax_rate = 0.072;
$customer_id = isset($_GET['customer_id']) ? intval($_GET['customer_id']) : 0;
$transactions = [];
$total = 0.0;
$customer_name = '';
$customers = $conn->query("SELECT id, first_name, last_name FROM customers ORDER BY last_name, first_name");
if ($customer_id > 0) {
$stmt = $conn->prepare("SELECT first_name, last_name FROM customers WHERE id = ?");
$stmt->bind_param("i", $customer_id);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
$customer_name = $row['first_name'] . ' ' . $row['last_name'];
} else {
$customer_id = 0;
}
if ($customer_id > 0) {
$stmt = $conn->prepare("SELECT * FROM transactions WHERE customer_id = ? ORDER BY date DESC");
$stmt->bind_param("i", $customer_id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$line_total = $row['price'] * $row['quantity'];
if ($row['taxable']) {
$line_total *= (1 + $tax_rate);
}
$total += $line_total;
$transactions[] = $row;
}
}
}
?>
<h1>View Customer Account</h1>
<!-- A�Z Filter -->
<h3>A�Z Customer Filter</h3>
<p>
<?php foreach (range('A', 'Z') as $l): ?>
<a href="index.php?letter=<?= $l ?>" style="margin-right:10px;"><?= $l ?></a>
<?php endforeach; ?>
</p>
<!-- Customer Dropdown -->
<form method="get">
<label>Select Customer:</label>
<select name="customer_id" onchange="this.form.submit()">
<option value="">-- Choose --</option>
<?php while ($c = $customers->fetch_assoc()): ?>
<option value="<?= $c['id'] ?>" <?= $c['id'] == $customer_id ? 'selected' : '' ?>>
<?= htmlspecialchars($c['last_name'] . ', ' . $c['first_name']) ?>
</option>
<?php endwhile; ?>
</select>
</form>
<?php if ($customer_id): ?>
<h3><?= htmlspecialchars($customer_name) ?> � Current Balance: $<?= number_format($total, 2) ?></h3>
<?php if (count($transactions)): ?>
<h4>Transactions by Date</h4>
<?php
$grouped = [];
foreach ($transactions as $t) {
$grouped[$t['date']][] = $t;
}
?>
<?php foreach ($grouped as $date => $entries): ?>
<h4><?= date('F j, Y', strtotime($date)) ?></h4>
<table border="1" cellpadding="5">
<tr>
<th>Qty</th>
<th>Item</th>
<th>Price</th>
<th>Taxable</th>
<th>Line Total</th>
</tr>
<?php
$daily_total = 0;
foreach ($entries as $t):
$line_total = $t['price'] * $t['quantity'];
if ($t['taxable']) {
$line_total *= (1 + $tax_rate);
}
$daily_total += $line_total;
?>
<tr>
<td><?= $t['quantity'] ?></td>
<td><?= htmlspecialchars($t['item_name']) ?></td>
<td>$<?= number_format($t['price'], 2) ?></td>
<td><?= $t['taxable'] ? 'Yes' : 'No' ?></td>
<td>$<?= number_format($line_total, 2) ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="4" style="text-align:right;"><strong>Daily Total:</strong></td>
<td><strong>$<?= number_format($daily_total, 2) ?></strong></td>
</tr>
</table>
<br>
<?php endforeach; ?>
<a href="export_qbo.php?customer_id=<?= $customer_id ?>">Export as QBO CSV</a>
<?php else: ?>
<p><em>No transactions yet for this customer.</em></p>
<?php endif; ?>
<!-- Add Items Form -->
<h3>Add More Items for <?= htmlspecialchars($customer_name) ?></h3>
<form method="post" action="add_transaction.php">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<table border="1" cellpadding="5" id="items-table">
<tr>
<th>Qty</th>
<th>Item Name</th>
<th>Price</th>
<th>Taxable</th>
</tr>
<?php for ($i = 0; $i < 3; $i++): ?>
<tr>
<td><input type="number" name="quantity[]" value="1" min="1"></td>
<td><input type="text" name="item_name[]"></td>
<td><input type="number" step="0.01" name="price[]"></td>
<td><input type="checkbox" name="taxable[]" checked></td>
</tr>
<?php endfor; ?>
</table>
<button type="button" onclick="addRow()">? Add Item(s)</button><br><br>
<input type="submit" value="Add Items to Account">
</form>
<!-- Clear Monthly Balance (2-step confirm) -->
<h3>Clear Customer Balance</h3>
<form method="post" action="clear_balance.php">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<input type="hidden" name="confirm" value="start">
<input type="submit" value="?? Clear Monthly Balance">
</form>
<!-- Delete Customer (2-step confirm) -->
<h3>Delete This Customer</h3>
<form method="post" action="delete_customer.php">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<input type="hidden" name="confirm" value="start">
<input type="submit" value="??? Delete Customer">
</form>
<?php endif; ?>
<hr>
<p><a href="index.php">?? Back to Dashboard</a></p>
<script>
function addRow() {
const table = document.getElementById('items-table');
const row = table.insertRow(-1);
row.innerHTML = `
<td><input type="number" name="quantity[]" value="1" min="1"></td>
<td><input type="text" name="item_name[]"></td>
<td><input type="number" step="0.01" name="price[]"></td>
<td><input type="checkbox" name="taxable[]" checked></td>
`;
}
</script>