query("SELECT id, name, name_ar FROM outlets ORDER BY name ASC"); $allOutlets = $outletsStmt->fetchAll(); // Base query additions $outletCondition = ""; $expenseOutletCondition = ""; $queryParams = [$startDate, $endDate]; if (!empty($outletId)) { $outletCondition = " AND o.outlet_id = ? "; $expenseOutletCondition = " AND e.outlet_id = ? "; $queryParams[] = $outletId; } // 1. Sales by Staff $staffStmt = $pdo->prepare(" SELECT u.full_name as staff_name, u.full_name_ar as staff_name_ar, u.username, COUNT(o.id) as order_count, SUM(o.total_amount) as total_sales FROM orders o JOIN users u ON o.user_id = u.id WHERE DATE(o.created_at) BETWEEN ? AND ? $outletCondition GROUP BY o.user_id ORDER BY total_sales DESC "); $staffStmt->execute($queryParams); $staffSales = $staffStmt->fetchAll(); // 2. Sales by Outlet $outletStmt = $pdo->prepare(" SELECT ot.name as outlet_name, ot.name_ar as outlet_name_ar, COUNT(o.id) as order_count, SUM(o.total_amount) as total_sales FROM orders o JOIN outlets ot ON o.outlet_id = ot.id WHERE DATE(o.created_at) BETWEEN ? AND ? $outletCondition GROUP BY o.outlet_id ORDER BY total_sales DESC "); $outletStmt->execute($queryParams); $outletSales = $outletStmt->fetchAll(); // 3. Sales by Category $categoryStmt = $pdo->prepare(" SELECT c.name as category_name, c.name_ar as category_name_ar, SUM(oi.quantity) as items_sold, SUM(oi.quantity * oi.unit_price) as total_sales FROM order_items oi JOIN orders o ON oi.order_id = o.id 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 ? $outletCondition GROUP BY c.id ORDER BY total_sales DESC "); $categoryStmt->execute($queryParams); $categorySales = $categoryStmt->fetchAll(); // 4. Expenses by Category $expenseCatStmt = $pdo->prepare(" SELECT ec.name as category_name, ec.name_ar as category_name_ar, SUM(e.amount) as total_amount FROM expenses e JOIN expense_categories ec ON e.category_id = ec.id WHERE e.expense_date BETWEEN ? AND ? $expenseOutletCondition GROUP BY ec.id ORDER BY total_amount DESC "); $expenseCatStmt->execute($queryParams); $expenseSales = $expenseCatStmt->fetchAll(); // Total Summary $totalStmt = $pdo->prepare(" SELECT COUNT(id) as total_orders, SUM(total_amount) as total_revenue FROM orders o WHERE DATE(o.created_at) BETWEEN ? AND ? $outletCondition "); $totalStmt->execute($queryParams); $summary = $totalStmt->fetch(); $totalExpStmt = $pdo->prepare(" SELECT SUM(amount) as total_expenses FROM expenses e WHERE expense_date BETWEEN ? AND ? $expenseOutletCondition "); $totalExpStmt->execute($queryParams); $totalExpenses = $totalExpStmt->fetchColumn() ?? 0; $netProfit = ($summary['total_revenue'] ?? 0) - $totalExpenses; ?>

Daily Reports

Overview of your business performance

Reset
Total Orders

Total Revenue

Total Expenses

Net Profit

Sales by Staff
Staff Name Orders Total Sales
No data found for this period
Sales by Outlet
Outlet Orders Total Sales
No data found for this period
Sales by Category
Category Items Sold Total Revenue
No data found for this period
Expenses by Category
Category Total Amount
No data found for this period