From 395faecd8704d320edc7f202720ca1479f51289c Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 4 Apr 2024 12:01:53 +0530 Subject: [PATCH] GWM:CHANGES:IN:AddOnPolicyApi --- app/Config/Routes.php | 1 + app/Controllers/EmployeeRestController.php | 291 ++++++++++++--------- 2 files changed, 171 insertions(+), 121 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 063d233a..497ecd21 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -245,6 +245,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getEmployeeAndDependenceByClientId", "EmployeeRestController::getEmployeeAndDependenceByClientId"); $routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy"); $routes->get("getClientDetails", "EmployeeRestController::getClientDetails"); + $routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy"); }); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 39388b35..be0ddc93 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -998,133 +998,13 @@ public function FloterNotesConvertion($array){ return $result; } - -// public function getClientDetails() -// { -// // try { - -// $client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first(); -// // Retrieve employee and dependents data by passing the employee code -// $employeeData = $this->employeeModel->where('emp_code','EMP001-K1')->where('is_addon_value',0)->findAll(); -// $addOnEmployeeData = $this->employeeModel->where('emp_code','EMP001-K1')->where('is_addon_value',1)->findAll(); -// if($client) { -// $client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo']; -// $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll(); -// $PolicyData = []; -// foreach ($clientPolicy as $key => $array) { -// // Reset employee array -// $empData = $employeeData; - -// $decodedArray = json_decode($array['policy_terms']); -// $policy_terms = $decodedArray; -// $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']); -// // print_r($getSlabAndGridData);die; -// $data['SlabRates'] = $getSlabAndGridData['slab_rates']; -// $data['GridMaster'] = $getSlabAndGridData['grid_master']; -// $data['client_id'] = $array['client_id']; -// $data['client_policy_id'] = $array['id']; -// $data['is_addon'] = $array['is_addon']; -// $data['open_for_enrollment'] = $array['open_for_enrollment']; -// $data['policy_terms'] = $decodedArray; - -// // Map family floaters that already exist in the employee table -// $familyFloates = $policy_terms->family_floaters; -// // Generate Notes string based on familyFloates terms -// $array['notes'] = $this->FloterNotesConvertion($familyFloates); -// // Convert familyFloaters terms data to plain array -// $floters = $this->FloterConvertion($familyFloates); -// print_r($familyFloates); -// print_r($floters); - -// $data1 = []; -// foreach ($floters as $familyFloatesValue) { -// $dependent = preg_replace('/\d/', '', $familyFloatesValue); -// if(count($addOnEmployeeData)){ -// foreach ($addOnEmployeeData as $key => $value) { -// if ($value['family_floater_key'] === $dependent) { -// $temp['is_value_exist'] = true; -// $temp['data']['family_floater_key'] = $familyFloatesValue; -// $temp['data']['employee_id'] = $value['id']; -// $temp['data']['relationship'] = $value['relationship']; -// $temp['data']['name'] = $value['name']; -// $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); -// $temp['data']['client_policy_id'] = $array['id']; -// $temp['data']['form_type'] = $dependent; -// array_push($data1,$temp); -// unset($addOnEmployeeData[$key]); -// $floters = array_diff($floters, [$familyFloatesValue]); -// break; -// } -// } -// } -// } - - -// //Remove Unwanted floter key from floters array based on either-parents-pil term value -// if($familyFloates->{'either-parents-pil'} == 1 && count($floters)) -// { -// if(count($addOnEmployeeData) == 0) -// { -// $GMCEmpData = $this->employeeModel->where('emp_code','EMP001-K1') -// ->where('is_addon_value',0) -// ->where('family_floater_key','parent') -// ->findAll(); -// if(count($GMCEmpData)){ -// $floters = array_diff($floters, [$familyFloatesValue]); -// } -// } -// $count_parent = 0; -// $count_parent_in_law = 0; -// foreach ($floters as $value) { -// if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } -// if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} -// } -// if($count_parent != 2) { -// $floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false); -// } -// if($count_parent_in_law != 2) { -// $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false); -// } -// } - - -// print_r($floters); -// // Add family floter buttons placement data for FE validation -// if(count($floters)){ -// foreach ($floters as $familyFloatesValue) { - -// $temp2['is_value_exist'] = false; -// $temp2['data']['family_floater_key'] = $familyFloatesValue; -// $temp2['data']['client_policy_id'] = $array['id']; -// $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); -// $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); - -// array_push($data1,$temp2); - -// } -// } - -// $data['mapped_family_floaters'] = $data1; - -// array_push($PolicyData, $data); -// return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$PolicyData]], 200); -// } -// return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$PolicyData]], 200); - -// }else{ -// return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); -// } -// // } catch (\Exception $e) { -// // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); -// // } -// } - public function getClientDetails() { try { $client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first(); if($client) { + $client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo']; $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll(); return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 200); @@ -1136,4 +1016,173 @@ public function getClientDetails() } } +public function getAddOnPolicy() +{ + try { + + $addOnEmployeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',1)->findAll(); + $GMCEmployeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',0)->findAll(); + + $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll(); + if(count($clientPolicy)) + { + $PolicyData = []; + foreach ($clientPolicy as $key => $array) { + + + $decodedArray = json_decode($array['policy_terms']); + $policy_terms = $decodedArray; + $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']); + + if($array['is_addon'] == 1) + { + + $responce['SlabRates'] = $getSlabAndGridData['slab_rates']; + $responce['GridMaster'] = $getSlabAndGridData['grid_master']; + $responce['client_id'] = $array['client_id']; + $responce['client_policy_id'] = $array['id']; + $responce['is_addon'] = $array['is_addon']; + $responce['open_for_enrollment'] = $array['open_for_enrollment']; + $responce['policy_terms'] = $decodedArray; + + + // Map family floaters that already exist in the employee table + $familyFloates = $policy_terms->family_floaters; + // Convert familyFloaters terms data to plain array + $floters = $this->FloterConvertion($familyFloates); + + + $data = []; + $dependent_and_si_value = null; + $dependent_and_si_premium_value = null; + foreach ($floters as $familyFloatesValue) { + $dependent = preg_replace('/\d/', '', $familyFloatesValue); + if(count($addOnEmployeeData)){ + foreach ($addOnEmployeeData as $key => $value) { + if ($value['family_floater_key'] === $dependent) { + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->get()->getRow(); + if(isset($employee_policy->basic_cover_si)){ $dependent_and_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->premium)){ $dependent_and_si_premium_value = $employee_policy->premium;} + + $temp['is_value_exist'] = true; + $temp['data']['family_floater_key'] = $familyFloatesValue; + $temp['data']['employee_id'] = $value['id']; + $temp['data']['relationship'] = $value['relationship']; + $temp['data']['name'] = $value['name']; + $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp['data']['client_policy_id'] = $array['id']; + $temp['data']['form_type'] = $dependent; + $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; + $temp['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; + array_push($data,$temp); + unset($addOnEmployeeData[$key]); + $floters = array_diff($floters, [$familyFloatesValue]); + break; + } + } + } + } + + + //Remove Unwanted floter key from floters array based on either-parents-pil term value + if($familyFloates->{'either-parents-pil'} == 1 && count($floters)) + { + if(count($addOnEmployeeData) == 0) + { + $GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value',0) + ->where('family_floater_key','parent') + ->findAll(); + + if(count($GMCEmpData) > 0){ + $floters = array_diff($floters, ["parent1","parent2"]); + }else{ + $floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]); + } + }else{ + + $count_parent = 0; + $count_parent_in_law = 0; + foreach ($floters as $value) { + if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } + if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} + } + if($count_parent != 2) { + $floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false); + } + if($count_parent_in_law != 2) { + $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false); + } + } + + + } + + + + // Add family floter buttons placement data for FE validation + if(count($floters)){ + foreach ($floters as $familyFloatesValue) { + + $temp2['is_value_exist'] = false; + $temp2['data']['family_floater_key'] = $familyFloatesValue; + $temp2['data']['client_policy_id'] = $array['id']; + $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); + $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); + + array_push($data,$temp2); + + } + } + + $responce['family_floaters_of_dependent_and_si_array'] = $data; + $responce['family_floaters_of_dependent_and_si_value'] = $dependent_and_si_value; + $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value; + + + $only_si_array = []; + $only_si_value = null; + $only_si_premium_value = null; + foreach ($GMCEmployeeData as $key => $value) { + + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->get()->getRow(); + if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->premium)){ $only_si_premium_value = $employee_policy->premium;} + $temp3['is_value_exist'] = true; + $temp3['data']['employee_id'] = $value['id']; + $temp3['data']['relationship'] = $value['relationship']; + $temp3['data']['name'] = $value['name']; + $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp3['data']['client_policy_id'] = $array['id']; + $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; + $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; + array_push($only_si_array,$temp3); + + } + + $responce['family_floaters_of_only_si_array'] = $only_si_array; + $responce['family_floaters_of_only_si_value'] = $only_si_value; + $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; + + + + + array_push($PolicyData, $responce); + } + + } + + + return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200); + + }else{ + return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); + } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } +} + + + } \ No newline at end of file