diff --git a/app/Config/Routes.php b/app/Config/Routes.php index fc3ee161..b68ae6c3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -246,7 +246,6 @@ $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfi $routes->post("/calculatePremium", "EmployeeRestController::calculatePremium"); - $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getEmployeeProfile", "EmployeeRestController::getEmployeeProfile"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 21652fe0..4ec8de9d 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -170,7 +170,7 @@ class EmployeeRestController extends AdminController public function addEmployeeAndDependence() { - // try { + try { $data = $this->request->getJSON(); if ($data) { @@ -197,10 +197,6 @@ class EmployeeRestController extends AdminController $employee = $this->employeeModel->insert($item); if ($employee) { - if(!isset($item->is_addon_value)) - { - $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id); - } $Count++; } @@ -210,10 +206,16 @@ class EmployeeRestController extends AdminController if ($Count > 0) { - if(!isset($data[0]->is_addon_value)) + if(!isset($item->is_addon_value)) { - $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); + $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id); + }else{ + $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id,$item->basic_cover_si); } + + + $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); + $result = []; return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); @@ -222,18 +224,19 @@ 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) + public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id,$basic_cover_si = null) { - + if($basic_cover_si != null){ $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; + }else{ $basic_cover_si = $basic_cover_si; } $checkDataExist = $this->employeePolicyModel->where('employee_id',$employee_id)->where('client_policy_id',$client_policy_id)->first(); @@ -679,8 +682,8 @@ class EmployeeRestController extends AdminController $file_data =$this->fileModel->insert($extractData); $extra = []; - if (count($data[0]) == 10) { - $value = ['Sno','Emp_Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI']; + if (count($data[0]) == 11) { + $value = ['Sno','Emp_Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI','Grade']; $check_miss_match = []; for ($i=0; $i respond(['status' => 'failed', 'code' => 404, 'message' => "Uploaded file row count is Not Match!" ], 200); } @@ -775,7 +778,8 @@ class EmployeeRestController extends AdminController 'email_corporate' => $extra['7'][$index], 'mobile'=> $extra['8'][$index], 'client_id' => $client_id, - 'emp_status'=>'draft' + 'emp_status'=>'draft', + 'band'=> $extra['10'][$index], ]; $basic_cover_si_value = null; @@ -988,6 +992,7 @@ public function getEmployeePolicy() // Map family floaters that already exist in the employee table $familyFloates = $array->Policy_Terms->family_floaters; + // Generate Notes string based on familyFloates terms $array->notes = $this->FloterNotesConvertion($familyFloates); // Convert familyFloaters terms data to plain array @@ -1058,9 +1063,9 @@ public function getEmployeePolicy() } - $result[] = $array; + // $result[] = $array; } - + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); }else{ @@ -1114,6 +1119,8 @@ public function FloterNotesConvertion($array){ $string = ucwords($string); $result .= ' + '.$string; }else if($value != 0 && $key ==='self') { + }else if($value != 0 && $key ==='childrens') { + if($value > 1){ $result .= ' + '.$value.' Children'; }else{ $result .= ' + '.$value.' Child'; } }else{ $string = str_replace('-', ' ', $key); $string = ucwords($string); @@ -1121,7 +1128,7 @@ public function FloterNotesConvertion($array){ } } } - + return $result; } @@ -1322,7 +1329,7 @@ public function getAddOnPolicy() } - // return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200); + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); @@ -1341,12 +1348,11 @@ public function iAgreeForAddOn() $this->employeeModel->where('emp_code', $emp_code ) ->where('is_active', 1 ) - ->set(array('emp_status'=>'Enrolled')) + ->set(array('emp_status'=>'enrolled')) ->update(); - $this->employeePolicyModel->where('client_id', $client_id ) - ->where('client_policy_id', $client_policy_id ) + $this->employeePolicyModel->where('client_policy_id', $client_policy_id ) ->where('is_active', 1 ) - ->set(array('status'=>'Enrolled')) + ->set(array('status'=>'enrolled')) ->update(); return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); } @@ -1357,12 +1363,6 @@ public function iAgreeForAddOn() public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null)//family level { helper('excel_util_helper'); - - // $client_policy_id = $this->request->getVar('client_policy_id'); - // $emp_code = $this->request->getVar('emp_code'); - - // dd($default_si); - $client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId; $emp_code = $this->request->getVar('emp_code') ?? $empCode; $default_si = $this->request->getVar('si') ?? $default_si;// si amt which choosed in add on policy @@ -1372,17 +1372,27 @@ public function calculatePremium($clientPolicyId = null , $empCode = null, $defa $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; // get policy and rack details $policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id); + $policy_type = $policy_terms[0]->is_addon; + $base_policy = $policy_terms[0]->base_policy; $policy_terms = (array) $policy_terms[0];// convert obj to array //get policy slab rates $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); - // dd($slab_details); + // print_r($slab_details);die(); $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']); + if(!count($existing_famility_details) && $policy_type == 2)//top up addon only + { + //get basepolicy id then pull emplist from base policy if only current policy is DA addon policy and emplist is zero + // echo 'inside'; + $client_policy_id = $base_policy; + $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(); + // print_r($existing_famility_details);die(); $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db'); // dd($employee_data_group_by_family); foreach ($employee_data_group_by_family as $emp_id => $family) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 808fa7a9..cc5cafeb 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -562,7 +562,7 @@ class EmployeeServiceController extends AdminController // get policy and rack details $policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id); $policy_terms = (array) $policy_terms[0];// convert obj to array - + //get policy slab rates $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index b283bc5a..4b14a8bd 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -130,6 +130,7 @@ class RestAuthenticationController extends AdminController try { $mobile_number = $this->request->getJSON()->mobile_number; $randomNumber = rand(100000, 999999); + $randomNumber = 123456; $HrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first(); if ($HrData) { diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 34e36e46..41fa05dd 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -873,6 +873,64 @@ if (!function_exists('premium_calculation_manager')) } break; + case "12": + //GMC - Employee + relationship + $max_count = $emp_data['temp']['maxcount']; + $employee_received_band = $emp_data['temp']['band']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + $emp_data['policy_details']['basic_cover_si'] = null; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + + if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + { + //calculate premium based on count + $familiy_si_covered = $employee_received_si * $max_count; + $familiy_si_covered = ($familiy_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $familiy_si_covered); + + $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $familiy_si_covered : null); + $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); + $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); + $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); + $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); + $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); + $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + + break; + } + } + break; + + case "13": + //GMC - Employee + relationship + age + $max_count = $emp_data['temp']['maxcount']; + $employee_received_band = $emp_data['temp']['band']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + $emp_data['policy_details']['basic_cover_si'] = null; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + + if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + { + //calculate premium based on count + $familiy_si_covered = $employee_received_si * $max_count; + $familiy_si_covered = ($familiy_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $familiy_si_covered); + + $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $familiy_si_covered : null); + $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); + $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); + $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); + $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); + $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); + $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + + break; + } + } + break; + + + default: echo "Not a valid grid"; } diff --git a/tests/unit/GridType12PremiumCalculationTest.php b/tests/unit/GridType12PremiumCalculationTest.php new file mode 100644 index 00000000..9b87a1d3 --- /dev/null +++ b/tests/unit/GridType12PremiumCalculationTest.php @@ -0,0 +1,72 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50000, 'max_si' => 0,'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 25000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 20000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'child'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 18000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 15000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 12,'policy_grid_type' => 'Employees + Relationship','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ + [1, 'Jane Doe', '1990-01-01', 'F', 'Spouse', 10000, '2024-01-01', '2020-01-01', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2, 'John Doe', '1990-01-01', 'M', 'Self', '', '', '', '', '', '', '', '', '', '', ''], + [3, 'Peter Doe', '1990-01-01', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4, 'Mary Doe', '1990-01-01', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5, 'Grace Doe', '1990-01-01', 'F', 'Mother-in-law', '', '', '', '', '', '', '', '', '', '', ''], + [6, 'George Doe', '1990-01-01', 'M', 'Father-in-law', '', '', '', '', '', '', '', '', '', '', ''], + [7, 'Alice Doe', '1995-02-02', 'F', 'Daughter', 8000, '2024-02-01', '2021-01-01', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8, 'Bob Doe', '1995-02-02', 'M', 'Son', '', '', '', '', '', '', '', '', '', '', ''], +]; + + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + // Sample action array + $actionArr = 'addition'; + + // Call the function + $result = check_dependent_conflict($family_data, $policy_terms, $actionArr); + Kint::dump($result); + // Assert that the status is true (no conflicts) + $this->assertTrue($result['status']); + } + + // public function testIsNull() + // { + // $i = null; + // $this->assertTrue($i); + + // } +} \ No newline at end of file