nhance/app/Views/policy_gpa_terms.php
2026-02-09 12:57:17 +05:30

1241 lines
54 KiB
PHP
Executable File

<style>
.button-like {
display: inline-block;
padding: 8px 15px;
background-color: #02a8b5;
color: white;
text-decoration: none;
border-radius: 2px;
cursor: pointer;
margin-right: -85px;
}
.radiobuttondiv {
margin-left: 32px;
}
.form-control-client-policy-master {
width: 62% !important;
margin-left: 30px;
margin-top: 3px
}
/* .form-group.col-md-6 */
.form-group-client-policy-master {
display: -webkit-box;
max-width: 100% !important;
/* border:1px solid; */
/* background-color: #0001; */
}
.form-group-client-policy-masters {
display: -webkit-box;
max-width: 100% !important;
}
.flex-container {
display: block;
/* flex-wrap: wrap; */
/* align-items: center; Align items vertically center */
}
.flex-container>div {
flex: 1;
/* Each div takes equal space */
}
label {
padding-top: 7px;
width: 400px;
/* background-color: #0001; */
height: 36px;
/* text-align: center; */
}
.jodit-status-bar {
display: none;
}
.input-group {
width: 64.5% !important;
}
.input-group-append-client-policy-master {
margin-top: 3px;
}
.jodit-wysiwyg {
margin-bottom: 162px;
}
.form-control-client-policy-masters {
margin-left: 30px;
width: 689px;
}
#policyGPATermsForm input ,
#policyGPATermsForm select,
#policyGPATermsForm .select2-container .select2-selection--single ,
#policyGPATermsForm .select2-container .select2-selection--multiple {
background-color: #ECECEC !important;
border:1px solid #ECECEC !important;
box-shadow: none !important;
}
</style>
<div id="policyGPATermsForm" style="display:none">
<span id="policyGPATermsClose" style="float: right;font-size: 26px;color: red;margin-top: -42px;margin-left: 3px;margin-right: 7px;">x</span>
<h5>
<label for="gpaTerms" style="margin-bottom: 20px;">Policy Terms <span id="nameOfThePolicyInGPA"></span></label>
</h5>
<form role="form" class="parsley-examples" method="post" id="policyGPATerms" enctype="multipart/form-data">
<input type="hidden" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="client_id" id="Client_id" value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
<input type="hidden" name="client_policy_id" id="gpa_client_policy_id" />
<input type="hidden" name="policy_id" id="gpa_policy_id" />
<input type="hidden" id="emp_count" />
<div class="form-group">
<!-- <div class="row" style="margin-bottom: 10px;">
REF: VR
<div class="col">
<div class="d-flex align-items-center gap-2">
<label for="sumInsured" class="form-label" >Sum Insured</label>
<input class="form-control mr-2" type="text" name="sumInsured2" id="sumInsured2" style="max-width:200px;"
onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this)">
<button type="button" class="btn btn-primary si-add-more mr-2" onclick="appendGPASIAddMore()"
style="background-color: #e26728; border:1px solid #e26728;"
>
<i class="mdi mdi-plus"></i>
</button>
<div id='numberToWordSumInsured' class="text-danger-2 mr-2"></div>
</div>
<div id="gpa_si_add_more"></div>
</div>
</div>
REF: VR
<div class="row" style="margin-bottom: 10px;">
<div class="col">
<div class="d-flex align-items-center gap-2">
<label for="totalSumInsured">Total Sum Assured</label>
<input type="text" style="max-width: 200px !important;" class="form-control mr-2" name="totalSumInsured"
id="totalSumInsured" onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this)">
<div id='numberToWordTotalSumInsured' class="text-danger-2 mr-2"></div>
</div>
</div>
</div> -->
<div class="row mb-2">
<div class="col-md-4">
<label for="sumInsured" class="form-label" >Sum Insured</label>
</div>
<div class="col-md-6">
<div class="d-flex align-items-center gap-2">
<input class="form-control mr-2" type="text" name="sumInsured2" id="sumInsured2" style="max-width:200px;"
onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this)">
<button type="button" class="btn btn-primary si-add-more ml-2" onclick="appendGPASIAddMore()"
style="background-color: #e26728; border:1px solid #e26728;">
<i class="mdi mdi-plus"></i>
</button>
</div>
<div id='numberToWordSumInsured' class="text-danger-2 mr-2"></div>
</div>
</div>
<div id="gpa_si_add_more"></div>
<div class="row mb-2">
<div class="col-md-4">
<label for="totalSumInsured">Total Sum Assured</label>
</div>
<div class="col-md-6">
<div class="d-flex align-items-center gap-2">
<input type="text" style="max-width: 200px !important;" class="form-control mr-2" name="totalSumInsured"
id="totalSumInsured" onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this)">
</div>
<div id='numberToWordTotalSumInsured' class="text-danger-2 mr-2"></div>
</div>
</div>
<div class="row" style="margin-bottom: 10px;">
<div class="col d-flex align-items-center"
style="background-color: #F5FFFF;border-radius:10px;box-shadow: 0px 2px 2px 0px #00000040;
padding:20px;">
<input disabled type="checkbox" style="color:black;" name="family_floaters[]"
value="self" id="self" checked>
<span style="margin-right: 40px;color:black; margin-left: 8px;">Self</span>
<div class="self-age" style="margin-right: 20px;">
<span style="margin-right: 20px;color:black;">Min Age:</span>
<input class="underline-input min_age"
style="background-color: white !important;"
value="<?php echo isset($self_min_age) ? $self_min_age : '18'; ?>"
type="number" name="self_min_age" id="self_min_age_gpa"
onchange="lowerIsEighteen(this)">
</div>
<div class="self-age" style="margin-right: 20px;">
<span style="margin-right: 20px;color:black;">Max Age:</span>
<input class="underline-input max_age"
style="background-color:white !important"
value="<?php echo isset($self_max_age) ? $self_max_age : '60'; ?>"
type="number" name="self_max_age" id="self_max_age_gpa"
onchange="lowerIsEighteen(this)">
</div>
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input class="form-check-input me-2 unchecked" type="checkbox" id="accidentalDeathBenefit_display" name="accidentalDeathBenefit_display" checked>
<label class="form-check-label mb-0" for="accidentalDeathBenefit_display">
Accidental Death Benefit
</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="accidentalDeathBenefit" class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input class="form-check-input me-2 unchecked" type="checkbox" id="permanentTotalDisablement_display" name="permanentTotalDisablement_display" checked>
<label class="form-check-label mb-0" for="permanentTotalDisablement_display">
Permanent Total Disablement
</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="permanentTotalDisablement" id="permanentTotalDisablement" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input me-2 unchecked" name="permanentPartialDisablement_display" id="permanentPartialDisablement_display" checked>
<label class="form-check-label mb-0" for="permanentPartialDisablement">Permanent Partial Disablement</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="permanentPartialDisablement" id="permanentPartialDisablement"
class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input me-2 unchecked" name="temporaryTotalDisablementBenefit_display" id="temporaryTotalDisablementBenefit_display" checked>
<label class="form-check-label mb-0" for="temporaryTotalDisablementBenefit">Temporary Total Disablement Benefit</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="temporaryTotalDisablementBenefit" id="temporaryTotalDisablementBenefit"
class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input me-2 unchecked" name="medical_expenses_medical_extension_display" id="medical_expenses_medical_extension_display" checked>
<label class="form-check-label mb-0" for="medical_expenses_medical_extension">Medical Expenses / Medical Extension (IPD)</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="medical_expenses_medical_extension" id="medical_expenses_medical_extension"
class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input me-2 unchecked" name="opd_treatment_cover_display" id="opd_treatment_cover_display" checked>
<label class="form-check-label mb-0" for="opd_treatment_cover">OPD Treatment Cover</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="opd_treatment_cover" id="opd_treatment_cover" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input me-2 unchecked" name="ambulanceCharges_display" id="ambulanceCharges_display" checked>
<label class="form-check-label mb-0" for="ambulanceCharges"> Ambulance Charges</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="ambulanceCharges" class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox"class="form-check-input me-2 unchecked" name="repatriation_of_mortal_remains_display" id="repatriation_of_mortal_remains_display" checked>
<label class="form-check-label mb-0" for="repatriation_of_mortal_remains">Repatriation of Mortal Remains</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="repatriation_of_mortal_remains" id="repatriation_of_mortal_remains" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input me-2 unchecked" name="childrenEducationWelfareFund_display" id="childrenEducationWelfareFund_display" checked>
<label class="form-check-label mb-0" for="childrenEducationWelfareFund">Children Education Welfare Fund</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="childrenEducationWelfareFund" id="childrenEducationWelfareFund" class="form-control">
</div>
<div class="col-md-2">
<div class="form-check align-items-center">
<input type="checkbox" class="form-check-input me-2 unchecked" name="terrorism_display" id="gpa_terrorism_display" checked>
<label class="form-check-label mb-0"for="terrorism">Terrorism</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="terrorism" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="worldwideCover_display" id="worldwideCover_display" checked>
<label class="form-check-label" for="worldwideCover">Worldwide Cover</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="worldwideCover" class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="family_transportation_benefits_display" id="family_transportation_benefits_display" checked>
<label class="form-check-label" for="family_transportation_benefits">Family Transportation Benefits</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="family_transportation_benefits" id="family_transportation_benefits" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="fractures_dislocation_burns_display" id="fractures_dislocation_burns_display" checked>
<label class="form-check-label"for="fractures_dislocation_burns">Fractures / Dislocation / Burns</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="fractures_dislocation_burns" id="fractures_dislocation_burns" class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="coma_display" id="coma_display" checked>
<label class="form-check-label" for="coma">Coma</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="coma" id="coma" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex-align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="carriageofDeadBody_display" id="carriageofDeadBody_display" checked>
<label class="form-check-label" for="carriageOfDeadBody">Carriage of Dead Body</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="carriageOfDeadBody" class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex-align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="compassionateVisitExpenses_display" id="compassionateVisitExpenses_display" checked>
<label class="form-check-label" for="compassionateVisitExpenses">Compassionate Visit Expenses</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="compassionateVisitExpenses" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="travel_expenses_for_medical_treatment_display" id="travel_expenses_for_medical_treatment_display" checked>
<label class="form-check-label" for="travel_expenses_for_medical_treatment">Travel expenses for Medical Treatment</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="travel_expenses_for_medical_treatment" id="travel_expenses_for_medical_treatment" class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="daily_cash_allowance_display" id="daily_cash_allowance_display" checked>
<label class="form-check-label" for="daily_cash_allowance">Daily cash Allowance</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="daily_cash_allowance" id="daily_cash_allowance" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="artifical_limb_and_prosthesis_display" id="artifical_limb_and_prosthesis_display" checked>
<label class="form-check-label" for="artifical_limb_and_prosthesis">Artifical Limb and Prosthesis</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="artifical_limb_and_prosthesis" id="artifical_limb_and_prosthesis" class="form-control">
</div>
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="animalSnakeInsectBite_display" id="animalSnakeInsectBite_display" checked>
<label class="form-check-label" for="animalSnakeInsectBite">Animal/Snake/Insect bite</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="animalSnakeInsectBite" id="animalSnakeInsectBite" class="form-control">
</div>
</div>
<div class="row mb-2">
<div class="col-md-2">
<div class="form-check d-flex align-items-center">
<input type="checkbox" class="form-check-input unchecked" name="air_ambulance_display" id="air_ambulance_display" checked>
<label class="form-check-label" for="air_ambulance">Air Ambulance</label>
</div>
</div>
<div class="col-md-4">
<input type="text" name="air_ambulance" id="air_ambulance" class="form-control">
</div>
</div>
</div>
<div class="gpa_special_condition">
</div>
<br>
<div class="form-group text-right m-b-0" style="margin-top: -49px;">
<a href="#" class="btn button-like" id="gpaButtonSpecialCondition" title="Special Condition">Special Condition</a>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="btnGPATermsSubmit" style="margin-top: 100px;">Submit</button>
</div>
</form>
</div>
<script>
var policy_grid_id = $('#client_id').val();
var grid_html = '';
var gpa_auto_save_enable = false;
$("#policyGPATerms").submit(function(event) {
if (!$('#self').prop('checked')) {
$('#self_min_age_gpa').removeAttr('name')
$('#self_max_age_gpa').removeAttr('name')
}
event.preventDefault();
var isValid = $('#policyGPATerms').parsley().validate();
console.log('isvalid', isValid);
if ($('#emp_count').val() == true) {
toastr.warning('Client has active employees', 'Warning');
return;
}
if (!isValid) {
console.log('Form is Empty', 'Warning');
return;
}
var specialConditions = [];
$(".removeDom").each(function () {
var isChecked = $(this).find("input[name='gpa_special_condition_display[]']").is(":checked");
if (isChecked) {
var label = $(this).find("input[name='gpa_special_condition_label[]']").val();
var input = $(this).find("input[name='gpa_special_condition_input[]']").val();
specialConditions.push({ [label]: input });
}
});
console.log("gpa_specialConditions", specialConditions);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var formData = new FormData($('#policyGPATerms')[0]);
var policy_form_action = '<?= base_url("client/terms/gpa_create") ?>';
formData.append("gpa_special_condition_display_value", JSON.stringify(specialConditions));
$.ajax({
data: formData,
url: policy_form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#policyGPATerms')[0].reset();
$('.text-danger-2').html('');
console.log(res);
if (res.status === false) {
toastr.error('Policy Dose Not Create', 'Error');
return;
}
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
window.scrollTo({ top: 0, behavior: 'smooth' });
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$('#policyGPATermsForm').css('display', 'none');
$('#police-tab').css('display', '');
$('.nav.nav-pills.navtab-bg').css('display', '');
$('.nav.nav-pills.navtab-bg').prev().css('display', '');
var message = 'Policy Terms Updated successfully';
toastr.success(message, 'Success');
}, 1000);
});
$('body').on('click', '.btnPolicyMaster', function() {
var client_policy_id = $(this).data('id');
// console.log('client_policy_id :' ,client_policy_id);
$('#gpa_client_policy_id').val(client_policy_id);
var gpa_policy_type_id = $(this).attr('id');
// console.log('gpa_policy_type_id', gpa_policy_type_id)
if (gpa_policy_type_id == 'GPA') {
$('#policyGPATermsForm').css('display', '');
$('#police-tab').css('display', 'none');
$('.nav.nav-pills.navtab-bg').css('display', 'none');
$('.nav.nav-pills.navtab-bg').prev().css('display', 'none');
$('.removeDom').remove()
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?= base_url("client/policy/getterms") ?>',
method: 'GET',
data: {
client_policy_id: client_policy_id
},
success: function(res) {
console.log(res);
console.log('count', res.emp_count_by_policy);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
// $('#nameOfThePolicyInGPA').html(' - ' + res.policy_name.name);
$('#emp_count').val(res.count)
if (res.emp_count_by_policy != 0) {
$("#btnGPATermsSubmit").hide();
$("#gpaButtonSpecialCondition").hide();
gpa_auto_save_enable = false;
} else {
$("#btnGPATermsSubmit").show();
$("#gpaButtonSpecialCondition").show();
startAutoSubmit('GPA');
gpa_auto_save_enable = true;
}
if (res && res.data) {
let gpaJsonObjectForSpecialCondition = JSON.parse(res.data);
Object.keys(gpaJsonObjectForSpecialCondition).forEach(function(key) {
// if (key.includes("gpa_special_condition_label") || key.includes("gpa_special_condition_input")) {
// if (key.includes("gpa_special_condition_label")) {
// for (let index = 0; index <
// gpaJsonObjectForSpecialCondition[key].length; index++) {
// specialConditionForGPA();
// }
// }
// let elements = document.getElementsByName(`${key}[]`);
// if (elements) {
// elements.forEach((element, index) => {
// if (gpaJsonObjectForSpecialCondition[key][
// index
// ] == undefined) {
// element.value = " ";
// } else {
// element.value =
// gpaJsonObjectForSpecialCondition[key][
// index
// ];
// if (key.includes("gpa_special_condition_label")) {
// let checkbox = $(element).closest('.form-group').find('input[name="gpa_special_condition_display[]"]');
// console.log("First element:", element);
// if (checkbox.length) {
// console.log("Checkbox found:", checkbox);
// // Correct way to set the 'id' attribute
// let formattedValue = gpaJsonObjectForSpecialCondition[key][index].replace(/[\s\-\/,&]+/g, '').toLowerCase();
// console.log('formattedValue', formattedValue);
// checkbox.attr('id', formattedValue + '_display');
// console.log("Updated Checkbox:", checkbox);
// } else {
// console.log("Checkbox not found for:", element);
// }
// }
// }
// });
// }
// }
if (key.includes("gpa_special_condition_label") || key.includes("gpa_special_condition_input")) {
if (key.includes("gpa_special_condition_label")) {
let count = gpaJsonObjectForSpecialCondition[key]?.length || 0;
for (let i = 0; i < count; i++) {
specialConditionForGPA(); // Called once per label entry
}
}
let elements = document.getElementsByName(`${key}[]`);
if (elements && elements.length) {
Array.from(elements).forEach((element, index) => {
let value = gpaJsonObjectForSpecialCondition[key]?.[index] || "";
element.value = value;
if (key.includes("gpa_special_condition_label")) {
let checkbox = $(element).closest('.form-group')
.find('input[name="gpa_special_condition_display[]"]');
if (checkbox.length) {
let formattedValue = value.replace(/[\s\-\/,&]+/g, '').toLowerCase();
checkbox.attr('id', formattedValue + '_display');
}
}
});
}
}
if (key.includes("multiple_sum_insured") && key != "") {
if (Array.isArray(gpaJsonObjectForSpecialCondition[key])) {
gpaJsonObjectForSpecialCondition[key].forEach((value,
index) => {
appendGPASIAddMore(value);
});
} else {
console.error(`${key} is not an array.`);
}
}
if (key.includes("enrollment_display_key") && key.length) {
console.log('enrollment_display_key');
console.log(gpaJsonObjectForSpecialCondition[key]);
processJsonObject2(gpaJsonObjectForSpecialCondition);
}
});
let jsonObject = JSON.parse(res.data);
$("#numberToWordSumInsured").text(convertCommaNumberToWords(jsonObject
.sumInsured2) ?? '');
$("#numberToWordTotalSumInsured").text(convertCommaNumberToWords(jsonObject
.totalSumInsured) ?? '');
if (jsonObject.compassionateVisitExpenses == '1') {
var element = $('input[name="compassionateVisitExpenses"]').parent()
.parent().next()[0];
$(element).css("display", "");
}
if (jsonObject.brokenBoneExpenses == '1') {
var element = $('input[name="brokenBoneExpenses"]').parent().parent()
.next()[0];
$(element).css("display", "");
}
if (jsonObject.ambulanceCharges == '1') {
var element = $('input[name="ambulanceCharges"]').parent().parent().next()[
0];
$(element).css("display", "");
}
if (jsonObject.burnExpenses == '1') {
var element = $('input[name="burnExpenses"]').parent().parent().next()[0];
$(element).css("display", "");
}
if (jsonObject.carriageOfDeadBody == '1') {
var element = $('input[name="carriageOfDeadBody"]').parent().parent()
.next()[0];
$(element).css("display", "");
}
// disableUnwantedTermsforGPA(jsonObject);
Object.keys(jsonObject).forEach(function(key) {
// console.log('jsonObject key', key)
// console.log('jsonObject value', jsonObject[key])
// console.log('jsonObject value type', typeof jsonObject[key])
let elements; // declare the element variable
if (key === "terrorism") {
let form = document.getElementById("policyGPATerms");
elements = form.querySelectorAll('[name="terrorism"]');
} else {
elements = document.getElementsByName(key);
}
// let elements = document.getElementsByName(key);
if (elements && elements.length > 0) {
let element = elements[0];
if (element.tagName === 'INPUT' && (element.type ===
'checkbox' || element.type === 'radio')) {
if (element.type === 'checkbox') {
element.checked = jsonObject[key] === '1';
} else if (element.type === 'radio') {
element.checked = element.value === jsonObject[key];
}
} else {
if (jsonObject[key] == undefined || jsonObject[key] == '') {
element.value = " ";
} else {
element.value = jsonObject[key] ?? '';
}
}
}
if (key.includes("age_ratio")) {
console.log("-------------------------");
console.log(jsonObject[key]);
console.log(jsonObject[key].self);
console.log(jsonObject[key].self.min);
$('#self_min_age_gpa').val(jsonObject[key].self.min);
$('#self_max_age_gpa').val(jsonObject[key].self.max);
}
});
}
$("#sumInsured2").trigger("keyup");
$('.multiple_sum_insured').trigger("keyup");
$("#totalSumInsured").trigger("keyup");
},
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);
}
});
} else if (gpa_policy_type_id != 'GPA' && gpa_policy_type_id != 'GMC') {
// toastr.warning("This policy has no policy terms.", 'Warning');
}
});
</script>
<script>
const gpaFields = [
'accidentalDeathBenefit',
'permanentTotalDisablement',
'permanentPartialDisablement',
'temporaryTotalDisablementBenefit',
'medical_expenses_medical_extension',
'opd_treatment_cover',
'ambulanceCharges',
'repatriation_of_mortal_remains',
'childrenEducationWelfareFund',
'terrorism',
'worldwideCover',
'family_transportation_benefits',
'fractures_dislocation_burns',
'coma',
'carriageOfDeadBody',
'compassionateVisitExpenses',
'travel_expenses_for_medical_treatment',
'daily_cash_allowance',
'artifical_limb_and_prosthesis',
'animalSnakeInsectBite',
'air_ambulance',
'gpa_special_condition_label',
'gpa_special_condition_input',
'multiple_sum_insured'
];
document.getElementById('gpaButtonSpecialCondition').addEventListener('click', function(event) {
console.log('specialConditionForGPA callback clicked')
event.preventDefault();
specialConditionForGPA();
});
function specialConditionForGPA(count = 0) {
console.log('specialConditionForGPA function called')
console.log('before if count', count)
if (count === 0) {
console.log('after if count', count)
var index = $('.modifyclassinput').length;
var appendElement = `<div class="form-group col-md-6 form-group-client-policy-masters removeDom">
<div class="col-md-1">
<input type="checkbox" style="margin-top: 12px" name="gpa_special_condition_display[]" id="special_condition_display" class="unchecked" checked>
</div>
<label for="specialconditionlabel" class="special_condition_label[]" style="width: 450px;position: relative;bottom: 6px;">
<input class="form-control" name="gpa_special_condition_label[]" id="gpa_special_condition_label[]" style="position: relative;right: 5px;">
<span class="specialConditionClose" style="color: red; float: right;position: relative;bottom: 28px;left: 15px;">X</span>
</label>
<input type="text" name="gpa_special_condition_input[]" id="gpa_special_condition_input[]" class="form-control s special_condition_input[]">
</div>`;
console.log($(this));
$('.gpa_special_condition').each(function() {
$(this).append(appendElement);
});
} else {
console.log('else')
}
}
$(document).on('click', '#policyGPATermsClose', function() {
//clear the intervel for the autosave
stopAutoSubmit();
$('#policyGPATermsForm').css('display', 'none');
$('#police-tab').css('display', '');
$('.nav.nav-pills.navtab-bg').css('display', '');
$('.nav.nav-pills.navtab-bg').prev().css('display', '');
$('#policyGPATerms')[0].reset();
$('.text-danger-2').html('');
});
$("#sumInsured2").on("keyup", function() {
var inputNumber = $(this).val();
if (inputNumber) {
var result = numberToWordsIndian(inputNumber);
$("#numberToWordSumInsured").text(result);
} else {
$("#numberToWordSumInsured").text("");
}
});
$(".multiple_sum_insured").on("keyup", function() {
console.log('multiple_sum_insured key up')
var inputNumber = $(this).val();
console.log('inputNumber', inputNumber);
if (inputNumber) {
var result = numberToWordsIndian(inputNumber);
console.log(result);
$(".numberToWordSumInsured").text(result);
} else {
$(".numberToWordSumInsured").text("");
}
});
// function numtowordinkeyup(input) {
// console.log('testing......')
// console.log(input);
// var inputNumber = $(input).val();
// console.log('inputNumber', inputNumber);
// if (inputNumber) {
// var result = numberToWordsIndian(inputNumber);
// console.log(result);
// var $parentRow = $(input).closest('.row');
// console.log('$parentRow', $parentRow)
// var $targetDiv = $parentRow.find('.numberToWordSumInsured');
// $targetDiv.text(result)
// console.log('$targetDiv', $targetDiv)
// }
// }
function numtowordinkeyup(input) {
var inputNumber = $(input).val().toString().replace(/,/g, '').trim();
var $parentRow = $(input).closest('.row');
var $targetDiv = $parentRow.find('.numberToWordSumInsured');
if (inputNumber) {
var result = convertCommaNumberToWords(inputNumber);
$targetDiv.text(result);
} else {
$targetDiv.text("");
}
}
$("#totalSumInsured").on("keyup", function() {
var inputNumber = $(this).val();
if (inputNumber) {
var result = convertCommaNumberToWords(inputNumber);
$("#numberToWordTotalSumInsured").text(result);
} else {
$("#numberToWordTotalSumInsured").text("");
}
});
//REF: VR function appendGPASIAddMore(data = null) {
// console.log('appendGPASIAddMore function called')
// console.log('appendGPASIAddMore function data', data)
// var html = `
// <div class="row" style="margin-bottom: 10px;">
// <div class="col">
// <div class="d-flex align-items-center gap-2">
// <label for="sumInsured" class="form-label" >Additional Sum Insured</label>
// <input
// style="max-width:200px;"
// value="${data == null || data == undefined || data == "" ? '' : data}" type="text" name="multiple_sum_insured[]"
// class="form-control multiple_sum_insured mr-2" onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this); numtowordinkeyup(this)">
// <button type="button" class="btn btn-primary si-add-more mr-2" onclick="appendGPASIAddMore()"
// style="background-color: #e26728; border:1px solid #e26728;" >
// <i class="mdi mdi-plus"></i>
// </button>
// <button type="button" class="btn btn-danger si-remove-multi mr-2" onclick="removeGMCAdditionalSI(this)"
// style="background-color: #BD0707;border:1px solid #BD0707">
// <i class="mdi mdi-delete"></i>
// </button>
// <div id='numberToWordSumInsured' class="text-danger-2 "></div>
// </div>
// </div>
// </div>
// `;
// $('#gpa_si_add_more').append(html);
// }
function appendGPASIAddMore(data = null) {
console.log('appendGPASIAddMore function called')
console.log('appendGPASIAddMore function data', data)
var html = `
<div class="row align-items-start mb-2">
<div class="col-md-4">
<label for="sumInsured" class="form-label" >Additional Sum Insured</label>
</div>
<div class="col-md-6">
<div class="d-flex align-items-center gap-2">
<input
style="max-width:200px;"
value="${data == null || data == undefined || data == "" ? '' : data}" type="text" name="multiple_sum_insured[]"
class="form-control multiple_sum_insured mr-2" onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this); numtowordinkeyup(this)">
<button type="button" class="btn btn-primary si-add-more ml-2" onclick="appendGPASIAddMore()"
style="background-color: #e26728; border:1px solid #e26728;" >
<i class="mdi mdi-plus"></i>
</button>
<button type="button" class="btn btn-danger si-remove-multi ml-2" onclick="removeGMCAdditionalSI(this)"
style="background-color: #BD0707;border:1px solid #BD0707">
<i class="mdi mdi-delete"></i>
</button>
</div>
<div class="text-danger-2 mr-2 numberToWordSumInsured"></div>
</div>
</div>`;
$('#gpa_si_add_more').append(html);
}
function inArray(key, array) {
return array.includes(key);
}
function processJsonObject2(jsonObject) {
if (typeof jsonObject !== 'object' || Array.isArray(jsonObject)) {
console.log("jsonObject Input is not a valid object.");
return;
}
$('.unchecked').prop('checked', false);
for (let key in jsonObject) {
if (typeof jsonObject[key] === 'object' && !Array.isArray(jsonObject[key])) {
// console.log('enrollment_display_key');
// console.log(jsonObject[key]);
for (let innerKey in jsonObject[key]) {
const keysToCheck = [
"OPD Treatment Cover",
"Repatriation of Mortal Remains",
"Family Transportation Benefits",
"Fractures / Dislocation / Burns",
"Travel expenses for Medical Treatment",
"Daily cash Allowance",
"Artifical Limb and Prosthesis",
"Air Ambulance",
];
//let base_id = innerKey.replace(/[\s\-\/,&]+/g, '').toLowerCase();
let base_id = innerKey.replace(/[\s\-\/,&]+/g, '');
base_id = base_id.charAt(0).toLowerCase() + base_id.slice(1);
if (keysToCheck.includes(innerKey)) {
// console.log("Key found: " + innerKey);
base_id = innerKey.replace(/[\s\-\/]+/g, '_').toLowerCase();
} else if (innerKey == "Medical Expenses / Medical Extension (IPD)") {
// console.log("Key found: " + innerKey);
base_id = "medical_expenses_medical_extension";
} else if (innerKey == "Terrorism") {
// console.log("Key found: " + innerKey);
base_id = "gpa_terrorism";
}
let display_id = base_id + "_display";
$('#' + display_id).prop('checked', true);
// console.log('display_id : ', display_id);
// console.log($('#' + display_id))
}
} else {
console.log(`${key} is not an object.`);
}
}
}
function disableUnwantedTermsforGPA(jsonObject) {
// alert("Disabling unwanted terms");
gpaFields.forEach(function(key) {
// If key NOT in jsonObject, then hide and disable its associated elements
if (!jsonObject.hasOwnProperty(key)) {
const elements = document.getElementsByName(key);
elements.forEach(element => {
element.style.display = "none";
element.disabled = true;
const label = document.querySelector(`label[for="${element.id}"]`);
if (label) {
label.style.display = "none";
}
const displayElement = document.getElementById(`${element.id}_display`);
if (displayElement) {
displayElement.checked = false;
displayElement.disabled = true;
displayElement.style.display = "none";
}
const rowDiv = element.closest('.row');
if (rowDiv) {
rowDiv.style.display = "none";
}
});
}
});
}
function autoSaveGpaTerms(){
console.log('autoSaveGpaTerms function called');
var form = $('#policyGPATerms')[0];
if (!form) {
console.error("Form #policyGPATerms not found");
return;
}
// Check if form has any data before proceeding
var formData = new FormData(form);
var hasData = false;
for (let [key, value] of formData.entries()) {
console.log("Key:", key, "Value:", value);
if(key == "sumInsured2"){
if (value && value.toString().trim() !== '') {
hasData = true;
break;
}
}
}
if (!hasData) {
console.warn("Form data is empty, skipping auto-save");
return;
}
var specialConditions = [];
$(".removeDom").each(function () {
var isChecked = $(this).find("input[name='gpa_special_condition_display[]']").is(":checked");
if (isChecked) {
var label = $(this).find("input[name='gpa_special_condition_label[]']").val();
var input = $(this).find("input[name='gpa_special_condition_input[]']").val();
specialConditions.push({ [label]: input });
}
});
console.log("gpa_specialConditions", specialConditions);
// var formData = new FormData($('#policyGPATerms')[0]);
var policy_form_action = '<?= base_url("client/terms/gpa_create") ?>';
console.log("policy_form_action", policy_form_action);
formData.append("gpa_special_condition_display_value", JSON.stringify(specialConditions));
$.ajax({
data: formData,
url: policy_form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
console.log('Auto Save Response : ', res);
if (res.status == true) {
showTinyToast();
}else{
console.log('Policy terms Dose Not save', 'Error');
return;
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
function debouncegpa(fn, delay) {
let timeout;
return function () {
clearTimeout(timeout);
timeout = setTimeout(fn, delay);
};
}
$(document).ready(function () {
const form = document.querySelector("#policyGPATerms");
// MutationObserver (always runs)
const observer = new MutationObserver(() => {
$("#policyGPATerms").find("input, select, textarea").each(function () {
if (gpa_auto_save_enable) { // only bind autosave if enabled
if (!$(this).attr("data-observed")) {
const debouncedSave = debouncegpa(autoSaveGpaTerms, 1000);
$(this).on("input change", debouncedSave);
$(this).attr("data-observed", "true");
}
}
});
});
observer.observe(form, { childList: true, subtree: true });
// Bind for existing fields (only if enabled)
if (gpa_auto_save_enable) {
const debouncedSave = debouncegpa(autoSaveGpaTerms, 1000);
$("#policyGPATerms").find("input, select, textarea").each(function () {
$(this).on("input change", debouncedSave);
$(this).attr("data-observed", "true");
});
} else {
console.log("This policy has employee processed (autosave disabled) -- GPA");
}
});
</script>