nhance-enrollment/app/Views/client_policy.php

2582 lines
96 KiB
PHP
Executable File
Raw Permalink 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>
#notification_slider .switch-label {
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
cursor: pointer;
font-weight: 500;
color: #333;
justify-content: flex-end;
margin-right: 40px;
}
#notification_slider .switch-label input {
opacity: 0;
width: 0;
height: 0;
}
#notification_slider .slider {
position: relative;
width: 50px;
height: 25px;
background-color: #fff;
border-radius: 25px;
box-shadow: 0 0 5px rgba(0,0,0,0.2);
transition: 0.3s;
}
#notification_slider .slider::before {
content: "";
position: absolute;
height: 19px;
width: 19px;
left: 3px;
top: 3px;
background-color: #ccc;
border-radius: 50%;
transition: 0.3s;
}
#notification_slider input:checked + .slider {
background-color: #ff4d4d; /* red when ON */
}
#notification_slider input:checked + .slider::before {
transform: translateX(25px);
background-color: #fff;
}
#notification_slider .switch-text {
user-select: none;
}
#table-client-policy_wrapper .row>.col-sm-12.col-md-6:first-child{
display: none;
}
#table-client-policy_filter{
text-align: left;
}
</style>
<style>
.switch {
position: relative;
display: inline-block;
width: 54px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 19px;
width: 19px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
<div class="tab-pane fade" id="police-tab">
<div class="row float-right" style="padding-bottom: 10px; position: relative;right: 13px;">
<button type="button" id="BtnAdd" class="btn btn-primary waves-effect waves-light btnAdd btn-sm" style="position: relative;right: 10px;"><span class="fa fa-plus-square" aria-hidden="true" style="padding: 5px 10px;"></span>Add Policy</button>
<!-- <button type="button" id="BtnAddSuccess" class="btn btn-success waves-effect waves-light BtnAddSuccess btn-sm" onclick="showModal()"><span class="fa fa-plus-square" aria-hidden="true" style="padding: 5px 10px;"></span>Add Policy From Lead</button> -->
</div>
<br>
<div class="" style="padding: 10px; position: absolute;
right: 0;" id="notification_slider">
<label class="switch-label">
<input type="checkbox" id="chk-show-expired">
<span class="slider"></span>
<span class="switch-text">Expired Policies</span>
</label>
</div>
<div class="table-responsive" id="table_list">
<table class="table table-borderless table mb-0" id="table-client-policy">
<thead class="thead-light">
<tr>
<!-- <th>Insurer</th> -->
<th>Policy</th>
<th>Client Branch</th>
<!-- <th>TPA</th> -->
<th>Date</th>
<!-- <th>Enrolment Status</th> -->
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody id="policy_table">
</tbody>
</table>
</div>
<div class="row" id="add_form">
<div class="col-12">
<div class="card-body">
<div class="row float-right" style="position: relative; bottom: 20px; right: 13px;">
<button type="button" id="btnPolicyBack"
class="btn btn-primary waves-effect waves-light btn-sm btnBack btn-sm"><span class="fa fa-list"
aria-hidden="true" style="padding: 5px 10px;"></span>Back To List</button>
</div>
<hr>
<form role="form" class="parsley-examples" method="post" id="policy_form" enctype="multipart/form-data">
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="PrimaryKey" id="policy_PrimaryKey" />
<input type="hidden" id="policy_form_action" />
<input type="hidden" name="policy_type_id" id="policy_type_id" />
<input type="hidden" id="insurer_policy_id" />
<input type="hidden" name="client_id" id="client_id_policy"
value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label for="client_branch">Client Branch<span class="text-danger">*</span></label>
<select class="form-control" id="client_branch" name="client_branch_id">
<option selected>Select Client Branch</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="policy_type"> Policy Type<span class="text-danger">*</span></label>
<select class="form-control" id="policy_type" name="policy_type_id" required>
<option value="0">Select Policy Type</option>
<?php foreach ($policy_types as $value) { ?>
<option value="<?= $value['id']?>"><?= $value['policy_type'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-4" id="base_policy_id" style="display: none;">
<label for="base_policy">Base Policy<span id="base_danger"
class="text-danger">*</span></label>
<select class="form-control" id="base_policy" name="base_policy">
<option value="" selected>Select Base Policy</option>
</select>
</div>
<!-- <div class="form-group col-md-4">
<label for="policy_no">Policy No<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Policy Number " name="policy_no" id="policy_no" required>
</div> -->
</div>
<div class="form-row" id="first" style="display: none;">
<!-- <div class="form-group col-md-4">
<label for="insurer">Insurer<span class="text-danger">*</span></label>
<select class="form-control" id="insurer" name="insurer" required>
<option value="">Select Insurer</option>
<?php foreach ($insurer as $value) { ?>
<option value="<?= $value['id'] . '-' . $value['insurer_id'] ?>">
<?= $value['insurer_name'] . '-' . $value['branch_code'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-4">
<label for="tpa">TPA<span id="tpa_danger" class="text-danger">*</span></label>
<select class="form-control" id="tpa" name="tpa" required>
<option value="">Select TPA</option>
<?php foreach ($tpa as $value) { ?>
<option value="<?= $value['id'] . '-' . $value['tpa_id'] ?>">
<?= $value['tpa_short_name'] . '-' . $value['branch_code'] ?></option>
<?php } ?>
</select>
</div> -->
<div class="form-group col-md-4">
<label for="policy_no">Policy No<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Policy Number "
name="policy_no" id="policy_no" required>
</div>
</div>
<div class="form-row" id="second" style="display: none;">
<div class="form-group col-md-4">
<label for="policy_start_date">Policy Start Date<span
class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Start Date "
name="policy_start_date" id="start_date" required>
</div>
<div class="form-group col-md-4">
<label for="policy_end_date">Policy End Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter End Date "
name="policy_end_date" id="end_date" required>
</div>
<div class="form-group col-md-4" id="policy_status_field">
<label for="policy_status">Policy Status</label>
<input value="" type="text" class="form-control" placeholder="Policy Status"
id="policy_status" readonly>
</div>
</div>
<div class="form-row" id="third" style="display: none; position: relative;top: 22px;">
<!-- <div class="form-group col-md-4">
<label for="cd_ac_no">CD Account Number<span id="tpa_danger" class="text-danger">*</span></label>
<select class="form-control" id="cd_ac_no" name="cd_ac_no" required>
<option value="">Select CD Account Number</option>
</select>
</div> -->
<div class="form-group col-md-4">
<label for="gst_no">GST ( % )<span id="tpa_danger" class="text-danger">*</span></label>
<input type="text" class="form-control" placeholder="GST (%)" id="gst_no" name="gst"
required>
</div>
<!-- <div class="form-group col-md-4">
<label class="switch" style="position: relative;top: 43px;left: 20px;">
<input id="inception_type" type="checkbox" name="inception_type">
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="inception_type" style="position: relative;bottom: 5px;left: 85px;">Enable
Employee Enrolment Process</label>
</div> -->
<!-- <div class="form-group col-md-4" style="padding-top:50px;padding-bottom: 0px;">
<label for="inception_type" style=" position: relative;bottom: 5px;">
<label class="switch">
<input id="inception_type" type="checkbox" name="inception_type">
<span class="slider round" style="height: 27px;"></span>
</label>Enable
Employee Enrolment Process
</label>
</div> -->
<!-- <div class="form-row">
<div class="form-group col-md-4">
<label for="open_date">Open Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control dateofdata"
placeholder="Enter Open Date " name="open_date" id="open_date">
</div>
<div class="form-group col-md-4">
<label for="close_date">Close Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control dateofdata"
placeholder="Enter Close Date " name="close_date" id="close_date">
</div>
<div class="form-group col-md-4">
<label for="reminder_date">Reminder Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control dateofdata"
placeholder="Enter Remainder Dates( eg, 28,29,30 )" name="reminder_date"
id="reminder_date">
</div>
</div> -->
<div class="form-group col-md-12">
<label for="disclaimer">Disclaimer<span class="text-danger"></span></label>
<textarea class="form-control" placeholder="Enter Disclaimer" name="disclaimer"
id="disclaimer"></textarea>
</div>
<div class="form-group col-md-4" style="padding-top:50px;padding-bottom: 0px;">
<label for="policy_visibility" style=" position: relative;bottom: 5px;">
<label class="switch">
<!-- <input id="policy_visibility" type="checkbox" name="policy_visibility" checked > -->
<input id="policy_visibility" type="checkbox" name="enrolment_visibility" checked>
<span class="slider round" style="height: 27px;"></span>
</label>
Policy Visibilty in Enrollment App
</label>
</div>
<!-- <div class="form-group col-md-4">
<label class="switch" style="position: relative;top: 43px;left: 20px;">
<input id="policy_visibility" type="checkbox" name="enrolment_visibility" checked>
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="policy_visibility" style="position: relative;bottom: 5px;left: 85px;">Policy Visibilty in Enrollment App</label>
</div> -->
<!-- <div class="form-group col-md-4">
<label class="switch" style="position: relative;top: 43px;left: 20px;">
<input id="is_member_modify_allowed" type="checkbox" name="is_member_modify_allowed" checked>
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="is_member_modify_allowed" style="position: relative;bottom: 5px;left: 85px;"> In Enrollment Member Data Modification Allowed</label>
</div> -->
<!-- <div class="form-group col-md-4">
<label class="switch" style="position: relative;top: 43px;left: 20px;">
<input id="is_lgbtq" type="checkbox" name="is_lgbtq">
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="is_lgbtq" style="position: relative;bottom: 5px;left: 85px;"> Is LGBTQ Enable</label>
</div>
<div class="form-group col-md-4">
<label class="switch" style="position: relative;top: 43px;left: 20px;">
<input id="is_premium_summery" type="checkbox" name="is_premium_summery" checked>
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="is_premium_summery" style="position: relative;bottom: 5px;left: 85px;"> Is Premium Summary Display Enabled </label>
</div> -->
<div class="form-group col-md-4" style="padding-top:50px;padding-bottom: 0px;">
<label for="is_lgbtq" style=" position: relative;bottom: 5px;">
<label class="switch">
<input id="is_lgbtq" type="checkbox" name="is_lgbtq" checked >
<span class="slider round" style="height: 27px;"></span>
</label>
Is LGBTQ Enable</label>
</div>
<div class="form-group col-md-4">
<label for="is_premium_summery">Premium Summary Display</label>
<select class="form-control" name="is_premium_summery" id="is_premium_summery">
<option value="0">Disable Premium Summary Display</option>
<option value="1" selected>Enable Premium Summary Display</option>
<option value="2">Enable Premium Total Display</option>
</select>
</div>
</div>
<div id="policy_fields"></div>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnSubmit">Submit</button>
<button type="button" class="btn btn-secondary waves-effect btnBack"
id="btnBack">Cancel</button>
</div>
</form>
</div>
</div> <!-- end col-->
</div>
</div>
<!-- end -->
<?php include('policy_grid.php'); ?>
<?php include('policy_gmc_terms.php'); ?>
<?php include('policy_gpa_terms.php'); ?>
<?php include('other_policy_terms.php'); ?>
<?php include('rack_rate_auto_si.php'); ?>
<?php include('si_mapping.php');?>
<!-- Center modal content -->
<div class="modal fade" id="lead_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="false">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel">Lead List</h4>
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="form-group col-md-12">
<label for="lead_id"> Lead List <span class="text-danger">*</span></label>
<select class="form-control" id="lead_id" name="lead_id" required>
<option value="">Select Lead</option>
<?php if(isset($lead_data)) { ?>
<?php foreach ($lead_data as $value) { ?>
<option value="<?= $value['id']?>" data-clientid="<?= $value['client_id']?>" ,
data-branchid="<?= $value['client_branch_id']?>"><?= $value['client_name'] ?> -
<?= $value['branch_name'] ?> - <?= $value['user_name'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="form-group text-right m-b-0" id="hide_smbt_btn">
<button type="submit" class="btn btn-primary" onclick="featchClient()">Fetch Client</button>
</div>
</div>
</div><!-- /.modal-content -->
</div>
</div><!-- /.modal -->
<script>
$('#inception_type').change(function() {
var open_data = $('#open_date').parent();
var close_data = $('#close_date').parent();
var reminder_data = $('#reminder_date').parent();
if ($(this).prop('checked')) {
$(open_data).show();
$(close_data).show();
$(reminder_data).show();
$('.dateofdata').attr('required', true);
} else {
$(open_data).hide();
$(close_data).hide();
$(reminder_data).hide();
$('.dateofdata').attr('required', false);
}
})
var policy_PrimaryKey = $('#client_id_policy').val();
var policy_client = $('#policy_PrimaryKey').val();
$(document).ready(function() {
// Initialize select2
$("#insurer").select2();
$("#policy").select2();
$("#tpa").select2();
$("#base_policy").select2();
$("#client_branch").select2();
});
$(document).ready(function() {
$('#policy_status_field').hide()
// Get today's date
var today = new Date();
const showExpired = $('#chk-show-expired').is(':checked');
var startDatePicker = flatpickr("#start_date", {
dateFormat: "d/m/Y",
defaultDate: today,
allowInput: false,
onChange: function(selectedDates, dateStr, instance) {
var endDate = new Date(selectedDates[0]);
endDate.setFullYear(endDate.getFullYear() + 1);
endDate.setDate(endDate.getDate() - 1); // Set end date to last day of selected year
endDatePicker.setDate(endDate);
}
});
// Initialize Flatpickr for the start date with today's date
var openDatePicker = flatpickr("#open_date", {
dateFormat: "d/m/Y",
defaultDate: today,
allowInput: false,
});
// Calculate the end date (today + 1 year)
var closeDate = new Date(today);
closeDate.setFullYear(closeDate.getFullYear() + 1);
closeDate.setDate(closeDate.getDate() - 1); // Set end date to last day of next year
var endDatePicker = flatpickr("#end_date", {
dateFormat: "d/m/Y",
defaultDate: closeDate,
allowInput: false
});
// Initialize Flatpickr for the end date with the calculated end date
var closeDatePicker = flatpickr("#close_date", {
dateFormat: "d/m/Y",
defaultDate: today,
allowInput: false
});
// var reminderDatePicker = flatpickr("#reminder_date", {
// dateFormat: "d/m/Y",
// defaultDate: today,
// allowInput: false
// });
$('#add_form').hide();
$('.btnBack').hide();
if (policy_PrimaryKey !== '') {
var policyTable = '';
var data = <?= isset($client_policy) ? json_encode($client_policy) : '[]' ?>;
console.log('client_policy_data', data)
var role = data.role
delete data.role;
$.each(data, function(index, item) {
// console.log('step 1');
var patternGMC = /gmc/i; // Case insensitive pattern for 'gmc'
var patternGPA = /gpa/i; // Case insensitive pattern for 'gpa'
var subject = item.policy_type_name;
//console.log('search terms subject', subject);
if (patternGMC.test(subject)) {
search_term = 'GMC';
} else if (patternGPA.test(subject)) {
search_term = 'GPA';
} else {
search_term = subject; // Set default value if neither 'GMC' nor 'GPA' exists
}
//console.log('search_term :', search_term)
var enrollmentStatus = '';
if (item.inception_type == 1) {
enrollmentStatus = 'N/A'
} else if (item.inception_type == 2) {
if (item.open_for_enrollment == 1) {
enrollmentStatus = '<a href="#" data-id="' + item.id + '" id="' + item.policy_id +
'" class="btnOpenEnroll" data-toggle="tooltip" data-placement="left" title="Click To Close Enrolment">Open</a>'
} else if (item.open_for_enrollment == 0) {
enrollmentStatus =
'<a href="#" data-toggle="tooltip" data-placement="top" title="Click To Open Enrolment" data-id="' +
item.id + '" id="' + item.policy_id + '" class="btnOpenEnroll">Closed</a>'
}
}
var tpaValue = 'TPA Unavailable';
if (item.tpa_short && item.tpa_branch_code) {
tpaValue = item.tpa_short + '-' + item.tpa_branch_code;
}
var policy_name_data = `${item.policy_type_name ?? ''}` + ' - ' + `${item.policy_no ?? ''}`;
// console.log("Inside of item "+ JSON.stringify(item,null,2));
let auto_si_menu = '';
let si_mapping = '';
if(item.policy_type_id == 2){
auto_si_menu = `<a href="#" data-id="${item.id}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="showModal('rack_rate_auto_si_modal'); getRackRateSIAmountAndAutoSiDataForAutoSI('${item.id}')"><i class="mdi mdi-autorenew mr-2 text-muted font-18 vertical-middle"></i>Auto SI</a>`;
}
if (item.policy_type_id == 3 && item.base_policy != null && item.base_policy != ''){
console.log('base policy '+ item.base_policy);
si_mapping = `<a href="#" data-id="${item.id}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="showModal('si_mapping'); loadModal('${item.id}','${item.base_policy}');"><i class="mdi mdi-swap-horizontal"></i> SI Mapping</a>`;
}
if(showExpired == false && checkDateStatus(item.policy_end_date) != 'Expired'){
policyTable +=
`
<tr>
<! -- <td>${item.insurer_short} - ${item.insurer_branch_name}</td> -->
<td>${policy_name_data}</td>
<td>${item.branch_name ? item.branch_name : ' - '}</td>
<!-- <td>${tpaValue}</td> -->
<td>${formatDisplayDate(item.policy_start_date)} - ${formatDisplayDate(item.policy_end_date)}</td>
<!-- <td style="text-align: center;">${(enrollmentStatus)}</td> -->
<td>${checkDateStatus(item.policy_end_date, 1)}</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 href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyMaster" data-toggle="modal"><i class="mdi mdi-wrench mr-2 text-muted font-18 vertical-middle"></i>Terms</a>
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyModel" data-toggle="modal" data-target="#bs-example-modal-lg"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Rack Rate</a>
${auto_si_menu}
${si_mapping}`;
// Conditionally render the delete option based on the role
if (role != 3 && role != 4) {
policyTable +=
`
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="removepolicy(this)"><i class="fa fa-trash mr-2 text-muted font-18 vertical-middle"></i>Delete</a>`;
}
policyTable += `
</div>
</div>
</td>
</tr>
`;
}
});
$('#policy_table').append(policyTable);
// console.log(policyTable);
}
$('#table-client-policy').DataTable({
paging: true,
searching: true,
autoWidth: false,
responsive: true,
});
});
$('.btnAdd').click(function() {
fetchClientBranch()
$('#notification_slider').hide();
$('#policy_form')[0].reset();
$('#add_form').show();
$('#table_list').hide();
$('.btnBack').show();
$('.btnAdd').hide();
$('.BtnAddSuccess').hide();
$('#insurer').val('').change();
$('#tpa').val('').change();
$('#policy_no').val('').change();
$('#policy_no').val('').change();
$('#start_date').val('').change();
$('#end_date').val('').change();
$('#close_date').val('').change();
// $('#policy').html('<option value="" selected>Select Policy</option>').change();
$('#policy_form_action').val('<?= base_url("client/policy/create"); ?>');
$('#policy_status_field').hide()
$('#base_policy_id').hide();
$('#policy_PrimaryKey').val("");
$('#insurer_policy_id').val("");
$('#gst_no').val(18);
$('#first').hide();
$('#second').hide();
$('#third').hide();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
})
$('.btnBack').click(function() {
$('#notification_slider').show();
$('#policy_form')[0].reset();
$('#add_form').hide();
$('#table_list').show();
$('.btnBack').hide();
$('.btnAdd').show();
$('.BtnAddSuccess').show();
$('#insurer').val('').change();
$('#tpa').val('').change();
$('#policy_no').val('').change();
$('#start_no').val('').change();
$('#end_date').val('').change();
$('#open_date').val('').change();
$('#close_date').val('').change();
$('#policy').html('<option value="" selected>Select Policy</option>');
$('#base_policy_id').hide();
$('#client_branch').val('').change();
})
/******** for form submit using AJAX *******/
$("#policy_form").submit(function(event) {
event.preventDefault();
$('#notification_slider').show();
policy_PrimaryKey = $('#client_id_policy').val();
policy_client = $('#policy_PrimaryKey').val();
var policyDataId = $('#policy').children('option:selected').attr('data-id');
var basePolicyDataId = $('#base_policy').children('option:selected').attr('data-id');
//console.log('policyDataId', policyDataId);
//console.log('basePolicyDataId', basePolicyDataId);
if (policy_PrimaryKey === '' && policy_client === '') {
toastr.error('Client is required', 'Error');
$('#insurer').val('');
$('#tpa').val('');
$('#policy').html('<option value="" selected>Select Policy</option>');
return;
}
// if (basePolicyDataId == policyDataId) {
// toastr.warning('The policy cannot be the same as the base policy.', 'Warning');
// return;
// }
if (basePolicyDataId == 3 || basePolicyDataId == 2) {
if (policyDataId == 1) {
toastr.warning('The GPA policy cannot be Select.', 'Warning');
return;
}
}
var isValid = $('#policy_form').parsley().validate();
if (!isValid) {
//console.log('Form is Empty', 'Warning');
return;
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var formData = new FormData($('#policy_form')[0]);
formData.set('policy_start_date', toBackendDateFormat($('#start_date').val()));
formData.set('policy_end_date', toBackendDateFormat($('#end_date').val()));
if ($('#open_date').val()) {
formData.set('open_date', toBackendDateFormat($('#open_date').val()));
}
if ($('#close_date').val()) {
formData.set('close_date', toBackendDateFormat($('#close_date').val()));
}
var policy_form_action = $('#policy_form_action').val();
console.log(formData + 'form data');
$.ajax({
data: formData,
url: policy_form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
console.log('client policy response', res);
$('#policy_form')[0].reset();
if (res.status === false) {
toastr.error('Policy Dose Not Create', 'Error');
return;
}
if (res) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$('#add_form').hide();
$('#table_list').show();
$('.btnBack').hide();
$('.btnAdd').show();
$('.BtnAddSuccess').show();
var message = (policy_PrimaryKey === '') ?
'Policy Created successfully' : 'Policy Updated Successfully';
toastr.success(message, 'Success');
}, 1000);
}
$('#policy_table tr').remove();
var policyTable = '';
var role = res.data.role
delete res.data.role;
$.each(res.data, function(index, item) {
// console.log(item);
var patternGMC = /gmc/i; // Case insensitive pattern for 'gmc'
var patternGPA = /gpa/i; // Case insensitive pattern for 'gpa'
var subject = item.policy_type_name;
if (patternGMC.test(subject)) {
search_term = 'GMC';
} else if (patternGPA.test(subject)) {
search_term = 'GPA';
} else {
search_term =
subject; // Set default value if neither 'GMC' nor 'GPA' exists
}
// //console.log('search_term :', search_term)
var enrollmentStatus = '';
if (item.inception_type == 1) {
enrollmentStatus = 'N/A'
} else if (item.inception_type == 2) {
if (item.open_for_enrollment == 1) {
enrollmentStatus =
'<a data-toggle="tooltip" data-placement="top" title="Click To Close Enrolment" href="#" data-id="' +
item.id + '" id="' + item.policy_id +
'" class="btnOpenEnroll">Open</a>'
} else if (item.open_for_enrollment == 0) {
enrollmentStatus =
'<a data-toggle="tooltip" data-placement="top" title="Click To Open Enrolment" href="#" data-id="' +
item.id + '" id="' + item.policy_id +
'" class="btnOpenEnroll">Closed</a>'
}
}
var tpaValue = 'TPA Unavailable';
if (item.tpa_short && item.tpa_branch_code) {
tpaValue = item.tpa_short + '-' + item.tpa_branch_code;
}
var policy_name_data = `${item.policy_type_name ?? ''}` + ' - ' +
`${item.policy_no ?? ''}`;
let auto_si_menu = '';
if(item.policy_type_id == 2){
auto_si_menu = `<a href="#" data-id="${item.id}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="showModal('rack_rate_auto_si_modal'); getRackRateSIAmountAndAutoSiDataForAutoSI('${item.id}')"><i class="mdi mdi-autorenew mr-2 text-muted font-18 vertical-middle"></i>Auto SI</a>`;
}
if(checkDateStatus(item.policy_end_date) != 'Expired'){
policyTable +=
`
<tr>
<!-- <td>${item.insurer_short} - ${item.insurer_branch_name}</td> -->
<td>${policy_name_data}</td>
<td>${item.branch_name ? item.branch_name : ' - '}</td>
<!-- <td>${tpaValue}</td> -->
<td>${formatDisplayDate(item.policy_start_date)} - ${formatDisplayDate(item.policy_end_date)}</td>
<!-- <td style="text-align: center;">${(enrollmentStatus)}</td> -->
<td>${checkDateStatus(item.policy_end_date, 1)}</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 href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyMaster" data-toggle="modal"><i class="mdi mdi-wrench mr-2 text-muted font-18 vertical-middle"></i>Terms</a>
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyModel" data-toggle="modal" data-target="#bs-example-modal-lg"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Rack Rate</a>
${auto_si_menu}`;
// Conditionally render the delete option based on the role
if (role != 3 && role != 4) {
policyTable +=
`
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="removepolicy(this)"><i class="fa fa-trash mr-2 text-muted font-18 vertical-middle"></i>Delete</a>`;
}
policyTable += `
</div>
</div>
</td>
</tr>
`;
}
});
$('#policy_table').append(policyTable);
// console.log(policyTable);
$('#insurer').val('');
$('#tpa').val('');
$('#policy_no').val('');
$('#open_date').val('');
$('#close_date').val('');
$('#policy').html('<option value="" selected>Select Policy</option>');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (xhr.status === 404) {
//console.log('Resource not found', 'Warning');
} else if (xhr.status === 500) {
//console.log('Internal server error', 'Warning');
} else {
//console.log('Unknown error occurred', 'Warning');
}
}, 1000);
},
complete:function(){
$('notification_slider').show();
}
});
});
$(document).ready(function() {
/********* To get the POLICY base on Insurer *******/
$('#insurer').change(function() {
var id = $(this).val();
var client_id = $('#client_id_policy').val()
var parts = id.split('-');
var secondPart = parts[1];
var url = "<?= base_url("util/police-by-insurer/") ?>" + secondPart;
var url_for_cd = "<?= base_url("util/get_cd_ac/") ?>" + client_id + '/' + secondPart;
var selectedOption = $('#base_policy').find(':selected');
var base_policy_data_id = selectedOption.data('id');
$.get(url_for_cd, function(response) {
// console.log(response)
// console.log(response.data)
if (response.status == false && response.insurer_id != 'undefined') {
toastr.warning('The CD Account Number not found.', 'Warning');
return;
}
appendCDACNO(response.data)
}).fail(function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
});
});
});
$(document).ready(function() {
/********* set the Policy_Type_id for Form Submit *******/
$('#policy_type').change(function() {
var policy_type_id = $(this).val();
if (policy_type_id == 1 || policy_type_id == 6 || policy_type_id == 7) {
$('#tpa').prop('required', false);
$('#tpa_danger').hide()
} else {
$('#tpa').prop('required', true);
$('#tpa_danger').show()
}
});
});
// get the client policy data for edit
$('body').on('click', '.btnPolicyEdit', function() {
var policy_form_action = '';
var policy_id = $(this).attr('data-id');
$('#notification_slider').hide();
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
fetchClientBranch()
$.ajax({
url: '<?= base_url("client/policy/list/") ?>' + policy_id,
type: "GET",
dataType: 'json',
success: function(res) {
console.log('client_policy_res', res);
var gst = (res.data.gst == 0.00) ? 18 : res.data.gst;
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1100);
$('#policy_form_action').val('<?= base_url("client/policy/edit"); ?>');
if (res.status === false) {
toastr.error(res.message);
return;
}
$('#add_form').show();
$('#table_list').hide();
$('.btnBack').show();
$('.btnAdd').hide();
$('.BtnAddSuccess').hide();
$('#insurer').val(res.data.insurer_branch_id + '-' + res.data.insurer_id).change();
var tpaValue = '';
if (res.data.tpa_branch_id && res.data.tpa_id) {
tpaValue = res.data.tpa_branch_id + '-' + res.data.tpa_id;
}
$('#tpa').val(tpaValue).change();
$('#policy_type').val(res.data.policy_type_id).change();
$('#base_policy').val(res.data.base_policy);
$('#policy_type_id').val(res.data.policy_type_id);
$('#policy_PrimaryKey').val(res.data.id);
$('#insurer_policy_id').val(res.data.policy_id);
$('#policy_no').val(res.data.policy_no);
$('#start_date').val(rearrangeDateFormat(res.data.policy_start_date));
$('#open_date').val(rearrangeDateFormat(res.data.open_date));
$('#end_date').val(rearrangeDateFormat(res.data.policy_end_date));
$('#close_date').val(rearrangeDateFormat(res.data.close_date));
$('#reminder_date').val(res.data.reminder_date);
$('#disclaimer').val(res.data.disclaimer);
$('#gst_no').val(gst);
$('#policy_status').val(checkDateStatus(res.data.policy_end_date));
$('#policy_status_field').show();
//Open for enrollment yes or no
if (res.data.inception_type == 2) {
$('#inception_type').prop('checked', true);
$('#open_date').parent().show();
$('#close_date').parent().show();
$('#reminder_date').parent().show();
$('.dateofdata').attr('required', true);
} else {
$('#inception_type').prop('checked', false);
$('#open_date').parent().hide();
$('#close_date').parent().hide();
$('#reminder_date').parent().hide();
$('.dateofdata').attr('required', false);
}
//Policy Visibility in Web App
if (res.data.enrolment_visibility == 1) {
$('#policy_visibility').prop('checked', true);
} else {
$('#policy_visibility').prop('checked', false);
}
if (res.data.is_lgbtq == 1) {
$('#is_lgbtq').prop('checked', true);
} else {
$('#is_lgbtq').prop('checked', false);
}
$('#is_premium_summery').val(res.data.is_premium_summery ?? 0).trigger('change');
// Member Modify Data Enable or Disable
// if (res.data.is_member_modify_allowed == 1) {
// $('#is_member_modify_allowed').prop('checked', true);
// } else {
// $('#is_member_modify_allowed').prop('checked', false);
// }
// if (res.data.is_addon != '1' && res.data.is_addon != '0') {
// $('#base_policy_id').show();
// $('#base_policy').prop('required', true);
// $('#first').show();
// $('#second').show();
// $('#third').show();
// } else if (res.data.is_addon == '0') {
// $('#first').hide();
// $('#second').hide();
// $('#third').hide();
// $('#base_policy_id').hide();
// $('#base_policy').prop('required', false);
// } else if (res.data.is_addon == '1') {
// $('#first').show();
// $('#second').show();
// $('#third').show();
// $('#base_policy_id').hide();
// $('#base_policy').prop('required', false);
// }
if (res.data.policy_type_id == '4' || res.data.policy_type_id == '5' || res.data.policy_type_id == '72') {
$('#base_policy_id').show();
$('#base_policy').prop('required', true);
$('#first').show();
$('#second').show();
$('#third').show();
} else if (res.data.policy_type_id == '0') {
$('#first').hide();
$('#second').hide();
$('#third').hide();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
} else if (res.data.policy_type_id == '1' || res.data.policy_type_id == '2' || res.data
.policy_type_id == '6' || res.data.policy_type_id == '7') {
$('#first').show();
$('#second').show();
$('#third').show();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
} else if (res.data.policy_type_id == '3') {
$('#first').show();
$('#second').show();
$('#third').show();
$('#base_policy_id').show();
$('#base_policy').prop('required', false);
$('#base_danger').hide();
}
if (res.data.is_addon == 2 || res.data.is_addon == 3) {
$("#insurer").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-insurer-container').css({
'background-color': '#ebebe0',
});
$("#tpa").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-tpa-container').css({
'background-color': '#ebebe0',
});
} else {
$("#insurer").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-insurer-container').css({
'background-color': 'transparent',
});
$("#tpa").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-tpa-container').css({
'background-color': 'transparent',
});
}
if (res.data.policy_type_id == '1' || res.data.policy_type_id == '6' || res.data
.policy_type_id == '7') {
$('#tpa').prop('required', false);
$('#tpa_danger').hide()
} else {
$('#tpa').prop('required', true);
$('#tpa_danger').show()
}
setTimeout(() => {
$('#client_branch').val(res.data.client_branch_id).select2();
}, 1000);
setTimeout(function() {
appendCDACNO(res.cd_data, res.data
.cd_ac_no) // append and select the current CD Account Number
appendBasePolicyList(res.client_policy_list, res.data.base_policy, res.data
.client_branch_id); // append and select the Base palicy
}, 2000)
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
//console.log('Something Wrong!', 'warning');
}, 1000);
},
complete:function() {
$('#notification_slider').hide();
console.log('complete call');
}
});
});
$('body').on('click', '.btnOpenEnroll', function() {
Swal.fire({
title: "Are you sure?",
text: "Do you want to approve this!",
icon: "info",
showCancelButton: true,
confirmButtonColor: "#3085d6",
confirmButtonText: "Yes",
}).then((result) => {
if (result.isConfirmed) {
var client_policy_id = $(this).attr('data-id');
var policy_id = $(this).attr('id');
var client_id = $('#client_id_policy').val()
if (client_policy_id) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
}
$.ajax({
url: '<?php echo base_url('util/update-policy-status'); ?>',
type: 'GET',
data: {
client_policy_id: client_policy_id,
},
success: function(res) {
console.log('OpenEnrollment response', res);
if (res) {
if (res.open_for_enrollment) {
var json_decode = JSON.parse(res.open_for_enrollment);
var open_for_enrollment = json_decode.open_for_enrollment;
var client_policy_id = json_decode.client_policy_id;
if (open_for_enrollment == 1) {
$('.btnOpenEnroll').each(function(index, element) {
if ($(element).data('id') == client_policy_id) {
$(element).html(
'<a data-toggle="tooltip" data-placement="top" title="Click To Close Enrolment" href="#" data-id="' +
res.client_policy_data.id +
'" id="' + res.client_policy_data
.policy_id +
'" class="btnOpenEnroll">Open</a>');
}
});
} else {
$('.btnOpenEnroll').each(function(index, element) {
if ($(element).data('id') == client_policy_id) {
$(element).html(
'<a data-toggle="tooltip" data-placement="top" title="Click To Open Enrolment" href="#" data-id="' +
res.client_policy_data.id +
'" id="' + res.client_policy_data
.policy_id +
'" class="btnOpenEnroll">Closed</a>'
);
}
});
}
}
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status === true) {
toastr.success(res.message, 'Success');
} else if (res.status === false) {
toastr.warning(res.message, 'Warning');
}
}, 1000);
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (xhr.status === 404) {
//console.log('Resource not found', 'Warning');
} else if (xhr.status === 500) {
//console.log('Internal server error', 'Warning');
} else {
//console.log('Unknown error occurred', 'Warning');
}
}, 1000);
}
});
}
});
});
// Convert stored/API dates to d/m/Y for display and form inputs
function rearrangeDateFormat(inputDate) {
return formatDisplayDate(inputDate);
}
function formatDisplayDate(inputDate) {
if (inputDate === null || inputDate === undefined) {
return '';
}
var value = String(inputDate).trim();
if (value === '' || value === 'null') {
return '';
}
if (/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(value)) {
return value;
}
if (/^\d{4}-\d{2}-\d{2}/.test(value)) {
var ymdParts = value.split('-');
return ymdParts[2] + '/' + ymdParts[1] + '/' + ymdParts[0];
}
if (/^\d{1,2}-\d{1,2}-\d{4}$/.test(value)) {
return value.replace(/-/g, '/');
}
var parsedDate = new Date(value);
if (!isNaN(parsedDate.getTime())) {
var day = String(parsedDate.getDate()).padStart(2, '0');
var month = String(parsedDate.getMonth() + 1).padStart(2, '0');
var year = parsedDate.getFullYear();
return day + '/' + month + '/' + year;
}
return '';
}
function toBackendDateFormat(displayDate) {
if (!displayDate) {
return displayDate;
}
var value = String(displayDate).trim();
if (/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(value)) {
return value.replace(/\//g, '-');
}
return value;
}
function parsePolicyDate(inputDate) {
if (!inputDate) {
return null;
}
var value = String(inputDate).trim();
if (/^\d{4}-\d{2}-\d{2}/.test(value)) {
return new Date(value);
}
var slashParts = value.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
if (slashParts) {
return new Date(slashParts[3], slashParts[2] - 1, slashParts[1]);
}
var hyphenParts = value.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/);
if (hyphenParts) {
return new Date(hyphenParts[3], hyphenParts[2] - 1, hyphenParts[1]);
}
var parsedDate = new Date(value);
return isNaN(parsedDate.getTime()) ? null : parsedDate;
}
function checkDateStatus(inputDate, bg = false) {
var givenDate = parsePolicyDate(inputDate);
var currentDate = new Date();
if (!givenDate) {
return bg ? '' : '';
}
if (bg != false) {
if (givenDate < currentDate) {
return `<span class="badge badge-danger">Expired</span>`;
} else {
return `<span class="badge badge-success">Active</span>`;
}
} else {
if (givenDate < currentDate) {
return `Expired`;
} else {
return `Active`;
}
}
}
const numberWords = {
0: "Zero",
1: "One",
2: "Two",
3: "Three",
4: "Four",
5: "Five",
6: "Six",
7: "Seven",
8: "Eight",
9: "Nine",
10: "Ten",
11: "Eleven",
12: "Twelve",
13: "Thirteen",
14: "Fourteen",
15: "Fifteen",
16: "Sixteen",
17: "Seventeen",
18: "Eighteen",
19: "Nineteen",
20: "Twenty",
30: "Thirty",
40: "Forty",
50: "Fifty",
60: "Sixty",
70: "Seventy",
80: "Eighty",
90: "Ninety"
};
function convertNumberToWords(number) {
if (number === 0) {
return numberWords[number];
}
let word = '';
if (number >= 10000000) {
const crore = Math.floor(number / 10000000);
if (crore > 0) {
word += convertNumberToWords(crore) + " Crore ";
}
number %= 10000000;
}
if (number >= 100000) {
const lakh = Math.floor(number / 100000);
if (lakh > 0) {
word += convertNumberToWords(lakh) + " Lakh ";
}
number %= 100000;
}
if (number >= 1000) {
const thousand = Math.floor(number / 1000);
if (thousand > 0) {
word += convertNumberToWords(thousand) + " Thousand ";
}
number %= 1000;
}
if (number >= 100) {
const hundred = Math.floor(number / 100);
if (hundred > 0) {
word += convertNumberToWords(hundred) + " Hundred ";
}
number %= 100;
}
if (number > 0) {
if (word !== '') {
word += "and ";
}
if (number <= 20) {
word += numberWords[number];
} else {
word += numberWords[Math.floor(number / 10) * 10] + " " + numberWords[number % 10];
}
}
return word.trim();
}
function convertCommaNumberToWords(input) {
let number;
// console.log( 'input type step 1', typeof input);
if (input instanceof HTMLElement && input.value) {
// Ensure input.value is defined and not null
const inputValue = input.value;
number = parseFloat(inputValue.replace(/,/g, ''), 10);
} else if (input) {
// console.log( 'input type step 2', typeof input);
// Handle the case where input is a string
// number = parseFloat(input.replace(/,/g, ''), 10);
number = parseFloat(String(input).replace(/,/g, ''), 10);
} else {
// Handle the case where input is undefined or null
number = NaN; // or handle as needed
}
const [integerPart, decimalPart] = number.toFixed(2).split('.');
const integerWord = convertNumberToWords(parseInt(integerPart, 10));
let result = `${integerWord}`;
////console.log('decimalPart',decimalPart)
//console.log('decimalPart',typeof decimalPart)
if (decimalPart != '00' && decimalPart != undefined) {
result += ` and `;
let decimalWord = convertNumberToWords(parseInt(decimalPart, 10))
result += `${decimalWord}`
result += ` Paisa`;
}
return result.trim();
}
function onlyNumbers(event) {
var charcode;
charcode = event.which || event.keyCode;
if (charcode >= 48 && charcode <= 57 || charcode == 46) return true;
return false;
}
function formatNumber(input, maxLength) {
//console.log("input", input);
//console.log("input value", input.value);
maxLength = 16;
let value = input.value.replace(/[^\d.]/g, ''); // Remove non-numeric characters
//console.log('Remove non-numeric characters', value)
// Limit the number of digits
value = value.slice(0, maxLength);
//console.log('Limited value', value);
// Format the number with commas using Indian numbering system
value = parseFloat(value).toLocaleString("en-IN", {
maximumFractionDigits: 2
});
// console.log('formatNumber function formetted value', value);
// console.log('formatNumber function formetted value type',typeof value);
if (value == 'NaN' || value == 'null' || value == 'undefined') {
value = '';
}
input.value = (value);
basicPayMultiple(input)
if (input.id == 'gpa_si') {
gpaSumInsureMultiplier();
}
convertCommaNumberToWords(input);
if (input.id == 'gpa_sum_si') {
gpaSumInsureMultiplier(input);
}
if (input.id == 'gpa_sum_si2') {
gpaSumInsureMultiplier(input);
}
// if(input.id == 'basic_pay'){
// var inputNumber = input.value;
// if (inputNumber) {
// var result = convertCommaNumberToWords(inputNumber);
// $("#gpa_basic_pay_number_word").text(result);
// } else {
// $("#gpa_basic_pay_number_word").text("");
// }
// }else if(input.id == 'basic_gpa_si'){
// var inputNumber = input.value;
// if (inputNumber) {
// var result = convertCommaNumberToWords(inputNumber);
// $("#basic_gpa_si_number_word").text(result);
// } else {
// $("#basic_gpa_si_number_word").text("");
// }
// }else if(input.id == 'basic_gpa_premium'){
// var inputNumber = input.value;
// if (inputNumber) {
// var result = convertCommaNumberToWords(inputNumber);
// $("#basic_gpa_premium_number_word").text(result);
// } else {
// $("#basic_gpa_premium_number_word").text("");
// }
// }else if(input.id == 'gpa_si'){
// var inputNumber = input.value;
// if (inputNumber) {
// var result = convertCommaNumberToWords(inputNumber);
// $("#gpa_sum_si_number_word").text(result);
// } else {
// $("#gpa_sum_si_number_word").text("");
// }
// }else if(input.id == 'gpa_premium'){
// var inputNumber = input.value;
// if (inputNumber) {
// var result = convertCommaNumberToWords(inputNumber);
// $("#gpa_sum_premium_number_word").text(result);
// } else {
// $("#gpa_sum_premium_number_word").text("");
// }
// }
return;
// }
}
$('#policy_type').change(function() {
$('#insurer').val('').change();
$('#tpa').val('').change();
$('#policy_no').val('');
$('#open_date').val('');
$('#close_date').val('');
$('#reminder_date').val('');
$('#base_policy').val('').change();
var client_id = $('#client_id_policy').val();
var client_branch_id = $('#client_branch').val();
var url_for_get_policy_type_list = '<?php echo base_url('util/get_policy_type_for_base_policy/') ?>' +
client_id + '/' + client_branch_id;
$.get(url_for_get_policy_type_list, function(response) {
console.log(response)
// console.log(response.data)
appendBasePolicyList(response.data);
}).fail(function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
});
if ($(this).val() == 4 || $(this).val() == 5 || $(this).val() == 72) {
$("#insurer").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-insurer-container').css({
'background-color': '#ebebe0',
});
$("#tpa").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-tpa-container').css({
'background-color': '#ebebe0',
});
var baseDanger = $('#base_danger');
if (baseDanger.css('display') === 'none') {
baseDanger.show();
}
} else {
$("#insurer").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-insurer-container').css({
'background-color': 'transparent',
});
$("#tpa").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-tpa-container').css({
'background-color': 'transparent',
});
}
if ($(this).val() == 5) {
toastr.warning('Please Change the Policy Terms after Submit the Policy!', 'Info');
}
if ($(this).val() == '4' || $(this).val() == '5' || $(this).val() == '72') {
$('#base_policy_id').show();
$('#base_policy').prop('required', true);
$('#first').show();
$('#second').show();
$('#third').show();
$('#base_danger').show();
} else if ($(this).val() == '0') {
$('#first').hide();
$('#second').hide();
$('#third').hide();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
$('#base_danger').show();
} else if ($(this).val() == '1' || $(this).val() == '2' || $(this).val() == '6' || $(this).val() == '7') {
$('#first').show();
$('#second').show();
$('#third').show();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
$('#base_danger').show();
} else if ($(this).val() == '3') {
$('#first').show();
$('#second').show();
$('#third').show();
$('#base_policy_id').show();
$('#base_policy').prop('required', false);
$('#base_danger').hide();
}
if ($('#inception_type').prop('checked')) {
} else {
$('#open_date').parent().hide();
$('#close_date').parent().hide();
$('#reminder_date').parent().hide();
}
})
// featch client policy to list in the Base policy Dropdown list
function fetchClientPolicyList() {
var client_id = $('#client_id_policy').val()
var client_branch_id = $('#client_branch').val()
//console.log('client_branch_id', client_branch_id)
$.ajax({
url: '<?= base_url("util/featch-client-policy-list/") ?>' + client_id,
type: "GET",
dataType: 'json',
success: function(res) {
//console.log('Base policy Dropdown list', res)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status === false) {
toastr.error(res.status);
return;
}
var OptionsHTML = '';
OptionsHTML += '<option value="" selected>Select Base Policy</option>';
$.each(res.data, function(index, item) {
// //console.log('item.client_branch_id', item.client_branch_id)
if (item.client_branch_id == client_branch_id) {
if ($('#policy_type').val() == 1) {
if (item.policy_type_id == 1 || item.policy_type_id == 2) {
// //console.log('if 2')
OptionsHTML += '<option data-id="' + item.policy_type_id + '" value="' +
item.id +
'">' + item.name + '( ' + item.policy_type + ' )</option>';
}
} else {
OptionsHTML += '<option data-id="' + item.policy_type_id + '" value="' +
item
.id +
'">' + item.name + '( ' + item.policy_type + ' )</option>';
}
}
});
$('#base_policy').html(OptionsHTML);
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
//console.log('Something Wrong!', 'warning');
}, 1000);
}
});
}
var dataId = 0;
$(document).ready(function() {
$('#base_policy').change(function() {
var client_policy_id = $(this).val() ? $(this).val() : 0;
var policy_type = $('#policy_type').val()
console.log('client_policy_id', client_policy_id);
base_policy_data_id = $(this).children('option:selected').attr('data-id');
console.log('base_policy_data_id', base_policy_data_id);
var uri = '<?= base_url('client/policy/list/') ?>' + client_policy_id
// console.log('uri', uri)
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: uri,
type: "GET",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
console.log('base policy ajax response', res)
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 500);
if (res.status == true) {
$('#insurer').val(res.data.insurer_branch_id + '-' + res.data
.insurer_id).change();
$('#tpa').val(res.data.tpa_branch_id + '-' + res.data.tpa_id).change();
$('#policy_no').val(res.data.policy_no).change();
// $('#open_date').val(rearrangeDateFormat(res.data.open_date)).change();
// $('#close_date').val(rearrangeDateFormat(res.data.close_date)).change();
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 500);
}
});
});
})
// fetch the client branch list for the dropdown
function fetchClientBranch() {
//console.log('function called');
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var client_id = 0;
if ($('#client_id_policy').val() != "") {
client_id = $('#client_id_policy').val();
} else if ($('#policy_PrimaryKey').val() != "") {
client_id = $('#policy_PrimaryKey').val();
}
$.ajax({
url: "<?= base_url('util/get-client-branch/') ?>" + client_id,
type: "GET",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
//console.log(res);
// //console.log(res.data.length);
if (res.data.length == 0) {
toastr.warning('The client does not have any branches.', 'Warning');
return;
}
appendClientBranch(res.data)
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}
});
}
//append the client branch list for the dropdown
function appendClientBranch(data) {
$('#client_branch').empty();
$('#client_branch').append($('<option>', {
value: '',
text: 'Select Branch',
selected: true
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.branch_name
});
$('#client_branch').append(option);
});
}
//append the CD Account number for the dropdown
function appendCDACNO(data, select = null) {
//console.log('appendCDACNO', data);
//console.log('appendCDACNO', select);
$('#cd_ac_no').empty();
$('#cd_ac_no').append($('<option>', {
value: '',
text: 'Select CD Account Number'
}));
$.each(data, function(index, item) {
const option = $('<option>', {
value: item.id,
text: item.cd_ac_no
});
if (select === item.cd_ac_no) {
//console.log('selected');
option.attr('selected', true);
}
$('#cd_ac_no').append(option);
});
}
// append Base Policy to the dropdown for edit only
function appendBasePolicyList(data, select = null) {
// console.log('appendBasePolicyList', 'function called');
// console.log('appendBasePolicyList data', data);
// console.log('appendBasePolicyList selected value', select);
$('#base_policy').empty();
$('#base_policy').append($('<option>', {
value: '',
text: 'Select Base Policy'
}));
$.each(data, function(index, item) {
const option = $('<option>', {
value: item.client_policy_id,
text: `${item.policy_type ?? ''} - ${item.policy_no ?? ''}`,
'data-id': item.id
});
if (select === item.client_policy_id) {
option.attr('selected', true);
}
$('#base_policy').append(option);
});
}
function removepolicy(element) {
Swal.fire({
title: "Are you sure?",
text: "Do you want to remove this Policy.",
icon: "info",
showCancelButton: true,
confirmButtonColor: "#3085d6",
confirmButtonText: "Yes",
}).then((result) => {
if (result.isConfirmed) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var id = element.getAttribute('data-id');
// console.log(id)
var form_action = '<?= base_url("client/policy/remove/") ?>' + id;
// console.log(form_action)
$.ajax({
url: form_action,
type: "GET",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log('removepolicy function response', res)
if (res) {
if (res.status == true) {
toastr.success('Policy removed successfully.', 'Success');
location.reload();
} else {
Swal.fire({
title: "Warning!",
text: res.message,
icon: "warning"
});
// toastr.warning('Failed to remove policy', 'Warning');
}
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log('Something Wrong!', 'warning');
}
});
}
});
}
$('#policy_no').change(function() {
var policy_no = $(this).val();
console.log(policy_no + '-' + policy_no.length);
policy_no = policy_no.trim();
console.log(policy_no + '-' + policy_no.length);
$.ajax({
url: '<?php echo base_url('util/check_policy_no/');?>' + policy_no,
type: "GET",
dataType: 'json',
success: function(res) {
console.log(res)
if (res.status == true) {
toastr.warning(res.message, 'Warning');
$('#policy_no').val('');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
})
$(document).ready(function() {
// Check if the URL contains a hash
const hash = window.location.hash;
// If hash is '#police-tab', trigger a click on the tab
if (hash === '#police-tab') {
$(`a[href="${hash}"]`).click();
// Get the `client_policy_id` from the URL
const urlParams = new URLSearchParams(window.location.search);
const clientPolicyId = urlParams.get('client_policy_id');
if (clientPolicyId) {
// Call your function with the `client_policy_id`
setTimeout(function() {
getClientPolicyDataForEdit(clientPolicyId);
}, 3000);
}
}
});
function getClientPolicyDataForEdit(client_policy_id) {
var policy_form_action = '';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
fetchClientBranch()
$.ajax({
url: '<?= base_url("client/policy/list/") ?>' + client_policy_id,
type: "GET",
dataType: 'json',
success: function(res) {
console.log('client_policy_res', res);
var gst = (res.data.gst == 0.00) ? 18 : res.data.gst;
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1100);
$('#policy_form_action').val('<?= base_url("client/policy/edit"); ?>');
if (res.status === false) {
toastr.error(res.message);
return;
}
$('#add_form').show();
$('#table_list').hide();
$('.btnBack').show();
$('.btnAdd').hide();
$('.BtnAddSuccess').hide();
$('#insurer').val(res.data.insurer_branch_id + '-' + res.data.insurer_id).change();
var tpaValue = '';
if (res.data.tpa_branch_id && res.data.tpa_id) {
tpaValue = res.data.tpa_branch_id + '-' + res.data.tpa_id;
}
$('#tpa').val(tpaValue).change();
$('#policy_type').val(res.data.policy_type_id).change();
$('#base_policy').val(res.data.base_policy);
$('#policy_type_id').val(res.data.policy_type_id);
$('#policy_PrimaryKey').val(res.data.id);
$('#insurer_policy_id').val(res.data.policy_id);
$('#policy_no').val(res.data.policy_no);
$('#start_date').val(rearrangeDateFormat(res.data.policy_start_date));
$('#open_date').val(rearrangeDateFormat(res.data.open_date));
$('#end_date').val(rearrangeDateFormat(res.data.policy_end_date));
$('#close_date').val(rearrangeDateFormat(res.data.close_date));
$('#reminder_date').val(res.data.reminder_date);
$('#disclaimer').val(res.data.disclaimer);
$('#gst_no').val(gst);
$('#policy_status').val(checkDateStatus(res.data.policy_end_date));
$('#policy_status_field').show();
if (res.data.inception_type == 2) {
$('#inception_type').prop('checked', true);
$('#open_date').parent().show();
$('#close_date').parent().show();
$('#reminder_date').parent().show();
$('.dateofdata').attr('required', true);
} else {
$('#inception_type').prop('checked', false);
$('#open_date').parent().hide();
$('#close_date').parent().hide();
$('#reminder_date').parent().hide();
$('.dateofdata').attr('required', false);
}
if (res.data.enrolment_visibility == 1) {
$('#policy_visibility').prop('checked', true);
} else {
$('#policy_visibility').prop('checked', false);
}
if (res.data.is_lgbtq == 1) {
$('#is_lgbtq').prop('checked', true);
} else {
$('#is_lgbtq').prop('checked', false);
}
$('#is_premium_summery').val(res.data.is_premium_summery ?? 0).trigger('change');
if (res.data.policy_type_id == '4' || res.data.policy_type_id == '5' || res.data.policy_type_id == '72') {
$('#base_policy_id').show();
$('#base_policy').prop('required', true);
$('#first').show();
$('#second').show();
$('#third').show();
} else if (res.data.policy_type_id == '0') {
$('#first').hide();
$('#second').hide();
$('#third').hide();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
} else if (res.data.policy_type_id == '1' || res.data.policy_type_id == '2' || res.data
.policy_type_id == '6' || res.data.policy_type_id == '7') {
$('#first').show();
$('#second').show();
$('#third').show();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
} else if (res.data.policy_type_id == '3') {
$('#first').show();
$('#second').show();
$('#third').show();
$('#base_policy_id').show();
$('#base_policy').prop('required', false);
$('#base_danger').hide();
}
if (res.data.is_addon == 2 || res.data.is_addon == 3) {
$("#insurer").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-insurer-container').css({
'background-color': '#ebebe0',
});
$("#tpa").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-tpa-container').css({
'background-color': '#ebebe0',
});
} else {
$("#insurer").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-insurer-container').css({
'background-color': 'transparent',
});
$("#tpa").next(".select2-container").css({
'pointer-events': 'auto',
});
$('#select2-tpa-container').css({
'background-color': 'transparent',
});
}
if (res.data.policy_type_id == '1' || res.data.policy_type_id == '6' || res.data
.policy_type_id == '7') {
$('#tpa').prop('required', false);
$('#tpa_danger').hide()
} else {
$('#tpa').prop('required', true);
$('#tpa_danger').show()
}
setTimeout(() => {
$('#client_branch').val(res.data.client_branch_id).select2();
}, 1000);
setTimeout(function() {
appendCDACNO(res.cd_data, res.data
.cd_ac_no) // append and select the current CD Account Number
appendBasePolicyList(res.client_policy_list, res.data.base_policy, res.data
.client_branch_id); // append and select the Base palicy
}, 2000)
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
//console.log('Something Wrong!', 'warning');
}, 1000);
}
});
}
function showModal($opener) {
console.log('showModal triggered with opener:', $opener);
if($opener == 'lead_modal'){
var myModal = new bootstrap.Modal(document.getElementById('lead_modal'));
myModal.show();
}else if($opener == 'rack_rate_auto_si_modal'){
}
else if ($opener == 'si_mapping') {
var si_mapping_modal = new bootstrap.Modal(document.getElementById('si_mapping'));
si_mapping_modal.show();
}
}
function featchClient() {
let lead_id = $('#lead_id').val();
let client_id = $('#lead_id option:selected').data('clientid');
let branch_id = $('#lead_id option:selected').data('branchid');
console.log('lead_id : ', lead_id)
let url = '<?= base_url('leads/featchClientPolicyFromLead/') ?>' + client_id + '/' + branch_id + '/' + lead_id
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: url,
type: "GET",
dataType: 'json',
success: function(res) {
console.log(res);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status == true) {
let client_url = '<?= base_url('client/list/') ?>' + res.client_id + '?client_policy_id=' +
res.client_policy_id + '#police-tab';
toastr.success(res.message, 'Success')
window.location.href = client_url;
} else {
toastr.warning(res.message, 'Warning');
}
$('.close').click()
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$('.close').click()
}
});
}
//----------------------------------------------------------------------------------------------------
</script>
<script>
$(document).ready(function () {
$('#chk-show-expired').on('change', function () {
const showExpired = $(this).is(':checked');
let policyTable = '';
let data = <?= isset($client_policy) ? json_encode($client_policy) : '[]' ?>;
let role = data.role
delete data.role;
console.log("checkbox working");
$.each(data, function(index, item) {
// console.log('step 1');
var patternGMC = /gmc/i; // Case insensitive pattern for 'gmc'
var patternGPA = /gpa/i; // Case insensitive pattern for 'gpa'
var subject = item.policy_type_name;
//console.log('search terms subject', subject);
if (patternGMC.test(subject)) {
search_term = 'GMC';
} else if (patternGPA.test(subject)) {
search_term = 'GPA';
} else {
search_term = subject; // Set default value if neither 'GMC' nor 'GPA' exists
}
//console.log('search_term :', search_term)
var enrollmentStatus = '';
if (item.inception_type == 1) {
enrollmentStatus = 'N/A'
} else if (item.inception_type == 2) {
if (item.open_for_enrollment == 1) {
enrollmentStatus = '<a href="#" data-id="' + item.id + '" id="' + item.policy_id +
'" class="btnOpenEnroll" data-toggle="tooltip" data-placement="left" title="Click To Close Enrolment">Open</a>'
} else if (item.open_for_enrollment == 0) {
enrollmentStatus =
'<a href="#" data-toggle="tooltip" data-placement="top" title="Click To Open Enrolment" data-id="' +
item.id + '" id="' + item.policy_id + '" class="btnOpenEnroll">Closed</a>'
}
}
var tpaValue = 'TPA Unavailable';
if (item.tpa_short && item.tpa_branch_code) {
tpaValue = item.tpa_short + '-' + item.tpa_branch_code;
}
var policy_name_data = `${item.policy_type_name ?? ''}` + ' - ' + `${item.policy_no ?? ''}`;
// console.log("Inside of item "+ JSON.stringify(item,null,2));
let auto_si_menu = '';
let si_mapping = '';
if(item.policy_type_id == 2){
auto_si_menu = `<a href="#" data-id="${item.id}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="showModal('rack_rate_auto_si_modal'); getRackRateSIAmountAndAutoSiDataForAutoSI('${item.id}')"><i class="mdi mdi-autorenew mr-2 text-muted font-18 vertical-middle"></i>Auto SI</a>`;
}
if (item.policy_type_id == 3 && item.base_policy != null && item.base_policy != ''){
console.log('base policy '+ item.base_policy);
si_mapping = `<a href="#" data-id="${item.id}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="showModal('si_mapping'); loadModal('${item.id}','${item.base_policy}');"><i class="mdi mdi-swap-horizontal"></i> SI Mapping</a>`;
}
if(showExpired == true && checkDateStatus(item.policy_end_date) == 'Expired'){
policyTable +=
`
<tr>
<! -- <td>${item.insurer_short} - ${item.insurer_branch_name}</td> -->
<td>${policy_name_data}</td>
<td>${item.branch_name ? item.branch_name : ' - '}</td>
<! -- <td>${tpaValue}</td> -->
<td>${formatDisplayDate(item.policy_start_date)} - ${formatDisplayDate(item.policy_end_date)}</td>
<!-- <td style="text-align: center;">${(enrollmentStatus)}</td> -->
<td>${checkDateStatus(item.policy_end_date, 1)}</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 href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyMaster" data-toggle="modal"><i class="mdi mdi-wrench mr-2 text-muted font-18 vertical-middle"></i>Terms</a>
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyModel" data-toggle="modal" data-target="#bs-example-modal-lg"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Rack Rate</a>
${auto_si_menu}
${si_mapping}`;
// Conditionally render the delete option based on the role
if (role != 3 && role != 4) {
policyTable +=
`
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="removepolicy(this)"><i class="fa fa-trash mr-2 text-muted font-18 vertical-middle"></i>Delete</a>`;
}
policyTable += `
</div>
</div>
</td>
</tr>
`;
}
if(showExpired == false && checkDateStatus(item.policy_end_date) != 'Expired'){
policyTable +=
`
<tr>
<! -- <td>${item.insurer_short} - ${item.insurer_branch_name}</td> -->
<td>${policy_name_data}</td>
<td>${item.branch_name ? item.branch_name : ' - '}</td>
<! -- <td>${tpaValue}</td> -->
<td>${formatDisplayDate(item.policy_start_date)} - ${formatDisplayDate(item.policy_end_date)}</td>
<! -- <td style="text-align: center;">${(enrollmentStatus)}</td> -->
<td>${checkDateStatus(item.policy_end_date, 1)}</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 href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyMaster" data-toggle="modal"><i class="mdi mdi-wrench mr-2 text-muted font-18 vertical-middle"></i>Terms</a>
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyModel" data-toggle="modal" data-target="#bs-example-modal-lg"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Rack Rate</a>
${auto_si_menu}
${si_mapping}`;
// Conditionally render the delete option based on the role
if (role != 3 && role != 4) {
policyTable +=
`
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="removepolicy(this)"><i class="fa fa-trash mr-2 text-muted font-18 vertical-middle"></i>Delete</a>`;
}
policyTable += `
</div>
</div>
</td>
</tr>
`;
}
});
const table = $('#table-client-policy').DataTable();
table.clear().destroy();
$('#table-client-policy tbody').html(policyTable); // replace tbody content
$('#table-client-policy').DataTable({
paging: true,
searching: true,
autoWidth: false,
responsive: true,
});
});
});
</script>