nhance/app/Views/client_policy.php

1647 lines
63 KiB
PHP

<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"><span class="fa fa-plus-square" aria-hidden="true" style="padding: 5px 10px;"></span>Add Policy</button>
</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>Enrollment 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="email"> Policy Type<span class="text-danger">*</span></label>
<select class="form-control" id="policy_type" name="is_addon" required>
<option value="0">Select Policy Type</option>
<?php foreach ($policy_type as $key => $value) { ?>
<option value="<?= $key ?>"><?= $value ?></option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-4" id="base_policy_id" style="display: none;">
<label for="addon_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="email">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="policy">Policies<span class="text-danger">*</span></label>
<select class="form-control" id="policy" name="policy_id" required>
<option value="" selected>Select Policy</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="mobile">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>
<div class="form-row" id="second" style="display: none;">
<div class="form-group col-md-3">
<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 class="form-group col-md-3">
<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-3">
<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-3" 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="mobile">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="mobile">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>
<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'); ?>
<script>
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();
// Initialize Flatpickr for the start date with today's date
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);
}
});
// Calculate the end date (today + 1 year)
var endDate = new Date(today);
endDate.setFullYear(endDate.getFullYear() + 1);
endDate.setDate(endDate.getDate() - 1); // Set end date to last day of next year
// Initialize Flatpickr for the end date with the calculated end date
var endDatePicker = flatpickr("#end_date", {
dateFormat: "d-m-Y",
defaultDate: endDate,
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)
data.forEach(function(item) {
// //console.log(item.open_for_enrollment);
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 Enrollment">Open</a>'
} else if (item.open_for_enrollment == 0) {
enrollmentStatus =
'<a href="#" data-toggle="tooltip" data-placement="top" title="Click To Open Enrollment" 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_name ?? ''}` + ' - ' + `${item.policy_no ?? ''}` + ' - ' + `${item.policy_type_name ?? ''}`;
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 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>
</div>
</div>
</td>
</tr>
`;
});
$('#policy_table').append(policyTable);
// console.log(policyTable);
}
$('#table-client-policy').DataTable({
paging: true,
searching: false,
// ordering: false
});
});
$('.btnAdd').click(function() {
fetchClientBranch()
$('#policy_form')[0].reset();
$('#add_form').show();
$('#table_list').hide();
$('.btnBack').show();
$('.btnAdd').hide();
$('#insurer').val('').change();
$('#tpa').val('').change();
$('#policy_no').val('').change();
$('#start_date').val('').change();
$('#end_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();
$('#insurer').val('').change();
$('#tpa').val('').change();
$('#policy_no').val('').change();
$('#start_date').val('').change();
$('#end_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();
$.ajax({
data: formData,
url: policy_form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
//console.log(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();
var message = (policy_PrimaryKey === '') ?
'Policy Created successfully' : 'Policy Updated Successfully';
toastr.success(message, 'Success');
}, 1000);
}
$('#policy_table tr').remove();
var policyTable = '';
$.each(res.data, function(index, 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 Enrollment" 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 Enrollment" 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;
}
policyTable += `
<tr>
<td>${item.insurer_short} - ${item.insurer_branch_name}</td>
<td>${item.policy_name} (${item.policy_type_name})</td>
<td>${item.branch_name}</td>
<td>${tpaValue}</td>
<td>${rearrangeDateFormat(item.policy_start_date)} / ${rearrangeDateFormat(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>
</div>
</div>
</td>
</tr>
`;
});
$('#policy_table').append(policyTable);
console.log(policyTable);
$('#insurer').val('');
$('#tpa').val('');
$('#policy_no').val('');
$('#start_date').val('');
$('#end_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);
}
});
});
$(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');
// //console.log('base_policy_data_id', base_policy_data_id);
$.get(url, function(res) {
// res = JSON.parse(res)//
//console.log('polices', res)
var OptionsHTML = '';
OptionsHTML += '<option value="" selected>Select Policy</option>';
$policy_type_value = $('#policy_type').val();
$.each(res.data, function(index, item) {
if ($policy_type_value == 3) {
if (base_policy_data_id == 3) {
if (item.policy_type_id == 5) {
OptionsHTML += '<option data-id="' + item.policy_type_id +
'" value="' +
item.id +
'">' + item.name + '( ' + item.policy_type +
' )</option>';
}
} else {
if (item.policy_type_id == 5 || item.policy_type_id == 3) {
OptionsHTML += '<option data-id="' + item.policy_type_id +
'" value="' +
item.id +
'">' + item.name + '( ' + item.policy_type +
' )</option>';
}
}
} else if ($policy_type_value == 2) {
if (item.policy_type_id == 4 || item.policy_type_id == 5) {
OptionsHTML += '<option data-id="' + item.policy_type_id +
'" value="' +
item.id +
'">' + item.name + '( ' + item.policy_type + ' )</option>';
}
} else if ($policy_type_value == 1) {
// const policyTypeId = Number(item.policy_type_id);
// if ([1, 2, 3, 6, 7,].includes(policyTypeId))
if (item.policy_type_id == 1 || item.policy_type_id == 2 || item
.policy_type_id == 3 || item.policy_type_id == 7 || item.policy_type_id == 6){
//console.log(item.policy_type_id)
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>';
}
});
$('#policy').html(OptionsHTML);
}).fail(function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
});
$.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').change(function() {
var id = $(this).val();
var dataId = $(this).children('option:selected').attr('data-id');
var branch_id = $('#client_branch').val();
var client_id = $('#client_id_policy').val();
console.log('client_id', client_id)
console.log('branch_id', branch_id)
console.log('policy_type_id', dataId)
console.log('client_policy_id', $('#policy_PrimaryKey').val())
$('#policy_type_id').val(dataId);
var url = '<?php echo base_url('util/check_policy_type/') ?>' + dataId + '/' + branch_id + '/' + client_id;
// if (dataId && branch_id && client_id) {
// // Check if all parameters exist
// if ($('#policy_PrimaryKey').val() == "" || id != $('#insurer_policy_id').val()) {
// $.get(url, function(response) {
// console.log(response);
// console.log(response.count);
// if (response.count > 0) {
// console.log('Policy already exist in the branch');
// toastr.error('Policy already exist in the branch', 'Error');
// $('#policy').val('').change();
// }
// console.log('outer');
// }).fail(function(xhr, status, error) {
// console.error(xhr.responseText);
// console.error(status, error);
// });
// }
// } else {
// console.log('Missing parameter(s): dataId, branch_id, or client_id');
// }
if (dataId == 1) {
$('#tpa').prop('required', false);
$('#tpa_danger').hide()
} else {
$('#tpa').prop('required', true);
$('#tpa_danger').show()
}
var base_policy_dataId = $('#base_policy').children('option:selected').attr('data-id');
if ($('#policy_type').val() == 1) {
// //console.log('step 1')
if (dataId == 3) {
// //console.log('step 2')
var displayStatus = $('#base_policy_id').css('display');
$('#base_policy_id').show();
$('#base_danger').hide();
// $('#base_policy').prop('required', true);
if (displayStatus === 'none') {
// //console.log('step 2.1')
$('#base_policy').val('').change();
}
// $('#base_policy').find('option[data-id="3"]').hide();
} else {
// //console.log('step 3')
var displayStatus = $('#base_policy_id').css('display');
$('#base_policy_id').hide();
$('#base_danger').show();
// $('#base_policy').prop('required', false);
if (displayStatus === 'none') {
// //console.log('step 3.1')
$('#base_policy').val('').change();
}
}
}
});
});
// get the client policy data for edit
$('body').on('click', '.btnPolicyEdit', function() {
var policy_form_action = '';
var policy_id = $(this).attr('data-id');
$('.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');
}, 1000);
$('#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();
$('#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.is_addon).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));
$('#end_date').val(rearrangeDateFormat(res.data.policy_end_date));
$('#policy_status').val(checkDateStatus(res.data.policy_end_date));
$('#gst_no').val(gst);
$('#policy_status_field').show();
if (res.data.inception_type == 2) {
$('#inception_type').prop('checked', true);
} else {
$('#inception_type').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.is_addon == 2 || res.data.is_addon == 3) {
$("#insurer").next(".select2-container").css({
'pointer-events': 'none',
});
$('#select2-insurer-container').css({
'background-color': '#ebebe0',
});
$("#tpa").next(".select2-container").css({
'pointer-events': 'none',
});
$('#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',
});
}
setTimeout(function(){
appendCDACNO(res.cd_data, res.data.cd_ac_no) // append and select the current CD Account Number
appendPolicyList(res.policy, res.data.policy_id, ); // append and select the current policy
appendBasePolicyList(res.client_policy_list, res.data.base_policy, res.data.client_branch_id); // append and select the Base palicy
}, 2000)
$('#client_branch').val(res.data.client_branch_id).change();
},
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', '.btnOpenEnroll', function() {
Swal.fire({
title: "Are you sure?",
text: "You need 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) {
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 Enrollment" 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 Enrollment" 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) {
if (inputDate !== null) {
var dateComponents = inputDate.split("-");
var rearrangedDate = dateComponents[2] + "-" + dateComponents[1] + "-" + dateComponents[0];
return rearrangedDate;
} else {
return '00-00-0000';
}
}
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;
if (input instanceof HTMLElement) {
const inputValue = input.value;
number = parseFloat(inputValue.replace(/,/g, ''), 10);
} else {
number = parseFloat(input.replace(/,/g, ''), 10);
}
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('formetted value', 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;
// }
}
function removeClientPolicy(element) {
// //console.log(element);
}
$('#policy_type').change(function() {
$('#insurer').val('').change();
$('#tpa').val('').change();
$('#policy_no').val('');
$('#start_date').val('');
$('#end_date').val('');
$('#base_policy').val('').change();
if ($(this).val() == 2 || $(this).val() == 3) {
$("#insurer").next(".select2-container").css({
'pointer-events': 'none',
});
$('#select2-insurer-container').css({
'background-color': '#ebebe0',
});
$("#tpa").next(".select2-container").css({
'pointer-events': 'none',
});
$('#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() == 3) {
toastr.warning('Please Change the Policy Terms after Submit the Policy!', 'INFO');
}
if ($(this).val() != '1' && $(this).val() != '0') {
$('#base_policy_id').show();
$('#base_policy').prop('required', true);
$('#first').show();
$('#second').show();
$('#third').show();
} else if ($(this).val() == '0') {
$('#first').hide();
$('#second').hide();
$('#third').hide();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
} else if ($(this).val() == '1') {
$('#first').show();
$('#second').show();
$('#third').show();
$('#base_policy_id').hide();
$('#base_policy').prop('required', false);
}
})
// 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);
dataId = $('#policy').children('option:selected').attr('data-id');
// //console.log('dataId', dataId)
base_policy_data_id = $(this).children('option:selected').attr('data-id');
// //console.log('base_policy_data_id', base_policy_data_id);
var queryParams = {
client_policy_id: client_policy_id,
policy_type: policy_type,
};
const queryString = objectToQueryString(queryParams);
// var uri = '<?= base_url('util/fetch-policy-for-policy-type') ?>?' + queryString
var uri = '<?= base_url('client/policy/list/') ?>' + client_policy_id
// //console.log('uri', uri)
// //console.log('queryString', queryString)
$('.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();
$('#start_date').val(rearrangeDateFormat(res.data.policy_start_date)).change();
$('#end_date').val(rearrangeDateFormat(res.data.policy_end_date)).change();
var policeOptionHTML = '';
$policy_type_value = $('#policy_type').val();
$.each(res.policy, function(index, item) {
policeOptionHTML += '<option data-id="' + item.policy_type_id +
'" value="' + item.id + '" ' + (res.data.policy_id === item
.id ?
'selected="selected"' : '') + '>' + item.name +
'</option>';
});
console.log('policeOptionHTML', policeOptionHTML)
$('#policy').html(policeOptionHTML);
if (dataId == 3 || policy_type == 1) {
setTimeout(function() {
var $option = $('#policy').find('option[data-id="3"]');
if ($option.length > 0) {
$option.prop('selected', true).change();
} else {
toastr.warning('The insurer does not have a GMC-Parents policy.', 'Warning');
}
}, 1500);
}
}
},
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');
}, 500);
}
});
});
})
function objectToQueryString(obj) {
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
}
// 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);
});
}
$(document).ready(function() {
$("#client_branch").on('change', function() {
fetchClientPolicyList();
});
})
//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.cd_ac_no,
text: item.cd_ac_no
});
if (select === item.cd_ac_no) {
//console.log('selected');
option.attr('selected', true);
}
$('#cd_ac_no').append(option);
});
}
// append Policies list to the dropdown for edit only
function appendPolicyList(data, select = null, ) {
console.log('appendPolicyList', 'function called');
console.log('appendPolicyList data', data);
console.log('appendPolicyList selected value', select);
$('#policy').empty();
$('#policy').append($('<option>', {
value: '',
text: 'Select Policy'
}));
$.each(data, function(index, item) {
const option = $('<option>', {
value: item.id, //policy id primary key
text: item.name + ' - ' + item.policy_type, // policy name
'data-id': item.policy_type_id //policy type id like gpa and gmc
});
if (select === item.id) {
option.attr('selected', true);
}
$('#policy').append(option);
});
}
// append Base Policy to the dropdown for edit only
function appendBasePolicyList(data, select = null, client_branch_id = 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) {
if (item.client_branch_id == client_branch_id) {
const option = $('<option>', {
value: item.id,
text: item.name + ' - ' + item.policy_type,
'data-id': item.policy_type_id
});
if (select === item.id) {
//console.log('selected');
option.attr('selected', true);
}
$('#base_policy').append(option);
}
});
}
</script>