diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 86556e52..ba3da3d8 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1907,7 +1907,7 @@ class ClientController extends AdminController "sum_insured" => "Sum Insured", "family_floater" => "Family Floater", "family_floaters" => "Family Floaters", - "member_count" => "Elders Count:", + "elders_count" => "Elders Count:", "other_member_min_age" => "Min Age:", "other_member_max_age" => "Min Age:", "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases", @@ -2067,19 +2067,27 @@ class ClientController extends AdminController } else if (array_key_exists($key, $mapping)) { $transformedData[$mapping[$key]] = $value; } else if ($key == 'special_condition_label') { - - foreach ($value as $key => $value) { - $transformedData[$value] = $data['special_condition_input'][$key]; + + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['special_condition_input'][$key]; + } } - } else if ($key == 'gpa_special_condition_label') { - foreach ($value as $key => $value) { - $transformedData[$value] = $data['gpa_special_condition_input'][$key]; + } else if ($key == 'gpa_special_condition_label') { + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['gpa_special_condition_input'][$key]; + } + } + } else if ($key == 'other_special_condition_label') { + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['other_special_condition_label'][$key]; + } } } else if ($key == 'age_ratio') { - if (isset($data['sumInsured2'])) { - $transformedData['Self'] = "(Min: " . $data['age_ratio']['self']['min'] . ", Max: " . $data['age_ratio']['self']['max'] . ")"; } } else { @@ -2217,23 +2225,52 @@ class ClientController extends AdminController } - public function getPolicyTerms($client_policy_id){ - + public function getPolicyTerms($client_policy_id) + { $policy_terms = $this->clientPolicyModel->where('id', $client_policy_id)->first(); - - if(isset($policy_terms['policy_terms']) && $policy_terms['policy_terms'] != null){ - - $JSON = json_decode($policy_terms['policy_terms']); - $si = $JSON->sum_insured ?? $JSON->sumInsured2; - $multi_si = $JSON->multiple_sum_insured; - $multi_si[] = $si; - }else{ - $$multi_si = []; + + if (!$policy_terms) { + return $this->respond(['status' => false, 'error' => 'Policy not found'], 404); } - - return $this->respond(['status' => true, 'data'=>$multi_si], 200); + + if (is_array($policy_terms)) { + if (!isset($policy_terms['policy_terms'])) { + return $this->respond(['status' => false, 'error' => 'Policy terms not found in array'], 500); + } + $JSON = json_decode($policy_terms['policy_terms']); + } elseif (is_object($policy_terms)) { + if (!isset($policy_terms->policy_terms)) { + return $this->respond(['status' => false, 'error' => 'Policy terms not found in object'], 500); + } + $JSON = json_decode($policy_terms->policy_terms); + } else { + return $this->respond(['status' => false, 'error' => 'Unexpected data type for policy terms'], 500); + } + + if (!$JSON) { + return $this->respond(['status' => false, 'error' => 'Invalid JSON format in policy terms'], 500); + } + + $multi_si = []; + + if (isset($JSON->sum_insured) && !empty($JSON->sum_insured)) { + $multi_si[] = $JSON->sum_insured; + } elseif (isset($JSON->sumInsured2) && !empty($JSON->sumInsured2)) { + $multi_si[] = $JSON->sumInsured2; + } + + if (isset($JSON->multiple_sum_insured) && is_array($JSON->multiple_sum_insured)) { + foreach ($JSON->multiple_sum_insured as $msi) { + if (!empty($msi)) { + $multi_si[] = $msi; + } + } + } + + return $this->respond(['status' => true, 'data' => $multi_si], 200); } - + + public function getPolicyTermsFormJson($policy_type_id){ diff --git a/app/Views/client_info.php b/app/Views/client_info.php index f029a2b0..9eebe82d 100644 --- a/app/Views/client_info.php +++ b/app/Views/client_info.php @@ -270,18 +270,30 @@ $(document).ready(function() { $(document).on('click', '.policy_terms', function() { var terms = $(this).data('id'); console.log(terms); + console.log(JSON.stringify(terms)); // terms = JSON.parse(terms); $('#modal_body').empty(); function createListItems(obj) { + const fragment = document.createDocumentFragment(); for (const key in obj) { - if (obj.hasOwnProperty(key) && obj[key] !== null && obj[key] !== '' && key != - 'family_floater' && key != 'gpa_special_condition_input' && key != - 'gpa_special_condition_label' && key != 'special_condition_label' && key != - 'special_condition_input' && key != 'age_ratio') { + if ( + obj.hasOwnProperty(key) && + obj[key] !== null && + obj[key] !== '' && + key != 'family_floater' && + key != 'family_floater' && + key != 'gpa_special_condition_input' && + key != 'gpa_special_condition_label' && + key != 'special_condition_label' && + key != 'special_condition_input' && + key != 'age_ratio' && + key != "multiple_sum_insured" && + key != "other_special_condition_label" && + key != "other_special_condition_input") { const listItem = document.createElement('li'); @@ -326,6 +338,7 @@ $(document).on('click', '.policy_terms', function() { } $('#modal_body').append(createListItems(terms)); + }); \ No newline at end of file diff --git a/app/Views/other_policy_terms.php b/app/Views/other_policy_terms.php index 6e1160c2..d21d40c4 100644 --- a/app/Views/other_policy_terms.php +++ b/app/Views/other_policy_terms.php @@ -78,7 +78,8 @@ label { x -