283 lines
12 KiB
PHP
283 lines
12 KiB
PHP
<div>
|
|
|
|
<div class="summary-box">
|
|
<div class="summary-row">
|
|
<span>Invoice Amount:</span>
|
|
<span id="utrInvoiceAmount" data-id="<?php echo isset($summary['invoice_amount']) && !empty($summary['invoice_amount']) ? $summary['invoice_amount'] : ""?>">
|
|
₹<?php echo isset($summary['invoice_amount']) && !empty($summary['invoice_amount']) ? format_indian_number($summary['invoice_amount']) : "0.00"?>
|
|
</span>
|
|
</div>
|
|
<div class="summary-row">
|
|
<span>Total Paid:</span>
|
|
<span id="utrTotalPaid" data-id="<?php echo isset($summary['total_utr_amount']) && !empty($summary['total_utr_amount']) ? $summary['total_utr_amount'] : ""?>">
|
|
₹<?php echo isset($summary['total_utr_amount']) && !empty($summary['total_utr_amount']) ? format_indian_number($summary['total_utr_amount']) : "0.00"?>
|
|
</span>
|
|
</div>
|
|
<div class="summary-row">
|
|
<span>Remaining Balance:</span>
|
|
<span id="utrRemaining" data-id="<?php echo isset($summary['balance_amount']) && !empty($summary['balance_amount']) ? $summary['balance_amount'] : ""?>">
|
|
₹<?php echo isset($summary['balance_amount']) && !empty($summary['balance_amount']) ? format_indian_number($summary['balance_amount']) : "0.00"?>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="utrContent">
|
|
<div class="utr-section">
|
|
<!-- <h5 class="utr-heading">Add New UTR</h5> -->
|
|
<form id="utrForm" role="form" class="parsley-examples">
|
|
<input type="hidden" name="utr_pk" id="utr_pk">
|
|
<input type="hidden" name="invoice_id" value="<?php echo isset($summary['id']) && !empty($summary['id']) ? $summary['id'] : ""?>">
|
|
<div class="row">
|
|
<div class="col-md-3">
|
|
<div class="form-group utr-form-group">
|
|
<label class="utr-label">UTR Number <span class="text-danger">*</span></label>
|
|
<input type="text" name="utr_no" id="utrNumber" class="form-control form-control-sm" placeholder="Enter UTR number" required>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="form-group utr-form-group">
|
|
<label class="utr-label">Amount (₹) <span class="text-danger">*</span></label>
|
|
<input type="number" name="amount" id="utrAmount" oninput="checkSum(this)" class="form-control form-control-sm" step="0.01" placeholder="Enter amount" required>
|
|
<!-- <small class="utr-small-text">
|
|
Max: <span id="maxUtrAmount">₹0.00</span>
|
|
</small> -->
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="form-group utr-form-group">
|
|
<label class="utr-label">Date <span class="text-danger">*</span></label>
|
|
<input type="text" name="utr_date" id="utrDate" class="form-control form-control-sm" placeholder="DD/MM/YYYY" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-3" style="<?= !isset($invoice_completed) ? 'display: block;' : 'display: none;' ?>">
|
|
<div class="form-group utr-submit-wrapper">
|
|
<a onclick="resetvalues()" class="btn btn-secondary btn-sm">Clear</a>
|
|
<button id="utr_submit_btn" onclick="saveUtrDetails(event)" class="btn btn-primary btn-sm">Add UTR</button>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="utr-list" id="utrList">
|
|
<h5 class="utr-heading">Existing UTRs</h5>
|
|
<div class="table-responsive">
|
|
<table data-custom-table-css="table" id="ticket-table" class="table table-sm w-100 nowrap utr-table">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th class="font-weight-medium">S.No.</th>
|
|
<th class="font-weight-medium">UTR No</th>
|
|
<th class="font-weight-medium">Amount</th>
|
|
<th class="font-weight-medium">Date</th>
|
|
<!-- <th class="font-weight-medium">User</th> -->
|
|
<th class="font-weight-medium">Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (isset($utr_list_data) && !empty($utr_list_data)) { ?>
|
|
<?php foreach($utr_list_data as $index => $row){
|
|
$row['utr_date'] = change_date_format($row['utr_date'], null, 'd/m/Y') ?? " - "
|
|
?>
|
|
<tr>
|
|
<td> <?= $index + 1 ?> </td>
|
|
<td> <?= $row['utr_no'] ?> </td>
|
|
<td> <?= format_indian_number($row['amount']) ?> </td>
|
|
<td> <?= $row['utr_date'] ?> </td>
|
|
<!-- <td> <?php // format_indian_number($row['created_user']) ?> </td> -->
|
|
<td>
|
|
<div class="btn-group dropdown">
|
|
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
|
|
<div class="dropdown-menu dropdown-menu-right">
|
|
|
|
<a style="<?= !isset($invoice_completed) ? 'display: block;' : 'display: none;' ?>" class="dropdown-item utr-dropdown-item" onclick='updateUtr(<?= htmlspecialchars(json_encode($row ?? []), ENT_QUOTES, "UTF-8") ?>)'><i class="mdi mdi-pencil mr-2 text-muted utr-icon vertical-middle"></i>Edit</a>
|
|
<a class="dropdown-item utr-dropdown-item" onclick="removeUtrApi(<?php echo isset($summary['id']) && !empty($summary['id']) ? $summary['id'] : ''?>, <?= $row['id'] ?>)"><i class="mdi mdi-delete mr-2 text-muted utr-icon vertical-middle"></i>Delete</a>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
var dob = flatpickr("#utrDate", {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false,
|
|
maxDate: "today"
|
|
});
|
|
|
|
function saveUtrDetails(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
console.log('saveUtrDetails function called');
|
|
|
|
var isValid = $('#utrForm').parsley().validate();
|
|
if (!isValid) {
|
|
$('#utrForm').find('input, select, textarea').each(function() {
|
|
if ($(this).parsley().isValid() === false && !$(this).val()) {
|
|
console.log(' :) Empty field ID:', this.id);
|
|
}
|
|
});
|
|
console.log('Form is Empty', 'Warning');
|
|
return;
|
|
}
|
|
|
|
var formData = new FormData($('#utrForm')[0]);
|
|
|
|
// Show loading state
|
|
$('#utr_submit_btn').prop('disabled', true).text('Saving...');
|
|
|
|
let url = '<?= base_url('payout/saveUtrDetails') ?>';
|
|
|
|
$.ajax({
|
|
url: url,
|
|
type: 'POST',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
|
|
console.log('Data fetched successfully:', response);
|
|
|
|
if (response.status == true) {
|
|
toastr.success(response.message, 'Success');
|
|
$('#modal_body').empty();
|
|
$('#modal_body').append(response.data);
|
|
window.location.href = '<?= base_url("payout/list") ?>';
|
|
}else{
|
|
toastr.warning(response.message || 'Unable to fetch data', 'Warning');
|
|
}
|
|
|
|
// Re-enable button
|
|
$('#utr_submit_btn').prop('disabled', false).text('Add UTR');
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
console.error('Error fetching data:', error);
|
|
console.error(xhr.responseText);
|
|
toastr.error('An error occurred while fetching the data.', 'Error');
|
|
},
|
|
complete: function() {
|
|
$('#utr_submit_btn').prop('disabled', false).text('Add UTR');
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
utrHasBeenChanged = true;
|
|
resetvalues();
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateUtr(data){
|
|
console.log("data", data)
|
|
if(data){
|
|
$('#utr_pk').val(data.id);
|
|
$('#utrNumber').val(data.utr_no);
|
|
$('#utrAmount').val(data.amount);
|
|
$('#utrDate').val(data.utr_date);
|
|
$('#utr_submit_btn').text('Update UTR');
|
|
$('#utrNumber').trigger('focus');
|
|
}
|
|
}
|
|
|
|
function resetvalues(){
|
|
$('#utr_pk').val("");
|
|
$('#utrNumber').val("");
|
|
$('#utrAmount').val("");
|
|
$('#utrDate').val("");
|
|
$('#utr_submit_btn').text('Add UTR');
|
|
}
|
|
|
|
function removeUtrApi(invoice_id, utr_id) {
|
|
Swal.fire({
|
|
title: "Are you sure?",
|
|
text: "Do you want to remove this UTR?",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonText: "Yes, Proceed!",
|
|
cancelButtonText: "Cancel"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
removeUtr(invoice_id, utr_id);
|
|
}
|
|
});
|
|
}
|
|
|
|
function removeUtr(invoice_id, utr_id){
|
|
|
|
let url = '<?= base_url('payout/removeUtrDetails') ?>';
|
|
|
|
// Data to send in the AJAX request
|
|
let requestData = {
|
|
invoice_id: invoice_id,
|
|
utr_id: utr_id,
|
|
};
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
// Send AJAX request
|
|
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
|
|
|
|
console.log('Data fetched successfully:', response);
|
|
|
|
$('#modal_body').empty();
|
|
$('#modal_body').append(response.data);
|
|
|
|
if (response.status == true) {
|
|
toastr.success(response.message, 'Success');
|
|
}else{
|
|
toastr.warning(response.message || 'Unable to fetch data', 'Warning');
|
|
}
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
}, function(xhr, status, error) {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
console.error('Error fetching data:', error);
|
|
console.error(xhr.responseText);
|
|
toastr.error('An error occurred while fetching the data.', 'Error');
|
|
});
|
|
|
|
utrHasBeenChanged = true;
|
|
}
|
|
|
|
function checkSum(input) {
|
|
|
|
let invoice_amt = parseFloat($('#utrInvoiceAmount').data('id')) || 0;
|
|
let utr_amt = parseFloat($('#utrTotalPaid').data('id')) || 0;
|
|
let balance_amt = parseFloat($('#utrRemaining').data('id')) || 0;
|
|
|
|
let input_amt = parseFloat($(input).val()) || 0;
|
|
|
|
console.log({ invoice_amt, utr_amt, balance_amt, input_amt });
|
|
|
|
let total_amt = utr_amt + input_amt;
|
|
|
|
if (total_amt > invoice_amt) {
|
|
toastr.warning('UTR amount exceeds the invoice amount');
|
|
$(input).val('');
|
|
$('#utr_submit_btn').prop('disabled', true);
|
|
}else{
|
|
$('#utr_submit_btn').prop('disabled', false);
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|