donation/app/Views/invoice_list.php

449 lines
20 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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-success" 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>
<a href="<?= base_url() . "export_receipt"; ?>" class="btn btn-info"><i class="ri-file-excel-2-fill"></i> Export Receipt </a>
<!-- <button type="button" class="btn btn-secondary" data-toggle="modal" data-target="#import-receipt-modal"><i class="ri-file-excel-2-line"></i> Import Receipt</button> -->
<?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">&times;</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">&times;</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>
<?php $donor = '';
foreach ($Donors as $DonorData) {
if ($row['donor_id'] === $DonorData->donor_id) {
$suffix = "";
if ($row['receipt_type'] == "organization" ) {
$suffix = !empty($DonorData->org_name) ? " (" . $DonorData->org_name . ")" : " (-)";
}
$donor = $DonorData->first_name . ' ' . $DonorData->last_name . $suffix;
break;
}
} ?>
<td><?= $donor; ?></td>
<td id="<?= $row['receipt_id'] ?>">
<?= $row['amount'].'('.$row['currency'].')'; ?>
</td>
<!-- Assuming this is the cell where you want to display payment_mode -->
<td>
<?php if ($row['payment_mode'] == 'debit'): ?>
<?= 'Debit Card'; ?>
<?php elseif ($row['payment_mode'] == 'credit'): ?>
<?= 'Credit Card'; ?>
<?php elseif ($row['payment_mode'] == 'cash'): ?>
<?= 'Cash'; ?>
<?php elseif ($row['payment_mode'] == 'upi'): ?>
<?= 'UPI'; ?>
<?php else: ?>
<?= $row['payment_mode']; ?>
<?php endif; ?>
</td>
<td><?= $row['receipt_header']; ?></td>
<td><?php echo ($row['reason'] == null) ? '-' : $row['reason']; ?></td>
<td>
<!-- for my clarification
assume that "receipt_header column like a Receipt Status"
Default is 'Temporary Receipt'
'Temporary Receipt' header means "Draft" Status
'Receipt' header means "Completed" Status
'Rejected' header means "Rejected" Status
-->
<?php if (isset($row['receipt_header']) && $row['receipt_header'] == 'Temporary Receipt') { ?>
<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>&nbsp;
<?php } ?>
<?php if (get_user_role() != 'volunteer') { ?>
<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>&nbsp;
<?php } ?>
<?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();
var string = $('#'+id).html();
var number = string.replace(/\D/g, '');
sum = parseInt(number) + 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 -->
<!-- import modal -->
<div id="import-receipt-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="import-receipt-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="import-receipt-label">Import Receipt</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<form id="form-upload">
<div class="modal-body">
<div class="form-group col-md-12">
<label for="control-label">Choose File <small class="text-danger">*</small></label>
<input type="file" class="form-control" style="border: 0px !important; " id="file" name="file" placeholder="csv,xlsx files" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-excel" required />
<span class="help-block"><small>Upload xlsx or csv file only.</small></span>
</div>
<div class="form-group">
<div class="text-center">
<div class="upload-loader" style="display: none; ">
<i class="fa fa-spinner fa-spin"></i> <small>Please wait ...</small>
</div>
<div class="result"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="btn-upload">Upload</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$(document).ready(function(){
$('#form-upload').on('submit', function(event) {
event.preventDefault(); // Prevent default form submission
var formData = new FormData($('#form-upload')[0]);
$.ajax({
type: "POST",
url: "<?= base_url() . 'import_receipt' ?>",
data: formData,
contentType: false,
processData: false,
beforeSend: function() {
$("#btn-upload").prop('disabled', true);
$(".upload-loader").show();
},
success: function(result) {
$("#btn-upload").prop('disabled', false);
if($.isEmptyObject(result.error_message)) {
$(".result").html(result.success_message).css("color", "green");
} else {
$(".result").html(result.error_message).css("color", "red");
}
$("#form-upload")[0].reset();
$(".upload-loader").hide();
setTimeout(function() {
$("#import-receipt-modal").dialog("close");
refreshPage();
}, 10000); // 10000 milliseconds = 10 seconds
}
});
});
});
</script>