diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 25d0064f..5449dedb 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1531,77 +1531,82 @@ class ClientController extends AdminController public function updateClientPolicyStatus() { - $client_policy_id = $this->request->getGet('client_policy_id'); - $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); - $message = 'Policy updated Successfully' ; - if($record['open_for_enrollment'] == 0){ - $open_for_enrollment_update_value = 1; - $message = 'Update Open Enrollment Successfully'; - }else if($record['open_for_enrollment'] == 1){ - $open_for_enrollment_update_value = 0; - $message = 'Update Open Enrollment Successfully'; - } - - $data = $this->policesModel->getPolicyPremium($record['policy_id']); - $pattern = '/gmc/i'; - $subject = $data[0]->policy_type; - if (preg_match($pattern, $subject)) { - $search_term = 'GMC'; - } else { - $search_term = 'GPA'; - } - - if($search_term === 'GPA'){ - $racRate = $this->policyPremium1Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults(); - }else if($search_term === 'GMC'){ - $racRate = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults(); - } - - $termsData = $this->clientPolicyModel->where(['id' => $client_policy_id, 'is_active' => 1])->first(); - if(empty($termsData['policy_terms'])){ - return $this->respond(['status' => false,'code' => 200,'message' => 'Please define policy terms '], 200); - } + $client_policy_id = $this->request->getGet('client_policy_id'); + $message = 'Policy updated Successfully'; - $termsData = json_decode($termsData['policy_terms']); + $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); - if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) { - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200); - } + if ($record['open_for_enrollment'] == 0) { + $open_for_enrollment_update_value = 1; + $message = 'Enrollment Opened Successfully'; + } else if ($record['open_for_enrollment'] == 1) { + $open_for_enrollment_update_value = 0; + $message = 'Enrollment Closed Successfully'; + } - if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) { - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Sum Insured field is empty'], 200); - } - - // Check if 'family_floater' key exists and has a value - if (isset($termsData->family_floater) && $termsData->family_floater == null) { - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Family Floater field is empty'], 200); - } - - // Check if 'family_floaters' key exists and has a value - if (isset($termsData->family_floaters) && is_array($termsData->family_floaters) && count($termsData->family_floaters) <= 0) { - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Family Members field is empty'], 200); - $familyFloatersCount = count($termsData->family_floaters); - } + $data = $this->policesModel->getPolicyPremium($record['policy_id']); + $pattern = '/gmc/i'; + $subject = $data[0]->policy_type; + if (preg_match($pattern, $subject)) { + $search_term = 'GMC'; + } else { + $search_term = 'GPA'; + } - if($racRate == 0){ + if ($search_term === 'GPA') { + $racRate = $this->policyPremium1Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults(); + } else if ($search_term === 'GMC') { + $racRate = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults(); + } - return $this->respond(['status' => false,'code' => 200,'message' => 'Please define policy premium'], 200); - } + $termsData = $this->clientPolicyModel->where(['id' => $client_policy_id, 'is_active' => 1])->first(); + if (empty($termsData['policy_terms'])) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'Please define policy terms '], 200); + } - $policy_status = $this->clientPolicyModel->where('id', $client_policy_id )->set('policy_status', 1)->update(); - $json_data =''; - $open_for_enrollment = $this->clientPolicyModel->where('id', $client_policy_id )->set('open_for_enrollment', $open_for_enrollment_update_value)->update(); - if ($open_for_enrollment) { - $open_for_enrollment_1 = $this->clientPolicyModel->where('id', $client_policy_id )->find(); - $open_for_enrollment_value = $open_for_enrollment_1[0]['open_for_enrollment']; - $client_policy_id_value = $client_policy_id; - $json_data = json_encode(['open_for_enrollment' => $open_for_enrollment_value, 'client_policy_id' => $client_policy_id_value]); - } + $termsData = json_decode($termsData['policy_terms']); - return $this->respond(['status' => true,'code' => 200, 'message' => $message, 'data' => $termsData, 'racRate' => $racRate, 'open_for_enrollment' => $json_data], 200); + if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200); + } + if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty'], 200); + } + + // Check if 'family_floater' key exists and has a value + if (isset($termsData->family_floater) && $termsData->family_floater == null) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Family Floater field is empty'], 200); + } + + // Check if 'family_floaters' key exists and has a value + if (isset($termsData->family_floaters) && is_array($termsData->family_floaters) && count($termsData->family_floaters) <= 0) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Family Members field is empty'], 200); + $familyFloatersCount = count($termsData->family_floaters); + } + + if ($racRate == 0) { + + return $this->respond(['status' => false, 'code' => 200, 'message' => 'Please define policy premium'], 200); + } + + // $policy_status = $this->clientPolicyModel->where('id', $client_policy_id )->set('policy_status', 1)->update(); + + $json_data = ''; + $open_for_enrollment = $this->clientPolicyModel->where('id', $client_policy_id)->set('open_for_enrollment', $open_for_enrollment_update_value)->update(); + if ($open_for_enrollment) { + $open_for_enrollment_1 = $this->clientPolicyModel->where('id', $client_policy_id)->find(); + $open_for_enrollment_value = $open_for_enrollment_1[0]['open_for_enrollment']; + $client_policy_id_value = $client_policy_id; + + $json_data = json_encode(['open_for_enrollment' => $open_for_enrollment_value, 'client_policy_id' => $client_policy_id_value]); + } + + + + return $this->respond(['status' => true, 'code' => 200, 'message' => $message, 'data' => $termsData, 'racRate' => $racRate, 'open_for_enrollment' => $json_data, 'client_policy_data' => $record], 200); } diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index e9174cf8..782c000d 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -14,6 +14,7 @@