diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 82a48f37..5e94105e 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -249,6 +249,7 @@ $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfi $routes->post("/calculatePremium", "EmployeeRestController::calculatePremium"); + $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getEmployeeProfile", "EmployeeRestController::getEmployeeProfile"); @@ -265,7 +266,15 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy"); $routes->get("getClientDetails", "EmployeeRestController::getClientDetails"); $routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy"); - $routes->get("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); + $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); + + $routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId"); + $routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData"); + $routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData"); + + $routes->get("removeEmpAndEmpPolicyData", "EmployeeRestController::removeEmpAndEmpPolicyData"); + + }); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 7261cec6..0431477a 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -131,9 +131,9 @@ class EmployeeController extends AdminController // print_r($this->request->getPost('policies')); // print_r($this->request->getPost('upload-action-type')); // die(); - // $empServiceController = new EmployeeServiceController(); - // $res = $empServiceController->excelFileFormatValidation(['file_id' => '42']); - // dd($res); + $empServiceController = new EmployeeServiceController(); + $res = $empServiceController->excelFileFormatValidation(['file_id' => '42']); + dd($res); // $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->excelFileDataValidation(['file_id' => '38']); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c51f62aa..f25e56cf 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -384,6 +384,83 @@ class EmployeeRestController extends AdminController } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } + + } + + + public function exportDataByClientPolicyId() + { + try { + $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0); + + if(count($empData)) + { + // Define headers and map database fields to Excel fields + $headers = [ + 'Employee Code' => 'emp_code', + 'Name' => 'name', + 'Relationship' => 'relationship', + 'DOB' => 'dob', + 'Gender' => 'gender', + 'Mobile' => 'mobile', + 'Email' => 'email_corporate', + 'SI' => 'basic_cover_si', + 'Premium' => 'rata_premimum', + 'Policy Name' => 'policy_name', + 'Insurer Branch Name' => 'insurer_branch_name', + 'TPA Name' => 'tpa_name', + 'Status' => 'emp_status' + ]; + + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Add headers + $column = 'A'; + foreach ($headers as $header => $dbField) { + $sheet->setCellValue($column . '1', $header); + $column++; + } + + // Add data + $row = 2; + foreach ($empData as $employee) { + $column = 'A'; + foreach ($headers as $dbField) { + $sheet->setCellValue($column . $row, $employee[$dbField]); + $column++; + } + $row++; + } + + + // Set the header for download + $filename = $empData[0]['policy_name'].'-Enrollment.xlsx'; + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $filename . '"'); + header('Cache-Control: max-age=0'); + + // Save the Excel file to output + $writer = new Xlsx($spreadsheet); + $writer->save('php://output'); + exit; + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200); + + }else{ + + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200); + } + + + + } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); } @@ -998,6 +1075,16 @@ public function getEmployeePolicy() // Generate Notes string based on familyFloates terms $array->notes = $this->FloterNotesConvertion($familyFloates); + + if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) + { + $array->floter_text_heading = 'Floater Sum Insured'; + $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; + }else{ + $array->floter_text_heading = 'Sum Insured'; + $array->floter_text_description = ''; + } + // Convert familyFloaters terms data to plain array $floters = $this->FloterConvertion($familyFloates); @@ -1181,6 +1268,16 @@ public function getAddOnPolicy() $responce['is_addon'] = $array['is_addon']; $responce['open_for_enrollment'] = $array['open_for_enrollment']; $responce['policy_terms'] = $decodedArray; + + if(count($getSlabAndGridData['slab_rates'])){ + if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) + { + $responce['floter_text_heading'] = 'Floater Sum Insured'; + }else{ + $responce['floter_text_heading'] = 'Sum Insured'; + } + } + if($array['is_addon'] == 3) { @@ -1345,18 +1442,26 @@ public function getAddOnPolicy() public function iAgreeForAddOn() { - $emp_code = $this->request->getGet('emp_code'); - $client_policy_id = $this->request->getGet('client_policy_id'); - $client_id = $this->request->getGet('client_id'); + $emp_code = $this->request->getPost('emp_code'); + $postData = json_decode($this->request->getBody(), true); + $client_policy_id = $postData['client_policy_id']; $this->employeeModel->where('emp_code', $emp_code ) ->where('is_active', 1 ) ->set(array('emp_status'=>'enrolled')) ->update(); - $this->employeePolicyModel->where('client_policy_id', $client_policy_id ) - ->where('is_active', 1 ) - ->set(array('status'=>'enrolled')) - ->update(); + + if (!is_null($client_policy_id) && is_array($client_policy_id)) + { + foreach ($client_policy_id as $key => $value) + { + $this->employeePolicyModel->where('client_policy_id', $value ) + ->where('is_active', 1 ) + ->set(array('status'=>'enrolled')) + ->update(); + } + } + return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); } @@ -1397,10 +1502,11 @@ public function calculatePremium($clientPolicyId = null , $empCode = null, $defa // dd($this->employeeModel->getLastQuery()); // 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); + // print_r(($employee_data_group_by_family));die(); foreach ($employee_data_group_by_family as $emp_id => $family) { $transformed_famility_details = transform_db_data_to_excel($family); + // print_r($transformed_famility_details);die(); $data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si); // dd($data); $employee_data_group_by_family[$emp_id] = $data; @@ -1418,4 +1524,209 @@ public function calculatePremium($clientPolicyId = null , $empCode = null, $defa } + +public function getCashDepositData() +{ + + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name') + ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->groupBy('client_policy.insurer_id') + ->findAll(); + $result = []; + + if(count($ClientPolicyData)) + { + foreach ($ClientPolicyData as $key => $value) { + + $data['clientId'] = $value['clientId']; + $data['insurerId'] = $value['insurerId']; + $data['insurerName'] = $value['insurer_name']; + $data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']); + $data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0; + + $data['policyDetails'] = []; + $ClientPolicyData =$this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id,policies.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon') + ->join('policies', 'client_policy.policy_id = policies.id', 'left') + ->where('client_policy.insurer_id', $value['insurerId'] ) + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->findAll(); + foreach ($ClientPolicyData as $key => $value) + { + $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']); + if($value['is_addon'] == "2"){ $value['type'] = 'SI TopUp'; }else if($value['is_addon'] == "3"){ $value['type'] = 'Dependent AddOn'; }else{ $value['type'] = $getSlabAndGridData['grid_master']['policy_type']; } + $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0); + $enrolledCount = 0; + $draftCount = 0; + if(count($employeeDetails)) + { + foreach ($employeeDetails as $item) { + if ($item['emp_status'] === 'enrolled') { + $enrolledCount++; + } elseif ($item['emp_status'] === 'draft') { + $draftCount++; + } + } + } + + $value['totalMembersCount'] = count($employeeDetails); + $value['membersCountOfEnrolled'] = $enrolledCount; + $value['membersCountOfDraft'] = $draftCount; + + array_push($data['policyDetails'],$value); + } + + + array_push($result,$data); + + } + } + + + + if($result) + { + return $this->respond(['status' => 'success','code' => (count($result) ? 200 : 404),'data' => $result ], 200); + }else{ + return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200); + } + +} + + + + +public function exportCashDepositData() +{ + + $CashDepositData = $this->clientPolicyModel->getdepositData($this->request->getGet('client_id'),$this->request->getGet('insurer_id')); + + // echo '
';print_r($CashDepositData); echo '';die; + + if(count($CashDepositData)) + { + // Define headers and map database fields to Excel fields + $headers = [ + 'Date' => 'created_at', + 'Type' => 'transaction_type', + 'Amount' => 'amount', + 'Balance' => 'balance', + 'Description' => 'description', + 'Insurer Name' => 'insurer_name', + 'Client Name' => 'clientname' + ]; + + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Add headers + $column = 'A'; + foreach ($headers as $header => $dbField) { + $sheet->setCellValue($column . '1', $header); + $column++; + } + + // Add data + $row = 2; + foreach ($CashDepositData as $Cashvalue) { + $column = 'A'; + foreach ($headers as $dbField) { + $sheet->setCellValue($column . $row, $Cashvalue->$dbField); + $column++; + } + $row++; + } + + + // Set the header for download + $filename = $CashDepositData[0]->insurer_name.'-CashDeposit.xlsx'; + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $filename . '"'); + header('Cache-Control: max-age=0'); + + // Save the Excel file to output + $writer = new Xlsx($spreadsheet); + $writer->save('php://output'); + exit; + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200); + + }else{ + + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200); + } + +} + + +public function removeEmpAndEmpPolicyData() +{ + try { + + $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id'))->findAll(); + + if(count($clientPolicy)) + { + + + if($clientPolicy[0]['is_addon'] == 2)//Topup + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 0 )->findAll(); + if(count($empData)) + { + foreach ($empData as $key => $value) { + + $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) + ->where('employee_id', $value['id'] ) + ->set(array('is_active'=> 0 )) + ->update(); + + } + } + + } + else if($clientPolicy[0]['is_addon'] == 3)//Dependent addon + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 1 )->findAll(); + if(count($empData)) + { + foreach ($empData as $key => $value) { + + $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) + ->where('employee_id', $value['id'] ) + ->set(array('is_active'=> 0 )) + ->update(); + + } + + $this->employeeModel->where('emp_code', $this->request->getGet('emp_code') ) + ->where('is_active', 1 )->where('is_addon_value', 1 ) + ->set(array('is_active'=> 0 )) + ->update(); + } + + } + + + + return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 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 diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index c7af743f..bf6179ee 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -35,7 +35,7 @@ class EmployeeServiceController extends AdminController protected $empEndorsementModel; protected $general_relationships = ['self' => ['name' => 'Self', 'gender' => 'M','age_min' => 18,'age_max' => null], 'spouse' => ['name' => 'Spouse', 'gender' => 'F','age_min' => 18,'age_max' => null], 'son' => ['name' => 'Son', 'gender' => 'M','age_min' => null,'age_max' => 25], 'daughter' => ['name' => 'Daughter', 'gender' => 'F','age_min' => null,'age_max' => 25], 'father' => ['name' => 'Father', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother' => ['name' => 'Mother', 'gender' => 'F','age_min' => 18,'age_max' => null], 'father-in-law' => ['name' => 'Father in Law', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother-in-law' => ['name' => 'Mother in Law', 'gender' => 'F','age_min' => 18,'age_max' => null]]; - protected $inception_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'dob'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'DOB','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_dob_diff','params'=>['row','relationship']],'gender'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Gender','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['M','F']],'relationship'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'RELATIONSHIP','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_relationship','params'=>['row','relationship','policy_terms']],'basic_cover_si'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'BASIC COVER SI','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'doc'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Date of Coverage','is_mandatory'=>['A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'params'=>['row']],'doj'=>['col_idx'=>8,'col_cell_name'=>'I','col_name'=>'DOJ','is_mandatory'=>false,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_doj','params'=>['row']],'basic_pay'=>['col_idx'=>9,'col_cell_name'=>'J','col_name'=>'Basic Pay','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_basic_pay','params'=>['row','policy_terms','slab_details']],'band_grade'=>['col_idx'=>10,'col_cell_name'=>'K','col_name'=>'Band/Grade','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_employee_band','params'=>['row','policy_terms','slab_details']],'designation'=>['col_idx'=>11,'col_cell_name'=>'L','col_name'=>'Designation','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'phone'=>['col_idx'=>12,'col_cell_name'=>'M','col_name'=>'Phone','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'email'=>['col_idx'=>13,'col_cell_name'=>'N','col_name'=>'Email','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'pre_existing_ailments'=>['col_idx'=>14,'col_cell_name'=>'O','col_name'=>'PRE EXISTING AILMENTS','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['0','1']],'change_event'=>['col_idx'=>15,'col_cell_name'=>'P','col_name'=>'Change event','is_mandatory'=>['A','DA','D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>16,'col_cell_name'=>'Q','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>17,'col_cell_name'=>'R','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; + protected $inception_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'dob'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'DOB','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_dob_diff','params'=>['row','relationship']],'gender'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Gender','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['M','F']],'relationship'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'RELATIONSHIP','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_relationship','params'=>['row','relationship','policy_terms']],'basic_cover_si'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'BASIC COVER SI','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'doc'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Date of Coverage','is_mandatory'=>['A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'params'=>['row']],'doj'=>['col_idx'=>8,'col_cell_name'=>'I','col_name'=>'DOJ','is_mandatory'=>false,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_doj','params'=>['row']],'basic_pay'=>['col_idx'=>9,'col_cell_name'=>'J','col_name'=>'Basic Pay','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_basic_pay','params'=>['row','policy_terms','slab_details']],'band_grade'=>['col_idx'=>10,'col_cell_name'=>'K','col_name'=>'Band/Grade','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_employee_band','params'=>['row','policy_terms','slab_details']],'designation'=>['col_idx'=>11,'col_cell_name'=>'L','col_name'=>'Designation','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'phone'=>['col_idx'=>12,'col_cell_name'=>'M','col_name'=>'Phone','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'email'=>['col_idx'=>13,'col_cell_name'=>'N','col_name'=>'Email','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'pre_existing_ailments'=>['col_idx'=>14,'col_cell_name'=>'O','col_name'=>'PRE EXISTING AILMENTS','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['0','1']],'change_event'=>['col_idx'=>15,'col_cell_name'=>'P','col_name'=>'Change event','is_mandatory'=>['A','DA','D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; protected $deletion_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'change_event'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'Change event','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; @@ -145,7 +145,7 @@ class EmployeeServiceController extends AdminController $policy_terms = json_decode($policy_terms[0]->policy_terms); $policy_terms = (array) $policy_terms;// convert obj to array // - // dd($policy_terms); + dd($policy_terms); //get policy slab rates $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); @@ -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/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 41fa05dd..6ed64b27 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -530,10 +530,13 @@ if (!function_exists('calculate_premimum')) // dd($transformed_familiy_member_data); //store emp id and emp band and attach it to their familiy members where band is always empty - $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = null; + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] : NULL; + + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : NULL; if(strtolower($transformed_familiy_member_data['relationship']) == 'self') { $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = $transformed_familiy_member_data['band']; + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = $transformed_familiy_member_data['policy_details']['basic_cover_si']; } //end of store emp id and emp band and attach it to their familiy members where band is always empty @@ -555,6 +558,7 @@ if (!function_exists('calculate_premimum')) $transformed_familiy_member_data['temp']['band'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']; $transformed_familiy_member_data['temp']['maxage'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage']; $transformed_familiy_member_data['temp']['maxcount'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount']; + $transformed_familiy_member_data['policy_details']['basic_cover_si'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']; if( $fileArr['id'] == null || (in_array($grid_type,[10,11]) || $transformed_familiy_member_data['temp']['source'] == 'excel'))//if file id is null then data coming from enrollment (from DB) otherwise data coming from xcel, so calculate only data from excel (new entry) note: even data coming from excel for event dependet additon we fetch other dependts from db and calculate premium for whole family { @@ -588,8 +592,8 @@ if (!function_exists('transform_excel_data_to_db')) $policy['basic_cover_si'] = $memArr[6]; $policy['pre_existing_alignments'] = $memArr[14]; - $policy['date_of_exit'] = isset($memArr[16]) ? change_date_format($memArr[16],'d-M-Y','Y-m-d') : NULL; - $policy['reason_for_exit'] = $memArr[17]; + // $policy['date_of_exit'] = isset($memArr[16]) ? change_date_format($memArr[16],'d-M-Y','Y-m-d') : NULL; + // $policy['reason_for_exit'] = $memArr[17]; $policy['client_policy_id'] = $actionArr['policy_id']; $policy['date_coverage'] = isset($memArr[7]) ? change_date_format($memArr[7],'d-M-Y','Y-m-d') : NULL;; $policy['policy_end_date'] = null; @@ -634,6 +638,8 @@ if (!function_exists('premium_calculation_manager')) { // grid type // 1 = premium => si + // dd($emp_data); + $slug = \Config\Services::slug(); $grid_type = $slab_details['grid_master']['ui_type']; switch ($grid_type) { @@ -745,7 +751,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -765,7 +771,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -787,7 +793,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -809,7 +815,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -831,15 +837,15 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { - $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $employee_received_si : 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); + $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = 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'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']; + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } @@ -849,24 +855,26 @@ if (!function_exists('premium_calculation_manager')) //GMC - Maximum count per Family $max_count = $emp_data['temp']['maxcount']; $employee_received_band = $emp_data['temp']['band']; + // echo $employee_received_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)) + if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { //calculate premium based on count + // echo $emp_data['name']; $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); + $emp_data['policy_details']['basic_cover_si'] = $familiy_si_covered; + $emp_data['policy_details']['date_coverage'] = (empty($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } @@ -875,26 +883,23 @@ if (!function_exists('premium_calculation_manager')) 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; + $employee_relationship = $slug->slugify($emp_data['relationship']); + $employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship); $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)) + if( $slab_value['si'] == $employee_received_si && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) ) { - //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); + $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = (empty($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } @@ -903,26 +908,23 @@ if (!function_exists('premium_calculation_manager')) 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; + $employee_relationship = $slug->slugify($emp_data['relationship']); + $employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship); $emp_data['policy_details']['basic_cover_si'] = null; + $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - - if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) ) { - //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); + $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = (empty($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 2c27280b..e5b4e591 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -185,6 +185,7 @@ class ClientPolicyModel extends Model ->where('cash_deposit.client_id', $clientId) ->where('cash_deposit.insurer_id', $insurerId) // Add this line to filter by insurer_id + ->orderBy('cash_deposit.id', 'DESC') ->get() ->getResult(); } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 105979be..3198d873 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -79,13 +79,17 @@ class EmployeePolicyModel extends Model ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //tpab - tpa brach ->join('clients cm', 'cp.client_id = cm.id') //cm - client master ->where('emp.client_id',$client_id) - ->where('employee_polices.client_policy_id',$policy_id); + ->where('employee_polices.is_active',1) + ->where('emp.is_active',1) + ->where('employee_polices.client_policy_id',$policy_id) + ->orderBy('emp.emp_code','ASC')->orderBy('employee_polices.employee_id','ASC'); + if($status != 0 && !empty($status)){ $result->where('employee_polices.status', $status); } - $result = $result->findAll(); + $result = $result->findAll(); return ($result); } diff --git a/tests/unit/GridType11PremiumCalculationTest.php b/tests/unit/GridType11PremiumCalculationTest.php new file mode 100644 index 00000000..5c6a5ef1 --- /dev/null +++ b/tests/unit/GridType11PremiumCalculationTest.php @@ -0,0 +1,177 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 5000000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => 1, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 5000000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => 1, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', 'G', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); + } + + public function testType11PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 500000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => NULL, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 500000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => NULL, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '500000', '', '', '', 'C', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType11PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 500000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => NULL, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 500000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => NULL, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', '', '01-Jan-2024', '01-Jan-2020', 50000, '', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '500000', '', '', '', 'C', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + +} \ No newline at end of file diff --git a/tests/unit/GridType12PremiumCalculationTest.php b/tests/unit/GridType12PremiumCalculationTest.php index 9b87a1d3..8615a834 100644 --- a/tests/unit/GridType12PremiumCalculationTest.php +++ b/tests/unit/GridType12PremiumCalculationTest.php @@ -11,14 +11,14 @@ use Tests\Support\Libraries\ConfigReader; // use App\Helpers\excel_util_helper; use Kint\Kint; -class GridType12PremiumCalculationTest.php extends CIUnitTestCase +class GridType12PremiumCalculationTest extends CIUnitTestCase { - public function testType12PremiumCalculation() + public function testType12PremiumCalculationWithPremiumTypeOne() { helper('excel_util_helper'); $slab_details = [ 'slab_rates' =>[ - [ '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' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, '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'], @@ -29,18 +29,17 @@ class GridType12PremiumCalculationTest.php extends CIUnitTestCase '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', '', '', '', '', '', '', '', '', '', '', ''], + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], ]; - // Sample policy terms $policy_terms = [ 'family_floater' => true, @@ -53,20 +52,126 @@ class GridType12PremiumCalculationTest.php extends CIUnitTestCase ], ]; - // 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']); + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); } - // public function testIsNull() - // { - // $i = null; - // $this->assertTrue($i); - - // } + public function testType12PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, 'max_si' => 0,'premium_type' => NULL, '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' => NULL, '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' => NULL, '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' => NULL, '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' => NULL, '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' => NULL, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => NULL, '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 = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType12PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, 'max_si' => 0,'premium_type' => 2, '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' => 2, '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' => 2, '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' => 2, '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' => 2, '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' => 2, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 2, '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 = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + } \ No newline at end of file diff --git a/tests/unit/GridType13PremiumCalculationTest.php b/tests/unit/GridType13PremiumCalculationTest.php new file mode 100644 index 00000000..24d7aaa3 --- /dev/null +++ b/tests/unit/GridType13PremiumCalculationTest.php @@ -0,0 +1,177 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, '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' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); + } + + public function testType13PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => NULL, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType13PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => 2, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + +} \ No newline at end of file