fix financial issues

This commit is contained in:
root
2026-06-01 02:08:27 -04:00
parent 090cb88573
commit 6444b61416
56 changed files with 4196 additions and 1824 deletions
+80 -105
View File
@@ -61,8 +61,8 @@
</div>
<div class="col-12 col-lg-6">
<div class="h-100 p-3 border rounded">
<h3 class="h5">Expense Breakdown</h3>
<canvas id="expenseChart" style="max-height:320px; width:100%;"></canvas>
<h3 class="h5">Expenses out of Net Amount</h3>
<canvas id="netExpenseChart" style="max-height:320px; width:100%;"></canvas>
</div>
</div>
</div>
@@ -77,10 +77,49 @@
<script>
function fmt(n){ return '$' + Number(n||0).toFixed(2); }
const initialSummaryData = {
schoolYear: <?= json_encode((string)($schoolYear ?? '')) ?>,
totalCharges: <?= json_encode((float)($totalCharges ?? 0)) ?>,
totalEventFees: <?= json_encode((float)($totalEventFees ?? 0)) ?>,
totalExtraCharges: <?= json_encode((float)($totalExtraCharges ?? 0)) ?>,
totalDiscounts: <?= json_encode((float)($totalDiscounts ?? 0)) ?>,
totalRefunds: <?= json_encode((float)($totalRefunds ?? 0)) ?>,
totalExpenses: <?= json_encode((float)($totalExpenses ?? 0)) ?>,
totalReimbursements: <?= json_encode((float)($totalReimbursements ?? 0)) ?>,
donationToSchool: <?= json_encode((float)($donationToSchool ?? 0)) ?>,
totalPaid: <?= json_encode((float)($totalPaid ?? 0)) ?>,
amountCollected: <?= json_encode((float)($amountCollected ?? 0)) ?>,
totalUnpaid: <?= json_encode((float)($totalUnpaid ?? 0)) ?>,
netAmount: <?= json_encode((float)($netAmount ?? 0)) ?>
};
function applySummaryData(d) {
document.getElementById('summaryPeriod').textContent = 'Report for School Year: ' + (d.schoolYear || '');
document.getElementById('sumCharges').textContent = fmt(d.totalCharges);
if (document.getElementById('sumEventFees')) {
document.getElementById('sumEventFees').textContent = fmt(d.totalEventFees || 0);
}
if (document.getElementById('sumExtraCharges')) {
document.getElementById('sumExtraCharges').textContent = fmt(d.totalExtraCharges || 0);
}
document.getElementById('sumDiscounts').textContent = fmt(d.totalDiscounts);
document.getElementById('sumRefunds').textContent = fmt(d.totalRefunds);
document.getElementById('sumExpenses').textContent = fmt(d.totalExpenses);
document.getElementById('sumReimb').textContent = fmt(d.totalReimbursements);
if (document.getElementById('sumDonationToSchool')) {
document.getElementById('sumDonationToSchool').textContent = fmt(d.donationToSchool);
}
document.getElementById('sumNet').textContent = fmt(d.netAmount);
document.getElementById('sumCollected').textContent = fmt(d.amountCollected || d.totalPaid || 0);
document.getElementById('sumUnpaid').textContent = fmt(d.totalUnpaid);
}
// Auto-submit school year on change and hydrate via API
document.addEventListener('DOMContentLoaded', function() {
const sel = document.querySelector('#summaryYearFilter select[name="school_year"]');
if (sel) sel.addEventListener('change', function(){ loadSummary(); });
applySummaryData(initialSummaryData);
renderCharts(initialSummaryData);
loadSummary();
});
@@ -97,26 +136,7 @@ function loadSummary(){
.then(d => {
if (mySeq !== __sumSeq) return; // stale response
if (!d || d.ok !== true) return;
document.getElementById('summaryPeriod').textContent = 'Report for School Year: ' + (d.schoolYear||'');
document.getElementById('sumCharges').textContent = fmt(d.totalCharges);
if (document.getElementById('sumEventFees')) {
document.getElementById('sumEventFees').textContent = fmt(d.totalEventFees || 0);
}
if (document.getElementById('sumExtraCharges')) {
document.getElementById('sumExtraCharges').textContent = fmt(d.totalExtraCharges || 0);
}
document.getElementById('sumDiscounts').textContent = fmt(d.totalDiscounts);
document.getElementById('sumRefunds').textContent = fmt(d.totalRefunds);
document.getElementById('sumExpenses').textContent = fmt(d.totalExpenses);
document.getElementById('sumReimb').textContent = fmt(d.totalReimbursements);
if (document.getElementById('sumDonationToSchool')) {
document.getElementById('sumDonationToSchool').textContent = fmt(d.donationToSchool);
}
document.getElementById('sumNet').textContent = fmt(d.netAmount);
document.getElementById('sumCollected').textContent = fmt(d.amountCollected);
document.getElementById('sumUnpaid').textContent = fmt(d.totalUnpaid);
// Refresh charts with new data
applySummaryData(d);
renderCharts(d);
})
.catch(()=>{});
@@ -127,7 +147,7 @@ function renderCharts(d){
// Destroy existing if present
if (window._summaryChart) { window._summaryChart.destroy(); }
if (window._collectedChart) { window._collectedChart.destroy(); }
if (window._expenseChart) { window._expenseChart.destroy(); }
if (window._netExpenseChart) { window._netExpenseChart.destroy(); }
const summaryCtx = document.getElementById('summaryChart').getContext('2d');
window._summaryChart = new Chart(summaryCtx, {
type: 'bar',
@@ -152,11 +172,44 @@ function renderCharts(d){
options: { responsive:true, plugins:{ legend:{ position:'bottom' } } }
});
const expenseCtx = document.getElementById('expenseChart').getContext('2d');
window._expenseChart = new Chart(expenseCtx, {
const netExpenseCtx = document.getElementById('netExpenseChart').getContext('2d');
const netAmount = Number(d.netAmount || 0);
const totalExpenses = Number(d.totalExpenses || 0);
const expensePortion = Math.max(0, Math.min(totalExpenses, netAmount));
const remainingNet = Math.max(0, netAmount - expensePortion);
const expensePercent = netAmount > 0 ? ((totalExpenses / netAmount) * 100).toFixed(1) : '0.0';
const remainingPercent = netAmount > 0 ? ((remainingNet / netAmount) * 100).toFixed(1) : '0.0';
const netExpenseValues = [expensePortion, remainingNet];
const netExpenseLabels = [
'Expenses (' + expensePercent + '%)',
'Remaining Net (' + remainingPercent + '%)'
];
window._netExpenseChart = new Chart(netExpenseCtx, {
type: 'pie',
data: { labels: ['Expenses','Reimbursements'], datasets: [{ data:[ d.totalExpenses||0, d.totalReimbursements||0 ], backgroundColor: ['#dc3545','#6f42c1']}]},
options: { responsive:true }
data: {
labels: netExpenseLabels,
datasets: [{
data: netExpenseValues,
backgroundColor: ['#20c997', '#dc3545'],
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: { position: 'bottom' },
tooltip: {
callbacks: {
label: function(context) {
if (context.dataIndex === 0) {
return 'Expenses: ' + fmt(totalExpenses) + ' (' + expensePercent + '% of net amount)';
}
return 'Remaining Net: ' + fmt(remainingNet) + ' (' + remainingPercent + '%)';
}
}
}
}
}
});
}
</script>
@@ -174,82 +227,4 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
// Bar chart summary
const summaryCtx = document.getElementById('summaryChart').getContext('2d');
window._summaryChart = new Chart(summaryCtx, {
type: 'bar',
data: {
labels: ['Charges', 'Event Fees', 'Paid', 'Unpaid', 'Discounts', 'Refunds', 'Expenses', 'Reimbursements', 'Net'],
datasets: [{
label: 'Amount (USD)',
data: [
<?= (float)$totalCharges ?>,
<?= (float)($totalEventFees ?? 0) ?>,
<?= (float)$totalPaid ?>,
<?= (float)$totalUnpaid ?>,
<?= (float)$totalDiscounts ?>,
<?= (float)$totalRefunds ?>,
<?= (float)$totalExpenses ?>,
<?= (float)$totalReimbursements ?>,
<?= (float)$netAmount ?>
],
backgroundColor: [
'#007bff', '#6610f2', '#28a745', '#ffc107', '#17a2b8', '#ffc107', '#dc3545', '#6f42c1', '#20c997'
]
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
// Collected vs Outstanding pie
const collectedCtx = document.getElementById('collectedChart').getContext('2d');
window._collectedChart = new Chart(collectedCtx, {
type: 'pie',
data: {
labels: ['Amount Collected (Paid)', 'Amount Outstanding (Unpaid)'],
datasets: [{
data: [
<?= (float)$amountCollected ?>,
<?= (float)$totalUnpaid ?>
],
backgroundColor: ['#28a745', '#ffc107']
}]
},
options: {
responsive: true,
plugins: { legend: { position: 'bottom' } }
}
});
// Pie chart expenses
const expenseCtx = document.getElementById('expenseChart').getContext('2d');
window._expenseChart = new Chart(expenseCtx, {
type: 'pie',
data: {
labels: ['Expenses', 'Reimbursements'],
datasets: [{
data: [
<?= (float)$totalExpenses ?>,
<?= (float)$totalReimbursements ?>
],
backgroundColor: ['#dc3545', '#6f42c1']
}]
},
options: {
responsive: true
}
});
});
</script>
<?= $this->endSection() ?>
+2 -2
View File
@@ -260,7 +260,7 @@
<td>
<?php if (!empty($payment['check_file'])): ?>
<a href="#" data-bs-toggle="modal" data-bs-target="#checkModal<?= (int)$payment['id'] ?>">View</a> /
<a href="<?= base_url('payment/serveCheckFile/' . esc($payment['check_file']) . '/download') ?>">Download</a>
<a href="<?= base_url('payment/file/' . (int) $payment['id'] . '/download') ?>">Download</a>
<!-- File Preview Modal -->
<div class="modal fade" id="checkModal<?= (int)$payment['id'] ?>" tabindex="-1" aria-hidden="true">
@@ -271,7 +271,7 @@
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body text-center">
<iframe src="<?= base_url('payment/serveCheckFile/' . esc($payment['check_file']) . '/inline') ?>" width="100%" height="600" style="border:none;"></iframe>
<iframe src="<?= base_url('payment/file/' . (int) $payment['id'] . '/inline') ?>" width="100%" height="600" style="border:none;"></iframe>
</div>
</div>
</div>
+2 -3
View File
@@ -91,10 +91,9 @@
<td><?= esc($payment['status']) ?></td>
<td>
<?php if (!empty($payment['check_file'])): ?>
<?php $file = rawurlencode((string)$payment['check_file']); ?>
<!-- Trigger Modal -->
<a href="#" data-bs-toggle="modal" data-bs-target="#checkModal<?= (int)$payment['id'] ?>">View</a> /
<a href="<?= base_url('payment/serveCheckFile/' . $file . '/download') ?>">Download</a>
<a href="<?= base_url('payment/file/' . (int) $payment['id'] . '/download') ?>">Download</a>
<!-- Modal -->
<div class="modal fade" id="checkModal<?= (int)$payment['id'] ?>" tabindex="-1" aria-hidden="true">
@@ -105,7 +104,7 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body text-center">
<iframe src="<?= base_url('payment/serveCheckFile/' . $file . '/inline') ?>"
<iframe src="<?= base_url('payment/file/' . (int) $payment['id'] . '/inline') ?>"
width="100%" height="600px" style="border:none;"></iframe>
</div>
</div>
-81
View File
@@ -1,81 +0,0 @@
<!-- This snippet supports rendering separate standalone buttons
in different parts of your page with unique payment methods.
Test EMAIL: sb-cbmre43313068@business.example.com
Test PASSWORD: 9JC?].qM
-->
<?= $this->extend('layout/register_layout') ?>
<?= $this->section('content') ?>
<div class="container d-flex justify-content-center align-items-start" style="min-height: 100vh; padding-top: 80px;">
<div class="registration-form text-center p-4 rounded-4 shadow"
style="background-color: white; max-width: 600px; width: 300%;">
<!-- Logo -->
<div class="mb-4">
<a href="<?= base_url('/parent_dashboard') ?>">
<img src="<?= base_url('assets/images/alrahma_logo.png') ?>" alt="Alrahma Logo"
style="width: 120px; height: 120px; border-radius: 50%; object-fit: cover;">
</a>
</div>
<!-- Page Title -->
<h3 class="text-success" style="font-family: Arial, sans-serif;">Payment</h3>
<br>
<!-- PayPal Button -->
<div class="d-flex justify-content-center">
<div id="paypal-button-container"></div>
</div>
<p class="text-success">
<br><strong>Your payment information, including credit card and bank account details, is securely stored only by PayPal and Venmo. </strong>
</p>
<p class="text-danger">
We do not collect or save any financial data on our website.
</p>
</div>
</div>
<?= $this->endSection() ?>
<?= $this->section('scripts') ?>
<script src="https://www.paypal.com/sdk/js?client-id=AYsiOekZUvrjgx9C5c554ZeSQ4W6yd0ZX-OHE93_D0fWoa4YXrMmroEeLiAjjdCKkELH8EVZR_yGMLPS&currency=USD&components=buttons,funding-eligibility&enable-funding=venmo&disable-funding=card,paylater">
</script>
<script>
const parentName = <?= json_encode($parentName) ?>;
const totalAmount = <?= json_encode(number_format($totalAmount, 2, '.', '')) ?>;
const schoolId = <?= json_encode($schoolId) ?>;
paypal.Buttons({
style: {
layout: 'vertical',
color: 'blue',
shape: 'rect',
label: 'paypal'
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: totalAmount
},
custom_id: `${schoolId}`,
description: `Payment by ${parentName}`
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name + ' for <?= esc($parentName) ?>');
});
},
onError: function(err) {
console.error('An error occurred during the transaction', err);
}
}).render('#paypal-button-container');
</script>
<?= $this->endSection() ?>