| 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.082;
$current_month = date('Y-m');
$selected_month = $_GET['month'] ?? $current_month;
$sort_by = $_GET['sort'] ?? 'name';
$month_display = date('F Y', strtotime($selected_month . '-01'));
$is_current_month = ($selected_month === $current_month);
// Fetch all customers
$customers = $conn->query("SELECT id, first_name, last_name FROM customers ORDER BY last_name, first_name");
$summary = [];
while ($cust = $customers->fetch_assoc()) {
$id = $cust['id'];
$name = $cust['first_name'] . ' ' . $cust['last_name'];
$item_total = $tax_total = 0;
if ($is_current_month) {
// Live data
$stmt = $conn->prepare("SELECT quantity, price, taxable FROM transactions WHERE customer_id = ? AND DATE_FORMAT(date, '%Y-%m') = ?");
$stmt->bind_param("is", $id, $selected_month);
} else {
// Archived data
$stmt = $conn->prepare("SELECT quantity, price, taxable FROM archived_transactions WHERE customer_id = ? AND DATE_FORMAT(archived_on, '%Y-%m') = ?");
$stmt->bind_param("is", $id, $selected_month);
}
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$line_total = $row['quantity'] * $row['price'];
$tax = $row['taxable'] ? $line_total * $tax_rate : 0;
$item_total += $line_total;
$tax_total += $tax;
}
$summary[] = [
'id' => $id,
'name' => $name,
'item_total' => $item_total,
'tax_total' => $tax_total,
'total_with_tax' => $item_total + $tax_total
];
}
// Sort
usort($summary, function($a, $b) use ($sort_by) {
switch ($sort_by) {
case 'total': return $b['item_total'] <=> $a['item_total'];
case 'tax': return $b['tax_total'] <=> $a['tax_total'];
case 'with_tax': return $b['total_with_tax'] <=> $a['total_with_tax'];
default: return strcmp($a['name'], $b['name']);
}
});
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Monthly Summary - <?= htmlspecialchars($month_display) ?></title>
<style>
body { font-family: 'Segoe UI', sans-serif; padding: 40px; background: #f7f7f7; 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: 10px; text-align: left; }
th { background: #eee; }
h2 { margin-bottom: 10px; }
.form-inline { margin-bottom: 20px; }
.form-inline select { padding: 5px; margin-right: 10px; }
.download-link { text-decoration: none; color: #007bff; }
.download-link:hover { text-decoration: underline; }
</style>
</head>
<body>
<div class="container">
<h2>Monthly Summary - <?= htmlspecialchars($month_display) ?></h2>
<form class="form-inline" method="get">
<label for="month">Month:</label>
<select name="month" id="month" onchange="this.form.submit()">
<?php
for ($i = 0; $i < 12; $i++) {
$month_option = date('Y-m', strtotime("-$i months"));
$label = date('F Y', strtotime($month_option . '-01'));
echo "<option value=\"$month_option\"" . ($month_option === $selected_month ? ' selected' : '') . ">$label</option>";
}
?>
</select>
<label for="sort">Sort By:</label>
<select name="sort" id="sort" onchange="this.form.submit()">
<option value="name" <?= $sort_by === 'name' ? 'selected' : '' ?>>Name</option>
<option value="total" <?= $sort_by === 'total' ? 'selected' : '' ?>>Item Total</option>
<option value="tax" <?= $sort_by === 'tax' ? 'selected' : '' ?>>Tax Total</option>
<option value="with_tax" <?= $sort_by === 'with_tax' ? 'selected' : '' ?>>Total with Tax</option>
</select>
</form>
<table>
<tr>
<th>Customer</th>
<th>Item Total</th>
<th>Tax Total</th>
<th>Total with Tax</th>
<th>Statement</th>
</tr>
<?php foreach ($summary as $s): ?>
<tr>
<td><?= htmlspecialchars($s['name']) ?></td>
<td>$<?= number_format($s['item_total'], 2) ?></td>
<td>$<?= number_format($s['tax_total'], 2) ?></td>
<td><strong>$<?= number_format($s['total_with_tax'], 2) ?></strong></td>
<td>
<a class="download-link" href="print_statement.php?customer_id=<?= $s['id'] ?>&month=<?= $selected_month ?>" target="_blank">💾 PDF</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<br>
<a href="index.php">← Back to Dashboard</a>
</div>
</body>
</html>