| 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';
include 'db.php';
include 'store_settings.php';
require_once __DIR__ . '/brand_header.php';
$tax_rate = getStoreTaxRate($conn);
$selected_month = $_GET['month'] ?? date('Y-m');
$start_date = $selected_month . '-01';
$end_date = date('Y-m-t', strtotime($start_date));
$months = [];
for ($i = 0; $i < 24; $i++) {
$months[] = date('Y-m', strtotime("-$i months"));
}
$stmt = $conn->prepare("
SELECT day, SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total FROM (
SELECT DATE(date) AS day, SUM(quantity * price) AS subtotal,
SUM(CASE WHEN taxable = 1 THEN quantity * price * ? ELSE 0 END) AS tax,
SUM(quantity * price + CASE WHEN taxable = 1 THEN quantity * price * ? ELSE 0 END) AS total
FROM transactions
WHERE date BETWEEN ? AND ?
GROUP BY day
UNION ALL
SELECT DATE(original_date) AS day, SUM(quantity * price),
SUM(CASE WHEN taxable = 1 THEN quantity * price * ? ELSE 0 END),
SUM(quantity * price + CASE WHEN taxable = 1 THEN quantity * price * ? ELSE 0 END)
FROM archived_transactions
WHERE original_date BETWEEN ? AND ?
GROUP BY day
) AS combined
GROUP BY day
ORDER BY day DESC
");
$stmt->bind_param('ddssddss', $tax_rate, $tax_rate, $start_date, $end_date, $tax_rate, $tax_rate, $start_date, $end_date);
$stmt->execute();
$result = $stmt->get_result();
$totals = [];
while ($row = $result->fetch_assoc()) {
$totals[] = [
'day' => $row['day'],
'subtotal' => $row['subtotal'],
'tax' => $row['tax'],
'total' => $row['total']
];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Daily Totals Report</title>
<style>
body { font-family: 'Segoe UI', sans-serif; padding: 30px; background: #f9f9f9; color: #333; }
.container { background: #fff; padding: 20px; max-width: 900px; margin: auto; box-shadow: 0 2px 5px 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: right; }
th { background: #f0f0f0; text-align: left; }
.btn { padding: 8px 16px; background: #4CAF50; color: #fff; text-decoration: none; border: none; cursor: pointer; }
.btn:hover { background: #45a049; }
h2 { margin-bottom: 20px; }
select { padding: 5px; font-size: 16px; }
.back-link { display: inline-block; margin-top: 30px; text-decoration: none; color: #2196F3; }
a.details-link { text-decoration: none; color: #2196F3; }
</style>
<?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
<?php renderAppBrandHeader(); ?>
<h2>Daily Totals Report</h2>
<form method="get">
<label for="month">Select Month:</label>
<select name="month" id="month" onchange="this.form.submit()">
<?php foreach ($months as $m): ?>
<option value="<?= $m ?>" <?= ($m === $selected_month) ? 'selected' : '' ?>>
<?= date('F Y', strtotime($m . '-01')) ?>
</option>
<?php endforeach; ?>
</select>
</form>
<table>
<tr>
<th>Date</th>
<th>Subtotal</th>
<th>Tax</th>
<th>Total</th>
</tr>
<?php foreach ($totals as $day): ?>
<tr>
<td><a class="details-link" href="daily_details.php?date=<?= urlencode($day['day']) ?>"><?= htmlspecialchars($day['day']) ?></a></td>
<td>$<?= number_format($day['subtotal'], 2) ?></td>
<td>$<?= number_format($day['tax'], 2) ?></td>
<td><strong>$<?= number_format($day['total'], 2) ?></strong></td>
</tr>
<?php endforeach; ?>
</table>
<br>
<a class="btn" href="export_daily_totals_pdf.php?start=<?= $start_date ?>&end=<?= $end_date ?>">Download PDF</a>
<br><br>
<a class="back-link" href="index.php">← Back to Dashboard</a>
</div>
</body>
</html>