diff --git a/admin/report_products.php b/admin/report_products.php index 5291737..3ffd066 100644 --- a/admin/report_products.php +++ b/admin/report_products.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'] ?? ''; @@ -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) { - + \ No newline at end of file diff --git a/admin/report_staff.php b/admin/report_staff.php index 01f446e..b164158 100644 --- a/admin/report_staff.php +++ b/admin/report_staff.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) { - + \ No newline at end of file diff --git a/admin/reports.php b/admin/reports.php index f0d8738..ef7a5b4 100644 --- a/admin/reports.php +++ b/admin/reports.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; + +
| Date | +Orders | +Revenue | +
|---|---|---|
| No sales found for the selected period | ||
| = date('M d, Y (D)', strtotime($day['sales_date'])) ?> | += $day['order_count'] ?> | += format_currency($day['total_sales']) ?> | +