nhance/app/Views/endorsement_list.php

779 lines
31 KiB
PHP
Executable File
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.

<?php
helper('datatable_view');
$end_header_labels = ['S.No', 'Name/code', 'Policy name', 'Endorsement ID', 'Insurer name', 'Remarks', 'Endorsement Type', 'Status', 'Action'];
$end_col_count = count($end_header_labels);
$end_col_max_len = array_fill(0, $end_col_count, 0);
for ($i = 0; $i < $end_col_count; $i++) {
$end_col_max_len[$i] = mb_strlen($end_header_labels[$i]);
}
$employees = $employees ?? [];
foreach ($employees as $key => $employee) {
$end_col_max_len[0] = max($end_col_max_len[0], mb_strlen((string) ($key + 1)));
$end_col_max_len[1] = max($end_col_max_len[1], mb_strlen(trim((string) ($employee['name'] ?? '')) . '( ' . trim((string) ($employee['emp_code'] ?? '')) . ' )'));
$policyLine = (isset($employee['policy_type']) ? (string) $employee['policy_type'] : '') . ' - ' . (isset($employee['policy_no']) ? (string) $employee['policy_no'] : '');
$end_col_max_len[2] = max($end_col_max_len[2], mb_strlen($policyLine));
$end_col_max_len[3] = max($end_col_max_len[3], mb_strlen((string) ($employee['endorsement_id'] ?? '')));
$end_col_max_len[4] = max($end_col_max_len[4], mb_strlen((string) ($employee['insurer_short_name'] ?? '')));
$end_col_max_len[5] = max($end_col_max_len[5], mb_strlen((string) ($employee['remarks'] ?? '')));
$act = $employee['actions'] ?? '';
$actionLabel = $act === 'c' ? 'Correction' : ($act === 'si' ? 'SI Enhancement' : ($act === 'd' ? 'Deletion' : (string) $act));
$end_col_max_len[6] = max($end_col_max_len[6], mb_strlen($actionLabel));
$end_col_max_len[7] = max($end_col_max_len[7], mb_strlen((string) ($employee['status'] ?? '')));
$end_col_max_len[8] = max($end_col_max_len[8], 4);
}
$end_col_min_px = [48, 120, 160, 110, 120, 120, 120, 96, 52];
$end_col_max_px = [64, 280, 400, 200, 240, 360, 200, 160, 72];
$end_col_width_px = nhance_dt_column_widths_px($end_header_labels, $end_col_max_len, $end_col_min_px, $end_col_max_px);
?>
<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
.btn .btn-secondary .buttons-csv .buttons-html5 .my_class {
position: relative;
left: 79px;
}
.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;
}
<?php for ($i = 0; $i < $end_col_count; $i++) : ?>
#endorsement-list-table_wrapper .dataTables_scrollHead table thead th:nth-child(<?= $i + 1 ?>),
#endorsement-list-table thead th:nth-child(<?= $i + 1 ?>) {
min-width: <?= (int) $end_col_width_px[$i] ?>px;
width: <?= (int) $end_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
overflow: visible !important;
}
#endorsement-list-table tbody td:nth-child(<?= $i + 1 ?>) {
width: <?= (int) $end_col_width_px[$i] ?>px;
max-width: <?= (int) $end_col_width_px[$i] ?>px;
min-width: <?= (int) $end_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
}
<?php endfor; ?>
#endorsement-list-table tbody td:nth-child(1),
#endorsement-list-table tbody td:nth-child(2),
#endorsement-list-table tbody td:nth-child(3),
#endorsement-list-table tbody td:nth-child(4),
#endorsement-list-table tbody td:nth-child(5),
#endorsement-list-table tbody td:nth-child(6),
#endorsement-list-table tbody td:nth-child(7),
#endorsement-list-table tbody td:nth-child(8) {
overflow: hidden;
text-overflow: ellipsis;
}
#endorsement-list-table tbody td:nth-child(9) {
overflow: visible;
text-overflow: clip;
}
#endorsement-list-table tbody td {
padding: 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
#endorsement-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>Client</label>
<select class="form-control" id="clients">
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-12">
<label>Branch</label>
<select name="branch_id" class="form-control" id="branch_id">
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-12">
<label>Policy</label>
<select class="form-control" id="policies">
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-12">
<label>Status</label> <br />
<select class="form-control" id="status1">
<option value="0">Select</option>
<?php foreach ($status as $key => $value) { ?>
<option value="<?= $key ?>" <?= (isset($getData) && $getData['status'] == $key) ? 'selected' : '' ?>>
<?= $value ?>
</option>
<?php } ?>
</select>
</div>
</div>
</div>
</div>
<div class="filter-sidebar-footer">
<a href="<?= base_url("/employee/endorsement-list"); ?>" class="btn btn-primary" id="get-emp-list" onclick="fetchEmpolyeeList(event);closeFilterNav();">Submit</a>
</div>
</div>
<div class="row" id="client_list">
<div class="col-12">
<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;">Endorsements</h4>
</div>
</div> -->
<table data-custom-table-css="table" class="table table-hover m-0 table-centered dt-responsive w-100" cellspacing="0" id="endorsement-list-table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">S.No&nbsp;</th>
<th class="font-weight-medium">Name/code</th>
<th class="font-weight-medium">Policy name</th>
<th class="font-weight-medium">Endorsement ID</th>
<th class="font-weight-medium">Insurer name</th>
<th class="font-weight-medium">Remarks</th>
<th class="font-weight-medium">Endorsement Type</th>
<th class="font-weight-medium">Status</th>
<th class="font-weight-medium">Action</th>
</tr>
</thead>
<tbody class="font-12">
<?php
if (isset($employees)) {
foreach ($employees as $key => $employee) { ?>
<tr>
<td><b><?php echo ($key + 1) ?></b></td>
<td><?php echo $employee['name'] ?>( <?php echo $employee['emp_code'] ?> )</td>
<!-- <td><?php echo isset($employee['policy_name']) ? $employee['policy_name'] : '' ?> - <?php echo isset($employee['policy_no']) ? $employee['policy_no'] : '' ?> - <?php echo isset($employee['policy_type']) ? $employee['policy_type'] : '' ?></td> -->
<td><?php echo isset($employee['policy_type']) ? $employee['policy_type'] : '' ?> - <?php echo isset($employee['policy_no']) ? $employee['policy_no'] : '' ?></td>
<td><?php echo $employee['endorsement_id'] ?></td>
<td><?php echo isset($employee['insurer_short_name']) ? $employee['insurer_short_name'] : '' ?>
</td>
<td><?php echo $employee['remarks'] ?></td>
<td>
<?php
if ($employee['actions'] == 'c') {
echo 'Correction';
} elseif ($employee['actions'] == 'si') {
echo 'SI Enhancement';
} elseif ($employee['actions'] == 'd') {
echo 'Deletion';
}
?>
</td>
<td>
<?php
if ($employee['status'] == 'pending') {
echo '<span class="badge badge-danger">' . $employee['status'] . '</span>';
} elseif ($employee['status'] == 'inprogress') {
echo '<span class="badge badge-warning">' . $employee['status'] . '</span>';
} elseif ($employee['status'] == 'complete') {
echo '<span class="badge badge-success">' . $employee['status'] . '</span>';
}
?>
</td>
<td class="text-center"><a href="#" data-id="<?php echo $employee['id'] ?>" class="mdi mdi-eye emp_data_model" aria-hidden="true" data-toggle="modal" data-target="#centermodal"></a>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
</div>
</div>
<!-- Center modal content -->
<div class="modal fade" id="centermodal" tabindex="-1" role="dialog" aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="background-color: gainsboro;">
<h4 class="modal-title" id="myCenterModalLabel">Endorsement Details <span id="heading"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="modal_body">
<div class="table-responsive">
<table data-custom-table-css="table" class="table table-hover mb-0">
<thead id="table_head_data">
</thead>
<tbody id="table_data">
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$(document).ready(function() {
// Initialize select2
$("#clients").select2();
$("#policies").select2();
$("#branch_id").select2();
});
// Declare a global variable to store API response data
var clientPolicies = [];
var clientPoliciesWithBranch = {
policies: []
};
var client_id = '<?= isset($getData) ? $getData['client_id'] : '0' ?>';
var client_branch_id = '<?= isset($getData) ? $getData['branch_id'] : '0' ?>';
$(window).on("load", function() {
console.log("window loaded");
fetchClientPolicies();
});
function fetchClientPolicies() {
$('#loader').show();
var apiURL = '<?php echo base_url(); ?>' + 'util/clients-with-policies';
console.log('fetchClientPolicies');
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
$('#loader').hide(); // ✅ hide AFTER data received
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
try {
clientPolicies = (response.data);
response.data.forEach(policy => {
// console.log('policies', policy.policies);
policy.policies.forEach(p => {
clientPoliciesWithBranch.policies.push(p);
});
});
// console.log(clientPolicies);
appendClients(clientPolicies);
setTimeout(function() {
if (client_id) {
var foundPolicies = clientPolicies.find(function(item) {
// console.log(typeof item.id)
return item.id == client_id;
});
appendBranch(foundPolicies.branchs);
}
}, 500);
setTimeout(function() {
if (client_branch_id) {
var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) {
// console.log('item', item);
return item.branch_id === client_branch_id;
});
if (foundPolicies) {
// console.log('foundPolicies', foundPolicies);
appendPolicies(foundPolicies);
} else {
console.log('No policies found for the selected client');
}
}
}, 500);
} catch (error) {
console.error('Error parsing API response data:', error);
}
} else if (response.code === 404 && response.dataStatus === false) {
console.error('no data found', response);
} else {
console.error('Something went wrong!');
}
},
error: function(xhr, status, error) {
$('#loader').hide(); // ✅ hide on error too
console.error('Error fetching data from API:', error);
}
});
}
/* Modified by Gemini Code Assist */
function openEndorsementListFilterNav() {
document.getElementById("filter-sidebar").style.width = "350px";
}
/* Modified by Gemini Code Assist */
function closeFilterNav() {
document.getElementById("filter-sidebar").style.width = "0";
}
function appendClients(data) {
var clientID = <?= isset($getData) ? $getData['client_id'] : '0' ?>;
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.client_name
});
if (clientID == item.id) {
option.attr('selected', true);
}
$('#clients').append(option);
});
}
function appendBranch(data) {
$('#branch_id').empty();
$('#branch_id').append($('<option>', {
value: '0',
text: 'Select'
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.branch_name
});
if (client_branch_id == item.id) {
option.attr('selected', true);
}
$('#branch_id').append(option);
});
}
function appendPolicies(data) {
$('#policies').empty();
$('#policies').append($('<option>', {
value: '0',
text: 'Select'
}));
var PolicyID = <?= isset($getData) ? $getData['policy_id'] : '0' ?>;
// console.log(PolicyID)
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.client_policy_id,
// text: `${item.name ?? ''} - ${item.policy_no ?? ''} - ${item.policy_type ?? ''}`
text: `${item.policy_type ?? ''} - ${item.policy_no ?? ''}`
});
if (PolicyID == item.client_policy_id) {
option.attr('selected', true);
}
$('#policies').append(option);
});
}
$(document).ready(function() {
$('#clients').on('change', function() {
$('#policies').empty();
$('#policies').append($('<option>', {
value: '0',
text: 'Select'
}));
var selectedClient = $(this).val();
// console.log(selectedClient);
// $('#selectedOptionInfo').text('Selected option: ' + selectedOption);
// Check if the selected option exists in apiData
var foundPolicies = clientPolicies.find(function(item) {
return item.id === selectedClient;
});
// console.log(foundPolicies.branchs);
appendBranch(foundPolicies.branchs);
});
});
$(document).ready(function() {
$('#branch_id').on('change', function() {
var selectedClient = $(this).val();
// console.log('selectedBranch', selectedClient);
// console.log('clientPolicies', clientPoliciesWithBranch);
var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) {
// console.log('item', item);
return item.branch_id === selectedClient;
});
if (Array.isArray(foundPolicies) && foundPolicies.length === 0) {
appendPolicies(foundPolicies);
toastr.warning('No policies found for the selected client branch.');
} else {
// console.log('foundPolicies', foundPolicies);
appendPolicies(foundPolicies);
}
});
});
// Function to convert object to query parameters
function objectToQueryString(obj) {
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
}
function fetchEmpolyeeList(event) {
event.preventDefault(); // Prevent default action
var client_id = $('#clients').val();
var policy_id = $('#policies').val();
var status = $('#status1').val();
var branch_id = $('#branch_id').val();
// console.log(client_id + '-' + policy_id);
if (client_id == '0' || policy_id == '0') {
alert('Please select values in both dropdowns.');
return;
}
var queryParams = {
client_id: client_id,
policy_id: policy_id,
branch_id: branch_id,
status: status,
};
const queryString = objectToQueryString(queryParams);
const apiURL = $('#get-emp-list').attr('href') + "?" + queryString;
// console.log(apiURL);
window.location.href = apiURL;
}
$('.emp_data_model').click(function() {
var myVal = $(this).data('id');
// console.log(myVal);
fetchEmpEndorsementData(myVal)
});
function fetchEmpEndorsementData(id) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var apiURL = '<?php echo base_url(); ?>' + 'util/get-emp-endorsement/' + id;
console.log('fetchEmpEndorsementData');
// console.log(apiURL);
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
// console.log(response);
if (response.code === 200 && response.dataStatus === true) {
try {
endorsementData = (response.data);
endorsementData2 = (response.data2);
e_actions = endorsementData2[0]['actions'];
var heading = "";
if (endorsementData2[0]['actions'] == 'si') {
heading = ' - ' + 'SI Enhancement';
heading += ' - ' + (endorsementData2[0]['endorsement_id'] !== null ? endorsementData2[0]['endorsement_id'] : endorsementData2[0]['status']);
} else if (endorsementData2[0]['actions'] == 'd') {
heading = ' - ' + 'Deletion';
heading += ' - ' + (endorsementData2[0]['endorsement_id'] !== null ? endorsementData2[0]['endorsement_id'] : endorsementData2[0]['status']);
} else if (endorsementData2[0]['actions'] == 'c') {
heading = ' - ' + 'Correction';
heading += ' - ' + (endorsementData2[0]['endorsement_id'] !== null ? endorsementData2[0]['endorsement_id'] : endorsementData2[0]['status']);
}
$('#heading').html(heading);
$('#table_data').empty();
$('#table_head_data').empty();
if (e_actions == 'd') {
$.each(endorsementData, function(index, item) {
var tableHtml = `
<tr>
<td>${item.field_name}</td>
<td>${formatNumberToIndianLocale(item.data, item.field_name, e_actions)}</td>
</tr>
`;
$('#table_data').append(tableHtml);
});
} else {
var table_head = `
<tr>
<th class="font-weight-medium"></th>
<th class="font-weight-medium">Old Value</th>
<th class="font-weight-medium">New Value</th>
</tr>
`;
$('#table_head_data').append(table_head);
$.each(endorsementData, function(index, item) {
var tableHtml = `
<tr>
<td>${item.field_name}</td>
<td>${formatNumberToIndianLocale(item.old_value, item.field_name)}</td>
<td>${formatNumberToIndianLocale(item.new_value, item.field_name, e_actions)}</td>
</tr>
`;
$('#table_data').append(tableHtml);
});
}
} catch (error) {
console.error('Error parsing API response data:', error);
}
} else if (response.code === 404 && response.dataStatus === false) {
console.error('no data found', response);
} else {
console.error('Something went wrong!');
}
},
error: function(xhr, status, error) {
console.error('Error fetching data from API:', error);
}
});
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 200);
}
function formatNumberToIndianLocale(value, field_name, action) {
// Check if the value is a valid number (either as a number or as a string)
if (!isNaN(value) && !isNaN(parseFloat(value)) && field_name != 'No of Days') {
// Convert the value to a number and format it using Indian English locale
var return_val = parseFloat(value).toLocaleString('en-IN');
if (field_name == 'Period of non coverage') {
return value + ' days';
}
if (field_name == 'Total Amount') {
return '₹ ' + return_val + ' ( To be Refunded )';
}
if (field_name == 'Total') {
if (action == 'd') {
return '₹ ' + return_val + ' ( To be Refunded )';
} else if (action == 'si') {
return '₹ ' + return_val + ' ( To be paid )';
}
}
return '₹ ' + return_val;
} else {
// Return the original value if it's not a valid number
return value;
}
}
$('.close').click(function() {
$('#table_data').empty();
})
$(document).ready(function() {
nhanceListDataTableBeforeInit();
var nhEndorsementTable = $('#endorsement-list-table').DataTable(nhanceMergeListDataTableOptions({
// dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
// "<'row'<'col-sm-12'tr>>" +
// "<'row'<'col-sm-5'i><'col-sm-7'p>>",
dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
"<'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-plus" ></i><span class=" btn-custom"> Add </span>',
// className: 'btn app-btn-primary mr-2',
// action: function(e, dt, node, config) {
// openTicket();
// }
// },
{
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) {
openEndorsementListFilterNav();
}
},
{
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>',
className: 'app-btn-primary ',
},
{
extend: 'excel',
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
exportOptions: {
orthogonal: 'sort'
},
className: 'app-btn-primary ',
sheetName: 'Endorsements'
}
]
}
],
initComplete: function(settings, json) {
$('.my_class').css({
"position": "relative",
"left": "79px"
});
},
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,
// pagingType: 'full_numbers'
columnDefs: [
<?php for ($i = 0; $i < $end_col_count; $i++) : ?>
<?php if ($i === 0) : ?>
{ targets: 0, width: '<?= (int) $end_col_width_px[0] ?>px', type: 'scientific' },
<?php else : ?>
{ targets: <?= $i ?>, width: '<?= (int) $end_col_width_px[$i] ?>px' },
<?php endif; ?>
<?php endfor; ?>
],
}));
nhanceListDataTableAfterInit();
nhanceListDataTableBindAdjust(nhEndorsementTable);
});
</script>