339 lines
14 KiB
PHP
339 lines
14 KiB
PHP
<style>
|
||
th,td {
|
||
text-align: center;
|
||
}
|
||
</style>
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body">
|
||
<div class="float-right">
|
||
<div id="checkAll" style="display:none;">
|
||
<span id="totalAmt" style="margin-right:30px;"></span>
|
||
<button type="button" class="btn btn-secondary" id="multi_success">Accept</button>
|
||
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#delete-all-modal">Reject</button>
|
||
</div>
|
||
<div id="addDonorBtn">
|
||
<?php if(get_user_role() != 'accounts') { ?>
|
||
<a href="<?= base_url() . "new_receipt/0"; ?>" class="btn btn-primary"><i class="ri-currency-line"></i> Add Receipt </a>
|
||
<?php } ?>
|
||
</div>
|
||
</div>
|
||
<br>
|
||
<h4 class="header-title mb-3"><?= $page_name; ?> (Temporary Receipt: <?= $temp_receipt_count ?>)</h4>
|
||
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
|
||
<?php if (session()->getFlashdata('success')) : ?>
|
||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||
<?= session('success') ?>
|
||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||
<span aria-hidden="true">×</span>
|
||
</button>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php if (session()->getFlashdata('error')) : ?>
|
||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||
<?= session('error') ?>
|
||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||
<span aria-hidden="true">×</span>
|
||
</button>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
<div class="table-responsive">
|
||
<table id="datatable-buttons" class="table w-100 nowrap">
|
||
<thead class="thead-light">
|
||
<tr>
|
||
<th hidden></th>
|
||
<th align="center" <?php if (get_user_role() != 'accounts') { echo 'hidden'; } ?>>Select</th>
|
||
<th align="center">Receipt Number</th>
|
||
<th align="center">Receipt Date</th>
|
||
<th align="center">Created By</th>
|
||
<th align="center">Donor Name</th>
|
||
<th align="center">Amount</th>
|
||
<th align="center">Payment Mode</th>
|
||
<th align="center">Status</th>
|
||
<th align="center">Reason</th>
|
||
<th align="center">Action</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($receipt as $row) : ?>
|
||
<tr>
|
||
<td hidden><?= $row['receipt_id']; ?></td>
|
||
<td <?php if (get_user_role() != 'accounts') { echo 'hidden'; } ?>>
|
||
<?php if($row['receipt_header'] != 'Receipt') { ?>
|
||
<input type="checkbox" class="select-checkbox" value="<?= $row['receipt_id'] ?>" >
|
||
<?php } ?>
|
||
</td>
|
||
<td><?= $row['receipt_number']; ?></td>
|
||
<td><?= date("d-m-Y", strtotime($row['receipt_date'])); ?> </td>
|
||
<td><?= $row['created_name']; ?></td>
|
||
<td>
|
||
<?php foreach ($Donors as $DonorData) : ?>
|
||
<?= $row['donor_id'] === $DonorData->donor_id ? $DonorData->first_name . $DonorData->last_name : ''; ?>
|
||
<?php endforeach; ?>
|
||
</td>
|
||
<td id="<?= $row['receipt_id'] ?>"><?= $row['amount']; ?></td>
|
||
<td><?= $row['payment_mode']; ?></td>
|
||
<td><?= $row['receipt_header']; ?></td>
|
||
<td><?php echo ($row['reason'] == null) ? '-' : $row['reason']; ?></td>
|
||
<td>
|
||
<a href="<?= base_url() . "new_receipt/" . $row['receipt_id']; ?>" class="edit-button" title="Edit the Invoice"><i class="ri-pencil-line" title="Edit the Invoice"></i></a>
|
||
<a href="<?= base_url("generate_invoice_pdf/{$row['receipt_id']}") ?>" class="download-pdf-button" title="Download the Invoice"><i class="ri-file-download-line"></i></a>
|
||
|
||
|
||
<?php if (get_user_role() == 'accounts') { ?>
|
||
<input type="hidden" id="donor_id" value="<?= isset($row['donor_id']) ? $row['donor_id'] : '' ?>">
|
||
<?php if (isset($row['receipt_header']) && $row['receipt_header'] != 'Receipt') { ?>
|
||
<i type="button" class="bx bx-check-circle donor_cash_success" id="<?= $row['receipt_id'] ?>" title="Accept"></i>
|
||
<?php } ?>
|
||
<?php if (isset($row['receipt_header']) && $row['receipt_header'] != 'Rejected') { ?>
|
||
<i type="button" class="fe-x-circle append_id" id="<?= $row['receipt_id'] ?>" data-toggle="modal" data-target="#info-alert-modal" title="Reject"></i>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
|
||
</div>
|
||
</div> <!-- end card body-->
|
||
</div> <!-- end card -->
|
||
</div><!-- end col-->
|
||
</div><!-- end row-->
|
||
|
||
<script>
|
||
// accept donor
|
||
$(function() {
|
||
$('.donor_cash_success').on('click', function(){
|
||
id = $(this).attr('id');
|
||
$.ajax({
|
||
type:"post",
|
||
url: "<?php echo base_url(); ?>/donor_cash_success",
|
||
data:{ 'id': id },
|
||
success:function(response)
|
||
{
|
||
console.log(response);
|
||
if(response) window.location.href = "<?php echo base_url(); ?>/receipt_list";
|
||
else console.log('update failed');
|
||
}
|
||
});
|
||
});
|
||
});
|
||
|
||
// multiple accept donation
|
||
$(function() {
|
||
$('#multi_success').on('click', function(){
|
||
|
||
for (const checkbox of $('.select-checkbox:checked')) {
|
||
const id = $(checkbox).val();
|
||
$.ajax({
|
||
type:"post",
|
||
url: "<?php echo base_url(); ?>/donor_cash_success",
|
||
data:{ 'id': id },
|
||
success:function(response)
|
||
{
|
||
console.log(response);
|
||
if(response) console.log('success');
|
||
else console.log('update failed');
|
||
}
|
||
});
|
||
}
|
||
window.location.href = "<?php echo base_url(); ?>/receipt_list";
|
||
|
||
});
|
||
});
|
||
|
||
// multiple delete/reject donation
|
||
$(function() {
|
||
$('#delete-all-submit').on('click', function(){
|
||
reason = $('#deleteallreason').val()
|
||
for (const checkbox of $('.select-checkbox:checked')) {
|
||
const id = $(checkbox).val();
|
||
$.ajax({
|
||
type:"post",
|
||
url: "<?php echo base_url(); ?>/donor_cash_delete",
|
||
data:{ 'id': id, 'reason': reason },
|
||
success:function(response)
|
||
{
|
||
console.log(response);
|
||
if(response) console.log('success');
|
||
else console.log('update failed');
|
||
}
|
||
});
|
||
}
|
||
window.location.href = "<?php echo base_url(); ?>/receipt_list";
|
||
|
||
});
|
||
});
|
||
|
||
// add id in delete form
|
||
$(function() {
|
||
$('.append_id').on('click', function(){
|
||
id = $(this).attr('id');
|
||
$('#append_id').val(id)
|
||
});
|
||
});
|
||
|
||
// show save,delete --ALL button based on checkbox selected length
|
||
$(function() {
|
||
$('.select-checkbox').on('change', function() {
|
||
var checkedLength = $('.select-checkbox:checked').length;
|
||
if(checkedLength) {
|
||
$('#addDonorBtn').hide();
|
||
$('#checkAll').show();
|
||
}
|
||
else {
|
||
$('#addDonorBtn').show();
|
||
$('#checkAll').hide();
|
||
}
|
||
totalAmt();
|
||
});
|
||
|
||
|
||
});
|
||
|
||
function totalAmt() {
|
||
sum = 0;
|
||
for (const checkbox of $('.select-checkbox:checked')) {
|
||
const id = $(checkbox).val();
|
||
sum = parseInt($('#'+id).html()) + sum;
|
||
}
|
||
$('#totalAmt').html('Total selected amount: <b>'+sum+'</b>');
|
||
}
|
||
|
||
$(document).ready(function() {
|
||
var table = $('#datatable-buttons').DataTable({
|
||
"order": [
|
||
[0, 'desc']
|
||
],
|
||
"dom": 'Bfrtip',
|
||
buttons: [{
|
||
extend: 'print',
|
||
text: 'Print',
|
||
title: 'General Invoice Report',
|
||
customize: function(win) {
|
||
// Exclude the first and last columns
|
||
$(win.document.body).find('table').find('th:first-child, td:first-child').remove();
|
||
}
|
||
},
|
||
{
|
||
extend: 'csv',
|
||
text: 'CSV',
|
||
title: 'General Invoice Report',
|
||
exportOptions: {
|
||
columns: ':not(:first-child)'
|
||
}
|
||
}
|
||
],
|
||
"searching": true,
|
||
columnDefs: [{
|
||
type: 'date',
|
||
targets: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||
orderable: false
|
||
}] // Specify the column index for date sorting and disable sorting
|
||
});
|
||
|
||
// Add date range filter and dropdowns
|
||
$('#datatable-buttons thead tr').clone(true).appendTo('#datatable-buttons thead');
|
||
$('#datatable-buttons thead tr:eq(1) th').each(function(i) {
|
||
var title = $(this).text();
|
||
if (i < $('#datatable-buttons thead tr:eq(1) th').length - 1) { // Check if it's not the last column
|
||
var uniqueValues = table.column(i).data().unique().sort();
|
||
|
||
var select = $('<select class="form-control form-control-sm"><option value="">Search ' + title + '</option></select>')
|
||
.appendTo($(this).empty())
|
||
.on('change', function() {
|
||
var val = $.fn.dataTable.util.escapeRegex($(this).val());
|
||
table.column(i)
|
||
.search(val ? '^' + val + '$' : '', true, false)
|
||
.draw();
|
||
});
|
||
|
||
if (i == 1) {
|
||
$(this).html('<input type="checkbox" id="select-all-checkbox"> All');
|
||
} else {
|
||
uniqueValues.each(function(d, j) {
|
||
select.append('<option value="' + d + '">' + d + '</option>');
|
||
});
|
||
}
|
||
|
||
$('input', this).on('keyup change', function() {
|
||
if (table.column(i).search() !== this.value && $(this).attr('id') != "select-all-checkbox") {
|
||
table
|
||
.column(i)
|
||
.search(this.value)
|
||
.draw();
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
// Handle "Select All" checkbox functionality
|
||
$('#select-all-checkbox').on('change', function() {
|
||
$('.select-checkbox').prop('checked', this.checked);
|
||
if(this.checked) {
|
||
$('#addDonorBtn').hide();
|
||
$('#checkAll').show();
|
||
}
|
||
else {
|
||
$('#addDonorBtn').show();
|
||
$('#checkAll').hide();
|
||
}
|
||
|
||
totalAmt()
|
||
});
|
||
});
|
||
|
||
</script>
|
||
|
||
<!-- Info Alert Modal -->
|
||
<div id="info-alert-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
|
||
<div class="modal-dialog modal-sm">
|
||
<div class="modal-content">
|
||
<div class="modal-body p-4">
|
||
<div class="text-center">
|
||
<form class="needs-validation" novalidate method="POST" enctype="multipart/form-data" action="<?= base_url() . "donor_cash_delete"; ?>" id="myForm1" name="myForm">
|
||
|
||
<input type="hidden" id="append_id" name="id" value="">
|
||
<h4 class="mt-2">REJECT!</h4>
|
||
<p class="mt-3">Are you sure you want to reject please continue with reason</p>
|
||
|
||
<div class="form-group">
|
||
<input class="form-control" type="text" id="reason" name="reason" required="" placeholder="Reason">
|
||
</div>
|
||
|
||
<button type="submit" class="btn btn-danger my-2" >Continue</button>
|
||
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|
||
|
||
<!-- Delete All Modal -->
|
||
<div id="delete-all-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
|
||
<div class="modal-dialog modal-sm">
|
||
<div class="modal-content">
|
||
<div class="closeBtn float-right" style="padding: 10px;"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button></div>
|
||
<div class="modal-body p-4">
|
||
<div class="text-center">
|
||
<form class="needs-validation" novalidate enctype="multipart/form-data" id="myForm2" name="myForm">
|
||
|
||
<h4 class="mt-2">REJECT ALL!</h4>
|
||
<p class="mt-3">Are you sure you want to reject please continue with reason</p>
|
||
|
||
<div class="form-group">
|
||
<input class="form-control" type="text" id="deleteallreason" name="reason" required="" placeholder="Reason">
|
||
</div>
|
||
|
||
<button type="submit" class="btn btn-danger my-2" id="delete-all-submit" >Continue</button>
|
||
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|