| 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'; ?>
<?php
include 'db.php';
include 'store_settings.php';
require_once __DIR__ . '/brand_header.php';
$tax_rate = getStoreTaxRate($conn);
$customer_id = isset($_GET['customer_id']) ? intval($_GET['customer_id']) : 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;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Account - <?= htmlspecialchars($customer_name) ?></title>
<style>
body { font-family: 'Segoe UI', sans-serif; background-color: #f9f9f9; padding: 30px; color: #333; }
.container { max-width: 1000px; margin: auto; background: #fff; padding: 30px; box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid #ddd; padding: 8px; }
th { background-color: #f0f0f0; }
.submit-btn { margin-top: 10px; padding: 10px 16px; background-color: #4CAF50; border: none; color: white; font-size: 16px; cursor: pointer; }
.submit-btn:hover { background-color: #45a049; }
.back-link { margin-top: 20px; display: inline-block; }
.delete-btn { padding: 4px 8px; background-color: #f44336; color: white; border: none; cursor: pointer; border-radius: 4px; }
.delete-btn:hover { background-color: #c62828; }
input.editable { width: 80px; border: 1px solid #ccc; padding: 4px; }
input.edit-notes { width: 100%; }
.total-section { margin-top: 20px; font-weight: bold; }
.tax-note { margin: 10px 0 0; color: #666; }
</style>
<?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
<?php renderAppBrandHeader(); ?>
<h2><?= htmlspecialchars($customer_name) ?> - Account Details</h2>
<p class="tax-note">Current store sales tax rate: <?= number_format($tax_rate * 100, 2) ?>%</p>
<?php if ($customer_id): ?>
<div style="margin-bottom: 20px;">
<form method="post" action="delete_customer.php" onsubmit="return confirm('Are you sure you want to delete this customer and all their data?')">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<input type="hidden" name="confirm" value="start">
<input type="submit" class="delete-btn" value="Delete Customer">
</form>
</div>
<h3>Add Items</h3>
<form method="post" action="add_transaction.php">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<table id="items-table">
<tr>
<th>Qty</th>
<th>Item</th>
<th>Price</th>
<th>Taxable</th>
<th>Notes</th>
</tr>
<?php for ($i = 0; $i < 3; $i++): ?>
<tr>
<td><input type="number" step="0.01" min="0" name="quantity[]" value="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[<?= $i ?>]"></td>
<td><input type="text" name="notes[]"></td>
</tr>
<?php endfor; ?>
</table>
<button type="button" onclick="addRow()">+ Add More Rows</button><br><br>
<input class="submit-btn" type="submit" value="Add Items to Account">
</form>
<h3>Transactions</h3>
<table id="transaction-table">
<thead>
<tr>
<th>Date</th>
<th>Qty</th>
<th>Item</th>
<th>Price</th>
<th>Taxable</th>
<th>Total</th>
<th>Notes</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$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();
$item_total = $tax_total = $grand_total = 0;
while ($row = $result->fetch_assoc()):
$line_total = $row['quantity'] * $row['price'];
$tax = $row['taxable'] ? $line_total * $tax_rate : 0;
$total_with_tax = $line_total + $tax;
$item_total += $line_total;
$tax_total += $tax;
$grand_total += $total_with_tax;
?>
<tr data-id="<?= $row['id'] ?>">
<td><?= htmlspecialchars($row['date']) ?></td>
<td><input class="editable" type="number" step="0.01" value="<?= $row['quantity'] ?>" onchange="updateField(<?= $row['id'] ?>, 'quantity', this.value)"></td>
<td><?= htmlspecialchars($row['item_name']) ?></td>
<td><input class="editable" type="number" step="0.01" value="<?= $row['price'] ?>" onchange="updateField(<?= $row['id'] ?>, 'price', this.value)"></td>
<td><input type="checkbox" <?= $row['taxable'] ? 'checked' : '' ?> onchange="updateTaxable(<?= $row['id'] ?>, this.checked)"></td>
<td class="row-total" data-base="<?= $row['quantity'] * $row['price'] ?>" data-taxable="<?= $row['taxable'] ? '1' : '0' ?>"></td>
<td><input class="edit-notes" type="text" value="<?= htmlspecialchars($row['notes']) ?>" onchange="updateField(<?= $row['id'] ?>, 'notes', this.value)"></td>
<td>
<form method="post" action="delete_transaction.php" onsubmit="return confirm('Delete this item?')">
<input type="hidden" name="id" value="<?= $row['id'] ?>">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<input type="submit" class="delete-btn" value="Delete">
</form>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<div class="total-section">
Item Total: $<span id="itemTotal">0.00</span><br>
Tax Total: $<span id="taxTotal">0.00</span><br>
<strong>Total with Tax:</strong> $<span id="grandTotal">0.00</span>
</div>
<?php endif; ?>
<a class="back-link" href="index.php">← Back to Dashboard</a>
</div>
<script>
let rowIndex = 3;
function addRow() {
const table = document.getElementById('items-table');
const row = table.insertRow(-1);
row.innerHTML = `
<td><input type="number" step="0.01" min="0" name="quantity[]" value="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[${rowIndex}]"></td>
<td><input type="text" name="notes[]"></td>
`;
rowIndex++;
}
function updateTotals() {
let itemTotal = 0, taxTotal = 0, taxRate = <?= $tax_rate ?>;
document.querySelectorAll('.row-total').forEach(td => {
let base = parseFloat(td.getAttribute('data-base')) || 0;
let isTaxable = td.getAttribute('data-taxable') === '1';
let tax = isTaxable ? base * taxRate : 0;
td.textContent = '$' + (base + tax).toFixed(2);
itemTotal += base;
taxTotal += tax;
});
document.getElementById('itemTotal').textContent = itemTotal.toFixed(2);
document.getElementById('taxTotal').textContent = taxTotal.toFixed(2);
document.getElementById('grandTotal').textContent = (itemTotal + taxTotal).toFixed(2);
}
function updateTaxable(id, checked) {
fetch('update_taxable.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'id=' + id + '&taxable=' + (checked ? '1' : '0')
}).then(() => {
const td = document.querySelector(`tr[data-id='${id}'] .row-total`);
td.setAttribute('data-taxable', checked ? '1' : '0');
updateTotals();
});
}
function updateField(id, field, value) {
fetch('update_transaction_field.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'id=' + id + '&field=' + encodeURIComponent(field) + '&value=' + encodeURIComponent(value)
}).then(() => {
if (field === 'quantity' || field === 'price') {
const tr = document.querySelector(`tr[data-id='${id}']`);
const qty = parseFloat(tr.querySelector('input[type=number]').value);
const price = parseFloat(tr.querySelectorAll('input[type=number]')[1].value);
const td = tr.querySelector('.row-total');
td.setAttribute('data-base', (qty * price).toFixed(2));
updateTotals();
}
});
}
updateTotals();
</script>
</body>
</html>