prepare("SELECT SUM(amount) FROM expenses WHERE date BETWEEN ? AND ?"); $stmt->execute([$start_date, $end_date]); $total = $stmt->fetchColumn() ?: 0; // By Category $stmt = $db->prepare("SELECT c.name, SUM(e.amount) as total FROM expenses e JOIN expense_categories c ON e.category_id = c.id WHERE e.date BETWEEN ? AND ? GROUP BY c.name ORDER BY total DESC"); $stmt->execute([$start_date, $end_date]); $by_category = $stmt->fetchAll(PDO::FETCH_ASSOC); return ['total' => $total, 'by_category' => $by_category]; } // Current month stats $current_month = date('m'); $current_year = date('Y'); $current_stats = getExpenseStats($current_month, $current_year); // Last 6 months trend $trend_data = []; for ($i = 5; $i >= 0; $i--) { $d = strtotime("-$i months"); $m = date('m', $d); $y = date('Y', $d); $s = getExpenseStats($m, $y); $trend_data[] = [ 'label' => date('M Y', $d), // English month names for Chart.js 'display_label' => date('m/Y', $d), 'total' => $s['total'] ]; } // Recent Expenses $stmt = db()->query("SELECT e.*, c.name as category_name FROM expenses e JOIN expense_categories c ON e.category_id = c.id ORDER BY e.date DESC, e.id DESC LIMIT 5"); $recent_expenses = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>
| التاريخ | التصنيف | الوصف/المورد | المبلغ | طريقة الدفع |
|---|---|---|---|---|
| لا توجد مصروفات مسجلة | ||||
| = $exp['date'] ?> | = htmlspecialchars($exp['category_name']) ?> |
= htmlspecialchars($exp['description'] ?: '-') ?>
= htmlspecialchars($exp['vendor'] ?: '') ?>
|
= number_format($exp['amount'], 2) ?> | = htmlspecialchars($exp['payment_method']) ?> |