diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 0503143e..ba3da3d8 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -2227,33 +2227,50 @@ class ClientController extends AdminController 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 = null; - if (isset($JSON->sum_insured) && !empty($JSON->sum_insured)) { - $si = $JSON->sum_insured; - } elseif (isset($JSON->sumInsured2) && !empty($JSON->sumInsured2)) { - $si = $JSON->sumInsured2; - } - - if ($si !== null) { - $multi_si = $JSON->multiple_sum_insured ?? []; - $multi_si[] = $si; - } else { - $multi_si = []; - } - } else { - $multi_si = []; + + if (!$policy_terms) { + return $this->respond(['status' => false, 'error' => 'Policy not found'], 404); } - + + 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 bcad4293..9eebe82d 100644 --- a/app/Views/client_info.php +++ b/app/Views/client_info.php @@ -280,10 +280,20 @@ $(document).on('click', '.policy_terms', function() { 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' && key != "multiple_sum_insured" && key != "other_special_condition_label" && key != "other_special_condition_input") { + 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'); diff --git a/app/Views/policy_gmc_terms.php b/app/Views/policy_gmc_terms.php index a28f44df..28ff4417 100644 --- a/app/Views/policy_gmc_terms.php +++ b/app/Views/policy_gmc_terms.php @@ -507,7 +507,7 @@