Current Directory: /home/aissorg/public_html/admin
Viewing File: /home/aissorg/public_html/admin/donation.php
<?php
include('include/config.php');
include('php/constant.php');
// Initialize Alert Variables
$alert = '';
$alert_class = '';
// Fetch All Donation Records
function fetchDonations($con) {
$sql = "SELECT * FROM donations ORDER BY donation_date DESC";
$result = mysqli_query($con, $sql);
$records = [];
while ($row = mysqli_fetch_assoc($result)) {
$records[] = $row;
}
return $records;
}
// Fetch Unique Customers with Total Donation Amount
function fetchUniqueCustomersWithTotal($con) {
$sql = "SELECT
name,
email,
mobile,
SUM(amount) AS total_donation
FROM donations
GROUP BY name, email, mobile
ORDER BY name ASC";
$result = mysqli_query($con, $sql);
$customers = [];
while ($row = mysqli_fetch_assoc($result)) {
$customers[] = $row;
}
return $customers;
}
// Check if Customer-Wise Report is Requested
$is_customer_wise = isset($_GET['customer_wise']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Donation Report</title>
<link rel="shortcut icon" type="image/x-icon" href="">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<!-- Fontawesome CSS -->
<link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
<link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Arimo:ital,wght@0,400..700;1,400..700&display=swap" rel="stylesheet">
<!-- Feather CSS -->
<link rel="stylesheet" href="assets/plugins/feather/feather.css">
<!-- Datepicker CSS -->
<link rel="stylesheet" href="assets/css/bootstrap-datetimepicker.min.css">
<!-- Daterangepikcer CSS -->
<link rel="stylesheet" href="assets/plugins/daterangepicker/daterangepicker.css">
<!-- Datatables CSS -->
<link rel="stylesheet" href="assets/plugins/datatables/datatables.min.css">
<!-- Main CSS -->
<link rel="stylesheet" href="assets/css/style.css">
<!-- Layout Js -->
<script type="text/javascript">
var BASE_PHP_URL = "<?php echo BASE_PHP_URL; ?>"; // This will contain the PHP constant
</script>
</head>
<body>
<div class="main-wrapper">
<?php include("include/header.php") ?>
<?php include("include/sidebar.php") ?>
<div class="page-wrapper">
<div class="content container-fluid">
<div class="page-header">
<h5>Donation Report</h5>
<form method="GET" action="">
<button type="submit" name="customer_wise" value="true" class="btn btn-primary">Generate Customer Wise Report</button>
</form>
</div>
<div class="row">
<div class="col-sm-12">
<div class="card-table">
<div class="card-body">
<div class="table-responsive">
<?php if (!$is_customer_wise): ?>
<table class="table table-striped datatable">
<thead>
<tr>
<th>#</th>
<th>Customer Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>Amount</th>
<th>Transaction ID</th>
<th>Donation Date</th>
<th>Notes</th>
<th>Created At</th>
</tr>
</thead>
<tbody>
<?php
$records = fetchDonations($con);
foreach ($records as $record) {
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . $record['name'] . "</td>";
echo "<td>" . ($record['mobile'] ?? 'N/A') . "</td>";
echo "<td>" . ($record['phone_number'] ?? 'N/A') . "</td>";
echo "<td>$" . number_format($record['amount'], 2) . "</td>";
echo "<td>" . ($record['pan_number'] ?? 'N/A') . "</td>";
echo "<td>" . $record['donation_date'] . "</td>";
echo "<td>" . ($record['purpose'] ?? 'N/A') . "</td>";
echo "<td>" . $record['created_at'] . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<?php else: ?>
<table class="table table-striped datatable">
<thead>
<tr>
<th>Customer Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>Total Donation</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$customers = fetchUniqueCustomersWithTotal($con);
foreach ($customers as $customer) {
echo "<tr>";
echo "<td>" . $customer['name'] . "</td>";
echo "<td>" . ($customer['email'] ?? 'N/A') . "</td>";
echo "<td>" . ($customer['phone_number'] ?? 'N/A') . "</td>";
echo "<td>$" . number_format($customer['total_donation'], 2) . "</td>";
echo "<td><button class='btn btn-sm btn-info view-donation' data-customer='" . htmlspecialchars($customer['name'], ENT_QUOTES) . "'><i class='fas fa-eye'></i></button></td>";
echo "</tr>";
}
?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Donation History Modal -->
<div class="modal fade" id="donationModal" tabindex="-1" aria-labelledby="donationModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="donationModalLabel">Donation History</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h6>Donations by: <span id="modal-customer-name"></span></h6>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Amount</th>
</tr>
</thead>
<tbody id="donation-history">
<!-- Donation data will be loaded here -->
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script data-cfasync="false" src="../../cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js" type="text/javascript"></script>
<!-- Bootstrap Core JS -->
<script src="assets/js/bootstrap.bundle.min.js" type="text/javascript"></script>
<!-- Datatable JS -->
<script src="assets/plugins/datatables/datatables.min.js" type="text/javascript"></script>
<!-- select CSS -->
<script src="assets/plugins/select2/js/select2.min.js" type="text/javascript"></script>
<!-- Slimscroll JS -->
<script src="assets/plugins/slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<!-- Datepicker Core JS -->
<script src="assets/plugins/moment/moment.min.js" type="text/javascript"></script>
<script src="assets/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<script src="assets/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<!-- multiselect JS -->
<script src="assets/js/jquery-ui.min.js" type="text/javascript"></script>
<!-- Theme Settings JS -->
<script src="assets/js/theme-settings.js" type="text/javascript"></script>
<script src="assets/js/greedynav.js" type="text/javascript"></script>
<!-- Custom JS -->
<script src="assets/js/script.js" type="text/javascript"></script>
<script src="../../cdn-cgi/scripts/7d0fa10a/cloudflare-static/rocket-loader.min.js" data-cf-settings="|49" defer></script>
<script>
$(document).ready(function() {
$('.datatable').DataTable();
});
</script>
<script>
$(document).ready(function() {
$('.view-donation').click(function() {
var customerName = $(this).data('customer');
$('#modal-customer-name').text(customerName);
$('#donation-history').html('<tr><td colspan="4">Loading...</td></tr>');
$.ajax({
url: BASE_PHP_URL + 'fetch-donation-history.php',
type: 'POST',
data: { customer_name: customerName },
success: function(response) {
$('#donation-history').html(response);
}
});
$('#donationModal').modal('show');
});
});
</script>
</body>
</html>