diff --git a/admin/includes/header.php b/admin/includes/header.php index 82ed6b8..b166a84 100644 --- a/admin/includes/header.php +++ b/admin/includes/header.php @@ -475,7 +475,7 @@ function can_view($module) { diff --git a/admin/report_cashiers.php b/admin/report_cashiers.php new file mode 100644 index 0000000..abd9c88 --- /dev/null +++ b/admin/report_cashiers.php @@ -0,0 +1,344 @@ +query("SELECT id, name, name_ar FROM outlets WHERE is_deleted = 0 ORDER BY name ASC"); +$allOutlets = $outletsStmt->fetchAll(); + +// Fetch Cashiers (Users) +$cashiersStmt = $pdo->query("SELECT id, full_name, full_name_ar FROM users WHERE is_deleted = 0 AND is_active = 1 ORDER BY full_name ASC"); +$allCashiers = $cashiersStmt->fetchAll(); + +// Fetch all payment types +$allPaymentTypesStmt = $pdo->query("SELECT name FROM payment_types WHERE is_deleted = 0 ORDER BY id ASC"); +$allPaymentTypes = $allPaymentTypesStmt->fetchAll(PDO::FETCH_COLUMN); + +// Define a set of Bootstrap colors to cycle through for payment types +$paymentColors = [ + 'text-success', + 'text-info', + 'text-warning', + 'text-danger', + 'text-secondary', + 'text-dark', + 'text-primary' +]; + +$paymentBadgeColors = [ + 'bg-success', + 'bg-info text-dark', + 'bg-warning text-dark', + 'bg-danger', + 'bg-secondary', + 'bg-dark', + 'bg-primary' +]; + +// Base query additions +$conditions = ["DATE(o.created_at) BETWEEN ? AND ? AND o.status != 'cancelled'"]; +$queryParams = [$startDate, $endDate]; + +if (!empty($outletId)) { + $conditions[] = "o.outlet_id = ?"; + $queryParams[] = $outletId; +} + +if (!empty($cashierId)) { + $conditions[] = "o.user_id = ?"; + $queryParams[] = $cashierId; +} + +$whereClause = implode(' AND ', $conditions); + +// Fetch total amounts grouped by cashier, outlet and payment type +$salesStmt = $pdo->prepare(" + SELECT + u.id as cashier_id, + u.full_name as cashier_name, + u.full_name_ar as cashier_name_ar, + outl.id as outlet_id, + outl.name as outlet_name, + outl.name_ar as outlet_name_ar, + pt.name as payment_name, + SUM(o.total_amount) as total_amount, + COUNT(o.id) as orders_count + FROM orders o + JOIN users u ON o.user_id = u.id + LEFT JOIN outlets outl ON o.outlet_id = outl.id + LEFT JOIN payment_types pt ON o.payment_type_id = pt.id + WHERE $whereClause + GROUP BY o.user_id, o.outlet_id, o.payment_type_id + ORDER BY u.full_name ASC, outl.name ASC +"); +$salesStmt->execute($queryParams); +$salesData = $salesStmt->fetchAll(); + +// Group by Cashier + Outlet +$cashierSales = []; +foreach ($salesData as $row) { + $key = $row['cashier_id'] . '_' . $row['outlet_id']; + if (!isset($cashierSales[$key])) { + $cashierSales[$key] = [ + 'name' => $row['cashier_name'], + 'name_ar' => $row['cashier_name_ar'], + 'outlet_name' => $row['outlet_name'] ?? 'Unknown Outlet', + 'outlet_name_ar' => $row['outlet_name_ar'] ?? '', + 'payments' => [], + 'total' => 0, + 'orders_count' => 0 + ]; + } + $pName = $row['payment_name'] ?? 'Unknown'; + $amount = (float)$row['total_amount']; + $count = (int)$row['orders_count']; + + $cashierSales[$key]['payments'][$pName] = $amount; + $cashierSales[$key]['total'] += $amount; + $cashierSales[$key]['orders_count'] += $count; +} + +?> + + +
+ + + +
+
+

Cashier Sales Report

+

Sales grouped by cashier and payment methods

+
+
+
+ +
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + Reset +
+
+
+
+ +
+
+
+
+
Cashier Breakdown
+ +
+
+
+ + + + + + $ptName): ?> + + + + + + + + + + + $data): ?> + + + + $ptName): ?> + + + + + + + + + + + + + + $pt): ?> + + + + + + + +
Cashier NameOutlet + + + + OrdersTotal Sales
No sales found for the selected criteria
+ + + + + + + + + + + +
Totals + +
+
+
+
+
+
+
+ + diff --git a/admin/reports.php b/admin/reports.php index 7b8b11e..f1899c2 100644 --- a/admin/reports.php +++ b/admin/reports.php @@ -29,7 +29,7 @@ try { $daily_sales = $pdo->prepare("SELECT DATE(o.created_at) as date, SUM(o.total_amount) as total FROM orders o WHERE o.created_at BETWEEN :from AND :to $outlet_query - AND o.status = 'completed' + AND o.status != 'cancelled' GROUP BY DATE(o.created_at) ORDER BY date ASC"); $daily_sales->execute($params); @@ -40,7 +40,7 @@ try { FROM orders o JOIN users u ON o.user_id = u.id WHERE o.created_at BETWEEN :from AND :to $outlet_query - AND o.status = 'completed' + AND o.status != 'cancelled' GROUP BY u.id ORDER BY total DESC"); $staff_sales->execute($params); @@ -51,7 +51,7 @@ try { FROM orders o JOIN outlets ou ON o.outlet_id = ou.id WHERE o.created_at BETWEEN :from AND :to $outlet_query - AND o.status = 'completed' + AND o.status != 'cancelled' GROUP BY ou.id ORDER BY total DESC"); $outlet_sales->execute($params); @@ -64,7 +64,7 @@ try { JOIN products p ON oi.product_id = p.id JOIN categories c ON p.category_id = c.id WHERE o.created_at BETWEEN :from AND :to $outlet_query - AND o.status = 'completed' + AND o.status != 'cancelled' GROUP BY c.id ORDER BY total DESC"); $cat_sales->execute($params);