| 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';
$selected_month = $_GET['month'] ?? '';
$months = [];
$month_stmt = $conn->query("SELECT DISTINCT DATE_FORMAT(archived_on, '%Y-%m') AS month FROM archived_transactions ORDER BY month DESC");
while ($row = $month_stmt->fetch_assoc()) {
$months[] = $row['month'];
}
?>
<h1>?? Monthly Customer Summary</h1>
<form method="get">
<label>Select Month:</label>
<select name="month" onchange="this.form.submit()">
<option value="">-- Choose Month --</option>
<?php foreach ($months as $m): ?>
<option value="<?= $m ?>" <?= $m == $selected_month ? 'selected' : '' ?>>
<?= date('F Y', strtotime($m . '-01')) ?>
</option>
<?php endforeach; ?>
</select>
</form>
<?php if ($selected_month): ?>
<h2>?? Summary for <?= date('F Y', strtotime($selected_month . '-01')) ?></h2>
<table border="1" cellpadding="6">
<tr>
<th>Customer</th>
<th>Total</th>
<th>Print</th>
</tr>
<?php
$stmt = $conn->prepare("
SELECT c.id, c.first_name, c.last_name,
SUM(at.price * at.quantity * (1 + IF(at.taxable, 0.072, 0))) AS total
FROM customers c
JOIN archived_transactions at ON c.id = at.customer_id
WHERE DATE_FORMAT(at.archived_on, '%Y-%m') = ?
GROUP BY c.id
ORDER BY c.last_name, c.first_name
");
$stmt->bind_param("s", $selected_month);
$stmt->execute();
$result = $stmt->get_result();
$has_data = false;
while ($row = $result->fetch_assoc()):
$has_data = true;
$customer_id = $row['id'];
$name = htmlspecialchars($row['first_name'] . ' ' . $row['last_name']);
$total = number_format($row['total'], 2);
?>
<tr>
<td><?= $name ?></td>
<td>$<?= $total ?></td>
<td>
<a href="print_statement.php?customer_id=<?= $customer_id ?>&month=<?= $selected_month ?>" target="_blank">
??? Print Statement
</a>
</td>
</tr>
<?php endwhile; ?>
</table>
<?php if ($has_data): ?>
<br>
<form method="get" action="print_all_statements.php" target="_blank">
<input type="hidden" name="month" value="<?= $selected_month ?>">
<input type="submit" value="??? Print All Statements">
</form>
<?php else: ?>
<p><em>No archived records found for this month.</em></p>
<?php endif; ?>
<?php endif; ?>
<hr>
<p><a href="index.php">?? Back to Dashboard</a></p>