475 lines
22 KiB
PHP
475 lines
22 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-nowrap mb-0">
|
|
<thead class="thead-light">
|
|
<tr>
|
|
<th>Insurer</th>
|
|
<th>Policy</th>
|
|
<th>TPA</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" 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" id="policy_type_id" id="policy_type_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="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
|
|
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">
|
|
<div class="form-group col-md-6">
|
|
<label for="policy_start_date">Policy Start Date<span class="text-danger">*</span></label>
|
|
<input value="" type="date" class="form-control" placeholder="Enter Start Date " name="policy_start_date" id="start_date" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="policy_end_date">Policy End Date<span class="text-danger">*</span></label>
|
|
<input value="" type="date" class="form-control" placeholder="Enter End Date " name="policy_end_date" id="end_date" required>
|
|
</div>
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<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'); ?>
|
|
|
|
<!-- *************************************************** -->
|
|
|
|
<script>
|
|
|
|
var policy_PrimaryKey = $('#client_id_policy').val();
|
|
var policy_client = $('#policy_PrimaryKey').val();
|
|
|
|
$(document).ready(function () {
|
|
|
|
//Configure Flatpicker for the policy start date datepicker.
|
|
flatpickr("#start_date", {
|
|
dateFormat: "d-m-Y",
|
|
defaultDate: "today",
|
|
allowInput: false,
|
|
});
|
|
|
|
//Configure Flatpicker for the policy end date datepicker.
|
|
flatpickr("#end_date", {
|
|
dateFormat: "d-m-Y",
|
|
defaultDate: "today",
|
|
allowInput: false
|
|
});
|
|
|
|
$('#add_form').hide();
|
|
$('.btnBack').hide();
|
|
|
|
|
|
$('.btnAdd').click(function(){
|
|
$('#add_form').show();
|
|
$('#table_list').hide();
|
|
$('.btnBack').show();
|
|
$('.btnAdd').hide();
|
|
$('#policy_form_action').val('<?= base_url("client/policy/create"); ?>');
|
|
|
|
})
|
|
|
|
|
|
$('.btnBack').click(function(){
|
|
|
|
$('#GMC').remove();
|
|
$('#GPA').remove();
|
|
$('#add_form').hide();
|
|
$('#table_list').show();
|
|
$('.btnBack').hide();
|
|
$('.btnAdd').show();
|
|
$('#insurer').val('');
|
|
$('#tpa').val('');
|
|
$('#start_date').val('');
|
|
$('#end_date').val('');
|
|
$('#policy').html('<option value="" selected>Select Policy</option>');
|
|
|
|
})
|
|
|
|
|
|
if (policy_PrimaryKey !== '') {
|
|
var policyTable = '';
|
|
var data = <?= isset($client_policy) ? json_encode($client_policy) : '[]' ?>;
|
|
|
|
data.forEach(function(item) {
|
|
policyTable += `
|
|
<tr>
|
|
<td>${item.insurer_short} - ${item.insurer_branch_name}</td>
|
|
<td>${item.policy_name}</td>
|
|
<td>${item.tpa_short} - ${item.tpa_branch_code}</td>
|
|
<td>
|
|
<a data-id="${item.id}" class="btnPolicyEdit mdi mdi-lead-pencil" href="#" style="font-size:18px;"></a>
|
|
<a data-id="${item.policy_id}" class="btnPolicyModel mdi mdi-book-open" href="#" data-toggle="modal" data-target="#bs-example-modal-lg" style="font-size:18px;"></a>
|
|
<a data-id="${item.policy_id}" class="btnPolicyMaster mdi mdi-wrench" href="#" data-toggle="modal" data-target="#bs-example-modal-sm" style="font-size:18px; margin-left: 7px;"></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
|
|
$('#policy_table').append(policyTable);
|
|
}
|
|
|
|
|
|
});
|
|
|
|
//for form submit using AJAX
|
|
$("#policy_form").submit(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
policy_PrimaryKey = $('#client_id_policy').val();
|
|
policy_client = $('#policy_PrimaryKey').val();
|
|
|
|
if (policy_PrimaryKey === '' && policy_client === '') {
|
|
toastr.error('Client is required', 'Error');
|
|
$('#insurer').val('');
|
|
$('#tpa').val('');
|
|
$('#policy').html('<option value="" selected>Select Policy</option>');
|
|
return;
|
|
}
|
|
|
|
var isValid = $('#policy_form').parsley().validate();
|
|
if (!isValid) {
|
|
console.log('Form is Empty', 'Warning');
|
|
return ;
|
|
}
|
|
|
|
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) {
|
|
|
|
if (res.status === false) {
|
|
toastr.error('Policy Dose Not Create', 'Error');
|
|
return;
|
|
}
|
|
|
|
console.log(res);
|
|
var message = (policy_PrimaryKey === '') ? 'Policy Created successfully' : 'Policy Updated Successfully';
|
|
toastr.success(message, 'Success');
|
|
|
|
$('#policy_table tr').remove();
|
|
var policyTable = '';
|
|
$.each(res.data, function(index, item) {
|
|
policyTable += `
|
|
<tr>
|
|
<td>${item.insurer_short} - ${item.insurer_branch_name}</td>
|
|
<td>${item.policy_name}</td>
|
|
<td>${item.tpa_short} - ${item.tpa_branch_code}</td>
|
|
<td>
|
|
<a data-id="${item.id}" class="btnPolicyEdit mdi mdi-lead-pencil" href="#" style="font-size:18px;"></a>
|
|
<a data-id="${item.policy_id}" class="btnPolicyModel mdi mdi-book-open" href="#" data-toggle="modal" data-target="#bs-example-modal-lg" style="font-size:18px;"></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
$('#policy_table').append(policyTable);
|
|
$('#add_form').hide();
|
|
$('#table_list').show();
|
|
$('.btnBack').hide();
|
|
$('.btnAdd').show();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
//To get th POLICY base on Insurer
|
|
$('#insurer').change(function() {
|
|
var id = $(this).val();
|
|
var url = "<?= base_url("util/police-by-insurer/") ?>" + id;
|
|
|
|
$.get(url, function(res) {
|
|
res = JSON.parse(res)
|
|
console.log(res)
|
|
var OptionsHTML = '';
|
|
OptionsHTML += '<option value="" selected>Select Policy</option>';
|
|
$.each(res.data, function(index, item) {
|
|
OptionsHTML += '<option data-id="' + item.policy_type_id + '" value="' + item.id + '">' + item.name + '</option>';
|
|
});
|
|
|
|
$('#policy').html(OptionsHTML);
|
|
}).fail(function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
});
|
|
});
|
|
|
|
|
|
// set the Policy_Type_id for Form Submit
|
|
$('#policy').change(function(){
|
|
var dataId = $(this).children('option:selected').attr('data-id');
|
|
$('#policy_type_id').val(dataId);
|
|
if(dataId == 1){
|
|
appendPolicyFormFields(1)
|
|
}else{
|
|
appendPolicyFormFields(2)
|
|
}
|
|
});
|
|
|
|
|
|
// get the client policy data for edit
|
|
$('body').on('click', '.btnPolicyEdit', function () {
|
|
|
|
var policy_form_action = '';
|
|
var policy_id = $(this).data('id');
|
|
console.log('1', policy_id)
|
|
var policyId = $(this).attr('data-id');
|
|
console.log('2', policyId)
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("client/policy/list/") ?>' + policy_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function (res) {
|
|
|
|
$('#policy_form_action').val('<?= base_url("client/policy/edit"); ?>');
|
|
|
|
if (res.status === false) {
|
|
toastr.error(res.status);
|
|
return;
|
|
}
|
|
|
|
$('#add_form').show();
|
|
$('#table_list').hide();
|
|
$('.btnBack').show();
|
|
$('.btnAdd').hide();
|
|
|
|
$('#insurer').val(res.data.insurer_branch_id + '-' + res.data.insurer_id);
|
|
$('#tpa').val(res.data.tpa_branch_id + '-' + res.data.tpa_id);
|
|
$('#policy').val(res.data.policy_id);
|
|
$('#policy_type_id').val(res.data.policy_type_id);
|
|
$('#policy_PrimaryKey').val(res.data.id);
|
|
$('#start_date').val(rearrangeDateFormat(res.data.policy_start_date));
|
|
$('#end_date').val(rearrangeDateFormat(res.data.policy_end_date));
|
|
|
|
if(res.data.policy_type_id == 1){
|
|
appendPolicyFormFields(1, res.data);
|
|
}else {
|
|
appendPolicyFormFields(2, res.data);
|
|
}
|
|
|
|
var policeOptionHTML = '';
|
|
$.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>';
|
|
});
|
|
$('#policy').html(policeOptionHTML);
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
function appendPolicyFormFields(policy_type, data = false){
|
|
|
|
var html = '';
|
|
var container = document.getElementById('policy_fields');
|
|
|
|
if(policy_type == 2){
|
|
|
|
$('#GMC').remove();
|
|
$('#GPA').remove();
|
|
|
|
html = `
|
|
<div id="GMC">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-3">
|
|
<label for="insured">Insured<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.insured : ''}" type="text" class="form-control" placeholder="Enter insured " name="insured" id="insured" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="no_of_employees">No of Employees<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.no_of_employees : ''}" type="text" class="form-control" placeholder="Enter No of Employees" name="no_of_employees" id="no_of_employees" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="no_of_lives">No of Lives<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.no_of_lives : ''}" type="text" class="form-control" placeholder="Enter No of Lives " name="no_of_lives" id="no_of_lives" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="no_lives_at_inception">No Lives at Inception<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.no_lives_at_inception : ''}" type="text" class="form-control" placeholder="Enter No Lives at Inception " name="no_lives_at_inception" id="no_lives_at_inception" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-3">
|
|
<label for="earned_premium_date">Earned Premium Date<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? rearrangeDateFormat(data.earned_premium_date) : ''}" type="date" class="form-control" placeholder="Enter Earned Premium Date " name="earned_premium_date" id="earned_premium_date" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="earned_premium_amount">Earned Premium<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.earned_premium_amount : ''}" type="text" class="form-control" placeholder="Enter Earned Premium " name="earned_premium_amount" id="earned_premium_amount" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="claims_incurred_date">Claims Incurred Date<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? rearrangeDateFormat(data.claims_incurred_date) : ''}" type="date" class="form-control" placeholder="Enter Claims Incurred Date " name="claims_incurred_date" id="claims_incurred_date" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="claims_incurred_amount">Claims Incurred<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.claims_incurred_amount : ''}" type="text" class="form-control" placeholder="Enter Claims Incurred " name="claims_incurred_amount" id="claims_incurred_amount" required>
|
|
</div>
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="premium_paid_at_inception">Premium paid at Inception<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.premium_paid_at_inception : ''}" type="text" class="form-control" placeholder="Enter Premium paid at Inception" name="premium_paid_at_inception" id="premium_paid_at_inception" required>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="incurred_claims_ratio">Incurred Claims Ratio<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.incurred_claims_ratio : ''}" type="text" class="form-control" placeholder="Enter Claims Ratio" name="incurred_claims_ratio" id="incurred_claims_ratio" required>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="policy_status">Policy Status<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.policy_status : ''}" type="text" class="form-control" placeholder="Enter Policy Status " name="policy_status" id="policy_status" required>
|
|
</div>
|
|
</div>
|
|
</div>`;
|
|
}else if(policy_type == 1){
|
|
|
|
$('#GMC').remove();
|
|
$('#GPA').remove();
|
|
|
|
html = `
|
|
<div class="form-row" id="GPA">
|
|
<div class="form-group col-md-3">
|
|
<label for="insured">Insured<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.insured : ''}" type="text" class="form-control" placeholder="Enter insured " name="insured" id="insured" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="no_of_employees">No of Employees<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.no_of_employees : ''}" type="text" class="form-control" placeholder="Enter No of Employees" name="no_of_employees" id="no_of_employees" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="policy_status">Policy Status<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.policy_status : ''}" type="text" class="form-control" placeholder="Enter Policy Status " name="policy_status" id="policy_status" required>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="claims_experience_for_last_3_years">Claims Experience for Last 3 Years<span class="text-danger">*</span></label>
|
|
<input value="${data !== false && data !== undefined && data !== '' ? data.claims_experience_for_last_3_years : ''}" type="text" class="form-control" placeholder="Enter Claims Experience for Last 3 Years " name="claims_experience_for_last_3_years" id="claims_experience_for_last_3_years" required>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
|
|
container.insertAdjacentHTML('beforeend', html);
|
|
|
|
if(policy_type == 2){
|
|
//Configure Flatpicker for the earned_premium_date datepicker.
|
|
flatpickr("#earned_premium_date", {
|
|
dateFormat: "d-m-Y",
|
|
defaultDate: "today",
|
|
allowInput: false,
|
|
});
|
|
|
|
//Configure Flatpicker for the claims_incurred_date datepicker.
|
|
flatpickr("#claims_incurred_date", {
|
|
dateFormat: "d-m-Y",
|
|
defaultDate: "today",
|
|
allowInput: false
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//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';
|
|
}
|
|
}
|
|
|
|
</script>
|