FEAT_OPD_TERMS

This commit is contained in:
VENKATESHWARAN 2025-12-24 18:51:14 +05:30
parent dc172e5c83
commit 6629b6465e
2 changed files with 392 additions and 41 deletions

View File

@ -4231,7 +4231,7 @@ class ClientController extends AdminController
$record = $this->clientPolicyModel->where('id', $client_policy_id)->first();
// print_r($policy_terms); die;
if(empty($policy_terms)){
if (empty($policy_terms)) {
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Policy terms data could not be empty', 'formdata' => $this->request->getPost()], 200);
}
@ -4239,38 +4239,137 @@ class ClientController extends AdminController
$data = [];
foreach ($policy_terms as $key => $value) {
if ($record['policy_type_id'] == 72) {
if (str_ends_with($key, '_display')) {
$data['sum_insured'] = $policy_terms['sum_insured'] ?? 0;
$data['multiple_sum_insured'] = $policy_terms['multiple_sum_insured'] ?? [];
$data['family_floater'] = $policy_terms['family_floater'] ?? 0;
$data['family_floaters'] = $policy_terms["family_floaters"] ?? [];
$original_key = substr($key, 0, -8);
$data['age_ratio']['self']['min'] = $policy_terms["self_min_age"] ?? 0;
$data['age_ratio']['self']['max'] = $policy_terms["self_max_age"] ?? 0;
$data['age_ratio']['spouse']['min'] = $policy_terms["spouse_min_age"] ?? 0;
$data['age_ratio']['spouse']['max'] = $policy_terms["spouse_max_age"] ?? 0;
$data['age_ratio']['child']['min'] = $policy_terms["child_min_age"] ?? 0;
$data['age_ratio']['child']['max'] = $policy_terms["child_max_age"] ?? 0;
$data['age_ratio']['elders']['min'] = $policy_terms["other_member_min_age"] ?? 0;
$data['age_ratio']['elders']['max'] = $policy_terms["other_member_max_age"] ?? 0;
$newKey = implode(' ', array_map('ucfirst', explode('_', $original_key)));
$temp_family_floaters = $data['family_floaters'];
$data['family_floaters'] = [];
$data['enrollment_display_key'][$newKey] = $policy_terms[$original_key] ?? " ";
if (in_array("self", $temp_family_floaters) == 1) {
$data['family_floaters']['self'] = 1;
} else {
$data['family_floaters']['self'] = 0;
}
$data[$key] = $value;
if (in_array("spouse", $temp_family_floaters) == 1) {
$data['family_floaters']['spouse'] = 1;
} else {
$data['family_floaters']['spouse'] = 0;
}
if (count($temp_family_floaters)) {
$children_value = 0;
$value = 0;
if (count($temp_family_floaters) == 2) {
$children_value = 0;
$value = 1;
} else if (count($temp_family_floaters) == 3) {
$children_value = 1;
$value = 2;
} else {
$children_value = 2;
$value = 3;
}
$data['family_floaters']['childrens'] = (int)$temp_family_floaters[$children_value];
if ($temp_family_floaters[$value] == '1P') {
$data['family_floaters']['parents'] = 1;
$data['family_floaters']['parents-in-law'] = 0;
$data['family_floaters']['either-parents-pil'] = 0;
} else if ($temp_family_floaters[$value] == '2P') {
$data['family_floaters']['parents'] = 2;
$data['family_floaters']['parents-in-law'] = 0;
$data['family_floaters']['either-parents-pil'] = 0;
} else if ($temp_family_floaters[$value] == '1PIL') {
$data['family_floaters']['parents'] = 0;
$data['family_floaters']['parents-in-law'] = 1;
$data['family_floaters']['either-parents-pil'] = 0;
} else if ($temp_family_floaters[$value] == '2PIL') {
$data['family_floaters']['parents'] = 0;
$data['family_floaters']['parents-in-law'] = 2;
$data['family_floaters']['either-parents-pil'] = 0;
} else if ($temp_family_floaters[$value] == '2EPORPIL') {
//Parents or PIL (Any two of Father, Mother, MIl, FIL)
$data['family_floaters']['parents'] = 0;
$data['family_floaters']['parents-in-law'] = 0;
$data['family_floaters']['either-parents-pil'] = 2;
} else if ($temp_family_floaters[$value] == 'EPORPIL') {
//Either Parents or PIL (Parents or Parents In Law)
$data['family_floaters']['parents'] = 0;
$data['family_floaters']['parents-in-law'] = 0;
$data['family_floaters']['either-parents-pil'] = 1;
} else if ($temp_family_floaters[$value] == '4EPORPIL') {
$data['family_floaters']['parents'] = 2;
$data['family_floaters']['parents-in-law'] = 2;
$data['family_floaters']['either-parents-pil'] = 0;
} else {
$data['family_floaters']['parents'] = 0;
$data['family_floaters']['parents-in-law'] = 0;
$data['family_floaters']['either-parents-pil'] = 0;
}
}
$data['family_floaters']['elders_count'] = $this->request->getPost("elder_member_count") ? $this->request->getPost("elder_member_count") : 0;
$data['special_condition_label'] = $policy_terms['special_condition_label'] ?? [];
$data['special_condition_input'] = $policy_terms["special_condition_input"] ?? [];
$data['enrollment_display_key'] = $this->otherPolicyTermsDisplayKeyConstruct($policy_terms);
} else {
foreach ($policy_terms as $key => $value) {
if (str_ends_with($key, '_display')) {
$original_key = substr($key, 0, -8);
$newKey = implode(' ', array_map('ucfirst', explode('_', $original_key)));
$data['enrollment_display_key'][$newKey] = $policy_terms[$original_key] ?? " ";
} else {
$data[$key] = $value;
}
}
}
if($record['policy_type_id'] == 72){
$data['enrollment_display_key'] = $this->otherPolicyTermsDisplayKeyConstruct($policy_terms);
}
if (!empty($data)) {
$policy_terms['is_payable_employee']['self'] = 0;
if ($record['policy_type_id'] == 72) {
$policy_terms['is_payable_employee']['self'] = 0;
$policy_terms['is_payable_employee']['spouse'] = 0;
$policy_terms['is_payable_employee']['childern'] = 0;
$policy_terms['is_payable_employee']['elders'] = 0;
} else {
$policy_terms['is_payable_employee']['self'] = 0;
}
$policy_terms = json_encode($data);
}
$update = $this->clientPolicyModel->where('id', $client_policy_id)->set('policy_terms', $policy_terms)->update();
$update = $this->clientPolicyModel->where('id', $client_policy_id)->set('policy_terms', $policy_terms)->update();
if ($update) {
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Data updated successfully', 'client_policy_id' => $client_policy_id], 200);
} else {
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update data', 'formdata' => $this->request->getPost()], 200);
}
if ($update) {
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Data updated successfully', 'client_policy_id' => $client_policy_id], 200);
} else {
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update data', 'formdata' => $this->request->getPost()], 200);
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to store data the policy therms.', 'formdata' => $this->request->getPost()], 200);
}
} else {
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to store data. The client policy does not exist', 'formdata' => $this->request->getPost()], 200);

View File

@ -114,8 +114,8 @@
<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 mb-2">
<div class="col-md-4">
<div id="familyFloaterDiv_others" class="row">
<div class="col-md-6">
<label class="form-label">Family Floater</label>
</div>
@ -130,11 +130,10 @@
</div>
</div>
<div id="familyFloaterDiv_others_two" class="row" style="margin-bottom: 10px;">
<!-- <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;">
<!-- SELF -->
<div class="d-flex align-items-center policy-base-info">
<input type="checkbox" name="family_floaters[]" value="self" id="self_others" checked>
@ -161,7 +160,6 @@
</div>
</div>
<!-- SPOUSE -->
<div class="d-flex align-items-center policy-base-info">
<input type="checkbox" name="family_floaters[]" value="spouse" id="spouse_others">
@ -188,7 +186,6 @@
</div>
</div>
<!-- CHILDREN -->
<div class="d-flex align-items-center policy-base-info">
<span style="color:black;" class="mr-2">Children:</span>
@ -219,20 +216,19 @@
</div>
</div>
<!-- OTHER MEMBERS -->
<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</option>
<option value="2P">Only two parents</option>
<option value="1PIL">Only one parent in law</option>
<option value="2PIL">Only two parents in law</option>
<option value="2EPORPIL">Parents or PIL (Any two)</option>
<option value="EPORPIL">Either Parents or PIL</option>
<option value="4EPORPIL">Parents + PIL</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>
@ -257,10 +253,150 @@
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">
<div class="other_special_condition" style="margin-top: 10px;">
</div>
@ -437,14 +573,14 @@
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") || key.includes("special_condition_input")) {
if (key.includes("special_condition_label")) {
for (let index = 0; index <
@ -452,6 +588,7 @@
specialConditionForOthers();
}
}
let elements = document.getElementsByName(`${key}[]`);
if (elements) {
@ -470,10 +607,9 @@
});
}
}
if (!key.startsWith("special_condition") && !key.startsWith('multiple_sum_insured') && !key.startsWith("sum_insured") && !key.startsWith("enrollment_display_key")) {
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;">
@ -510,7 +646,6 @@
});
//normal terms fields
let jsonObject = JSON.parse(res.data);
Object.keys(jsonObject).forEach(function(key) {
@ -551,17 +686,134 @@
}
}
});
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) {