@@ -61,6 +64,9 @@ $donations = $pdo->query("SELECT d.*, c.title_en as case_title, cat.name_en as c
|
= htmlspecialchars($don['donor_name'] ?: 'Anonymous') ?>
+
+ Gift
+
|
= htmlspecialchars($don['donor_email']) ?>
diff --git a/admin/donors.php b/admin/donors.php
new file mode 100644
index 0000000..319de5c
--- /dev/null
+++ b/admin/donors.php
@@ -0,0 +1,88 @@
+query("
+ SELECT
+ donor_email,
+ donor_name,
+ donor_phone,
+ SUM(amount) as total_contributed,
+ COUNT(*) as donation_count,
+ MAX(created_at) as last_donation
+ FROM donations
+ WHERE status = 'completed'
+ GROUP BY donor_email
+ ORDER BY total_contributed DESC
+")->fetchAll();
+?>
+
+
+
+
+
+ Donors CRM - CharityHub Admin
+
+
+
+
+
+
+
+
+
+ Donor CRM
+
+
+
+
+
+
+
+ | Donor Name |
+ Email |
+ Phone |
+ Donations |
+ Total Amount |
+ Last Donation |
+
+
+
+
+
+ |
+ = htmlspecialchars($donor['donor_name'] ?: 'Anonymous') ?>
+ |
+ = htmlspecialchars($donor['donor_email']) ?> |
+ = htmlspecialchars($donor['donor_phone'] ?? 'N/A') ?> |
+ = $donor['donation_count'] ?> |
+ OMR = number_format($donor['total_contributed'], 3) ?> |
+ = date('M j, Y', strtotime($donor['last_donation'])) ?> |
+
+
+
+
+ | No donors found with completed payments. |
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/admin/export_donations.php b/admin/export_donations.php
new file mode 100644
index 0000000..b70d820
--- /dev/null
+++ b/admin/export_donations.php
@@ -0,0 +1,47 @@
+query("
+ SELECT d.id, d.donor_name, d.donor_email, d.donor_phone, c.title_en as case_title, d.amount, d.status, d.transaction_id, d.created_at, d.is_gift, d.gift_recipient_name, d.gift_recipient_phone
+ FROM donations d
+ JOIN cases c ON d.case_id = c.id
+ ORDER BY d.created_at DESC
+");
+
+$filename = "donations_" . date('Y-m-d') . ".csv";
+
+header('Content-Type: text/csv; charset=utf-8');
+header('Content-Disposition: attachment; filename=' . $filename);
+
+$output = fopen('php://output', 'w');
+
+// Set CSV headers
+fputcsv($output, [
+ 'ID',
+ 'Donor Name',
+ 'Donor Email',
+ 'Donor Phone',
+ 'Case',
+ 'Amount (OMR)',
+ 'Status',
+ 'Transaction ID',
+ 'Date',
+ 'Is Gift',
+ 'Recipient Name',
+ 'Recipient Phone'
+]);
+
+while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ // Clean up status for CSV
+ $row['status'] = ucfirst($row['status']);
+ $row['is_gift'] = $row['is_gift'] ? 'Yes' : 'No';
+ fputcsv($output, $row);
+}
+
+fclose($output);
+exit;
diff --git a/admin/financial_summary.php b/admin/financial_summary.php
new file mode 100644
index 0000000..f09d674
--- /dev/null
+++ b/admin/financial_summary.php
@@ -0,0 +1,281 @@
+query("
+ SELECT
+ COUNT(*) as total_count,
+ SUM(CASE WHEN status = 'completed' THEN amount ELSE 0 END) as total_revenue,
+ AVG(CASE WHEN status = 'completed' THEN amount ELSE NULL END) as avg_donation,
+ SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) as pending_count,
+ SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END) as completed_count
+ FROM donations
+")->fetch();
+
+// Revenue by Category
+$category_revenue = $pdo->query("
+ SELECT c.name_en, SUM(d.amount) as total
+ FROM categories c
+ JOIN cases cs ON cs.category_id = c.id
+ JOIN donations d ON d.case_id = cs.id
+ WHERE d.status = 'completed'
+ GROUP BY c.id
+ ORDER BY total DESC
+")->fetchAll();
+
+$cat_labels = [];
+$cat_totals = [];
+foreach ($category_revenue as $row) {
+ $cat_labels[] = $row['name_en'];
+ $cat_totals[] = (float)$row['total'];
+}
+
+// Monthly Revenue Trend (Last 12 Months)
+$monthly_trend = $pdo->query("
+ SELECT
+ DATE_FORMAT(created_at, '%Y-%m') as month,
+ SUM(amount) as total
+ FROM donations
+ WHERE status = 'completed' AND created_at >= DATE_SUB(NOW(), INTERVAL 12 MONTH)
+ GROUP BY month
+ ORDER BY month ASC
+")->fetchAll();
+
+$trend_labels = [];
+$trend_totals = [];
+foreach ($monthly_trend as $row) {
+ $trend_labels[] = date('M Y', strtotime($row['month'] . '-01'));
+ $trend_totals[] = (float)$row['total'];
+}
+
+// Top Cases by Revenue
+$top_cases = $pdo->query("
+ SELECT cs.title_en, SUM(d.amount) as total, cs.goal
+ FROM cases cs
+ JOIN donations d ON d.case_id = cs.id
+ WHERE d.status = 'completed'
+ GROUP BY cs.id
+ ORDER BY total DESC
+ LIMIT 5
+")->fetchAll();
+
+// Gift vs Regular
+$gift_stats = $pdo->query("
+ SELECT
+ is_gift,
+ COUNT(*) as count,
+ SUM(amount) as total
+ FROM donations
+ WHERE status = 'completed'
+ GROUP BY is_gift
+")->fetchAll();
+
+$gift_labels = ['Regular', 'Gift'];
+$gift_totals = [0, 0];
+foreach ($gift_stats as $row) {
+ if ($row['is_gift']) {
+ $gift_totals[1] = (float)$row['total'];
+ } else {
+ $gift_totals[0] = (float)$row['total'];
+ }
+}
+
+?>
+
+
+
+
+
+ Financial Summary - CharityHub Admin
+
+
+
+
+
+
+
+
+
+
+
+ Financial Summary
+ Detailed analysis of donations and revenue streams.
+
+ = date('l, F j, Y') ?>
+
+
+
+
+
+
+ Total Revenue
+ OMR = number_format($stats['total_revenue'] ?? 0, 3) ?>
+ From = $stats['completed_count'] ?> donations
+
+
+
+
+ Avg. Donation
+ OMR = number_format($stats['avg_donation'] ?? 0, 3) ?>
+ Per completed donation
+
+
+
+
+ Pending Revenue
+ = $stats['pending_count'] ?>
+ Awaiting payment
+
+
+
+
+ Total Donations
+ = $stats['total_count'] ?>
+ All statuses included
+
+
+
+
+
+
+
+
+ Monthly Revenue Trend (Last 12 Months)
+
+
+
+
+
+
+
+
+ Revenue by Category
+
+
+
+
+
+
+
+
+
+
+
+ Top Performing Cases
+
+
+
+
+ = htmlspecialchars($case['title_en']) ?>
+ OMR = number_format($case['total'], 3) ?>
+
+ 0 ? ($case['total'] / $case['goal']) * 100 : 0;
+ ?>
+
+ = number_format($percent, 1) ?>% of OMR = number_format($case['goal'], 0) ?> goal
+
+
+
+
+
+
+
+
+ Regular vs Gift Donations (Revenue)
+
+
+
+
+
+ Regular
+ OMR = number_format($gift_totals[0], 3) ?>
+
+
+ Gift
+ OMR = number_format($gift_totals[1], 3) ?>
+
+
+
+
+
+
+
+
+
+
diff --git a/admin/index.php b/admin/index.php
index c92e5b2..a3cafbc 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -11,6 +11,22 @@ $total_categories = $pdo->query("SELECT COUNT(*) FROM categories")->fetchColumn(
$total_cases = $pdo->query("SELECT COUNT(*) FROM cases")->fetchColumn();
$total_donations = $pdo->query("SELECT SUM(amount) FROM donations WHERE status = 'completed'")->fetchColumn() ?: 0;
+// Fetch chart data (last 30 days)
+$chart_data = $pdo->query("
+ SELECT DATE(created_at) as date, SUM(amount) as total
+ FROM donations
+ WHERE status = 'completed' AND created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)
+ GROUP BY DATE(created_at)
+ ORDER BY date ASC
+")->fetchAll(PDO::FETCH_ASSOC);
+
+$labels = [];
+$totals = [];
+foreach ($chart_data as $row) {
+ $labels[] = date('M j', strtotime($row['date']));
+ $totals[] = (float)$row['total'];
+}
+
// Fetch recent donations
$recent_donations = $pdo->query("
SELECT d.*, c.title_en as case_title
@@ -28,6 +44,7 @@ $recent_donations = $pdo->query("
Dashboard - CharityHub Admin
+
@@ -92,6 +110,27 @@ $recent_donations = $pdo->query("
+
+
+
+ Donation Trends (Last 30 Days)
+
+
+
+
+
+
+
+
Recent Donations
@@ -136,5 +175,42 @@ $recent_donations = $pdo->query("
+
+
|