-
-
Notifications
You must be signed in to change notification settings - Fork 523
Expand file tree
/
Copy pathDepositSlipEditor.php
More file actions
467 lines (442 loc) · 17.4 KB
/
DepositSlipEditor.php
File metadata and controls
467 lines (442 loc) · 17.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<?php
require_once 'Include/Config.php';
require_once 'Include/Functions.php';
use ChurchCRM\Authentication\AuthenticationManager;
use ChurchCRM\dto\SystemURLs;
use ChurchCRM\model\ChurchCRM\DepositQuery;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\Utils\RedirectUtils;
// Security: User must have finance permission or be the one who created this deposit
if (!(AuthenticationManager::getCurrentUser()->isFinanceEnabled() || AuthenticationManager::getCurrentUser()->getId() === $thisDeposit->getEnteredby())) {
RedirectUtils::securityRedirect('Finance');
}
$iDepositSlipID = 0;
$thisDeposit = 0;
if (array_key_exists('DepositSlipID', $_GET)) {
$iDepositSlipID = InputUtils::legacyFilterInput($_GET['DepositSlipID'], 'int');
}
$noDeposit = true;
if ($iDepositSlipID) {
$thisDeposit = DepositQuery::create()->findOneById($iDepositSlipID);
if ($thisDeposit) {
$noDeposit = false;
// Set the session variable for default payment type so the new payment form will come up correctly
if ($thisDeposit->getType() === 'Bank') {
$_SESSION['idefaultPaymentMethod'] = 'CHECK';
} elseif ($thisDeposit->getType() === 'CreditCard') {
$_SESSION['idefaultPaymentMethod'] = 'CREDITCARD';
} elseif ($thisDeposit->getType() === 'BankDraft') {
$_SESSION['idefaultPaymentMethod'] = 'BANKDRAFT';
} elseif ($thisDeposit->getType() === 'eGive') {
$_SESSION['idefaultPaymentMethod'] = 'EGIVE';
}
}
}
if ($noDeposit) {
RedirectUtils::redirect('FindDepositSlip.php');
}
$sPageTitle = $thisDeposit->getType() . ' ' . gettext('Deposit Slip Number: ') . $iDepositSlipID;
//Is this the second pass?
if (isset($_POST['DepositSlipLoadAuthorized'])) {
$thisDeposit->loadAuthorized();
} elseif (isset($_POST['DepositSlipRunTransactions'])) {
$thisDeposit->runTransactions();
}
$_SESSION['iCurrentDeposit'] = $iDepositSlipID; // Probably redundant
/* @var $currentUser User */
$currentUser = AuthenticationManager::getCurrentUser();
$currentUser->setCurrentDeposit($iDepositSlipID);
$currentUser->save();
require_once 'Include/Header.php';
?>
<!-- Deposit Slip Editor Main Container -->
<div id="depositSlipEditorContainer">
<div class="row">
<!-- Deposit Details Column -->
<div class="col-lg-7 col-md-12 mb-3">
<div class="card">
<div class="card-header with-border bg-primary text-white">
<h3 class="card-title mb-0">
<i class="fa-solid fa-file-invoice-dollar"></i> <?php echo gettext('Deposit Details'); ?>
</h3>
</div>
<div class="card-body">
<form method="post" action="DepositSlipEditor.php?DepositSlipID=<?= $iDepositSlipID ?>" name="DepositSlipEditor" id="DepositSlipEditor">
<div class="row">
<div class="col-md-6 mb-3">
<label for="DepositDate" class="form-label"><?= gettext('Date'); ?>:</label>
<input type="text" class="form-control date-picker" name="Date" value="<?php echo $thisDeposit->getDate('Y-m-d'); ?>" id="DepositDate" required>
</div>
<div class="col-md-6 mb-3">
<label for="Closed" class="form-label"><?php echo gettext('Status'); ?>:</label>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" name="Closed" id="Closed" value="1" <?php if ($thisDeposit->getClosed()) {
echo ' checked';
} ?>>
<label class="form-check-label" for="Closed">
<?php echo $thisDeposit->getClosed() ? '<span class="badge badge-danger">Closed</span>' : '<span class="badge badge-success">Open</span>'; ?>
</label>
</div>
</div>
</div>
<div class="mb-3">
<label for="Comment" class="form-label"><?php echo gettext('Comment'); ?>:</label>
<textarea class="form-control" name="Comment" id="Comment" rows="3" placeholder="<?= gettext('Add any additional notes about this deposit'); ?>"><?php echo InputUtils::escapeHTML($thisDeposit->getComment()); ?></textarea>
</div>
<?php
if ($thisDeposit->getType() == 'BankDraft' || $thisDeposit->getType() == 'CreditCard') {
echo '<div class="alert alert-warning alert-dismissible fade show" role="alert">';
echo '<i class="fa-solid fa-triangle-exclamation"></i> ' . gettext('Important: Failed transactions will be deleted permanently when the deposit slip is closed.');
echo '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
echo '</div>';
}
?>
<div class="row mt-4">
<div class="col-12">
<div class="d-flex flex-wrap align-items-center">
<!-- Primary Actions -->
<button type="submit" class="btn btn-primary mr-2" name="DepositSlipSubmit">
<i class="fa-solid fa-save"></i> <?= gettext('Save'); ?>
</button>
<?php if (!$thisDeposit->getClosed()): ?>
<?php if ($thisDeposit->getType() == 'eGive'): ?>
<a href="eGive.php?DepositSlipID=<?= $iDepositSlipID ?>&linkBack=DepositSlipEditor.php?DepositSlipID=<?= $iDepositSlipID ?>&PledgeOrPayment=Payment&CurrentDeposit=<?= $iDepositSlipID ?>" class="btn btn-success mr-2">
<i class="fa-solid fa-download"></i> <?= gettext('Import eGive'); ?>
</a>
<?php else: ?>
<a href="PledgeEditor.php?CurrentDeposit=<?= $iCurrentDeposit ?>&PledgeOrPayment=Payment&linkBack=DepositSlipEditor.php?DepositSlipID=<?= $iDepositSlipID ?>&PledgeOrPayment=Payment&CurrentDeposit=<?= $iDepositSlipID ?>" class="btn btn-success mr-2">
<i class="fa-solid fa-plus-circle"></i> <?= gettext('Add Payment'); ?>
</a>
<?php endif; ?>
<?php endif; ?>
<!-- Secondary Action -->
<button type="button" class="btn btn-outline-secondary ml-auto" name="DepositSlipGeneratePDF" data-deposit-id="<?= $thisDeposit->getId() ?>">
<i class="fa-solid fa-file-pdf"></i> <?= gettext('Generate Report'); ?>
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Summary Stats Column -->
<div class="col-lg-5 col-md-12 mb-3">
<!-- Summary Stats Section -->
<div class="row">
<!-- Total Deposit - Hero Stat -->
<div class="col-12 mb-3">
<div class="stat-card text-center py-4 border-0 shadow-sm" style="background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%);">
<div style="font-size: 3rem; font-weight: 700; color: white; letter-spacing: -1px;">
$<?= number_format($thisDeposit->getVirtualColumn('totalAmount'), 2); ?>
</div>
<div class="text-white-50 text-uppercase small font-weight-bold mt-2" style="letter-spacing: 1px;"><?= gettext('Total Deposit'); ?></div>
</div>
</div>
<!-- Bottom Row: 3 columns for breakdown -->
<div class="col-md-4 mb-3">
<div class="stat-card text-center h-100">
<?php if ($thisDeposit->getCountCash()): ?>
<div class="mb-3">
<i class="fa-solid fa-money-bill fa-2x text-success mb-2"></i>
<div class="font-weight-bold h5 text-success">$<?= number_format($thisDeposit->getTotalCash(), 2); ?></div>
<div class="small text-muted"><?= gettext('Cash'); ?> (<?= $thisDeposit->getCountCash(); ?>)</div>
</div>
<?php endif; ?>
<?php if (!$thisDeposit->getCountCash()): ?>
<div class="text-muted small">
<i class="fa-solid fa-money-bill fa-2x mb-2 opacity-25"></i>
<div><?= gettext('No Cash'); ?></div>
</div>
<?php endif; ?>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="stat-card text-center h-100">
<?php if ($thisDeposit->getCountChecks()): ?>
<div class="mb-3">
<i class="fa-solid fa-money-check fa-2x text-info mb-2"></i>
<div class="font-weight-bold h5 text-info">$<?= number_format($thisDeposit->getTotalChecks(), 2); ?></div>
<div class="small text-muted"><?= gettext('Checks'); ?> (<?= $thisDeposit->getCountChecks(); ?>)</div>
</div>
<?php endif; ?>
<?php if (!$thisDeposit->getCountChecks()): ?>
<div class="text-muted small">
<i class="fa-solid fa-money-check fa-2x mb-2 opacity-25"></i>
<div><?= gettext('No Checks'); ?></div>
</div>
<?php endif; ?>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="stat-card text-center h-100 d-flex flex-column justify-content-center">
<div class="mb-2">
<i class="fa-solid fa-receipt fa-2x text-primary mb-2"></i>
</div>
<div class="stat-value text-dark" style="font-size: 2.5rem;"><?= $thisDeposit->getCountChecks() + $thisDeposit->getCountCash(); ?></div>
<div class="stat-label"><?= gettext('Total Payments'); ?></div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Charts Section Above Payments -->
<div class="row mt-4">
<div class="col-12">
<div class="card card-sm">
<div class="card-header with-border bg-light d-flex justify-content-between align-items-center">
<h5 class="card-title mb-0">
<i class="fa-solid fa-chart-bar"></i> <?= gettext('Funds'); ?>
<small class="text-muted ms-2"><?= gettext('Click a bar to filter payments'); ?></small>
</h5>
<button type="button" class="btn btn-sm btn-outline-secondary d-none" id="clearFundFilter">
<i class="fa-solid fa-times"></i> <?= gettext('Clear Filter'); ?>
</button>
</div>
<div class="card-body" style="padding: 1rem 0.75rem 1rem 1.5rem;">
<canvas id="fund-bar"></canvas>
</div>
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-header with-border bg-secondary text-white d-flex justify-content-between align-items-center">
<h3 class="card-title mb-0">
<i class="fa-solid fa-receipt"></i> <?php echo gettext('Payments'); ?>
<span class="badge badge-light text-dark" id="payment-count">0</span>
</h3>
<?php if ($iDepositSlipID && $thisDeposit->getType() && !$thisDeposit->getClosed() && ($thisDeposit->getType() == 'BankDraft' || $thisDeposit->getType() == 'CreditCard')): ?>
<div class="btn-group" role="group">
<button type="submit" class="btn btn-sm btn-primary" name="DepositSlipLoadAuthorized">
<i class="fa-solid fa-sync"></i> <?= gettext('Load Authorized'); ?>
</button>
<button type="submit" class="btn btn-sm btn-warning" name="DepositSlipRunTransactions">
<i class="fa-solid fa-play-circle"></i> <?= gettext('Run Transactions'); ?>
</button>
</div>
<?php endif; ?>
</div>
<div class="card-body p-0">
<div class="px-3 py-3 border-bottom bg-light">
<!-- Subtle spacing -->
</div>
<div class="table-responsive">
<table class="table table-hover mb-0" id="paymentsTable"></table>
</div>
<?php
if ($iDepositSlipID && $thisDeposit->getType() && !$thisDeposit->getClosed()) {
if ($thisDeposit->getType() == 'Bank') {
?>
<div class="card-footer">
<button type="button" id="deleteSelectedRows" class="btn btn-sm btn-danger" disabled>
<i class="fa-solid fa-trash-can"></i> <?php echo gettext('Delete Selected'); ?>
</button>
</div>
<?php
}
}
?>
</div>
</div>
<script src="<?= SystemURLs::getRootPath() ?>/skin/js/DepositSlipEditor.js"></script>
<style>
.card {
margin-bottom: 1.5rem;
border: none;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
transition: box-shadow 0.3s ease;
}
.card:hover {
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.card-header {
background-color: #f8f9fa;
border-bottom: 2px solid #e9ecef;
padding: 1.25rem;
}
.card-header.bg-primary {
background-color: #0d6efd !important;
border-bottom: none;
}
#paymentsTable {
margin-bottom: 0;
}
#paymentsTable_wrapper .dataTables_length,
#paymentsTable_wrapper .dataTables_filter {
padding: 1rem 0.75rem;
}
#paymentsTable_wrapper .dataTables_info,
#paymentsTable_wrapper .dataTables_paginate {
padding: 1rem 0.75rem;
}
.dt-buttons {
padding: 1rem 0.75rem !important;
}
#paymentsTable tbody tr {
transition: background-color 0.2s ease;
}
#paymentsTable tbody tr.paymentRow {
cursor: pointer;
}
#paymentsTable tbody tr:hover {
background-color: #f8f9fa;
}
#paymentsTable tbody tr.selected,
#paymentsTable tbody tr.table-active {
background-color: #e7f3ff;
border-left: 3px solid #0d6efd;
}
#paymentsTable tbody tr td {
vertical-align: middle;
padding: 0.875rem 0.75rem !important;
}
#paymentsTable thead th {
padding: 1rem 0.75rem !important;
background-color: #f8f9fa;
border-bottom: 2px solid #dee2e6;
font-weight: 600;
}
#paymentsTable tbody td {
line-height: 1.6;
}
#paymentsTable .badge {
font-size: 0.75rem;
padding: 0.35rem 0.65rem;
font-weight: 500;
}
.stat-card {
padding: 1.25rem 1rem;
background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
border-radius: 0.5rem;
border: 2px solid #e9ecef;
transition: all 0.3s ease;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.stat-card:hover {
transform: translateY(-3px);
border-color: #dee2e6;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.stat-value {
font-size: 2rem;
font-weight: 700;
line-height: 1.2;
margin-bottom: 0.75rem;
letter-spacing: -0.5px;
}
.stat-label {
font-size: 0.8rem;
color: #6c757d;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 600;
}
.row-select {
cursor: pointer;
margin: 0;
}
code {
background-color: #f4f4f4;
padding: 0.2rem 0.4rem;
border-radius: 3px;
font-size: 0.875rem;
}
.form-label {
font-weight: 600;
color: #212529;
margin-bottom: 0.5rem;
}
.form-control, .form-select {
border: 1px solid #e0e0e0;
transition: all 0.2s ease;
}
.form-control:focus, .form-select:focus {
border-color: #0d6efd;
box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.1);
}
.btn {
font-weight: 600;
transition: all 0.2s ease;
border-radius: 0.375rem;
}
.btn-primary {
box-shadow: 0 2px 6px rgba(13, 110, 253, 0.2);
}
.btn-primary:hover {
box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
transform: translateY(-1px);
}
</style>
<?php
$fundLabels = [];
$fundData = [];
$fundBackgroundColor = [];
foreach ($thisDeposit->getFundTotals() as $tmpfund) {
$label = $tmpfund['Name'];
$data = (float)$tmpfund['Total'];
$backgroundColor = '#' . random_color();
$fundLabels[] = $label;
$fundData[] = $data;
$fundBackgroundColor[] = $backgroundColor;
}
?>
<script nonce="<?= SystemURLs::getCSPNonce() ?>">
var depositType = '<?php echo $thisDeposit->getType(); ?>';
var depositSlipID = <?php echo $iDepositSlipID; ?>;
var isDepositClosed = Boolean(<?= $thisDeposit->getClosed(); ?>);
var fundLabels = <?= json_encode(array_values($fundLabels)) ?>;
var fundData = <?= json_encode(array_values($fundData)) ?>;
var fundBackgroundColor = <?= json_encode(array_values($fundBackgroundColor)) ?>;
$(document).ready(function() {
window.CRM.onLocalesReady(function() {
initPaymentTable();
initCharts(null,
null,
null,
fundLabels,
fundData,
fundBackgroundColor);
initDepositSlipEditor();
$('#deleteSelectedRows').click(function() {
var deletedRows = dataT.rows('.selected').data();
bootbox.confirm({
title:'<?= gettext("Confirm Delete")?>',
message: '<p><?= gettext("Are you sure you want to delete the selected")?> ' + deletedRows.length + ' <?= gettext("payments(s)?") ?></p>' +
'<p><?= gettext("This action CANNOT be undone, and may have legal implications!") ?></p>'+
'<p><?= gettext("Please ensure this what you want to do.</p>") ?>',
buttons: {
cancel : {
label: '<?= gettext("Close"); ?>'
},
confirm: {
label: '<?php echo gettext("Delete"); ?>'
}
},
callback: function ( result ) {
if ( result )
{
window.CRM.deletesRemaining = deletedRows.length;
$.each(deletedRows, function(index, value) {
window.CRM.APIRequest({
method: 'DELETE',
path: 'payments/' + value.GroupKey,
})
.done(function(data) {
dataT.rows('.selected').remove().draw(false);
window.CRM.deletesRemaining --;
if ( window.CRM.deletesRemaining == 0 )
{
location.reload();
}
});
});
}
}
})
});
});
});
</script>
<?php
require_once 'Include/Footer.php';