From 7af224f0cfcdc7b9efc49930a053410a2599be5f Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 17 Apr 2024 10:55:19 +0530 Subject: [PATCH] CHANGE_ADDONPOILICYAPI:GWM --- app/Controllers/EmployeeRestController.php | 88 ++++++++++++++++------ 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 5245fcae..fcb784fa 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -170,16 +170,18 @@ class EmployeeRestController extends AdminController public function addEmployeeAndDependence() { - try { + // try { $data = $this->request->getJSON(); if ($data) { + $Count = 0; foreach ($data as $item) { if (isset($item->id)) { //update old data $id = $item->id; $item->family_floater_key = $this->RelationshipMap($item->relationship); + $item->gender = $this->GenderMap($item->relationship , $item->emp_code); $item->dob = $this->convertDateFormatYMD($item->dob); $item->emp_status = 'Draft'; $employee = $this->employeeModel->where('is_active', 1 )->update($id, (array)$item); @@ -189,9 +191,10 @@ class EmployeeRestController extends AdminController }else{ //create new data $item->family_floater_key = $this->RelationshipMap($item->relationship); + $item->gender = $this->GenderMap($item->relationship , $item->emp_code); $item->dob = $this->convertDateFormatYMD($item->dob); $item->emp_status = 'Draft'; - $employee = $this->employeeModel->where('is_active', 1 )->insert($item); + $employee = $this->employeeModel->insert($item); if ($employee) { if(!isset($item->is_addon_value)) @@ -206,6 +209,7 @@ class EmployeeRestController extends AdminController } if ($Count > 0) { + $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); $result = []; return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); } else { @@ -213,40 +217,57 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404); } } - } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - } + // } catch (\Exception $e) { + // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + // } } public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id) { - - $client_policy = $this->clientPolicyModel->where('id', $client_policy_id)->where('client_id', $client_id)->first(); $policy_terms = json_decode($client_policy['policy_terms']); $basic_cover_si = $policy_terms->sum_insured; - $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); - $SlabRatesArray = $getSlabAndGridData['slab_rates']; - $premium = $this->findPremiumAmount($SlabRatesArray, $basic_cover_si); - - - $data['employee_id']= $employee_id; $data['client_policy_id']= $client_policy_id; $data['basic_cover_si']= $basic_cover_si; - $data['premium']= $premium; + $data['status']= 'draft'; $this->employeePolicyModel->insert($data); - - return true; - - } + public function updatePremiumAmount($client_policy_id , $emp_code) + { + $response = $this->calculatePremium($client_policy_id , $emp_code); + + if(count($response[$emp_code])) + { + print_r($response[$emp_code]); + foreach ($response[$emp_code] as $key => $value) + { + + $checkIfExist = $this->employeePolicyModel->where('employee_id', $value['temp']['emp_id']) + ->where('client_policy_id', $value['policy_details']['client_policy_id']) + ->where('is_active', 1 ) + ->findAll(); + if($checkIfExist) + { + $this->employeePolicyModel + ->where('client_policy_id',$value['policy_details']['client_policy_id'] ) + ->where('employee_id' , $value['temp']['emp_id'] ) + ->where('is_active', 1 ) + ->set(array('premium'=> $value['policy_details']['premium'] )) + ->update(); + + } + } + } + } + + public function RelationshipMap($value){ if ($value === 'Mother' || $value === 'Father') { @@ -260,6 +281,19 @@ class EmployeeRestController extends AdminController } } + public function GenderMap($value,$empCode){ + + if ($value === 'Mother' || $value === 'Daughter' || $value === 'Mother in Law') { + return 'F'; + } else if($value === 'Son' || $value === 'Father' || $value === 'Father in Law'){ + return 'M'; + }else if($value === 'Spouse'){ + + $Gender = $this->employeeModel->where('emp_code',$empCode)->where('relationship','Self')->get()->getRow()->gender; + if($Gender == 'M'){ return 'F'; }else{ return 'M'; } + } +} + private function convertDateFormatYMD($dateString) { // Attempt to create a DateTime object from the provided date string @@ -1293,11 +1327,11 @@ public function iAgreeForAddOn() //Post method - which receives client_policy id and empcode of the family. //Pull records againest emp code and calculate premium // retun array -public function calculatePremium()//family level +public function calculatePremium($clientPolicyId = null , $empCode = null)//family level { helper('excel_util_helper'); - $client_policy_id = $this->request->getVar('client_policy_id'); - $emp_code = $this->request->getVar('emp_code'); + $client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId; + $emp_code = $this->request->getVar('emp_code') ?? $empCode; // dd($client_policy_id); $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; @@ -1308,8 +1342,7 @@ public function calculatePremium()//family level //get policy slab rates $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); - $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['active'],policy_status:['active']); - + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception']; // dd($this->employeeModel->getLastQuery()); // dd($existing_famility_details);die(); @@ -1324,8 +1357,15 @@ public function calculatePremium()//family level } - // dd ($employee_data_group_by_family); + if($clientPolicyId != null && $empCode != null) + { + return $employee_data_group_by_family; + }else{ + // dd ($employee_data_group_by_family); return $this->respond(['status' => 'success','code' => (count($employee_data_group_by_family) ? 200 : 404),'data' => [$employee_data_group_by_family] ], 200); + + } + } } \ No newline at end of file