| 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;
$archive_month = $_GET['archive_month'] ?? '';
$transactions = [];
$total = 0.0;
$customer_name = '';
$customers = $conn->query("SELECT id, first_name, last_name FROM customers ORDER BY last_name, first_name");
// Get customer 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;
}
}
?>
<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 and Action Buttons -->
<form method="get" style="display:flex; align-items:center; gap:10px;">
<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): ?>
<!-- Top Buttons -->
<div style="margin-top:10px; display:flex; gap:10px;">
<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 Tab">
</form>
<form method="post" action="delete_customer.php" onsubmit="return confirm('Are you sure you want to delete this customer?');">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<input type="hidden" name="confirm" value="start">
<input type="submit" value="??? Delete Customer">
</form>
</div>
<h3><?= htmlspecialchars($customer_name) ?>
<?php if ($archive_month): ?>
� Archived: <?= date('F Y', strtotime($archive_month . '-01')) ?>
<?php else: ?>
� Current Balance: $
<?php
$stmt = $conn->prepare("SELECT * FROM transactions WHERE customer_id = ?");
$stmt->bind_param("i", $customer_id);
$stmt->execute();
$result = $stmt->get_result();
$total = 0;
while ($row = $result->fetch_assoc()) {
$line_total = $row['price'] * $row['quantity'];
if ($row['taxable']) {
$line_total *= (1 + $tax_rate);
}
$total += $line_total;
}
echo number_format($total, 2);
?>
<?php endif; ?>
</h3>
<!-- Archived Months -->
<?php
$months = [];
$stmt = $conn->prepare("SELECT DISTINCT DATE_FORMAT(archived_on, '%Y-%m') AS month FROM archived_transactions WHERE customer_id = ? ORDER BY month DESC");
$stmt->bind_param("i", $customer_id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$months[] = $row['month'];
}
?>
<?php if ($months): ?>
<h4>?? Archived Months:</h4>
<div style="display:flex; flex-wrap:wrap; gap:10px;">
<?php foreach ($months as $m): ?>
<form method="post" action="unarchive_month.php" style="display:inline;">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<input type="hidden" name="archive_month" value="<?= $m ?>">
<a href="view_account.php?customer_id=<?= $customer_id ?>&archive_month=<?= $m ?>">
<?= date('F Y', strtotime($m . '-01')) ?>
</a>
<button type="submit" style="font-size: 0.8em;">??</button>
</form>
<?php endforeach; ?>
</div>
<?php if ($archive_month): ?>
<p><a href="view_account.php?customer_id=<?= $customer_id ?>">?? Return to Current Tab</a></p>
<?php endif; ?>
<?php endif; ?>
<?php if (!$archive_month): ?>
<!-- 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>
<?php endif; ?>
<?php
if ($archive_month) {
$stmt = $conn->prepare("
SELECT * FROM archived_transactions
WHERE customer_id = ? AND DATE_FORMAT(archived_on, '%Y-%m') = ?
ORDER BY original_date DESC
");
$stmt->bind_param("is", $customer_id, $archive_month);
$stmt->execute();
$result = $stmt->get_result();
$transactions = [];
$total = 0;
while ($row = $result->fetch_assoc()) {
$line_total = $row['price'] * $row['quantity'];
if ($row['taxable']) {
$line_total *= (1 + $tax_rate);
}
$total += $line_total;
$transactions[] = $row;
}
echo "<h4>Transactions for " . date('F Y', strtotime($archive_month . '-01')) . "</h4>";
} else {
$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();
$transactions = [];
while ($row = $result->fetch_assoc()) {
$transactions[] = $row;
}
}
?>
<?php if ($transactions): ?>
<table border="1" cellpadding="5">
<tr>
<th>Date</th>
<th>Qty</th>
<th>Item</th>
<th>Price</th>
<th>Taxable</th>
<th>Total</th>
</tr>
<?php foreach ($transactions as $t): ?>
<?php
$line_total = $t['price'] * $t['quantity'];
if ($t['taxable']) {
$line_total *= (1 + $tax_rate);
}
?>
<tr>
<td><?= $archive_month ? $t['original_date'] : $t['date'] ?></td>
<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="5" align="right"><strong>Total:</strong></td>
<td><strong>$<?= number_format($total, 2) ?></strong></td>
</tr>
</table>
<?php else: ?>
<p><em>No transactions <?= $archive_month ? 'in this month.' : 'yet for this customer.' ?></em></p>
<?php endif; ?>
<?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>