nhance/app/Views/other_policy_terms.php
2025-12-24 18:51:14 +05:30

1396 lines
58 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;
}
.other-speciial-condition{
margin-left: 150px;
width: 564px;
}
</style>
<div id="OtherPolicyTermsForm" style="display:none">
<span id="otherPolicyTermsClose" 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="nameOfThePolicyOnOther"></span></label>
</h5>
<form role="form" class="parsley-examples" method="post" id="otherPolicyTerms" 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="other_client_policy_id" />
<input type="hidden" name="policy_id" id="gpa_policy_id" />
<input type="hidden" id="emp_count" />
<div id="sumInsuredDiv" class="row" style="margin-bottom: 10px;">
<div class="col-md-6">
<label for="sumInsured">Sum Insured</label>
</div>
<div class="col-md-4">
<input style="width: 128%;" type="text" name="sum_insureds" id="sum_insured_others" class="form-control" onkeypress="return onlyNumbers(event)" onkeyup=" formatNumber(this); si_keup_num_to_word2(this)">
</div>
<div class="col-md-2" style="position: relative;left: 88px;">
<button type="button" class="btn btn-primary si-add-more" onclick="appendOtherSIAddMore()">+</button>
</div>
<div class="col-md-6">
</div>
<div class="col-md-6">
<div id='numberToWordOthers' class="text-danger-2"></div>
</div>
</div>
<div style="margin-top: 10px;margin-bottom:15px;" id="sum_insured_add_more"></div>
<div id="append_html_for_other_policy_terms"></div>
<div id="familyFloaterDiv_others" class="row">
<div class="col-md-6">
<label class="form-label">Family Floater</label>
</div>
<div class="col-md-6">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="familyFloaterYes_others" name="family_floater" value="1">
<label class="form-check-label" for="familyFloaterYes_others" style="width: 52px !important">Yes</label>
<input class="form-check-input" type="radio" id="familyFloaterNo_others" name="family_floater" value="0">
<label class="form-check-label" for="familyFloaterNo_others">No</label>
</div>
</div>
</div>
<!-- <div id="familyFloaterDiv_others_two" class="row" style="margin-bottom: 10px;">
<div class="col" style="background-color:#F5FFFF;border-radius:10px;box-shadow:0px 2px 2px 0px #00000040;padding:20px;">
<div class="d-flex align-items-center policy-base-info">
<input type="checkbox" name="family_floaters[]" value="self" id="self_others" checked>
<span style="margin-right:150px;color:black;">Self:</span>
<div class="self-age">
<span style="margin-right:10px;color:black;">Min Age:</span>
<input class="underline-input min_age"
type="number"
name="self_min_age"
id="self_min_age_others"
value="<?= isset($self_min_age) && $self_min_age > 0 ? $self_min_age : '18'; ?>"
onchange="lowerIsEighteenOthers(this)">
</div>
<div class="self-age">
<span style="margin-right:10px;color:black;">Max Age:</span>
<input class="underline-input max_age"
type="number"
name="self_max_age"
id="self_max_age_others"
value="<?= isset($self_max_age) ? $self_max_age : '60'; ?>"
onchange="lowerIsEighteenOthers(this)">
</div>
</div>
<div class="d-flex align-items-center policy-base-info">
<input type="checkbox" name="family_floaters[]" value="spouse" id="spouse_others">
<span style="margin-right:125px;color:black;">Spouse:</span>
<div class="spouse-age">
<span style="margin-right:10px;color:black;">Min Age:</span>
<input class="underline-input min_age"
type="number"
name="spouse_min_age"
id="spouse_min_age_others"
value="<?= isset($spouse_min_age) ? $spouse_min_age : '18'; ?>"
onchange="lowerIsEighteenOthers(this)">
</div>
<div class="spouse-age">
<span style="margin-right:10px;color:black;">Max Age:</span>
<input class="underline-input max_age"
type="number"
name="spouse_max_age"
id="spouse_max_age_others"
value="<?= isset($spouse_max_age) ? $spouse_max_age : '60'; ?>"
onchange="lowerIsEighteenOthers(this)">
</div>
</div>
<div class="d-flex align-items-center policy-base-info">
<span style="color:black;" class="mr-2">Children:</span>
<select name="family_floaters[]" id="children_others" class="px-1" style="margin-right:60px;">
<option value="0">None</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<div class="child-age">
<span style="margin-right:10px;color:black;">Min Age:</span>
<input class="underline-input min_age"
type="number"
name="child_min_age"
id="child_min_age_others"
value="<?= isset($child_min_age) ? $child_min_age : '0'; ?>">
</div>
<div class="child-age">
<span style="margin-right:10px;color:black;">Max Age:</span>
<input class="underline-input max_age"
type="number"
name="child_max_age"
id="child_max_age_others"
value="<?= isset($child_max_age) ? $child_max_age : '25'; ?>">
</div>
</div>
<div class="d-flex align-items-center policy-base-info flex-nowrap">
<span class="fw-bold text-dark mr-3"><b>Select Other Members:</b></span>
<select name="family_floaters[]" id="family_floaters_others" class="form-select mr-3 px-1">
<option value="0">None</option>
<option value="1P">Only one parent (Either Father / Mother)</option>
<option value="2P">Only two parents (Father+Mother)</option>
<option value="1PIL">Only one parent in law (Either MIL / FIL)</option>
<option value="2PIL">Only two parents in law (FIL + MIL)</option>
<option value="2EPORPIL">Parents or PIL (Any two of Father, Mother, MIL, FIL)</option>
<option value="EPORPIL">Either Parents or PIL (Parents or Parents In Law)</option>
<option value="4EPORPIL">Parents + PIL (Father + Mother + MIL + FIL)</option>
</select>
<span class="text-dark mr-2">Elders Count:</span>
<input class="underline-input"
type="number"
name="elder_member_count"
id="member_count_others"
readonly>
<span class="text-dark mr-2">Min Age:</span>
<input class="underline-input"
type="number"
name="other_member_min_age"
id="other_member_min_age_others"
value="<?= isset($other_member_min_age) ? $other_member_min_age : '18'; ?>">
<span class="text-dark mr-2">Max Age:</span>
<input class="underline-input"
type="number"
name="other_member_max_age"
id="other_member_max_age_others"
value="<?= isset($other_member_max_age) ? $other_member_max_age : '60'; ?>">
</div>
</div>
</div> -->
<div id="familyFloaterDiv_others_two" class="row mb-3">
<div class="col" style="background-color:#F5FFFF;border-radius:10px;box-shadow:0px 2px 2px 0px #00000040;padding:20px;">
<!-- SELF -->
<div class="row align-items-center mb-2">
<div class="col-md-6">
<input type="checkbox" name="family_floaters[]" value="self" id="self_others" checked>
<span class="text-dark ms-2">Self</span>
</div>
<div class="col-md-3 d-flex align-items-center">
<span class="me-2 text-dark">Min Age</span>
<input class="underline-input min_age w-50"
type="number"
name="self_min_age"
id="self_min_age_others"
value="<?= isset($self_min_age) && $self_min_age > 0 ? $self_min_age : '18'; ?>"
onchange="lowerIsEighteenOthers(this)">
</div>
<div class="col-md-3 d-flex align-items-center">
<span class="me-2 text-dark">Max Age</span>
<input class="underline-input max_age w-50"
type="number"
name="self_max_age"
id="self_max_age_others"
value="<?= isset($self_max_age) ? $self_max_age : '60'; ?>"
onchange="lowerIsEighteenOthers(this)">
</div>
</div>
<!-- SPOUSE -->
<div class="row align-items-center mb-2">
<div class="col-md-6">
<input type="checkbox" name="family_floaters[]" value="spouse" id="spouse_others">
<span class="text-dark ms-2">Spouse</span>
</div>
<div class="col-md-3 d-flex align-items-center">
<span class="me-2 text-dark">Min Age</span>
<input class="underline-input min_age w-50"
type="number"
name="spouse_min_age"
id="spouse_min_age_others"
value="<?= isset($spouse_min_age) ? $spouse_min_age : '18'; ?>"
onchange="lowerIsEighteenOthers(this)">
</div>
<div class="col-md-3 d-flex align-items-center">
<span class="me-2 text-dark">Max Age</span>
<input class="underline-input max_age w-50"
type="number"
name="spouse_max_age"
id="spouse_max_age_others"
value="<?= isset($spouse_max_age) ? $spouse_max_age : '60'; ?>"
onchange="lowerIsEighteenOthers(this)">
</div>
</div>
<!-- CHILDREN -->
<div class="row align-items-center mb-2">
<div class="col-md-2 text-dark">Children</div>
<div class="col-md-4">
<select name="family_floaters[]" id="children_others" class="form-select form-control">
<option value="0">None</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
<div class="col-md-3 d-flex align-items-center">
<span class="me-2 text-dark">Min Age</span>
<input class="underline-input min_age w-50"
type="number"
name="child_min_age"
id="child_min_age_others"
value="<?= isset($child_min_age) ? $child_min_age : '0'; ?>">
</div>
<div class="col-md-3 d-flex align-items-center">
<span class="me-2 text-dark">Max Age</span>
<input class="underline-input max_age w-50"
type="number"
name="child_max_age"
id="child_max_age_others"
value="<?= isset($child_max_age) ? $child_max_age : '25'; ?>">
</div>
</div>
<!-- OTHER MEMBERS -->
<div class="row align-items-center">
<div class="col-md-2 fw-bold text-dark">
Other Members
</div>
<div class="col-md-4">
<select name="family_floaters[]" id="family_floaters_others" class="form-select form-control">
<option value="0">None</option>
<option value="1P">Only one parent (Either Father / Mother)</option>
<option value="2P">Only two parents (Father+Mother)</option>
<option value="1PIL">Only one parent in law (Either MIL / FIL)</option>
<option value="2PIL">Only two parents in law (FIL + MIL)</option>
<option value="2EPORPIL">Parents or PIL (Any two of Father, Mother, MIL, FIL)</option>
<option value="EPORPIL">Either Parents or PIL (Parents or Parents In Law)</option>
<option value="4EPORPIL">Parents + PIL (Father + Mother + MIL + FIL)</option>
</select>
</div>
<div class="col-md-2">
<input class="underline-input w-100"
type="number"
name="elder_member_count"
id="member_count_others"
readonly>
</div>
<div class="col-md-2">
<input class="underline-input w-100"
type="number"
name="other_member_min_age"
id="other_member_min_age_others"
value="<?= isset($other_member_min_age) ? $other_member_min_age : '18'; ?>">
</div>
<div class="col-md-2">
<input class="underline-input w-100"
type="number"
name="other_member_max_age"
id="other_member_max_age_others"
value="<?= isset($other_member_max_age) ? $other_member_max_age : '60'; ?>">
</div>
</div>
</div>
</div>
<div class="other_special_condition" style="margin-top: 10px;">
</div>
<br>
<div class="form-group text-right m-b-0" style="margin-top: -49px;">
<a href="#" class="button-like" id="otherButtonSpecialCondition" title="Special Condition">Special
Condition</a>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="btnOtherTermsSubmit"
style="margin-top: 100px;">Submit</button>
</div>
</form>
</div>
<script>
$("#otherPolicyTerms").submit(function(event) {
event.preventDefault();
var isValid = $('#otherPolicyTerms').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;
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var formData = new FormData($('#otherPolicyTerms')[0]);
var policy_form_action = '<?= base_url("client/terms/other_terms") ?>';
// Convert the FormData object to a JSON object
const formObject = {};
formData.forEach((value, key) => {
if (key != 'csrf_test_name' && key != 'client_policy_id' && key != 'policy_id' && key !=
'client_id') {
if (key.endsWith('[]')) {
const baseKey = key.slice(0, -2);
if (!formObject[baseKey]) {
formObject[baseKey] = [];
}
formObject[baseKey].push(value.replace(/,/g, ''));
} else if (key == 'sum_insureds') {
formObject['sum_insured'] = value.replace(/,/g, '');
} else {
formObject[key] = value;
}
}
});
console.log("formObject : ", formObject);
const jsonString = JSON.stringify(formObject);
console.log(jsonString);
// return;
// Append the JSON string to the FormData object
formData.append('policy_terms', jsonString);
formData.forEach((value, key) => {
console.log(key + ': ' + value);
});
$.ajax({
data: formData,
url: policy_form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#otherPolicyTerms')[0].reset();
$('.text-danger-2').html('');
console.log(res);
if (res.status === false) {
toastr.error(res.message, 'Error');
return;
}
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
location.reload();
},
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');
$('#OtherPolicyTermsForm').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);
});
var policy_type_id = "";
var other_auto_save_enable = false;
$('body').on('click', '.btnPolicyMaster', function() {
$("#append_html_for_other_policy_terms").empty();
var client_policy_id = $(this).data('id');
policy_type_id = $(this).data('typeid');
console.log('policy_type_id', policy_type_id);
console.log('client_policy_id :', client_policy_id);
$('#other_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 (policy_type_id > 5) {
$('#OtherPolicyTermsForm').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('response of the other policy terms', res);
console.log('employee count', res.emp_count_by_policy);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 500);
// $('#nameOfThePolicyOnOther').html(' - ' + res.policy_name.name);
$('#emp_count').val(res.count)
if (res.emp_count_by_policy != 0) {
$("#btnOtherTermsSubmit").hide();
$("#otherButtonSpecialCondition").hide();
other_auto_save_enable = false;
} else {
$("#btnOtherTermsSubmit").show();
$("#otherButtonSpecialCondition").show();
// startAutoSubmit('OTHERS');
other_auto_save_enable = true;
}
if (res.data) {
//special conditions fields
let otherTermsJsonObjectSpecialCondition = JSON.parse(res.data);
Object.keys(otherTermsJsonObjectSpecialCondition).forEach(function(key) {
if (key.includes("special_condition_label") || key.includes("special_condition_input")) {
if (key.includes("special_condition_label")) {
for (let index = 0; index <
otherTermsJsonObjectSpecialCondition[key].length; index++) {
specialConditionForOthers();
}
}
let elements = document.getElementsByName(`${key}[]`);
if (elements) {
elements.forEach((element, index) => {
if (otherTermsJsonObjectSpecialCondition[key][
index
] == undefined) {
element.value = " ";
} else {
element.value =
otherTermsJsonObjectSpecialCondition[key][
index
];
}
});
}
}
if (policy_type_id != 72 && !key.startsWith("special_condition") && !key.startsWith('multiple_sum_insured') && !key.startsWith("sum_insured") && !key.startsWith("enrollment_display_key")) {
termsHTML = `
<div class="row" style="margin-bottom: 10px;">
<div class="col-md-1">
<input type="checkbox" style="margin-top: 12px" name="${key}_display"
id="${key}_display" class="unchecked" checked>
</div>
<div class="col-md-5">
<label for="${key}">${beautifyString(key)}</label>
</div>
<div class="col-md-6">
<input type="text" name="${key}" id="${key}" class="form-control">
</div>
</div>
`
$("#append_html_for_other_policy_terms").append(termsHTML);
}
if (key.includes("multiple_sum_insured")) {
const value = otherTermsJsonObjectSpecialCondition[key];
if (Array.isArray(value)) {
value.forEach(item => appendOtherSIAddMore(item));
} else if (typeof value === 'object' && value !== null) {
Object.values(value).forEach(item => appendOtherSIAddMore(item));
}
// else if (typeof value === 'string') {
// appendOtherSIAddMore(value); // Use directly, no loop
// }
}
});
//normal terms fields
let jsonObject = JSON.parse(res.data);
Object.keys(jsonObject).forEach(function(key) {
console.log(key)
let elements = document.getElementsByName(key);
if (key == 'sum_insured') {
elements = document.getElementsByName('sum_insureds')
}
console.log(elements)
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) {
element.value = " ";
} else {
element.value = jsonObject[key];
console.log(element);
console.log(jsonObject[key]);
console.log(element.value);
}
}
}
if(policy_type_id == 72){
if(key == "family_floater"){
if(jsonObject[key] == 1){
$('#familyFloaterYes_others').prop('checked', true);
} else {
$('#familyFloaterNo_others').prop('checked', true);
}
}
if (key.includes("family_floaters")) {
let checkboxes = document.querySelectorAll(`input[name="${key}[]"]`);
if (jsonObject[key]) {
console.log(jsonObject[key]);
if (jsonObject[key].childrens) {
$('#children_others').val(jsonObject[key].childrens);
}
if (jsonObject[key].self == 0) {
$('#self_others').prop('checked', false);
}
if (jsonObject[key].spouse == 0) {
$('#spouse_others').prop('checked', false);
} else {
$('#spouse_others').prop('checked', true);
}
if (jsonObject[key]['either-parents-pil'] == 1) {
$('#family_floaters_others').val('EPORPIL');
} else if (jsonObject[key].parents == 1 && jsonObject[key][
'parents-in-law'
] == 1) {
$('#family_floaters_others').val('2EPORPIL');
} else if (jsonObject[key].parents == 2 && jsonObject[key][
'parents-in-law'
] == 2) {
$('#family_floaters_others').val('4EPORPIL');
} else if (jsonObject[key].parents == 1) {
$('#family_floaters_others').val('1P');
} else if (jsonObject[key].parents == 2) {
$('#family_floaters_others').val('2P');
} else if (jsonObject[key]['parents-in-law'] == 1) {
$('#family_floaters_others').val('1PIL');
} else if (jsonObject[key]['parents-in-law'] == 2) {
$('#family_floaters_others').val('2PIL');
} else if (jsonObject[key]['either-parents-pil'] == 2) {
$('#family_floaters_others').val('2EPORPIL');
}
}
}
if (key.includes("age_ratio")) {
$('#self_min_age_others').val(jsonObject[key].self.min);
$('#self_max_age_others').val(jsonObject[key].self.max);
$('#spouse_min_age_others').val(jsonObject[key].spouse.min);
$('#spouse_max_age_others').val(jsonObject[key].spouse.max);
$('#child_min_age_others').val(jsonObject[key].child.min);
$('#child_max_age_others').val(jsonObject[key].child.max);
$('#other_member_min_age_others').val(jsonObject[key].elders.min);
$('#other_member_max_age_others').val(jsonObject[key].elders.max);
}
}
});
} else {
appendPolicyTermsHTML(policy_type_id);
}
$('#sum_insured_others').trigger('keyup');
$(".multiple_sum_insured").trigger("keyup");
if(policy_type_id == 72) {
if ($('#self_others').prop('checked')) {
$('.self-age').css('display', '');
} else {
$('.self-age').css('display', 'none');
}
if ($('#spouse_others').prop('checked')) {
$('.spouse-age').css('display', '');
} else {
$('.spouse-age').css('display', 'none');
}
if ($('#children_others').val() != 0) {
$('.child-age').css('display', '');
} else {
$('.child-age').css('display', 'none');
}
var family_floaters = $('#family_floaters_others').val();
console.log("family_floaters_others", family_floaters);
if (family_floaters != 0) {
$('.other-member-age').css('display', '');
} else {
$('.other-member-age').css('display', 'none');
}
if (family_floaters == '1P') {
$('#member_count_others').val(1);
} else if (family_floaters == '2P') {
$('#member_count_others').val(2);
} else if (family_floaters == '1PIL') {
$('#member_count_others').val(1);
} else if (family_floaters == '2PIL') {
$('#member_count_others').val(2);
} else if (family_floaters == '2EPORPIL') {
$('#member_count_others').val(2);
} else if (family_floaters == 'EPORPIL') {
$('#member_count_others').val(2);
} else if (family_floaters == '4EPORPIL') {
$('#member_count_others').val(4);
}
}
},
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');
}
});
}
if (policy_type_id > 7 && policy_type_id != 72) {
$("#sumInsuredDiv").empty();
}
if(policy_type_id != 72){
$("#familyFloaterDiv_others").empty();
$("#familyFloaterDiv_others_two").empty();
}
});
</script>
<script>
document.getElementById('otherButtonSpecialCondition').addEventListener('click', function(event) {
console.log('specialConditionForOthers callback clicked')
event.preventDefault();
specialConditionForOthers();
});
function specialConditionForOthers(count = 0) {
console.log('specialConditionForOthers 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">
<label for="specialconditionlabel" class="special_condition_label[]" style="width: 450px;position: relative;bottom: 6px;">
<input class="form-control" name="special_condition_label[]" id="special_condition_label[]" style="position: relative;right: 0px;">
<span class="specialConditionClose" style="color: red; float: right;position: relative;bottom: 28px;left: 15px;">X</span>
</label>
<input type="text" name="special_condition_input[]" id="special_condition_input[]" class="form-control other-speciial-condition special_condition_input[]">
</div>`;
console.log($(this));
$('.other_special_condition').each(function() {
$(this).append(appendElement);
});
} else {
console.log('else')
}
}
$(document).on('click', '#otherPolicyTermsClose', function() {
//clear the intervel for the autosave
stopAutoSubmit();
$('#OtherPolicyTermsForm').css('display', 'none');
$('#police-tab').css('display', '');
$('.nav.nav-pills.navtab-bg').css('display', '');
$('.nav.nav-pills.navtab-bg').prev().css('display', '');
$('#otherPolicyTerms')[0].reset();
$('.text-danger-2').html('');
});
$("#sum_insured_others").on("keyup", function() {
var inputNumber = $(this).val();
console.log('sum_insured_others keyup', inputNumber)
if (inputNumber) {
var result = convertCommaNumberToWords(inputNumber);
$("#numberToWordOthers").text(result);
} else {
$("#numberToWordOthers").text("");
}
});
$("#totalSumInsured").on("keyup", function() {
var inputNumber = $(this).val();
if (inputNumber) {
var result = convertCommaNumberToWords(inputNumber);
$("#numberToWordTotalSumInsured").text(result);
} else {
$("#numberToWordTotalSumInsured").text("");
}
});
function si_keup_num_to_word2(input) {
console.log('keyup sum insured');
var inputNumber = $(input).val();
console.log(inputNumber)
if (inputNumber) {
var result = convertCommaNumberToWords(inputNumber);
$("#numberToWordOthers").text(result);
} else {
$("#numberToWordOthers").text("");
}
};
function appendPolicyTermsHTML(policy_type) {
var termsHTML = ""
$('#append_html_for_other_policy_terms').empty();
if (policy_type == 7) {
// <div class="row" style="margin-bottom: 10px;">
// <div class="col-md-6">
// <label for="sumInsured">Sum Insured</label>
// </div>
// <div class="col-md-4">
// <input style="width: 128%;" type="text" name="sum_insureds" id="sum_insured_others" class="form-control" onkeypress = "return onlyNumbers(event)" onkeyup=" formatNumber(this); si_keup_num_to_word2(this)">
// </div>
// <div class="col-md-2" style="position: relative;left: 88px;">
// <button type="button" class="btn btn-primary si-add-more" onclick="appendOtherSIAddMore()">+</button>
// </div>
// <div class="col-md-6">
// </div>
// <div class="col-md-6">
// <div id='numberToWordOthers' class="text-danger-2" ></div>
// </div>
// </div>
// <div id="sum_insured_add_more" ></div>
termsHTML = `
<div class="form-group">
<div class="row" style="margin-bottom: 10px;">
<div class="col-md-6">
<label for="totalSumInsured">Policy Type</label>
</div>
<div class="col-md-6">
<input type="text" name="policy_type" id="policy_type" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;">
<div class="col-md-6">
<label for="totalSumInsured">Existing Insurer</label>
</div>
<div class="col-md-6">
<input type="text" name="existing_insurer" id="existing_insurer" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;">
<div class="col-md-6">
<label for="renewal_lives">Renewal Lives</label>
</div>
<div class="col-md-6">
<input type="text" name="renewal_lives" id="renewal_lives" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;">
<div class="col-md-6">
<label for="totalSumInsured">Total Sum Assured</label>
</div>
<div class="col-md-6">
<input type="text" style="width: 100% !important;" class="form-control" name="total_sum_insured"
id="total_sum_insured" onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this)">
</div>
<div class="col-md-6">
</div>
<div class="col-md-6">
<div id='numberToWordTotalSumInsured' class="text-danger-2"></div>
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="lives_at_inception">Lives at Inception</label>
</div>
<div class="col-md-6">
<input type="text" name="lives_at_inception" id="lives_at_inception" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="totalSumInsured">Total Sum Insured at Inception</label>
</div>
<div class="col-md-6">
<input type="text" name="total_sum_insured_at_inception" id="total_sum_insured_at_inception"
class="form-control" onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this)">
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="totalSumInsured">Premium at Inception (Excl GST)</label>
</div>
<div class="col-md-6">
<input type="text" name="premium_at_inception" id="premium_at_inception" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="coverage">Coverage</label>
</div>
<div class="col-md-6">
<input type="text" name="coverage " id="coverage" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="free_cover_limit">Free Cover Limit</label>
</div>
<div class="col-md-6">
<input type="text" name="free_cover_limit" id="free_cover_limit" class="form-control">
</div>
</div>
</div>
`
} else if (policy_type == 6) {
// <div class="row" style="margin-bottom: 10px;">
// <div class="col-md-6">
// <label for="sumInsured">Sum Insured</label>
// </div>
// <div class="col-md-4" >
// <input style="width: 128%;" type="text" name="sum_insureds" id="sum_insured_others" class="form-control" onkeypress = "return onlyNumbers(event)" onkeyup=" formatNumber(this); si_keup_num_to_word2(this)">
// </div>
// <div class="col-md-2" style="position: relative;left: 88px;">
// <button type="button" class="btn btn-primary si-add-more" onclick="appendOtherSIAddMore()">+</button>
// </div>
// <div class="col-md-6">
// </div>
// <div class="col-md-6">
// <div id='numberToWordOthers' class="text-danger-2" ></div>
// </div>
// </div>
// <div id="sum_insured_add_more" ></div>
termsHTML = `
<div class="form-group EDLI">
<div class="row" style="margin-bottom: 10px;">
<div class="col-md-6">
<label for="totalSumInsured">Existing Insurer</label>
</div>
<div class="col-md-6">
<input type="text" name="existing_insurer" id="existing_insurer" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;">
<div class="col-md-6">
<label for="renewal_lives">Renewal Lives</label>
</div>
<div class="col-md-6">
<input type="text" name="renewal_lives" id="renewal_lives" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="lives_at_inception">Lives at Inception</label>
</div>
<div class="col-md-6">
<input type="text" name="lives_at_inception" id="lives_at_inception" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="totalSumInsured">Total Sum Insured at Inception</label>
</div>
<div class="col-md-6">
<input type="text" name="total_sum_insured_at_inception" id="total_sum_insured_at_inception"
class="form-control" onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this)">
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="coverage">Coverage</label>
</div>
<div class="col-md-6">
<input type="text" name="coverage " id="coverage" class="form-control">
</div>
</div>
<div class="row" style="margin-bottom: 10px;display:true;">
<div class="col-md-6">
<label for="free_cover_limit">Free Cover Limit for Base Cover</label>
</div>
<div class="col-md-6">
<input type="text" name="free_cover_limit_for_base_cover" id="free_cover_limit_for_base_cover" class="form-control">
</div>
</div>
</div>
`
}
$('#append_html_for_other_policy_terms').append(termsHTML);
}
function appendOtherSIAddMore(data = null) {
const addMoreContainer = document.getElementById('sum_insured_add_more');
// addMoreContainer.innerHTML = ''; // Clear previous content if needed
console.log(addMoreContainer)
const html = `
<div class="row">
<div class="col-md-6">
<label for="sumInsured">Additional Sum Insured</label>
</div>
<div class="col-md-4">
<input style="width: 128%;" value="${data ? data : ''}" type="text" name="multiple_sum_insured[]" class="form-control multiple_sum_insured" onkeypress="return onlyNumbers(event)" onkeyup="formatNumber(this); numtowordinkeyup(this)">
</div>
<div class="col-md-2" style="position: relative;left: 88px;">
<button type="button" class="btn btn-primary si-add-more" onclick="appendOtherSIAddMore()">+</button>
<button type="button" class="btn btn-danger si-remove-multi" onclick="removeGMCAdditionalSI(this)">x</button>
</div>
<div class="col-md-6">
</div>
<div class="col-md-6">
<div class="text-danger-2 numberToWordSumInsured"></div>
</div>
</div>`;
addMoreContainer.insertAdjacentHTML('beforeend', html);
}
function beautifyString(str) {
return str
.split('_') // Split the string by underscores
.map(word =>
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() // Capitalize each word
)
.join(' '); // Join with spaces instead of underscores
}
function autoSaveOtherTerms() {
console.log('autoSaveOtherTerms function called');
// var formData = new FormData($('#otherPolicyTerms')[0]);
// console.log("formData", formData);
var form = $('#otherPolicyTerms')[0];
if (!form) {
console.error("Form #otherPolicyTerms 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 == "sum_insureds") {
if (value && value.toString().trim() !== '') {
hasData = true;
break;
}
}
}
if (!hasData) {
console.warn("Form data is empty, skipping auto-save");
return;
}
var policy_form_action = '<?= base_url("client/terms/other_terms") ?>';
console.log("policy_form_action", policy_form_action);
// Convert the FormData object to a JSON object
const formObject = {};
formData.forEach((value, key) => {
if (key != 'csrf_test_name' && key != 'client_policy_id' && key != 'policy_id' && key !=
'client_id') {
if (key.endsWith('[]')) {
const baseKey = key.slice(0, -2);
if (!formObject[baseKey]) {
formObject[baseKey] = [];
}
formObject[baseKey].push(value.replace(/,/g, ''));
} else if (key == 'sum_insureds') {
formObject['sum_insured'] = value.replace(/,/g, '');
} else {
formObject[key] = value;
}
}
});
console.log("formObject : ", formObject);
const jsonString = JSON.stringify(formObject);
console.log('jsonString', jsonString);
// Append the JSON string to the FormData object
formData.append('policy_terms', jsonString);
// formData.forEach((value, key) => {
// console.log(key + ': ' + value);
// });
$.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 debounceothers(fn, delay) {
let timeout;
return function() {
clearTimeout(timeout);
timeout = setTimeout(fn, delay);
};
}
$(document).ready(function() {
const form = document.querySelector("#otherPolicyTerms");
// MutationObserver (always runs)
const observer = new MutationObserver(() => {
$("#otherPolicyTerms").find("input, select, textarea").each(function() {
if (other_auto_save_enable) { // only bind autosave if enabled
if (!$(this).attr("data-observed")) {
const debouncedSave = debounceothers(autoSaveOtherTerms, 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 (other_auto_save_enable) {
const debouncedSave = debounceothers(autoSaveOtherTerms, 1000);
$("#otherPolicyTerms").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) -- OTHERS");
}
});
$('#self_others').change(function() {
if ($(this).prop('checked')) {
$('.self-age').css('display', '');
} else {
$('.self-age').css('display', 'none');
}
});
$('#spouse_others').change(function() {
console.log('spouse changed')
if ($(this).prop('checked')) {
$('.spouse-age').css('display', '');
if ($('#spouse_min_age_others').val() < 17 || $('#spouse_min_age_others').val() == '') {
$('#spouse_min_age_others').val(18);
}
if ($('#spouse_max_age_others').val() < 17 || $('#spouse_max_age_others').val() == '') {
$('#spouse_max_age_others').val(60);
}
} else {
$('.spouse-age').css('display', 'none');
}
});
$('#children_others').change(function() {
if ($(this).val() != 0) {
$('.child-age').css('display', '');
if ($('#child_min_age_others').val() < 0 || $('#child_min_age_others').val() == '') {
$('#child_min_age_others').val(0);
}
if ($('#child_max_age_others').val() < 24 || $('#child_max_age_others').val() == '') {
$('#child_max_age_others').val(25);
}
} else {
$('.child-age').css('display', 'none');
}
});
$('#family_floaters_others').change(function() {
checkAdditionPremiumJSON()
var family_floaters = $(this).val();
if ($('#family_floaters').val() != 0) {
$('.other-member-age').css('display', '');
if ($('#other_member_min_age_others').val() < 17 || $('#other_member_min_age_others').val() == '') {
$('#other_member_min_age_others').val(18);
}
if ($('#other_member_max_age_others').val() < 79 || $('#other_member_max_age_others').val() == '') {
$('#other_member_max_age_others').val(60);
}
} else {
$('.other-member-age').css('display', 'none');
}
if (family_floaters == '1P') {
$('#member_count_others').val(1);
} else if (family_floaters == '2P') {
$('#member_count_others').val(2);
} else if (family_floaters == '1PIL') {
$('#member_count_others').val(1);
} else if (family_floaters == '2PIL') {
$('#member_count_others').val(2);
} else if (family_floaters == '2EPORPIL') {
$('#member_count_others').val(2);
} else if (family_floaters == 'EPORPIL') {
$('#member_count_others').val(2);
} else if (family_floaters == '4EPORPIL') {
$('#member_count_others').val(4);
}
});
function lowerIsEighteenOthers(params) {
var value = $(params).val();
if (value < 18) {
$(params).val(18);
} else if (value > 99) {
$(params).val(99);
}
}
</script>