nhance/app/Views/outstanding_report_list.php

616 lines
25 KiB
PHP

<?php
helper('datatable_view');
$or_header_labels = [
'S.No', 'Insurer', 'Insurer Branch', 'Statement Month', 'Statement No', 'Invoice No', 'Invoice Status',
'Invoice Date', 'Invoice Amount', 'Realization Amount', 'Outstanding Amount',
];
$or_col_count = count($or_header_labels);
$or_col_max_len = array_fill(0, $or_col_count, 0);
for ($i = 0; $i < $or_col_count; $i++) {
$or_col_max_len[$i] = mb_strlen($or_header_labels[$i]);
}
$outstanting_list = $outstanting_list ?? [];
foreach ($outstanting_list as $index => $row) {
$or_col_max_len[0] = max($or_col_max_len[0], mb_strlen((string) ($index + 1)));
$or_col_max_len[1] = max($or_col_max_len[1], mb_strlen((string) ($row['short_name'] ?? '')));
$or_col_max_len[2] = max($or_col_max_len[2], mb_strlen((string) ($row['branch_name'] ?? '')));
$or_col_max_len[3] = max($or_col_max_len[3], mb_strlen((string) change_date_format($row['month'] ?? '', 'Y-m-d', 'Y-m')));
$or_col_max_len[4] = max($or_col_max_len[4], mb_strlen((string) ($row['stmt_sno'] ?? '')));
$or_col_max_len[5] = max($or_col_max_len[5], mb_strlen((string) ($row['invoice_no'] ?? '')));
$or_col_max_len[6] = max($or_col_max_len[6], mb_strlen((string) (isset($row['invoice_status']) ? $row['invoice_status'] : ' - ')));
$or_col_max_len[7] = max($or_col_max_len[7], mb_strlen((string) change_date_format($row['invoice_date'] ?? '', 'Y-m-d', 'd-M-Y')));
$or_col_max_len[8] = max($or_col_max_len[8], mb_strlen((string) (isset($row['invoice_amount']) ? $row['invoice_amount'] : '0.00')));
$or_col_max_len[9] = max($or_col_max_len[9], mb_strlen((string) (isset($row['total_paid']) ? $row['total_paid'] : '0.00')));
$or_col_max_len[10] = max($or_col_max_len[10], mb_strlen((string) (isset($row['outstanding_amount']) ? $row['outstanding_amount'] : '0.00')));
}
$or_col_min_px = array_fill(0, $or_col_count, 88);
$or_col_min_px[0] = 48;
$or_col_max_px = array_fill(0, $or_col_count, 360);
$or_col_max_px[0] = 64;
$or_col_width_px = nhance_dt_column_widths_px($or_header_labels, $or_col_max_len, $or_col_min_px, $or_col_max_px);
?>
<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
.dataTables_filter {
position: absolute;
}
.right-align-input {
text-align: right;
}
.center-align-input {
text-align: center;
}
.column-header {
margin-right: 10px; /* Adjust this value as needed */
}
/* Center align header text and icons */
table[data-custom-table-css="table"].dataTable thead th {
padding-top: 3px !important;
padding-bottom: 4px !important;
padding-right: 15px !important;
padding-left: 15px !important;
}
.dataTables_length label {height: 21px !important;}
.filter-sidebar {
height: 100%;
width: 0;
position: fixed;
z-index: 1001;
top: 0;
right: 0;
background-color: #f8f9fa;
overflow-x: hidden;
transition: 0.5s;
box-shadow: -2px 0 5px rgba(0,0,0,0.1);
display: flex;
flex-direction: column;
}
.filter-sidebar-header {
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #dee2e6;
flex-shrink: 0;
}
.filter-sidebar-header .closebtn {
font-size: 28px;
text-decoration: none;
color: #6c757d;
}
.filter-sidebar .closebtn:hover {
color: #000;
}
.filter-sidebar-content {
padding: 20px;
flex-grow: 1;
overflow-y: auto;
}
.filter-sidebar-footer {
padding: 15px 20px;
display: flex;
justify-content: flex-end;
border-top: 1px solid #dee2e6;
flex-shrink: 0;
gap: 10px;
}
</style>
<style>
<?php for ($i = 0; $i < $or_col_count; $i++) : ?>
#outstanding-report-list-table_wrapper .dataTables_scrollHead table thead th:nth-child(<?= $i + 1 ?>),
#outstanding-report-list-table thead th:nth-child(<?= $i + 1 ?>) {
min-width: <?= (int) $or_col_width_px[$i] ?>px;
width: <?= (int) $or_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
overflow: visible !important;
}
#outstanding-report-list-table tbody td:nth-child(<?= $i + 1 ?>) {
width: <?= (int) $or_col_width_px[$i] ?>px;
max-width: <?= (int) $or_col_width_px[$i] ?>px;
min-width: <?= (int) $or_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
}
<?php endfor; ?>
#outstanding-report-list-table tbody td {
overflow: hidden;
text-overflow: ellipsis;
padding: 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
#outstanding-report-list-table thead th {
padding: 5px 2.35rem 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
</style>
<div class="container-fluid-min">
<div id="filter-sidebar" class="filter-sidebar">
<div class="filter-sidebar-header">
<h4 class="m-0">Filter</h4>
<a href="javascript:void(0)" class="closebtn" onclick="closeFilterNav()">&times;</a>
</div>
<div class="filter-sidebar-content">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-12">
<label for="addon_policy"> Insurer <span
class="text-danger">*</span></label>
<select class="form-control" id="insurer_id" name="insurer_id" onchange="getInsurerBranch()">
<option value="0" selected>Select Insurer</option>
<?php if (isset($insurer) && count($insurer)) { ?>
<?php foreach ($insurer as $value) { ?>
<option value="<?= $value['id'] ?>"><?= $value['name'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="form-group col-md-12">
<label for="addon_policy"> Insurer Branch<span
class="text-danger">*</span></label>
<select class="form-control" id="insurer_branch_id" name="insurer_branch_id">
<option value="0" selected>Select Insurer Branch</option>
</select>
</div>
<div class="form-group col-md-12" style="display: true;" id="date_div">
<label>Statement Month<span class="text-danger"></span></label>
<div class="input-icon">
<input type="text" id="reportrange" class="form-control" readonly style="caret-color: transparent;">
<i class="mdi mdi-calendar-blank-outline additional-icon"></i>
</div>
<input type="hidden" id="startDate">
<input type="hidden" id="endDate">
</div>
</div>
</div>
</div>
<div class="filter-sidebar-footer">
<a href="<?= base_url("/policy_tranction/report/report-outstanding-list"); ?>"
class="btn btn-secondary" id="clear-filters">Clear</a>
<a href="<?= base_url("/policy_tranction/report/report-outstanding-list"); ?>"
class="btn btn-primary" id="get-emp-list"
onclick="fetchEmpolyeeList(event);closeFilterNav();">Submit</a>
</div>
</div>
<div class="col-12" id="outstanding_list">
<div class="card">
<div class="card-body">
<!--
<div class="row" style="padding-bottom: 10px;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Outstanding Report</h4>
</div>
</div>
-->
<div class="table-responsive">
<table data-custom-table-css="table" data-nhance-list-dt="1" id="outstanding-report-list-table" class="table mb-0 nowrap w-100 table-centered" cellspacing="0" >
<thead class="bg-light">
<tr>
<th><div class="column-header">S.No</div></th>
<!-- <th>Client Name</th> -->
<th><div class="column-header">Insurer</div></th>
<th><div class="column-header">Insurer<br> Branch</div></th>
<th><div class="column-header">Statement<br> Month</div></th>
<th><div class="column-header">Statement<br> No</div></th>
<th><div class="column-header">Invoice No</div></th>
<th><div class="column-header">Invoice Status</div></th>
<th><div class="column-header">Invoice Date</div></th>
<th><div class="column-header">Invoice Amount</div></th>
<th><div class="column-header">Realization <br>Amount</div></th>
<th><div class="column-header">Outstanding <br>Amount</div></th>
</tr>
</thead>
<tbody>
<?php
// dd($outstanting_list);
if (isset($outstanting_list)) { ?>
<?php foreach ($outstanting_list as $index => $row) { ?>
<tr>
<td><?= $index + 1 ?></td>
<td><?php echo $row['short_name']; ?></td>
<td><?php echo $row['branch_name']; ?></td>
<td><?php echo change_date_format($row['month'],'Y-m-d','Y-m') ?></td>
<td><?php echo $row['stmt_sno']; ?></td>
<td><?php echo $row['invoice_no']; ?></td>
<td class="center-align-input"><?php echo isset($row['invoice_status']) ? $row['invoice_status'] : ' - '; ?></td>
<td><?php echo change_date_format($row['invoice_date'],'Y-m-d','d-M-Y'); ?></td>
<td class="right-align-input"><?php echo isset($row['invoice_amount']) ? $row['invoice_amount'] : '0.00'; ?></td>
<td class="right-align-input"><?php echo isset($row['total_paid']) ? $row['total_paid'] : '0.00'; ?></td>
<td class="right-align-input"><?php echo isset($row['outstanding_amount']) ? $row['outstanding_amount'] : '0.00'; ?></td>
</tr>
<?php } ?>
<?php } ?>
</tbody>
</table>
<div>
</div>
</div>
</div><!-- end col -->
</div>
</div>
</div>
<script>
function openOutstandingFilterNav() {
document.getElementById("filter-sidebar").style.width = "350px";
}
function closeFilterNav() {
document.getElementById("filter-sidebar").style.width = "0";
}
$(document).ready(function() {
var ticketsTable = $('#outstanding-report-list-table');
if (ticketsTable.length) {
nhanceListDataTableBeforeInit();
var nhOutstandingTable = ticketsTable.DataTable(nhanceMergeListDataTableOptions({
// dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" + // Filter left, buttons right
// "<'row'<'col-sm-12'tr>>" +
// "<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" + // Filter left, buttons right
"<'row'<'col-sm-12'tr>>" +
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
buttons: [
{
text: '<i class="mdi mdi-filter"></i><span class="btn-custom"> Filter </span>',
className: 'btn app-btn-primary mr-2',
action: function (e, dt, node, config) {
openOutstandingFilterNav();
},
attr: {
id: 'openOutstandingFilterNav'
}
},
{
extend: 'collection',
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
className: 'btn app-btn-secondary ',
buttons: [{
extend: 'csv',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
title: 'Outstanding Report',
},
{
extend: 'excel',
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
title: 'Outstanding Report',
sheetName: 'Outstanding Report',
customize: function(xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
var total = 0;
// Find cells in column AB (28th column in Excel)
$('row c[r^="AB"]', sheet).each(function() {
var value = parseFloat($('v', this)
.text()); // Get the value inside the cell
if (!isNaN(value)) {
total += value;
}
});
// Get the last row index and append the total row
var lastRow = $('row:last', sheet);
var rowIndex = parseInt(lastRow.attr('r')) +
2; // Find the next row index
var totalRow = '<row r="' + rowIndex + '">' +
'<c t="inlineStr" r="AA' + rowIndex +
'"><is><t>Total</t></is></c>' + // Insert "Total" in AA
'<c t="n" r="AB' + rowIndex + '"><v>' + total.toFixed(2) +
'</v></c>' + // Insert sum in AB
'</row>';
// Append the new total row to the sheet
$(sheet).find('sheetData').append(totalRow);
}
}
]
}],
language: {
search: `
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
<i class="mdi mdi-close-circle datatable-clear-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
</div>`,
searchPlaceholder: "Search",
emptyTable: '<div class="text-center text-muted">No Data found</div>'
},
paging: true, // Enable pagination
pageLength: 25, // Set default number of rows per page (optional)
columnDefs: [
<?php for ($i = 0; $i < $or_col_count; $i++) : ?>
{ targets: <?= $i ?>, width: '<?= (int) $or_col_width_px[$i] ?>px' },
<?php endfor; ?>
],
}));
nhanceListDataTableAfterInit();
nhanceListDataTableBindAdjust(nhOutstandingTable);
} else {
console.error("Table not found.");
}
});
$(document).ready(function() {
getURLParams()
$('#client_id').select2();
$('#insurer_id').select2();
$('#insurer_branch_id').select2();
$('#policy_type_id').select2();
})
function fetchEmpolyeeList(event) {
event.preventDefault(); // Prevent default action
var start_date = $('#startDate').val();
var end_date = $('#endDate').val();
var client_id = $('#client_id').val();
var insurer_id = $('#insurer_id').val();
var insurer_branch_id = $('#insurer_branch_id').val();
var policy_type_id = $('#policy_type_id').val();
var date_type = $('#date_type').val();
var issuer = $('#issuer').val();
if(insurer_id == false || insurer_branch_id == false){
alert("Please Choose Insurer and its branch to Proceed .. !!");
return;
}
console.log(start_date + '-' + end_date);
var queryParams = {
start_date: start_date,
end_date: end_date,
client_id: client_id,
insurer_id: insurer_id,
insurer_branch_id : insurer_branch_id,
policy_type_id: policy_type_id,
date_type: date_type,
issuer: issuer,
};
const queryString = objectToQueryString(queryParams);
const apiURL = $('#get-emp-list').attr('href') + "?" + queryString;
console.log(apiURL);
window.location.href = apiURL;
}
function objectToQueryString(obj) {
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
}
function getURLParams() {
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
const startDate = params.get('start_date') || 0; // Default to 0 if not found
const endDate = params.get('end_date') || 0; // Default to 0 if not found
const client_id = params.get('client_id') || 0; // Default to 0 if not found
const insurer_id = params.get('insurer_id') || 0; // Default to 0 if not found
const insurer_branch_id = params.get('insurer_branch_id') || 0 ; // Default to 0 if not found
const policy_type_id = params.get('policy_type_id') || 0; // Default to 0 if not found
const date_type = params.get('date_type') || 0; // Default to 0 if not found
const issuer = params.get('issuer') || 0; // Default to 0 if not found
hideDateField(date_type)
console.log('startDate', startDate)
console.log('endDate', endDate)
console.log('client_id', client_id)
console.log('insurer_id', insurer_id)
console.log('insurer_branch_id',insurer_branch_id)
console.log('policy_type_id', policy_type_id)
console.log('date_type', date_type)
console.log('issuer', issuer)
// Log the values or use them as needed
console.log('Start Date:', startDate);
console.log('End Date:', endDate);
if (startDate != 0 && endDate != 0) {
setTimeout(function() {
$('#start_date').val(startDate)
$('#end_date').val(endDate)
$('#client_id').val(client_id).change()
$('#insurer_id').val(insurer_id)
$('#insurer_branch_id').val(insurer_branch_id).change()
$('#policy_type_id').val(policy_type_id).change()
$('#date_type').val(date_type)
$('#issuer').val(issuer)
}, 1000)
}
}
$(function() {
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
// Get start and end dates from URL parameters, or use default values
const startDateParam = params.get('start_date') || moment().subtract(29, 'days').format('DD-MM-YYYY');
const endDateParam = params.get('end_date') || moment().format('DD-MM-YYYY');
// Parse the dates to moment objects
var start = moment(startDateParam, 'DD-MM-YYYY');
var end = moment(endDateParam, 'DD-MM-YYYY');
// var start = moment().subtract(29, 'days');
// var end = moment();
function cb(start, end) {
// codeword : ***2***
// if you cross check means also uncomment "star1star" (***1***)
// $('#reportrange span').html(start.format('D-MM-YYYY') + ' - ' + end.format('D-MM-YYYY'));
$('#reportrange').html(start.format('D-MM-YYYY') + ' - ' + end.format('D-MM-YYYY'));
$('#startDate').val(start.format('DD-MM-YYYY'));
$('#endDate').val(end.format('DD-MM-YYYY'));
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
// autoUpdateInput: false,
locale: {
format: 'DD-MM-YYYY' // 👈 force input format
},
ranges: {
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end);
$('#clear-filters').on('click', function() {
// Reset all select dropdowns to the first option
$('#client_id').val('0').change();
$('#insurer_id').val('0').change();
$('#insurer_branch_id').val('0').change();
$('#policy_type_id').val('0').change();
$('#date_type').val('0');
$('#issuer').val('0');
$('#date_div').hide()
// Reset the date range picker to default
$('#reportrange').data('daterangepicker').setStartDate(moment().subtract(29, 'days'));
$('#reportrange').data('daterangepicker').setEndDate(moment());
cb(start, end); // Update the displayed date range
});
});
function hideDateField(input = null) {
let val = $('#date_type').val();
if (input) {
val = input;
}
if (val != 0) {
$('#date_div').show()
} else {
$('#date_div').hide()
}
}
function sendPolicyTransactionID(event, pt_id) {
event.preventDefault(); // Prevent default action
console.log(pt_id);
var queryParams = {
pt_id: pt_id,
};
const queryString = objectToQueryString(queryParams);
const apiURL = $('#get-policy-list').attr('href') + "?" + queryString;
console.log(apiURL);
window.location.href = apiURL;
}
function getInsurerBranch(){
let insurer_id = $('#insurer_id').val();
if(insurer_id == 0){
return;
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn('slow');
$.ajax({
url: '<?= base_url('master/insurer/branch/getList?') ?>',
type: 'POST',
data: {insurer_id},
success: function(response) {
console.log(response)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (response.data && response.data != []) {
let options ="";
let insurer_branch_list = response.data;
insurer_branch_list.forEach(element => {
options += `<option value="${element['id']}"> ${element['branch_name']} </option>`;
});
$('#insurer_branch_id').html('<option value="0" selected>Select Insurer Branch</option>' + options);
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// Handle error
console.error('Upload error occurred:');
console.error('Status: ', status); // Status of the request
console.error('Error: ', error); // Specific error message
console.error('XHR Object: ', xhr); // Full XHR object with response details
// Optionally log server response, if available
if (xhr.responseText) {
console.error('Response Text: ', xhr.responseText);
}
toastr.warning('Error uploading file', 'Werning');
console.error('Upload error:', error);
},
complete: function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log("Ajax call completed successfully");
}
});
}
</script>