diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 4a029f00..a3953889 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -129,9 +129,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 ffa655ba..f9b54af5 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1487,10 +1487,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; diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index cc5cafeb..ac2b2c86 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/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