reports editing
This commit is contained in:
parent
16f05ef073
commit
4ea856ec88
@ -9,7 +9,7 @@ if (function_exists('require_permission')) {
|
||||
$pdo = db();
|
||||
|
||||
// Date and Outlet Filter
|
||||
$startDate = $_GET['start_date'] ?? date('Y-m-d');
|
||||
$startDate = $_GET['start_date'] ?? date('Y-m-d', strtotime('-7 days'));
|
||||
$endDate = $_GET['end_date'] ?? date('Y-m-d');
|
||||
$outletId = $_GET['outlet_id'] ?? '';
|
||||
|
||||
@ -37,6 +37,7 @@ $productSalesStmt = $pdo->prepare("
|
||||
JOIN orders o ON oi.order_id = o.id
|
||||
JOIN products p ON oi.product_id = p.id
|
||||
WHERE DATE(o.created_at) BETWEEN ? AND ?
|
||||
AND o.status != 'cancelled'
|
||||
$outletCondition
|
||||
GROUP BY p.id
|
||||
ORDER BY qty_sold DESC
|
||||
@ -144,4 +145,4 @@ foreach ($productSales as $p) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
@ -9,7 +9,7 @@ if (function_exists('require_permission')) {
|
||||
$pdo = db();
|
||||
|
||||
// Date and Outlet Filter
|
||||
$startDate = $_GET['start_date'] ?? date('Y-m-d');
|
||||
$startDate = $_GET['start_date'] ?? date('Y-m-d', strtotime('-7 days'));
|
||||
$endDate = $_GET['end_date'] ?? date('Y-m-d');
|
||||
$outletId = $_GET['outlet_id'] ?? '';
|
||||
|
||||
@ -36,6 +36,7 @@ $staffPaymentStmt = $pdo->prepare("
|
||||
JOIN users u ON o.user_id = u.id
|
||||
LEFT JOIN payment_types pt ON o.payment_type_id = pt.id
|
||||
WHERE DATE(o.created_at) BETWEEN ? AND ?
|
||||
AND o.status != 'cancelled'
|
||||
$outletCondition
|
||||
GROUP BY o.user_id, o.payment_type_id
|
||||
ORDER BY u.full_name ASC, total_amount DESC
|
||||
@ -168,4 +169,4 @@ foreach ($staffPaymentSales as $row) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
@ -9,7 +9,7 @@ if (function_exists('require_permission')) {
|
||||
$pdo = db();
|
||||
|
||||
// Date and Outlet Filter
|
||||
$startDate = $_GET['start_date'] ?? date('Y-m-d');
|
||||
$startDate = $_GET['start_date'] ?? date('Y-m-d', strtotime('-7 days'));
|
||||
$endDate = $_GET['end_date'] ?? date('Y-m-d');
|
||||
$outletId = $_GET['outlet_id'] ?? '';
|
||||
|
||||
@ -27,6 +27,22 @@ if (!empty($outletId)) {
|
||||
$queryParams[] = $outletId;
|
||||
}
|
||||
|
||||
// 0. Daily Sales
|
||||
$dailyStmt = $pdo->prepare("
|
||||
SELECT
|
||||
DATE(o.created_at) as sales_date,
|
||||
COUNT(o.id) as order_count,
|
||||
SUM(o.total_amount) as total_sales
|
||||
FROM orders o
|
||||
WHERE DATE(o.created_at) BETWEEN ? AND ?
|
||||
AND o.status != 'cancelled'
|
||||
$outletCondition
|
||||
GROUP BY DATE(o.created_at)
|
||||
ORDER BY DATE(o.created_at) DESC
|
||||
");
|
||||
$dailyStmt->execute($queryParams);
|
||||
$dailySales = $dailyStmt->fetchAll();
|
||||
|
||||
// 1. Sales by Staff
|
||||
$staffStmt = $pdo->prepare("
|
||||
SELECT
|
||||
@ -38,6 +54,7 @@ $staffStmt = $pdo->prepare("
|
||||
FROM orders o
|
||||
JOIN users u ON o.user_id = u.id
|
||||
WHERE DATE(o.created_at) BETWEEN ? AND ?
|
||||
AND o.status != 'cancelled'
|
||||
$outletCondition
|
||||
GROUP BY o.user_id
|
||||
ORDER BY total_sales DESC
|
||||
@ -55,6 +72,7 @@ $outletStmt = $pdo->prepare("
|
||||
FROM orders o
|
||||
JOIN outlets ot ON o.outlet_id = ot.id
|
||||
WHERE DATE(o.created_at) BETWEEN ? AND ?
|
||||
AND o.status != 'cancelled'
|
||||
$outletCondition
|
||||
GROUP BY o.outlet_id
|
||||
ORDER BY total_sales DESC
|
||||
@ -74,6 +92,7 @@ $categoryStmt = $pdo->prepare("
|
||||
JOIN products p ON oi.product_id = p.id
|
||||
JOIN categories c ON p.category_id = c.id
|
||||
WHERE DATE(o.created_at) BETWEEN ? AND ?
|
||||
AND o.status != 'cancelled'
|
||||
$outletCondition
|
||||
GROUP BY c.id
|
||||
ORDER BY total_sales DESC
|
||||
@ -104,6 +123,7 @@ $totalStmt = $pdo->prepare("
|
||||
SUM(total_amount) as total_revenue
|
||||
FROM orders o
|
||||
WHERE DATE(o.created_at) BETWEEN ? AND ?
|
||||
AND o.status != 'cancelled'
|
||||
$outletCondition
|
||||
");
|
||||
$totalStmt->execute($queryParams);
|
||||
@ -215,6 +235,45 @@ $netProfit = ($summary['total_revenue'] ?? 0) - $totalExpenses;
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Daily Breakdown -->
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-header bg-white py-3 border-0 d-flex justify-content-between align-items-center">
|
||||
<h5 class="fw-bold mb-0"><i class="bi bi-bar-chart me-2 text-primary"></i> Daily Sales Breakdown</h5>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-sm btn-light border dropdown-toggle" type="button" data-bs-toggle="dropdown">Export</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="#" onclick="window.print()"><i class="bi bi-printer me-2"></i> Print</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="bg-light text-muted small text-uppercase">
|
||||
<tr>
|
||||
<th class="ps-4">Date</th>
|
||||
<th class="text-center">Orders</th>
|
||||
<th class="text-end pe-4">Revenue</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($dailySales)): ?>
|
||||
<tr><td colspan="3" class="text-center py-5 text-muted">No sales found for the selected period</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($dailySales as $day): ?>
|
||||
<tr>
|
||||
<td class="ps-4 fw-bold text-dark"><?= date('M d, Y (D)', strtotime($day['sales_date'])) ?></td>
|
||||
<td class="text-center"><?= $day['order_count'] ?></td>
|
||||
<td class="text-end pe-4 fw-bold text-primary"><?= format_currency($day['total_sales']) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<!-- Sales by Category -->
|
||||
<div class="col-md-6">
|
||||
@ -347,7 +406,7 @@ $netProfit = ($summary['total_revenue'] ?? 0) - $totalExpenses;
|
||||
<tr>
|
||||
<th class="ps-3">Outlet</th>
|
||||
<th class="text-center">Orders</th>
|
||||
<th class="text-end pe-3">Total Sales</th>
|
||||
<th class="text-end pe-4">Total Sales</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -363,7 +422,7 @@ $netProfit = ($summary['total_revenue'] ?? 0) - $totalExpenses;
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="text-center"><?= $outlet['order_count'] ?></td>
|
||||
<td class="text-end pe-3 fw-bold text-success"><?= format_currency($outlet['total_sales']) ?></td>
|
||||
<td class="text-end pe-4 fw-bold text-success"><?= format_currency($outlet['total_sales']) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user