2809 lines
110 KiB
PHP
Executable File
2809 lines
110 KiB
PHP
Executable File
<style>
|
||
|
||
.save-indicator {
|
||
position: absolute;
|
||
top: 10px;
|
||
right: 10px;
|
||
background: #28a745;
|
||
color: white;
|
||
padding: 2px 8px;
|
||
border-radius: 10px;
|
||
font-size: 11px;
|
||
opacity: 0;
|
||
transition: opacity 0.3s;
|
||
}
|
||
|
||
.save-indicator.show {
|
||
opacity: 1;
|
||
}
|
||
|
||
#lead_modal .modal-dialog{
|
||
width:600px !important;
|
||
}
|
||
|
||
#lead_modal .modal-body{
|
||
min-height: 200px !important;
|
||
}
|
||
|
||
</style>
|
||
|
||
<style>
|
||
.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;
|
||
}
|
||
|
||
.switch-label input {
|
||
opacity: 0;
|
||
width: 0;
|
||
height: 0;
|
||
}
|
||
|
||
.slider,
|
||
.slider_blue {
|
||
position: relative;
|
||
width: 50px;
|
||
height: 25px;
|
||
background-color: #cccccc;
|
||
border-radius: 25px;
|
||
box-shadow: 0 0 5px rgba(0,0,0,0.2);
|
||
transition: 0.3s;
|
||
}
|
||
|
||
/* Round knob (always white) */
|
||
.slider::before,
|
||
.slider_blue::before {
|
||
content: "";
|
||
position: absolute;
|
||
height: 19px;
|
||
width: 19px;
|
||
left: 3px;
|
||
top: 3px;
|
||
background-color: #fff; /* always white */
|
||
border-radius: 50%;
|
||
transition: 0.3s;
|
||
}
|
||
|
||
input:checked + .slider {
|
||
background-color: #ff4d4d; /* red when ON */
|
||
}
|
||
|
||
input:checked + .slider_blue {
|
||
background-color: #268ef5ff; /* blue when ON */
|
||
}
|
||
|
||
input:checked + .slider::before ,
|
||
input:checked + .slider_blue::before {
|
||
transform: translateX(25px);
|
||
background-color: #fff;
|
||
}
|
||
|
||
.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>
|
||
|
||
<div class="save-indicator" id="saveIndicator">Saved</div>
|
||
<div class="tab-pane fade" id="police-tab">
|
||
|
||
<div class="row" style="padding-bottom: 10px; position: relative;right: 13px; justify-content: end;">
|
||
<button type="button" id="BtnAdd" class="btn btn-primary waves-effect waves-light btnAdd btn-sm" style="position: relative;right: 10px;"><span class="mdi mdi-plus-box-outline" 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="mdi mdi-plus-box-outline" aria-hidden="true" style="padding: 5px 10px;"></span>Add Policy From Opportunities</button>
|
||
</div>
|
||
|
||
<br>
|
||
|
||
<div class="" style="padding-bottom: 10px; position: absolute;
|
||
right: 0;">
|
||
<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 data-custom-table-css="table" class="table table-borderless table mb-0" id="table-client-policy">
|
||
<thead class="">
|
||
<tr style="color:black !important;">
|
||
<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="mdi mdi-format-list-bulleted" 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>
|
||
|
||
<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" onchange="setInsuerAndBranchValue(this)" required>
|
||
<option value="">Select Insurer</option>
|
||
<?php foreach ($insurer as $value) { ?>
|
||
<option data-id="<?= $value['insurer_id']?>" 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" oninput="checkPolicyNo(this)" 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 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>
|
||
<option value="add_cd">+ Add New CD</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="gst_no">GST ( % )<span 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 for="wellness_plan_id">Wellness Plan ID<span class="text-danger"></span></label>
|
||
<input type="text" class="form-control" id="wellness_plan_id" name="wellness_plan_id">
|
||
</div>
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="wellness_vendor_id">Wellness Vendor ID<span class="text-danger"></span></label>
|
||
<select class="form-control" id="wellness_vendor_id" name="wellness_vendor_id">
|
||
<option value="0">Visit</option>
|
||
<?php if(isset($tpa_list)) : ?>
|
||
<?php foreach ($tpa_list as $value) { ?>
|
||
<option value="<?= $value['id'] ?>">
|
||
<?= $value['short_name'] ?></option>
|
||
<?php } ?>
|
||
<?php endif; ?>
|
||
</select>
|
||
</div>
|
||
|
||
<!-- <div class="form-group col-md-4 EB">
|
||
<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">
|
||
<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 class="form-group col-md-12 EB">
|
||
<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-12 EB mt-3 ">
|
||
<label class="switch-label">
|
||
<input id="policy_visibility" type="checkbox" name="enrolment_visibility" checked>
|
||
<span class="slider_blue"></span>
|
||
<span class="switch-text">Policy Visibilty in Employee App</span>
|
||
</label>
|
||
|
||
<label class="switch-label" >
|
||
<input id="is_lgbtq" type="checkbox" name="is_lgbtq">
|
||
<span class="slider_blue"></span>
|
||
<span class="switch-text">Is LGBTQ Enable</span>
|
||
</label>
|
||
</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('cd_master_add_modal.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 modal-lg">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">Opportunity 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"> Opportunity List <span class="text-danger">*</span></label>
|
||
<select class="form-control" id="lead_id" name="lead_id" required>
|
||
<option value="">Select Opportunity</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();
|
||
var submitInterval = null;
|
||
|
||
|
||
$(document).ready(function() {
|
||
// Initialize select2
|
||
$("#insurer").select2();
|
||
$("#policy").select2();
|
||
$("#tpa").select2();
|
||
$("#base_policy").select2();
|
||
$("#client_branch").select2();
|
||
$("#wellness_vendor_id").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 ?? ''}`;
|
||
|
||
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>${(item.policy_start_date)} / ${(item.policy_end_date)}</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}" data-cdamt="${item.lead_cd_amount}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>`;
|
||
|
||
var isNonEb = (item.allocg === 'Non-EB' || item.allocg === 'Marine');
|
||
|
||
if (!isNonEb) {
|
||
policyTable += `
|
||
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyMaster" ><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>`;
|
||
} else {
|
||
policyTable += `
|
||
<a href="#" data-misc='${item.lead_misc || ""}' class="dropdown-item btnNonEbTerms"><i class="mdi mdi-file-document-outline mr-2 text-muted font-18 vertical-middle"></i>Non EB Terms</a>
|
||
<a href="#" data-id="${item.id}" class="dropdown-item btnNonEbRackRateModal"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Non EB Rack Rate</a>`;
|
||
}
|
||
|
||
// 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="mdi mdi-delete 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,
|
||
language: {
|
||
search: `
|
||
<div class="datatable-search-wrapper" style="position:relative; display:inline-block; width:100%;">
|
||
_INPUT_
|
||
<i class="mdi mdi-magnify datatable-search-icon"
|
||
style="position:absolute; right:122px !important; top:50%; transform:translateY(-50%); color:#666;"></i>
|
||
|
||
<i class="mdi mdi-close-circle datatable-clear-icon"
|
||
style="position:absolute; right:122px !important; top:50%; transform:translateY(-50%); color:#666; display:none; cursor:pointer;"></i>
|
||
</div>
|
||
`,
|
||
searchPlaceholder: "Search",
|
||
emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||
},
|
||
|
||
});
|
||
|
||
|
||
|
||
});
|
||
|
||
$('.btnAdd').click(function() {
|
||
|
||
fetchClientBranch()
|
||
|
||
$('#policy_form')[0].reset();
|
||
$('#add_form').show();
|
||
// console.log("Policy Form Added")
|
||
$('#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() {
|
||
|
||
$('#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();
|
||
|
||
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]);
|
||
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');
|
||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||
}, 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 ?? ''}`;
|
||
|
||
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>${(item.policy_start_date)} / ${(item.policy_end_date)}</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}" data-cdamt="${item.lead_cd_amount}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>`;
|
||
|
||
var isNonEb = (item.allocg === 'Non-EB' || item.allocg === 'Marine');
|
||
|
||
if (!isNonEb) {
|
||
policyTable += `
|
||
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyMaster" ><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>`;
|
||
} else {
|
||
policyTable += `
|
||
<a href="#" data-misc='${item.lead_misc || ""}' class="dropdown-item btnNonEbTerms"><i class="mdi mdi-file-document-outline mr-2 text-muted font-18 vertical-middle"></i>Non EB Terms</a>
|
||
<a href="#" data-id="${item.id}" class="dropdown-item btnNonEbRackRateModal"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Non EB Rack Rate</a>`;
|
||
}
|
||
|
||
// 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="mdi mdi-delete-outline 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>');
|
||
|
||
const urlParams = new URLSearchParams(window.location.search);
|
||
const clientPolicyId = urlParams.get('client_policy_id');
|
||
if (clientPolicyId) {
|
||
let client_url = '<?= base_url('client/list/') ?>' + res.client_id ;
|
||
window.location.href = client_url
|
||
}
|
||
},
|
||
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 === 400) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
let errorMessages = "";
|
||
let seenMessages = []; // Array to store unique messages
|
||
if (response.errors) {
|
||
$.each(response.errors, function (field, message) {
|
||
if (!seenMessages.includes(message)) {
|
||
errorMessages += `• ${message}<br>`;
|
||
seenMessages.push(message); // Mark this message as "seen"
|
||
}
|
||
});
|
||
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
||
} else {
|
||
toastr.warning(response.message || 'Validation failed', 'Warning');
|
||
}
|
||
} else if (xhr.status === 403) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
toastr.error(response.message, 'Security Policy');
|
||
} else if (xhr.status === 500) {
|
||
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
||
} else {
|
||
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
||
}
|
||
// else 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(){
|
||
$('#opening_bal').val("")
|
||
console.log('AJAX request completed');
|
||
}
|
||
});
|
||
|
||
});
|
||
|
||
$(document).ready(function() {
|
||
/********* To get the POLICY base on Insurer *******/
|
||
$('#insurer').change(function() {
|
||
|
||
var id = $(this).val();
|
||
var insurer_id = $(this).find('option:selected').data('id');
|
||
console.log('insurer_id', insurer_id)
|
||
console.log('insurer and branch ids', id)
|
||
var client_id = $('#client_id_policy').val()
|
||
var parts = id.split('-');
|
||
|
||
var firstPart = parts[0];
|
||
var secondPart = parts[1];
|
||
|
||
console.log('firstPart', firstPart);
|
||
console.log('secondPart', secondPart);
|
||
|
||
var url = "<?= base_url("util/police-by-insurer/") ?>" + secondPart;
|
||
var url_for_cd = "<?= base_url("util/get_cd_ac/") ?>" + client_id + '/' + secondPart + '/' + firstPart;
|
||
|
||
var selectedOption = $('#base_policy').find(':selected');
|
||
var base_policy_data_id = selectedOption.data('id');
|
||
|
||
if(secondPart && firstPart){
|
||
$.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');
|
||
|
||
$('#cd_ac_no').empty();
|
||
$('#cd_ac_no').append($('<option>', {
|
||
value: '',
|
||
text: 'Select CD Account Number'
|
||
}));
|
||
$('#cd_ac_no').append($('<option>', {
|
||
value: 'add_cd',
|
||
text: '+ Add New CD'
|
||
}));
|
||
|
||
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() {
|
||
// alert('policy_type change');
|
||
|
||
var policy_type_id = $(this).val();
|
||
// alert(policy_type_id);
|
||
|
||
if (policy_type_id == 1 || policy_type_id == 6 || policy_type_id == 7 || policy_type_id > 10) {
|
||
$('#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');
|
||
var opening_bal = $(this).attr('data-cdamt') ?? "";
|
||
console.log('opening_bal', opening_bal)
|
||
console.log('opening_bal', $('#opening_bal'))
|
||
|
||
if(opening_bal != "null"){
|
||
$('#opening_bal').val(opening_bal);
|
||
}
|
||
|
||
|
||
$('.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 by btnPolicyEdit', 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);
|
||
$('#wellness_plan_id').val(res.data.wellness_plan_id);
|
||
$('#wellness_vendor_id').val(res.data.wellness_vendor_id ?? 0).select2();
|
||
$('#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);
|
||
}
|
||
|
||
|
||
// 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') {
|
||
|
||
$('#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.policy_type_id > 7) {
|
||
|
||
$('#first').show();
|
||
$('#second').show();
|
||
$('#third').show();
|
||
$('#base_policy_id').hide();
|
||
$('#base_policy').prop('required', false);
|
||
$("#tpa").prop('required', false);
|
||
$('#tpa_danger').hide();
|
||
$(".EB").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_pk) // 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);
|
||
}
|
||
});
|
||
});
|
||
|
||
$('body').on('click', '.btnNonEbTerms', function(e) {
|
||
e.preventDefault();
|
||
var miscData = $(this).attr('data-misc');
|
||
if (miscData && miscData !== '' && miscData !== 'null') {
|
||
try {
|
||
var misc = JSON.parse(miscData);
|
||
if (misc.placement_sheet_id) {
|
||
window.open('https://docs.google.com/spreadsheets/d/' + misc.placement_sheet_id, '_blank');
|
||
} else {
|
||
alert('No terms found');
|
||
}
|
||
} catch (e) {
|
||
alert('No terms found');
|
||
}
|
||
} else {
|
||
alert('No terms found');
|
||
}
|
||
});
|
||
|
||
$('body').on('click', '.btnNonEbRackRateModal', function(e) {
|
||
e.preventDefault();
|
||
var clientPolicyId = $(this).data('id');
|
||
$('#non_eb_rack_rate_client_policy_id').val(clientPolicyId);
|
||
$('#non_eb_rack_rate_file_list').empty();
|
||
$('#non_eb_rack_rate_file').val('');
|
||
|
||
// Load existing files
|
||
$.ajax({
|
||
url: '<?= base_url("client/policy/getNonEbRackRateFiles") ?>',
|
||
method: 'GET',
|
||
data: { client_policy_id: clientPolicyId },
|
||
success: function(res) {
|
||
if (res.status && res.files && res.files.length > 0) {
|
||
res.files.forEach(function(file) {
|
||
appendNonEbRackRateFile(file);
|
||
});
|
||
}
|
||
}
|
||
});
|
||
|
||
window._nonEbModal = new bootstrap.Modal(document.getElementById('nonEbRackRateModal'));
|
||
window._nonEbModal.show();
|
||
});
|
||
|
||
function appendNonEbRackRateFile(file) {
|
||
var icon = file.type === 'pdf' ? 'mdi-file-pdf text-danger' : 'mdi-file-excel text-success';
|
||
var html = `<div class="d-flex align-items-center justify-content-between border rounded p-1 mb-1" data-filename="${file.name}" style="font-size:12px;">
|
||
<div><i class="mdi ${icon} font-16 mr-1"></i>${file.original_name}</div>
|
||
<button type="button" class="btn btn-sm btn-outline-danger py-0 px-1 btnRemoveNonEbFile" data-filename="${file.name}"><i class="mdi mdi-close"></i></button>
|
||
</div>`;
|
||
$('#non_eb_rack_rate_file_list').append(html);
|
||
}
|
||
|
||
$('body').on('click', '#btnUploadNonEbFile', function() {
|
||
var fileInput = document.getElementById('non_eb_rack_rate_file');
|
||
var file = fileInput.files[0];
|
||
if (!file) {
|
||
toastr.warning('Please select a file first.', 'Warning');
|
||
return;
|
||
}
|
||
|
||
var ext = file.name.split('.').pop().toLowerCase();
|
||
if (!['pdf', 'xlsx', 'xls'].includes(ext)) {
|
||
toastr.error('Only PDF and Excel files are allowed.', 'Invalid File');
|
||
$('#non_eb_rack_rate_file').val('');
|
||
return;
|
||
}
|
||
|
||
var formData = new FormData();
|
||
formData.append('file', file);
|
||
formData.append('client_policy_id', $('#non_eb_rack_rate_client_policy_id').val());
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
$.ajax({
|
||
url: '<?= base_url("client/policy/uploadNonEbRackRateFile") ?>',
|
||
method: 'POST',
|
||
data: formData,
|
||
processData: false,
|
||
contentType: false,
|
||
success: function(res) {
|
||
setTimeout(function() {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}, 500);
|
||
if (res.status) {
|
||
toastr.success('File uploaded successfully', 'Success');
|
||
appendNonEbRackRateFile(res.file);
|
||
$('#non_eb_rack_rate_file').val('');
|
||
} else {
|
||
toastr.error(res.message || 'Upload failed', 'Error');
|
||
}
|
||
},
|
||
error: function(xhr) {
|
||
setTimeout(function() {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}, 500);
|
||
toastr.error('Something went wrong', 'Error');
|
||
}
|
||
});
|
||
});
|
||
|
||
$('body').on('click', '.btnRemoveNonEbFile', function() {
|
||
var btn = $(this);
|
||
var filename = btn.data('filename');
|
||
var clientPolicyId = $('#non_eb_rack_rate_client_policy_id').val();
|
||
|
||
Swal.fire({
|
||
title: "Are you sure?",
|
||
text: "This file will be removed.",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#d33",
|
||
confirmButtonText: "Yes, remove it",
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
$.ajax({
|
||
url: '<?= base_url("client/policy/removeNonEbRackRateFile") ?>',
|
||
method: 'POST',
|
||
data: { client_policy_id: clientPolicyId, filename: filename },
|
||
success: function(res) {
|
||
if (res.status) {
|
||
btn.closest('[data-filename]').remove();
|
||
toastr.success('File removed', 'Success');
|
||
} else {
|
||
toastr.error(res.message || 'Remove failed', 'Error');
|
||
}
|
||
},
|
||
error: function() {
|
||
toastr.error('Something went wrong', 'Error');
|
||
}
|
||
});
|
||
}
|
||
});
|
||
});
|
||
|
||
$('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);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
});
|
||
|
||
});
|
||
|
||
//for date convert to indian formate like this 'yyyy-mm-dd' to this 'dd-mm-yyyy'
|
||
function rearrangeDateFormat(inputDate) {
|
||
|
||
console.log('inputDate', inputDate)
|
||
// Check if inputDate is a string and not empty
|
||
if (typeof inputDate === 'string' && inputDate.trim() !== '') {
|
||
var dateComponents = inputDate.split("-");
|
||
|
||
// Check if dateComponents has the expected number of parts
|
||
if (dateComponents.length === 3) {
|
||
var rearrangedDate = dateComponents[2] + "-" + dateComponents[1] + "-" + dateComponents[0];
|
||
return rearrangedDate;
|
||
} else {
|
||
// Handle unexpected date format
|
||
return '';
|
||
}
|
||
} else {
|
||
// Handle the case where inputDate is not a valid string
|
||
return '';
|
||
}
|
||
}
|
||
|
||
function checkDateStatus(inputDate, bg = false) {
|
||
|
||
var givenDate = new Date(inputDate);
|
||
var currentDate = new Date();
|
||
|
||
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) {
|
||
|
||
$("#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') {
|
||
|
||
$('#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 ($(this).val() > 7) {
|
||
|
||
$('#first').show();
|
||
$('#second').show();
|
||
$('#third').show();
|
||
$('#base_policy_id').hide();
|
||
$('#base_policy').prop('required', false);
|
||
$(".EB").hide();
|
||
setTimeout(() => {
|
||
$("#tpa").prop('required', false);
|
||
$('#tpa_danger').hide();
|
||
}, 100);
|
||
|
||
}
|
||
|
||
// 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() {
|
||
// alert('Base Policy Change');
|
||
|
||
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'
|
||
}));
|
||
|
||
if(data.length == 0){
|
||
$('#cd_ac_no').append($('<option>', {
|
||
value: 'add_cd',
|
||
text: '+ Add New CD'
|
||
}));
|
||
}
|
||
|
||
$.each(data, function(index, item) {
|
||
const option = $('<option>', {
|
||
value: item.id,
|
||
text: item.cd_ac_no
|
||
});
|
||
|
||
if (select == item.id) {
|
||
//console.log('selected');
|
||
option.attr('selected', true);
|
||
}
|
||
|
||
$('#cd_ac_no').append(option);
|
||
});
|
||
|
||
if (select) {
|
||
$('#cd_ac_no').val(select).trigger('change');
|
||
}
|
||
}
|
||
|
||
// 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');
|
||
}
|
||
});
|
||
}
|
||
|
||
});
|
||
|
||
}
|
||
|
||
//check dublicate policy number
|
||
function checkPolicyNo() {
|
||
|
||
var policy_no = $('#policy_no').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,
|
||
url: '<?php echo base_url('util/get_client_policy_data_using_policy_no');?>',
|
||
type: "GET",
|
||
data : {policy_no : policy_no},
|
||
dataType: 'json',
|
||
success: function (res) {
|
||
console.log(res);
|
||
if (res.status == true) {
|
||
|
||
toastr.warning(res.message, 'Warning');
|
||
$('#policy_no').val('');
|
||
|
||
}else{
|
||
|
||
}
|
||
},
|
||
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');
|
||
const cd_amt = urlParams.get('cd_amt');
|
||
|
||
if (clientPolicyId) {
|
||
// Call your function with the `client_policy_id`
|
||
setTimeout(function() {
|
||
getClientPolicyDataForEdit(clientPolicyId);
|
||
}, 3000);
|
||
}
|
||
|
||
if(cd_amt){
|
||
$('#opening_bal').val(cd_amt);
|
||
}
|
||
}
|
||
});
|
||
|
||
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(rearrangeDateFormat(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);
|
||
}
|
||
|
||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||
|
||
console.log(res.data.is_lgbtq)
|
||
|
||
if (res.data.is_lgbtq == 1) {
|
||
$('#is_lgbtq').prop('checked', true);
|
||
} else {
|
||
$('#is_lgbtq').prop('checked', false);
|
||
}
|
||
|
||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||
|
||
|
||
|
||
if (res.data.policy_type_id == '4' || res.data.policy_type_id == '5') {
|
||
|
||
$('#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()
|
||
}
|
||
|
||
if (res.data.policy_type_id > 7) {
|
||
|
||
$('#first').show();
|
||
$('#second').show();
|
||
$('#third').show();
|
||
$('#base_policy_id').hide();
|
||
$('#base_policy').prop('required', false);
|
||
$("#tpa").prop('required', false);
|
||
$('#tpa_danger').hide();
|
||
$(".EB").hide();
|
||
}
|
||
|
||
setTimeout(() => {
|
||
$('#client_branch').val(res.data.client_branch_id).select2();
|
||
}, 1000);
|
||
|
||
setTimeout(function(){
|
||
appendCDACNO(res.cd_data, res.data.cd_ac_pk) // 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(){
|
||
var myModal = new bootstrap.Modal(document.getElementById('lead_modal'));
|
||
myModal.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.success(res.message, 'INFO');
|
||
}
|
||
|
||
$('.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()
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
// for CD master
|
||
$('#cd_ac_no').change(function(){
|
||
|
||
let cd_ac_no = $(this).val();
|
||
|
||
if(cd_ac_no == "add_cd"){
|
||
showCdMasterAddModal();
|
||
$(this).val("");
|
||
}
|
||
|
||
})
|
||
|
||
function setInsuerAndBranchValue(input){
|
||
|
||
var id = $(input).val();
|
||
console.log('id', id);
|
||
|
||
var parts = id.split('-');
|
||
console.log('parts', parts);
|
||
|
||
var firstPart = parts[0];
|
||
console.log('firstPart', firstPart);
|
||
|
||
var secondPart = parts[1];
|
||
console.log('secondPart', secondPart);
|
||
|
||
$('#insurer_branch_id').val(firstPart).trigger('change');
|
||
$('#insurer_id_for_cd').val(secondPart).trigger('change');
|
||
}
|
||
// End
|
||
|
||
function numberToWordsIndian(num) {
|
||
|
||
num = num.toString();
|
||
if (typeof num === 'string') {
|
||
// Remove all commas and convert to number
|
||
num = parseFloat(num.replace(/,/g, ''));
|
||
// Check if conversion resulted in NaN
|
||
if (isNaN(num)) {
|
||
return "invalid number";
|
||
}
|
||
}
|
||
|
||
if (num === 0) return "zero";
|
||
if (num < 0) return "minus " + numberToWordsIndian(-num);
|
||
|
||
const ones = [
|
||
"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
|
||
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
|
||
"seventeen", "eighteen", "nineteen"
|
||
];
|
||
|
||
const tens = [
|
||
"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"
|
||
];
|
||
|
||
function convertHundreds(n) {
|
||
let result = "";
|
||
|
||
if (n >= 100) {
|
||
result += ones[Math.floor(n / 100)] + " hundred";
|
||
n %= 100;
|
||
if (n > 0) result += " ";
|
||
}
|
||
|
||
if (n >= 20) {
|
||
result += tens[Math.floor(n / 10)];
|
||
n %= 10;
|
||
if (n > 0) result += " " + ones[n];
|
||
} else if (n > 0) {
|
||
result += ones[n];
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
let result = "";
|
||
let crores = Math.floor(num / 10000000);
|
||
num %= 10000000;
|
||
|
||
let lakhs = Math.floor(num / 100000);
|
||
num %= 100000;
|
||
|
||
let thousands = Math.floor(num / 1000);
|
||
num %= 1000;
|
||
|
||
let hundreds = num;
|
||
|
||
if (crores > 0) {
|
||
result += convertHundreds(crores) + " crore";
|
||
if (lakhs > 0 || thousands > 0 || hundreds > 0) result += " ";
|
||
}
|
||
|
||
if (lakhs > 0) {
|
||
result += convertHundreds(lakhs) + " lakh";
|
||
if (thousands > 0 || hundreds > 0) result += " ";
|
||
}
|
||
|
||
if (thousands > 0) {
|
||
result += convertHundreds(thousands) + " thousand";
|
||
if (hundreds > 0) result += " ";
|
||
}
|
||
|
||
if (hundreds > 0) {
|
||
result += convertHundreds(hundreds);
|
||
}
|
||
|
||
return result.trim();
|
||
}
|
||
|
||
// Start the interval
|
||
function startAutoSubmit(attrId) {
|
||
// if (!submitInterval) {
|
||
// submitInterval = setInterval(function() {
|
||
// if(attrId == "GMC"){
|
||
// autoSaveGmcTerms();
|
||
// }else if(attrId == "GPA"){
|
||
// autoSaveGpaTerms();
|
||
// }else if(attrId == "OTHERS"){
|
||
// autoSaveOtherTerms();
|
||
// }
|
||
// }, 20000);
|
||
// console.log("Auto-submit started.");
|
||
// }
|
||
console.log("Auto-submit Disabled.");
|
||
}
|
||
|
||
// Stop the interval
|
||
function stopAutoSubmit() {
|
||
if (submitInterval) {
|
||
clearInterval(submitInterval);
|
||
submitInterval = null;
|
||
console.log("Auto-submit stopped.");
|
||
}
|
||
}
|
||
|
||
//Tiny Toastr
|
||
function showTinyToast(attrId = "saveIndicator"){
|
||
const saveIndicator = document.getElementById(attrId);
|
||
saveIndicator.classList.add('show');
|
||
setTimeout(() => {
|
||
saveIndicator.classList.remove('show');
|
||
}, 2000);
|
||
}
|
||
|
||
</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');
|
||
let patternGMC = /gmc/i; // Case insensitive pattern for 'gmc'
|
||
let patternGPA = /gpa/i; // Case insensitive pattern for 'gpa'
|
||
let 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
|
||
}
|
||
|
||
let tpaValue = 'TPA Unavailable';
|
||
|
||
if (item.tpa_short && item.tpa_branch_code) {
|
||
tpaValue = item.tpa_short + '-' + item.tpa_branch_code;
|
||
}
|
||
|
||
let policy_name_data = `${item.policy_type_name ?? ''}` + ' - ' + `${item.policy_no ?? ''}`;
|
||
|
||
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>${(item.policy_start_date)} / ${(item.policy_end_date)}</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}" data-cdamt="${item.lead_cd_amount}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>`;
|
||
|
||
let isNonEb3 = (item.allocg === 'Non-EB' || item.allocg === 'Marine');
|
||
|
||
if (!isNonEb3) {
|
||
policyTable += `
|
||
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyMaster" ><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>`;
|
||
} else {
|
||
policyTable += `
|
||
<a href="#" data-misc='${item.lead_misc || ""}' class="dropdown-item btnNonEbTerms"><i class="mdi mdi-file-document-outline mr-2 text-muted font-18 vertical-middle"></i>Non EB Terms</a>
|
||
<a href="#" data-id="${item.id}" class="dropdown-item btnNonEbRackRateModal"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Non EB Rack Rate</a>`;
|
||
}
|
||
|
||
// 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="mdi mdi-delete 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>${(item.policy_start_date)} / ${(item.policy_end_date)}</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}" data-cdamt="${item.lead_cd_amount}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>`;
|
||
|
||
let isNonEb4 = (item.allocg === 'Non-EB' || item.allocg === 'Marine');
|
||
|
||
if (!isNonEb4) {
|
||
policyTable += `
|
||
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item btnPolicyMaster" ><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>`;
|
||
} else {
|
||
policyTable += `
|
||
<a href="#" data-misc='${item.lead_misc || ""}' class="dropdown-item btnNonEbTerms"><i class="mdi mdi-file-document-outline mr-2 text-muted font-18 vertical-middle"></i>Non EB Terms</a>
|
||
<a href="#" data-id="${item.id}" class="dropdown-item btnNonEbRackRateModal"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Non EB Rack Rate</a>`;
|
||
}
|
||
|
||
// 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="mdi mdi-delete 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,
|
||
// language: {
|
||
// search: `
|
||
// <div class="datatable-search-wrapper" style="position:relative; display:inline-block; width:100%;">
|
||
// _INPUT_
|
||
// <i class="mdi mdi-magnify datatable-search-icon"
|
||
// style="position:absolute; right:122px !important; top:50%; transform:translateY(-50%); color:#666;"></i>
|
||
|
||
// <i class="mdi mdi-close-circle datatable-clear-icon"
|
||
// style="position:absolute; right:122px !important; top:50%; transform:translateY(-50%); color:#666; display:none; cursor:pointer;"></i>
|
||
// </div>
|
||
// `,
|
||
// searchPlaceholder: "Search",
|
||
// emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||
// },
|
||
});
|
||
|
||
|
||
|
||
|
||
});
|
||
});
|
||
</script>
|
||
|
||
|
||
|