Repository navigation
Expand file tree
/
Copy pathinterest_tracker.php
More file actions
317 lines (293 loc) · 16.4 KB
/
Copy pathinterest_tracker.php
File metadata and controls
317 lines (293 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
$page_title = "Interest Tracker";
require_once __DIR__ . '/autoload.php';
use App\Core\Bootstrap;
use App\Helpers\SecurityHelper;
use App\Helpers\Html;
use App\Helpers\Layout;
Bootstrap::init();
Layout::header();
Layout::sidebar();
$year = filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT, ['options' => ['min_range' => 2000, 'max_range' => 2100]]) ?: (int) date('Y');
// Get total interest per month for the selected year
$stmt = $pdo->prepare("
SELECT MONTH(interest_date) as month, SUM(amount) as total
FROM interest_tracker
WHERE tenant_id = :tenant_id AND YEAR(interest_date) = :year
GROUP BY MONTH(interest_date)
");
$stmt->execute(['tenant_id' => $_SESSION['tenant_id'], 'year' => $year]);
$monthly_totals = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
// Get Year-Specific Totals (Due vs Paid for SELECTED YEAR)
$stmt = $pdo->prepare("SELECT SUM(CASE WHEN amount > 0 THEN amount ELSE 0 END) as total_accrued,
SUM(CASE WHEN amount < 0 THEN ABS(amount) ELSE 0 END) as total_paid
FROM interest_tracker WHERE tenant_id = ? AND YEAR(interest_date) = ?");
$stmt->execute([$_SESSION['tenant_id'], $year]);
$year_stats = $stmt->fetch();
$total_accrued = $year_stats['total_accrued'] ?? 0;
$total_paid = $year_stats['total_paid'] ?? 0;
$current_balance = $total_accrued - $total_paid;
// Get Global Pending Breakdown (For the new Modal)
$stmt = $pdo->prepare("SELECT YEAR(interest_date) as year, SUM(amount) as net_balance
FROM interest_tracker
WHERE tenant_id = ?
GROUP BY YEAR(interest_date)
HAVING net_balance > 0
ORDER BY year ASC");
$stmt->execute([$_SESSION['tenant_id']]);
$global_pending_breakdown = $stmt->fetchAll();
$global_net_pending = 0;
foreach ($global_pending_breakdown as $row) {
$global_net_pending += $row['net_balance'];
}
$months = [
1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'August',
9 => 'September',
10 => 'October',
11 => 'November',
12 => 'December'
];
$current_month = date('n');
$current_year = date('Y');
?>
<!-- Premium Header Banner -->
<div class="row mb-4">
<div class="col-12">
<div class="gradient-card-primary p-4 rounded-4 hover-lift position-relative overflow-hidden shadow-sm" style="border-radius: 16px;">
<div class="position-absolute top-0 end-0 p-3 opacity-10">
<i class="fa-solid fa-percent fa-9x"></i>
</div>
<div class="d-flex justify-content-between align-items-center flex-wrap gap-3 position-relative" style="z-index: 2;">
<div>
<h1 class="h3 fw-bold mb-1 text-white">Interest Tracker</h1>
<p class="text-white text-opacity-75 mb-0">Monitor non-permissible interest and manage charitable offset payments for <?php echo $year; ?></p>
</div>
<div class="d-flex gap-2">
<button class="btn btn-white text-primary border-0 rounded-pill px-3 py-1.5 fw-bold shadow-sm hover-lift" data-bs-toggle="modal" data-bs-target="#globalPendingModal">
<i class="fa-solid fa-calculator me-1"></i> Total Due Breakdown
</button>
<form action="" method="GET" class="d-inline-block">
<select name="year" class="form-select rounded-pill px-3 fw-bold" data-autosubmit style="min-width: 100px; border: none; height: 38px;">
<?php
$start_year = min(2025, $year);
$end_year = max((int) date('Y') + 5, $year);
for ($y = $start_year; $y <= $end_year; $y++):
$selected = ($y == $year) ? 'selected' : '';
?>
<option value="<?php echo $y; ?>" <?php echo $selected; ?>><?php echo $y; ?></option>
<?php endfor; ?>
</select>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Stats Row -->
<div class="row g-4 mb-4">
<div class="col-md-6">
<div class="glass-panel-premium p-4 h-100 hover-lift position-relative overflow-hidden" style="border-left: 4px solid #f43f5e !important;">
<div class="position-absolute end-0 top-50 translate-middle-y me-4 opacity-10">
<i class="fa-solid fa-circle-exclamation fa-4x text-danger"></i>
</div>
<h6 class="text-muted fw-bold text-uppercase small mb-2">Remaining Interest Due (<?php echo $year; ?>)</h6>
<h2 class="fw-bold text-danger mb-1">
<small class="fs-6 text-muted">AED</small>
<span class="blur-sensitive"><?php echo number_format($current_balance, 2); ?></span>
</h2>
<p class="text-muted small mb-0">Total interest received needing disposal</p>
</div>
</div>
<div class="col-md-6">
<div class="glass-panel-premium p-4 h-100 hover-lift position-relative overflow-hidden" style="border-left: 4px solid #10b981 !important;">
<div class="position-absolute end-0 top-50 translate-middle-y me-4 opacity-10">
<i class="fa-solid fa-circle-check fa-4x text-success"></i>
</div>
<h6 class="text-muted fw-bold text-uppercase small mb-2">Total Paid / Disposed (<?php echo $year; ?>)</h6>
<h2 class="fw-bold text-success mb-1">
<small class="fs-6 text-muted">AED</small>
<span class="blur-sensitive"><?php echo number_format($total_paid, 2); ?></span>
</h2>
<p class="text-muted small mb-0">Charitable payments cleared for this year</p>
</div>
</div>
</div>
<?php if (($_SESSION['permission'] ?? 'edit') !== 'read_only'): ?>
<div class="mb-4">
<button class="btn btn-dark w-100 py-3 rounded-4 fw-bold hover-lift shadow-sm d-flex align-items-center justify-content-center gap-2"
data-bs-toggle="modal" data-bs-target="#recordPaymentModal">
<i class="fa-solid fa-hand-holding-dollar fa-lg text-primary"></i>
<span>Record Interest Payment (Charity Donation)</span>
</button>
</div>
<?php endif; ?>
<!-- Monthly Grid -->
<div class="row g-4">
<?php foreach ($months as $num => $name): ?>
<?php
$total = $monthly_totals[$num] ?? 0;
$is_current = ($year == $current_year && $num == $current_month);
$has_data = $total != 0;
?>
<div class="col-6 col-md-4 col-lg-3">
<a href="monthly_interest.php?month=<?php echo $num; ?>&year=<?php echo $year; ?>" class="text-decoration-none d-block h-100">
<?php if ($is_current): ?>
<!-- Current Month (Accent Gradient) -->
<div class="card border-0 h-100 shadow-md hover-lift transition-all"
style="background: linear-gradient(135deg, #06b6d4, #0891b2); border-radius: 16px;">
<div class="card-body p-4 d-flex flex-column justify-content-between text-center min-h-140">
<div>
<h5 class="fw-bold mb-1 text-white">
<?php echo $name; ?>
</h5>
<span class="badge rounded-pill bg-white bg-opacity-25 text-white small px-2 py-0.5">Current</span>
</div>
<div class="mt-4">
<?php if ($total > 0): ?>
<h4 class="fw-bold mb-0 text-white">
<small style="font-size: 0.65em;">AED</small>
<span class="blur-sensitive"><?php echo number_format($total, 2); ?></span>
</h4>
<small class="text-white text-opacity-75">Outstanding</small>
<?php elseif ($total < 0): ?>
<h4 class="fw-bold mb-0 text-white">
<small style="font-size: 0.65em;">AED</small>
<span class="blur-sensitive"><?php echo number_format(abs($total), 2); ?></span>
</h4>
<small class="text-white text-opacity-75">Credit</small>
<?php else: ?>
<div class="text-white text-opacity-75 small py-1">- No Entry -</div>
<?php endif; ?>
</div>
</div>
</div>
<?php else: ?>
<!-- Glass Card -->
<div class="glass-panel-premium h-100 hover-lift text-center">
<div class="p-4 d-flex flex-column justify-content-between min-h-140">
<div>
<h5 class="fw-bold mb-1 text-dark">
<?php echo $name; ?>
</h5>
<small class="text-muted"><?php echo $year; ?></small>
</div>
<div class="mt-4">
<?php if ($total > 0): ?>
<h4 class="fw-bold mb-0 text-danger">
<small style="font-size: 0.65em;">AED</small>
<span class="blur-sensitive"><?php echo number_format($total, 2); ?></span>
</h4>
<small class="text-muted">Outstanding</small>
<?php elseif ($total < 0): ?>
<h4 class="fw-bold mb-0 text-success">
<small style="font-size: 0.65em;">AED</small>
<span class="blur-sensitive"><?php echo number_format(abs($total), 2); ?></span>
<i class="fa-solid fa-check-double ms-1"></i>
</h4>
<small class="text-muted">Overpaid / Credit</small>
<?php elseif ($has_data && $total == 0): ?>
<h4 class="fw-bold mb-0 text-success"><i class="fa-solid fa-check-circle"></i> Paid</h4>
<small class="text-muted">Settled</small>
<?php else: ?>
<div class="text-muted small py-1">- No Entry -</div>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
</a>
</div>
<?php endforeach; ?>
</div>
<!-- Record Payment Modal -->
<div class="modal fade" id="recordPaymentModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content glass-panel-premium border-0 shadow-lg p-0">
<div class="modal-header border-bottom border-light p-4">
<h5 class="modal-title fw-bold text-dark">Record Interest Disposal</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body p-4">
<form action="interest_actions.php" method="POST">
<input type="hidden" name="csrf_token" value="<?php echo SecurityHelper::generateCsrfToken(); ?>">
<input type="hidden" name="action" value="add_payment">
<div class="mb-3">
<label for="paymentDate" class="form-label fw-bold text-muted small">Payment Date</label>
<input type="date" name="payment_date" id="paymentDate" class="form-control rounded-pill px-3"
value="<?php echo date('Y-m-d'); ?>" required>
</div>
<div class="mb-3">
<label for="targetMonthYear" class="form-label fw-bold text-muted small">Paying For (Month/Year)</label>
<input type="month" name="target_month_year" id="targetMonthYear" class="form-control rounded-pill px-3" required>
</div>
<div class="mb-3">
<label for="amountPaid" class="form-label fw-bold text-muted small">Amount Paid</label>
<div class="input-group">
<span class="input-group-text bg-light text-muted border-end-0" style="border-top-left-radius: 20px; border-bottom-left-radius: 20px;">AED</span>
<input type="number" step="0.01" name="amount" id="amountPaid" class="form-control border-start-0"
placeholder="0.00" style="border-top-right-radius: 20px; border-bottom-right-radius: 20px;" required>
</div>
</div>
<div class="mb-4">
<label for="paymentTitle" class="form-label fw-bold text-muted small">Description / Charity Target</label>
<input type="text" name="title" id="paymentTitle" class="form-control rounded-pill px-3"
placeholder="e.g. Charity via Red Crescent" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary fw-bold py-2.5 rounded-pill shadow-sm hover-lift">
Record Payment <i class="fa-solid fa-check ms-1"></i>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Global Pending Modal -->
<div class="modal fade" id="globalPendingModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content glass-panel-premium border-0 shadow-lg p-0">
<div class="modal-header border-bottom border-light p-4">
<h5 class="modal-title fw-bold text-dark">Outstanding Interest Balances</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body p-4">
<div class="text-center mb-4">
<h6 class="text-muted text-uppercase small fw-bold">Cumulative Outstanding</h6>
<h1 class="display-5 fw-bold text-danger mb-1">
<small class="fs-6 text-muted">AED</small> <span class="blur-sensitive"><?php echo number_format($global_net_pending, 2); ?></span>
</h1>
<p class="text-muted small mb-0">Total across all historic tracking years</p>
</div>
<div class="p-3 bg-light rounded-4 border border-light">
<div class="fw-bold small text-uppercase text-muted mb-2 ps-1">
Yearly Outstanding Breakdown
</div>
<div class="d-flex flex-column gap-2">
<?php if (empty($global_pending_breakdown)): ?>
<div class="text-center text-muted py-3 small">All interest is fully cleared.</div>
<?php else: ?>
<?php foreach ($global_pending_breakdown as $row): ?>
<div class="d-flex justify-content-between align-items-center py-2 px-3 bg-white rounded-3 shadow-sm border-light">
<span class="fw-bold text-dark"><?php echo $row['year']; ?></span>
<span class="text-danger fw-bold">AED <?php echo number_format($row['net_balance'], 2); ?></span>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="modal-footer border-0 p-3">
<button type="button" class="btn btn-light w-100 rounded-pill py-2.5" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php Layout::footer(); ?>