diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 89069011..db355961 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -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); diff --git a/app/Views/other_policy_terms.php b/app/Views/other_policy_terms.php index 5174a53c..8e0b4360 100755 --- a/app/Views/other_policy_terms.php +++ b/app/Views/other_policy_terms.php @@ -114,8 +114,8 @@
-
-
+
+
@@ -130,11 +130,10 @@
-
+
@@ -161,7 +160,6 @@
-
@@ -188,7 +186,6 @@
-
Children: @@ -219,20 +216,19 @@
-
Select Other Members: Elders Count: @@ -257,10 +253,150 @@ value="">
+ + --> + +
+
+ + +
+
+ + Self +
+ +
+ Min Age + +
+ +
+ Max Age + +
+
+ + +
+
+ + Spouse +
+ +
+ Min Age + +
+ +
+ Max Age + +
+
+ + +
+
Children
+ +
+ +
+ +
+ Min Age + +
+ +
+ Max Age + +
+
+ + +
+
+ Other Members +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+
-
+ +
@@ -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 = `
@@ -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) {