1728 lines
66 KiB
PHP
Executable File
1728 lines
66 KiB
PHP
Executable File
<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>Enrolment Status</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="policy_table">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="row" id="add_form">
|
|
<div class="col-12">
|
|
<div class="card-body">
|
|
|
|
<div class="row float-right" style="position: relative; bottom: 20px; right: 13px;">
|
|
<button type="button" id="btnPolicyBack" class="btn btn-primary waves-effect waves-light btn-sm btnBack btn-sm"><span class="fa fa-list" aria-hidden="true" style="padding: 5px 10px;"></span>Back To List</button>
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<form role="form" class="parsley-examples" method="post" id="policy_form" enctype="multipart/form-data">
|
|
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
|
<input type="hidden" name="PrimaryKey" id="policy_PrimaryKey" />
|
|
<input type="hidden" id="policy_form_action" />
|
|
<input type="hidden" name="policy_type_id" id="policy_type_id" />
|
|
<input type="hidden" id="insurer_policy_id" />
|
|
<input type="hidden" name="client_id" id="client_id_policy" value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
|
|
<div class="form-group">
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="client_branch">Client Branch<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="client_branch" name="client_branch_id">
|
|
<option selected >Select Client Branch</option>
|
|
</select>
|
|
</div>
|
|
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="email"> 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="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="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 class="form-group col-md-4">
|
|
<label for="policy_no">Policy No<span class="text-danger">*</span></label>
|
|
<input value="" type="text" class="form-control" placeholder="Enter Policy Number " name="policy_no" id="policy_no" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row" id="second" style="display: none;">
|
|
<div class="form-group col-md-4">
|
|
<label for="policy_start_date">Policy Start Date<span class="text-danger">*</span></label>
|
|
<input value="" type="text" class="form-control" placeholder="Enter Start Date " name="policy_start_date" id="start_date" required>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="policy_end_date">Policy End Date<span class="text-danger">*</span></label>
|
|
<input value="" type="text" class="form-control" placeholder="Enter End Date " name="policy_end_date" id="end_date" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4" id="policy_status_field">
|
|
<label for="policy_status">Policy Status</label>
|
|
<input value="" type="text" class="form-control" placeholder="Policy Status" id="policy_status" readonly>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row" id="third" style="display: none; position: relative;top: 22px;">
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="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 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 Reminder Date " name="reminder_date" id="reminder_date" >
|
|
</div>
|
|
|
|
<div class="form-group col-md-12">
|
|
<label for="disclaimer">Disclaimer<span class="text-danger">*</span></label>
|
|
<textarea class="form-control" placeholder="Enter Disclaimer" name="disclaimer" id="disclaimer" ></textarea>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label class="switch" style="position: relative;top: 43px;left: 20px;">
|
|
<input id="policy_visibility" type="checkbox" name="enrolment_visibility" checked>
|
|
<span class="slider round" style="height: 27px;"></span>
|
|
</label>
|
|
|
|
<label for="inception_type" style="position: relative;bottom: 5px;left: 85px;">Policy Visibilty</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>
|
|
|
|
$('#inception_type').change(function () {
|
|
var open_data = $('#open_date').parent();
|
|
var close_data = $('#close_date').parent();
|
|
var reminder_data = $('#reminder_date').parent();
|
|
if($(this).prop('checked')){
|
|
$(open_data).show();
|
|
$(close_data).show();
|
|
$(reminder_data).show();
|
|
$('.dateofdata').attr('required', true);
|
|
}else{
|
|
$(open_data).hide();
|
|
$(close_data).hide();
|
|
$(reminder_data).hide();
|
|
$('.dateofdata').attr('required', false);
|
|
|
|
}
|
|
})
|
|
|
|
|
|
var policy_PrimaryKey = $('#client_id_policy').val();
|
|
var policy_client = $('#policy_PrimaryKey').val();
|
|
|
|
$(document).ready(function() {
|
|
// Initialize select2
|
|
$("#insurer").select2();
|
|
$("#policy").select2();
|
|
$("#tpa").select2();
|
|
$("#base_policy").select2();
|
|
$("#client_branch").select2();
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('#policy_status_field').hide()
|
|
|
|
// Get today's date
|
|
var today = new Date();
|
|
|
|
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 ?? ''}`;
|
|
|
|
|
|
|
|
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>`;
|
|
|
|
// Conditionally render the delete option based on the role
|
|
if (role !== 3 && role !== 4) {
|
|
policyTable += `
|
|
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="removepolicy(this)"><i class="fa fa-trash mr-2 text-muted font-18 vertical-middle"></i>Delete</a>`;
|
|
}
|
|
|
|
policyTable += `
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
|
|
});
|
|
|
|
$('#policy_table').append(policyTable);
|
|
// console.log(policyTable);
|
|
}
|
|
|
|
|
|
$('#table-client-policy').DataTable({
|
|
paging: true,
|
|
searching: 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();
|
|
$('#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();
|
|
$('#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();
|
|
|
|
$.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();
|
|
var message = (policy_PrimaryKey === '') ?
|
|
'Policy Created successfully' : 'Policy Updated Successfully';
|
|
toastr.success(message, 'Success');
|
|
}, 1000);
|
|
}
|
|
|
|
|
|
$('#policy_table tr').remove();
|
|
var policyTable = '';
|
|
var role = res.data.role
|
|
delete res.data.role;
|
|
|
|
$.each(res.data, function(index, item) {
|
|
// console.log(item);
|
|
var patternGMC = /gmc/i; // Case insensitive pattern for 'gmc'
|
|
var patternGPA = /gpa/i; // Case insensitive pattern for 'gpa'
|
|
var subject = item.policy_type_name;
|
|
|
|
if (patternGMC.test(subject)) {
|
|
search_term = 'GMC';
|
|
} else if (patternGPA.test(subject)) {
|
|
search_term = 'GPA';
|
|
} else {
|
|
search_term =
|
|
subject; // Set default value if neither 'GMC' nor 'GPA' exists
|
|
}
|
|
|
|
// //console.log('search_term :', search_term)
|
|
|
|
var enrollmentStatus = '';
|
|
if (item.inception_type == 1) {
|
|
|
|
enrollmentStatus = 'N/A'
|
|
|
|
} else if (item.inception_type == 2) {
|
|
|
|
if (item.open_for_enrollment == 1) {
|
|
|
|
enrollmentStatus =
|
|
'<a data-toggle="tooltip" data-placement="top" title="Click To Close Enrolment" href="#" data-id="' +
|
|
item.id + '" id="' + item.policy_id +
|
|
'" class="btnOpenEnroll">Open</a>'
|
|
|
|
|
|
} else if (item.open_for_enrollment == 0) {
|
|
|
|
enrollmentStatus =
|
|
'<a data-toggle="tooltip" data-placement="top" title="Click To Open Enrolment" href="#" data-id="' +
|
|
item.id + '" id="' + item.policy_id +
|
|
'" class="btnOpenEnroll">Closed</a>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var tpaValue = 'TPA Unavailable';
|
|
|
|
if (item.tpa_short && item.tpa_branch_code) {
|
|
tpaValue = item.tpa_short + '-' + item.tpa_branch_code;
|
|
}
|
|
|
|
var policy_name_data = `${item.policy_type_name ?? ''}` + ' - ' + `${item.policy_no ?? ''}`;
|
|
|
|
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>`;
|
|
|
|
// Conditionally render the delete option based on the role
|
|
if (role !== 3 && role !== 4) {
|
|
policyTable += `
|
|
<a href="#" data-id="${item.id}" id="${search_term}" data-typeid="${item.policy_type_id}" class="dropdown-item" onclick="removepolicy(this)"><i class="fa fa-trash mr-2 text-muted font-18 vertical-middle"></i>Delete</a>`;
|
|
}
|
|
|
|
policyTable += `
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
$('#policy_table').append(policyTable);
|
|
// console.log(policyTable);
|
|
|
|
|
|
$('#insurer').val('');
|
|
$('#tpa').val('');
|
|
$('#policy_no').val('');
|
|
$('#open_date').val('');
|
|
$('#close_date').val('');
|
|
$('#policy').html('<option value="" selected>Select Policy</option>');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
if (xhr.status === 404) {
|
|
//console.log('Resource not found', 'Warning');
|
|
} else if (xhr.status === 500) {
|
|
//console.log('Internal server error', 'Warning');
|
|
} else {
|
|
//console.log('Unknown error occurred', 'Warning');
|
|
}
|
|
}, 1000);
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
/********* To get the POLICY base on Insurer *******/
|
|
$('#insurer').change(function() {
|
|
|
|
var id = $(this).val();
|
|
var client_id = $('#client_id_policy').val()
|
|
var parts = id.split('-');
|
|
var secondPart = parts[1];
|
|
var url = "<?= base_url("util/police-by-insurer/") ?>" + secondPart;
|
|
var url_for_cd = "<?= base_url("util/get_cd_ac/") ?>" + client_id + '/' + secondPart;
|
|
|
|
var selectedOption = $('#base_policy').find(':selected');
|
|
var base_policy_data_id = selectedOption.data('id');
|
|
|
|
|
|
$.get(url_for_cd, function(response){
|
|
|
|
//console.log(response)
|
|
//console.log(response.data)
|
|
|
|
if(response.status == false && response.insurer_id != 'undefined'){
|
|
toastr.warning('The CD Account Number not found.', 'Warning');
|
|
return;
|
|
}
|
|
|
|
appendCDACNO(response.data)
|
|
|
|
}).fail(function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
});
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
/********* set the Policy_Type_id for Form Submit *******/
|
|
$('#policy_type').change(function() {
|
|
|
|
var policy_type_id = $(this).val();
|
|
|
|
if (policy_type_id == 1 || policy_type_id == 6 || policy_type_id == 7) {
|
|
$('#tpa').prop('required', false);
|
|
$('#tpa_danger').hide()
|
|
} else {
|
|
$('#tpa').prop('required', true);
|
|
$('#tpa_danger').show()
|
|
}
|
|
});
|
|
});
|
|
|
|
// get the client policy data for edit
|
|
$('body').on('click', '.btnPolicyEdit', function() {
|
|
|
|
|
|
var policy_form_action = '';
|
|
var policy_id = $(this).attr('data-id');
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
fetchClientBranch()
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("client/policy/list/") ?>' + policy_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
console.log('client_policy_res', res);
|
|
|
|
var gst = (res.data.gst == 0.00) ? 18 : res.data.gst;
|
|
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1100);
|
|
|
|
$('#policy_form_action').val('<?= base_url("client/policy/edit"); ?>');
|
|
|
|
if (res.status === false) {
|
|
toastr.error(res.message);
|
|
return;
|
|
}
|
|
|
|
$('#add_form').show();
|
|
$('#table_list').hide();
|
|
$('.btnBack').show();
|
|
$('.btnAdd').hide();
|
|
|
|
$('#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);
|
|
}
|
|
|
|
|
|
// 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.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',
|
|
});
|
|
}
|
|
|
|
if (res.data.policy_type_id == '1' || res.data.policy_type_id == '6' || res.data.policy_type_id == '7') {
|
|
$('#tpa').prop('required', false);
|
|
$('#tpa_danger').hide()
|
|
} else {
|
|
$('#tpa').prop('required', true);
|
|
$('#tpa_danger').show()
|
|
}
|
|
|
|
setTimeout(() => {
|
|
$('#client_branch').val(res.data.client_branch_id).select2();
|
|
}, 1000);
|
|
|
|
setTimeout(function(){
|
|
appendCDACNO(res.cd_data, res.data.cd_ac_no) // append and select the current CD Account Number
|
|
appendBasePolicyList(res.client_policy_list, res.data.base_policy, res.data.client_branch_id); // append and select the Base palicy
|
|
}, 2000)
|
|
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
//console.log('Something Wrong!', 'warning');
|
|
}, 1000);
|
|
}
|
|
});
|
|
});
|
|
|
|
$('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);
|
|
} 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': '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() == 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($('#inception_type').prop('checked')){
|
|
|
|
}else{
|
|
$('#open_date').parent().hide();
|
|
$('#close_date').parent().hide();
|
|
$('#reminder_date').parent().hide();
|
|
}
|
|
})
|
|
|
|
|
|
// featch client policy to list in the Base policy Dropdown list
|
|
function fetchClientPolicyList() {
|
|
|
|
var client_id = $('#client_id_policy').val()
|
|
var client_branch_id = $('#client_branch').val()
|
|
|
|
//console.log('client_branch_id', client_branch_id)
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("util/featch-client-policy-list/") ?>' + client_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
//console.log('Base policy Dropdown list', res)
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
if (res.status === false) {
|
|
toastr.error(res.status);
|
|
return;
|
|
}
|
|
|
|
var OptionsHTML = '';
|
|
OptionsHTML += '<option value="" selected>Select Base Policy</option>';
|
|
$.each(res.data, function(index, item) {
|
|
|
|
// //console.log('item.client_branch_id', item.client_branch_id)
|
|
|
|
|
|
if (item.client_branch_id == client_branch_id) {
|
|
|
|
if ($('#policy_type').val() == 1) {
|
|
|
|
if (item.policy_type_id == 1 || item.policy_type_id == 2) {
|
|
// //console.log('if 2')
|
|
OptionsHTML += '<option data-id="' + item.policy_type_id + '" value="' +
|
|
item.id +
|
|
'">' + item.name + '( ' + item.policy_type + ' )</option>';
|
|
}
|
|
|
|
} else {
|
|
OptionsHTML += '<option data-id="' + item.policy_type_id + '" value="' + item
|
|
.id +
|
|
'">' + item.name + '( ' + item.policy_type + ' )</option>';
|
|
}
|
|
|
|
}
|
|
});
|
|
$('#base_policy').html(OptionsHTML);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
//console.log('Something Wrong!', 'warning');
|
|
}, 1000);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
var dataId = 0;
|
|
$(document).ready(function() {
|
|
|
|
$('#base_policy').change(function() {
|
|
|
|
var client_policy_id = $(this).val() ? $(this).val() : 0;
|
|
var policy_type = $('#policy_type').val()
|
|
console.log('client_policy_id', client_policy_id);
|
|
|
|
|
|
base_policy_data_id = $(this).children('option:selected').attr('data-id');
|
|
console.log('base_policy_data_id', base_policy_data_id);
|
|
|
|
|
|
var uri = '<?= base_url('client/policy/list/') ?>' + client_policy_id
|
|
// console.log('uri', uri)
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$.ajax({
|
|
url: uri,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
|
|
console.log('base policy ajax response', res)
|
|
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 500);
|
|
|
|
if(res.status == true){
|
|
|
|
$('#insurer').val(res.data.insurer_branch_id + '-' + res.data.insurer_id).change();
|
|
$('#tpa').val(res.data.tpa_branch_id + '-' + res.data.tpa_id).change();
|
|
$('#policy_no').val(res.data.policy_no).change();
|
|
// $('#open_date').val(rearrangeDateFormat(res.data.open_date)).change();
|
|
// $('#close_date').val(rearrangeDateFormat(res.data.close_date)).change();
|
|
}
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 500);
|
|
}
|
|
});
|
|
|
|
});
|
|
})
|
|
|
|
// fetch the client branch list for the dropdown
|
|
function fetchClientBranch() {
|
|
|
|
//console.log('function called');
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
var client_id = 0;
|
|
|
|
if ($('#client_id_policy').val() != "") {
|
|
client_id = $('#client_id_policy').val();
|
|
} else if ($('#policy_PrimaryKey').val() != "") {
|
|
client_id = $('#policy_PrimaryKey').val();
|
|
}
|
|
|
|
$.ajax({
|
|
url: "<?= base_url('util/get-client-branch/') ?>" + client_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
//console.log(res);
|
|
// //console.log(res.data.length);
|
|
|
|
if (res.data.length == 0) {
|
|
toastr.warning('The client does not have any branches.', 'warning');
|
|
return;
|
|
}
|
|
|
|
appendClientBranch(res.data)
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}
|
|
});
|
|
}
|
|
|
|
//append the client branch list for the dropdown
|
|
function appendClientBranch(data) {
|
|
|
|
$('#client_branch').empty();
|
|
|
|
$('#client_branch').append($('<option>', {
|
|
value: '',
|
|
text: 'Select Branch',
|
|
selected: true
|
|
}));
|
|
|
|
$.each(data, function(index, item) {
|
|
var option = $('<option>', {
|
|
value: item.id,
|
|
text: item.branch_name
|
|
});
|
|
|
|
$('#client_branch').append(option);
|
|
});
|
|
|
|
}
|
|
|
|
//append the CD Account number for the dropdown
|
|
function appendCDACNO(data, select = null) {
|
|
|
|
//console.log('appendCDACNO', data);
|
|
//console.log('appendCDACNO', select);
|
|
|
|
$('#cd_ac_no').empty();
|
|
$('#cd_ac_no').append($('<option>', {
|
|
value: '',
|
|
text: 'Select CD Account Number'
|
|
}));
|
|
|
|
$.each(data, function(index, item) {
|
|
const option = $('<option>', {
|
|
value: item.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 Base Policy to the dropdown for edit only
|
|
function appendBasePolicyList(data, select = null)
|
|
{
|
|
|
|
// console.log('appendBasePolicyList', 'function called');
|
|
// console.log('appendBasePolicyList data', data);
|
|
// console.log('appendBasePolicyList selected value', select);
|
|
|
|
$('#base_policy').empty();
|
|
$('#base_policy').append($('<option>', {
|
|
value: '',
|
|
text: 'Select Base Policy'
|
|
}));
|
|
|
|
$.each(data, function(index, item) {
|
|
|
|
const option = $('<option>', {
|
|
value: item.client_policy_id,
|
|
text:`${item.policy_type ?? ''} - ${item.policy_no ?? ''}`,
|
|
'data-id': item.id
|
|
});
|
|
|
|
if (select === item.client_policy_id) {
|
|
option.attr('selected', true);
|
|
}
|
|
$('#base_policy').append(option);
|
|
});
|
|
}
|
|
|
|
function removepolicy(element)
|
|
{
|
|
|
|
Swal.fire({
|
|
title: "Are you sure?",
|
|
text: "Do you want to remove this Policy.",
|
|
icon: "info",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "Yes",
|
|
}).then((result) => {
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
var id = element.getAttribute('data-id');
|
|
// console.log(id)
|
|
var form_action = '<?= base_url("client/policy/remove/") ?>' + id;
|
|
// console.log(form_action)
|
|
$.ajax({
|
|
url: form_action,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
console.log('removepolicy function response', res)
|
|
|
|
if(res){
|
|
if (res.status == true) {
|
|
toastr.success('Policy removed successfully.', 'success');
|
|
location.reload();
|
|
} else {
|
|
Swal.fire({
|
|
title: "warning!",
|
|
text: res.message,
|
|
icon: "warning"
|
|
});
|
|
// toastr.warning('Failed to remove policy', 'warning');
|
|
}
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
console.log('Something Wrong!', 'warning');
|
|
}
|
|
});
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$('#policy_no').change(function(){
|
|
|
|
var policy_no = $(this).val();
|
|
console.log(policy_no +'-'+policy_no.length);
|
|
policy_no = policy_no.trim();
|
|
console.log(policy_no +'-'+policy_no.length);
|
|
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url('util/check_policy_no/');?>'+policy_no,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function (res) {
|
|
|
|
console.log(res)
|
|
if(res.status == true){
|
|
toastr.warning(res.message, 'warning');
|
|
$('#policy_no').val('');
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
|
|
})
|
|
|
|
</script>
|