| 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';
$customer_id = isset($_GET['customer_id']) ? intval($_GET['customer_id']) : 0;
$month = $_GET['month'] ?? '';
if (!$customer_id || !$month) {
echo "Missing customer or month.";
exit;
}
$tax_rate = getStoreTaxRate($conn);
$business_name = "Wilson Creek Farm Supply";
$address = "117 3rd St S, Wilson Creek WA 98860";
$phone = "509-345-2572";
$email = "info@wilsoncreekfarmsupply.com";
$website = "www.wilsoncreekfarmsupply.com";
$stmt = $conn->prepare("SELECT first_name, last_name FROM customers WHERE id = ?");
$stmt->bind_param("i", $customer_id);
$stmt->execute();
$customer = $stmt->get_result()->fetch_assoc();
$customer_name = $customer['first_name'] . ' ' . $customer['last_name'];
$is_current_month = ($month === date('Y-m'));
if ($is_current_month) {
$stmt = $conn->prepare("
SELECT *, date AS original_date FROM transactions
WHERE customer_id = ? AND DATE_FORMAT(date, '%Y-%m') = ?
ORDER BY date ASC
");
} else {
$stmt = $conn->prepare("
SELECT *, archived_on AS original_date FROM archived_transactions
WHERE customer_id = ? AND DATE_FORMAT(archived_on, '%Y-%m') = ?
ORDER BY original_date ASC
");
}
$stmt->bind_param("is", $customer_id, $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;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Statement - <?= htmlspecialchars($customer_name) ?></title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
padding: 40px;
margin: 0;
color: #333;
}
.header {
border-bottom: 2px solid #ccc;
padding-bottom: 10px;
margin-bottom: 20px;
}
.header-info {
font-size: 14px;
}
h2 {
margin-top: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: left;
}
th {
background-color: #f0f0f0;
}
.total-row {
font-weight: bold;
background-color: #fafafa;
}
.print-btn {
margin-bottom: 20px;
}
@media print {
.print-btn {
display: none;
}
}
</style>
</head>
<body>
<div class="print-btn">
<button onclick="window.print()">Print This Statement</button>
</div>
<div class="header">
<div class="header-info">
<strong><?= $business_name ?></strong><br>
<?= $address ?><br>
<?= $phone ?><br>
<?= $email ?><br>
<?= $website ?>
</div>
</div>
<h2>Statement for <?= htmlspecialchars($customer_name) ?></h2>
<p>For the month of <strong><?= date('F Y', strtotime($month . '-01')) ?></strong></p>
<?php if (count($transactions)): ?>
<table>
<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><?= $t['original_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 class="total-row">
<td colspan="5" align="right">Total:</td>
<td>$<?= number_format($total, 2) ?></td>
</tr>
</table>
<?php else: ?>
<p><em>No transactions found for this month.</em></p>
<?php endif; ?>
</body>
</html>