| 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';
$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;
}
}
?>
<!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;
margin: 0;
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);
}
.top-bar {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 20px;
}
.top-bar select {
padding: 8px;
font-size: 16px;
min-width: 250px;
}
.actions {
display: flex;
gap: 10px;
}
.actions form {
display: inline-block;
}
.actions input[type="submit"] {
padding: 8px 12px;
background-color: #f44336;
border: none;
color: #fff;
cursor: pointer;
border-radius: 4px;
}
.actions input[type="submit"]:hover {
background-color: #c62828;
}
.add-items {
margin-top: 30px;
margin-bottom: 30px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
th {
background-color: #f0f0f0;
}
.total-row {
font-weight: bold;
background: #f5f5f5;
}
input[type="text"], input[type="number"] {
width: 100%;
padding: 6px;
box-sizing: border-box;
}
.submit-btn {
margin-top: 10px;
padding: 10px 16px;
background-color: #4CAF50;
border: none;
color: white;
font-size: 16px;
border-radius: 4px;
cursor: pointer;
}
.submit-btn:hover {
background-color: #45a049;
}
.archive-list a {
margin-right: 10px;
text-decoration: none;
}
.back-link {
margin-top: 30px;
}
.unarchive-form {
margin-top: 15px;
}
.unarchive-form input[type="submit"] {
background-color: #2196F3;
}
.unarchive-form input[type="submit"]:hover {
background-color: #1976D2;
}
</style>
</head>
<body>
<div class="container">
<h1>View Customer Account</h1>
<div class="top-bar">
<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): ?>
<div class="actions">
<form method="post" action="clear_balance.php" onsubmit="return confirm('Archive this customer�s current tab?')">
<input type="hidden" name="customer_id" value="<?= $customer_id ?>">
<input type="hidden" name="confirm" value="start">
<input type="submit" value="Archive 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>
<?php endif; ?>
</div>
<?php if ($customer_id): ?>
<h2><?= htmlspecialchars($customer_name) ?></h2>
<div class="add-items">
<h3>Add More 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 Name</th>
<th>Price</th>
<th>Taxable</th>
<th>Notes</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>
<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>
</div>
<?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();
$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;
}
?>
<?php if ($transactions): ?>
<table>
<tr>
<th>Date</th>
<th>Qty</th>
<th>Item</th>
<th>Price</th>
<th>Taxable</th>
<th>Total</th>
<th>Notes</th>
</tr>
<?php foreach ($transactions as $t): ?>
<?php
$line_total = $t['price'] * $t['quantity'];
if ($t['taxable']) {
$line_total *= (1 + $tax_rate);
}
?>
<tr>
<td><?= $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>
<td><?= htmlspecialchars($t['notes'] ?? '') ?></td>
</tr>
<?php endforeach; ?>
<tr class="total-row">
<td colspan="6" align="right">Total:</td>
<td>$<?= number_format($total, 2) ?></td>
</tr>
</table>
<?php else: ?>
<p><em>No transactions found for this customer.</em></p>
<?php endif; ?>
<?php endif; ?>
<p class="back-link"><a href="index.php">← Back to Dashboard</a></p>
</div>
<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>
<td><input type="text" name="notes[]"></td>
`;
}
</script>
</body>
</html>