CHANGE_RACK_RATE_CALC,SI_ENHANCE_AT_INCEPTION

This commit is contained in:
velz 2024-05-04 16:40:56 +05:30
parent f64a695cf3
commit 65e93a9117
3 changed files with 234 additions and 94 deletions

View File

@ -222,7 +222,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->cli('cli/processjob', 'JobWorker::processJob');
$routes->cli('cli/processjobs', 'JobWorker::processJobs');
$routes->get("processjob", "JobWorker::processJob");
//Employee login api's

View File

@ -350,13 +350,15 @@ class EmployeeServiceController extends AdminController
if($file['action'] == 'dependent_addition')
{
$existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status:['active']);
// dd($existing_famility_details);
// dd(($existing_famility_details));
//transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites
$existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file);
// dd($existing_famility_details);
// dd(array_keys($existing_famility_details[0]));
$family = array_merge($family,$existing_famility_details);
// kint::dump($family);
$family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array
}
// kint::dump($family);die();
// kint::dump($family);//die();
//check name dup within a family
if($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition')
@ -373,14 +375,14 @@ class EmployeeServiceController extends AdminController
}
}
if(($file['action'] == 'inception' || $file['action'] == 'addition') && ($policy_details['is_addon'] != 3)) // 3 is depent addon
if(($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition') && ($policy_details['is_addon'] != 3)) // 3 is dependent addon
{
$res = check_self_available_in_family($family,$file['action']);
// dd($res);
if(!$res['is_self_found'])
{
array_push($result['error_summary'],14); // Self not found
$result['error_data'][ $res['emp_code'] ]['name_of_emp_dep']['error'][] = "Self not found ";
$result['error_data'][ $res['row_id'] ]['sno']['error'][] = "Self not found ";
}
}
@ -501,7 +503,12 @@ class EmployeeServiceController extends AdminController
}
$columns_to_check = [];
if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; }
if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; }
if($file['action'] == 'addition'){ $columns_to_check = $this->inception_excel_columns; }
if($file['action'] == 'dependent_addition'){ $columns_to_check = $this->inception_excel_columns; }
if($file['action'] == 'deletion'){ $columns_to_check = $this->deletion_excel_columns; }
if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; }
if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; }
// get policy and rack details
$policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']);
@ -515,6 +522,7 @@ class EmployeeServiceController extends AdminController
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
$allowedHighestColumn = end($columns_to_check);
// dd($allowedHighestColumn);
$excel_data = $sheet->rangeToArray('A1:' . $allowedHighestColumn['col_cell_name'] . $highestRowAndColumn['row']);
unset($excel_data[0]);
@ -537,6 +545,7 @@ class EmployeeServiceController extends AdminController
$existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file);
// Kint::dump($existing_famility_details);
$family = array_merge($family,$existing_famility_details);
$family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array
// dd($family);
}
@ -826,15 +835,10 @@ class EmployeeServiceController extends AdminController
{
$familiy_data = $params['familiy_data'];
$file = $params['file'];
// dd($file);
// print_r($familiy_data);
// echo '------------------------------------------------------';
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']);
foreach($familiy_data as $fkey => $value)
{
if($file['id'] == null || $value['temp']['source'] == 'excel') //insert data come from excel and from db i.e. ( $file['id'] == null for enrollment data)
if($file['id'] == null || $value['temp']['source'] == 'excel' || (($file['action'] == 'dependent_addition' && in_array($value['temp']['source'],[10,11]) && ($slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($slab_details['slab_rates'][0]['premium_type'] == 1 || $slab_details['slab_rates'][0]['premium_type'] == null)))) //insert data come from excel and from db i.e. ( $file['id'] == null for enrollment data)
{
$employee = $this->employeeModel->checkExistingEmp($value);
@ -842,11 +846,25 @@ class EmployeeServiceController extends AdminController
$temp = $value['temp'];
unset($value['policy_details']);
unset($value['temp']);
//start implemet of si enhancement of grid type 10,11
if(count($employee) && (($file['action'] == 'dependent_addition' && in_array($value['temp']['source'],[10,11]) && ($slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($slab_details['slab_rates'][0]['premium_type'] == 1 || $slab_details['slab_rates'][0]['premium_type'] == null))))
{
$res = $this->employeesSIEnhanceProcessWhileOnbboard(employee:$employee[0],policy_data: $policy_data,file:$file);// where employee holds existing emp data and policy_data holds new si enhancement
if(!$res)
{
//if endorsement not happend no need to update emp/policy details in DB.
break;
}
}
//end implemet of si enhancement of grid type 10,11
//save employee table
if(count($employee))
{
$value['updated_by'] = $file['created_by'];
$value['id'] = $employee[0]['id'];
$value['emp_status'] = 'active';
$log_message = 'Update Employee - '.$employee[0]['name'].'('.$employee[0]['emp_code'].') with PK '.$employee[0]['id'];
// $this->myLogger->logme('error',('Update - ' . $employee[0]['id'].' - '. $employee[0]['emp_code'] .' - '.$employee[0]['name']));
}
@ -895,7 +913,50 @@ class EmployeeServiceController extends AdminController
}// for end
}//function end
// $employee -> holds existing emp model obj and $policy_data holds new policy changes as array
public function employeesSIEnhanceProcessWhileOnbboard(array $employee,array $policy_data,array $file)
{
$employee = $this->employeeModel->where('emp_code', $employee['emp_code'])->where('name',$employee['name'])->where('client_id',$employee['client_id'])->where('is_active',1)->first();
$employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first();
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($employee_policy['policy_id'],$employee['client_id']);
//check si has changed in normal case OR check premium only changed, still treat as SI enhancement in grid type 10
if($employee_policy['basic_cover_si'] != $policy_data['basic_cover_si'] || ($slab_details['grid_master']['ui_type'] == 10 && $policy_data['premimum'] != null && $policy_data['premimum'] != "" && $employee_policy['premimum'] != $policy_data['premimum']))
{
$existing_endorsements = $this->empEndorsementModel->where('actions','si')
->where('table_name','employee_polices')
->where('endorsement_id is null')
->where('emp_code',$employee['emp_code'])
->where('name',$employee['name'])
->where('field_name','basic_cover_si')
->findAll();
// dd($existing_endorsements);
//make entry in endorsement table
if(!count($existing_endorsements))
{
foreach ($slab_details['slab_rates'] as $skey => $slab_value)
{
if($slab_value['si'] == $policy_data['basic_cover_si'])
{
$group_key = rand(100000, 999999);
$this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $policy_data['basic_cover_si'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]);
$this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]);
$this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => date('Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]);
$this->myLogger->logme('error',($employee['emp_code'].' - '.$employee['name'].'- ( NEW/OLD SI - '.$employee_policy['basic_cover_si'].'/'.$policy_data['basic_cover_si'].')'. '( NEW/OLD PREMIUM - '.$employee_policy['premium'].'/'.$policy_data['premimum'].') '.' - si enhancement via DA'));
return true; //retun true when endorsement inserted
}
}
}
return false; //retun false when endorsement not happend
}
return false; //retun false when endorsement not happend
}
// ---------------------------------------------------------------------------------

View File

@ -1,6 +1,7 @@
<?php
use App\Models\EmployeeModel;
use Kint\Kint;
if(!function_exists('calculate_days_bw_dates'))
@ -170,21 +171,55 @@ if(!function_exists('check_si'))
{
function check_si($row,$policy_terms,$slab_details)
{
$return_array = array('status' => true,'error' => '');
$is_si_found = false;
$is_age_slab_found = false;
if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','SI']))// check rule only of action column data available
{
$received_si = $row['current_action'] == 'SI' ? $row[3] : $row[6];
$found = false;
foreach ($slab_details['slab_rates'] as $skey => $slab_value)
{
if($slab_value['si'] == $received_si)
if($is_si_found && $is_age_slab_found)
{
$found = true;
break;
}
if(!$is_si_found && $slab_value['si'] == $received_si) //match si amount
{
$is_si_found = true;
}
// check age slab
if($row[3] != null)// dob
{
$dob = change_date_format($row[3],'d-M-Y','Y-m-d');
// echo $row[3].' - '.$dob;echo '<br>';
$currentDateTime = new DateTime();//die();
$passedDateTime = new DateTime($dob);
$interval = $currentDateTime->diff($passedDateTime);
// echo $row[0].' - '.$row[3].' - '.$interval->y;echo '<br>';
if(!$is_age_slab_found && ($slab_value['age_from'] !== null && $slab_value['age_to'] !== null) && ($slab_value['age_from'] <= $interval->y && $slab_value['age_to'] >= $interval->y) && $slab_value['si'] == $received_si)
{
$is_age_slab_found = true;
}
}//end of check age slab
}
if(!$found) { return array('status' => false,'error' => "Sum insured not found"); }
return array('status' => true);
}else { return array('status' => true); } // in else condition no need to check rule, just return true
}
if(!$is_si_found)
{
$return_array['status'] = false;
$return_array['error'] = "Sum insured not found";
}
if(!$is_age_slab_found)
{
$return_array['status'] = false;
$return_array['error'] = !empty($return_array['error']) ? ($return_array['error'].', '.'Sum insured not configured for this age slab') : 'Sum insured not configured for this age slab';
}
return $return_array;
}
}
@ -247,7 +282,7 @@ if (!function_exists('data_group_by_family'))
function data_group_by_family($emp_data,$data_source = 'excel')
{
$result = [];
// dd($emp_data);
// Kint::dump($emp_data);
foreach ($emp_data as $rkey => $row)
{
if($data_source == 'excel')
@ -305,8 +340,13 @@ if (!function_exists('check_self_available_in_family'))
{
function check_self_available_in_family($family_data)
{
$is_self_found = false;
$row_id_from_excel = array_filter($family_data,function($item){ return !isset($item['temp']);});
// Kint::dump($row_id_from_excel);
$row_id_from_excel = current($row_id_from_excel); // get excel sno/rowid of employee amoung familiy array where this array has both data from excel and db
$row_id_from_excel = $row_id_from_excel[0];
foreach ($family_data as $rkey => $row)
{
if($row[5] != null && strtolower($row[5]) == 'self')//$row[5] = relationship $row[4] = Gender
@ -317,7 +357,7 @@ if (!function_exists('check_self_available_in_family'))
}
return ['is_self_found' => $is_self_found,'emp_code' => $family_data[0][1]];
return ['is_self_found' => $is_self_found,'emp_code' => $family_data[0][1],'row_id' => $row_id_from_excel];
}
}
@ -335,28 +375,31 @@ if (!function_exists('name_and_empid_check_in_db'))
foreach ($family_data as $rkey => $row)
{
$res = $employeeModel
->join('client_policy cp',"employees.client_id = cp.client_id")
->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
// ->where("cp.id",$policy_id)
->where("employees.client_id",$client_id)
->where("employees.is_active",1)
->where("ep.is_active",1)
// ->where("ep.client_id",$client_id)
->where('name',$row[2])->where('emp_code',$row[1])
->findAll();
// dd($employeeModel->getLastQuery());
if(($current_action == 'deletion' || $current_action == 'correction' || $current_action == 'si_enhancement') && !count($res))
{
array_push($result['del'],$row[0]);
}
if(($current_action == 'inception' || $current_action == 'dependent_addition' || $current_action == 'addition') && count($res))
{
array_push($result['i'],$row[0]);
}
if(isset($row['temp']) && $row['temp']['source'] != 'db')
{
$res = $employeeModel
->join('client_policy cp',"employees.client_id = cp.client_id")
->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
// ->where("cp.id",$policy_id)
->where("employees.client_id",$client_id)
->where("employees.is_active",1)
->where("ep.is_active",1)
// ->where("ep.client_id",$client_id)
->where('name',$row[2])->where('emp_code',$row[1])
->findAll();
// dd($employeeModel->getLastQuery());
if(($current_action == 'deletion' || $current_action == 'correction' || $current_action == 'si_enhancement') && !count($res))
{
array_push($result['del'],$row[0]);
}
if(($current_action == 'inception' || $current_action == 'dependent_addition' || $current_action == 'addition') && count($res))
{
array_push($result['i'],$row[0]);
}
}
}
@ -466,7 +509,7 @@ if (!function_exists('check_dependent_conflict'))
if(($allowed_spouse_count < $received_spouse_count) || ($allowed_child_count < $received_child_count) )
{
$result['status'] = false;
$result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: Dependent count greater than allowed dependent count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch
$result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: As per policy, count of dependents has exceeded configured count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch
}
// || ($allowed_parents_count < $received_parents_count) || ($allowed_parent_in_laws_count < $received_parent_in_laws_count)
@ -478,7 +521,7 @@ if (!function_exists('check_dependent_conflict'))
if((2 < $received_parents_count) || (2 < $received_parent_in_laws_count))
{
$result['status'] = false;
$result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: Dependent count greater than allowed dependent count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch
$result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: As per policy, count of dependents has exceeded configured count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch
}
}
@ -488,7 +531,7 @@ if (!function_exists('check_dependent_conflict'))
{
// dd($allowed_adults);
$result['status'] = false;
$result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: Dependent count greater than allowed dependent count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch
$result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict:As per policy, count of dependents has exceeded configured count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch
}
@ -525,7 +568,7 @@ if (!function_exists('calculate_premimum'))
function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr,$default_si = null)
{
//
// dd($fileArr);
// dd($slab_details);
// grid type
// 1 = premium => si
$result = [];
@ -574,7 +617,7 @@ if (!function_exists('calculate_premimum'))
$transformed_familiy_member_data['policy_details']['basic_cover_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'] : $transformed_familiy_member_data['policy_details']['basic_cover_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
if( $fileArr['id'] == null || $transformed_familiy_member_data['temp']['source'] == 'excel' || ($fileArr['action'] == 'dependent_addition' && in_array($grid_type,[10,11]) && $slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($transformed_familiy_member_data['relationship']) == 'self'))//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
{
$transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details,$default_si);
@ -652,6 +695,8 @@ if (!function_exists('premium_calculation_manager'))
{
function premium_calculation_manager($emp_data,$policy_terms,$slab_details,$default_si = null)
{
$myLogger = \Config\Services::mylogger();
// grid type
// 1 = premium => si
// dd($emp_data);
@ -687,7 +732,7 @@ if (!function_exists('premium_calculation_manager'))
//gird and calculation start
$slug = \Config\Services::slug();
$grid_type = $slab_details['grid_master']['ui_type'];
$is_match_found = false;
switch ($grid_type) {
case "1":
//GPA - Sum Insured (SI) * Multiplier
@ -703,7 +748,7 @@ if (!function_exists('premium_calculation_manager'))
$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,'.','');
$is_match_found = true;
break;
}
}
@ -723,7 +768,7 @@ if (!function_exists('premium_calculation_manager'))
$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,'.','');
$is_match_found = true;
break;
}
}
@ -742,7 +787,7 @@ if (!function_exists('premium_calculation_manager'))
$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,'.','');
$is_match_found = true;
break;
}
}
@ -766,7 +811,7 @@ if (!function_exists('premium_calculation_manager'))
$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,'.','');
$is_match_found = true;
break;
}
}
@ -786,7 +831,7 @@ if (!function_exists('premium_calculation_manager'))
$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,'.','');
$is_match_found = true;
break;
}
}
@ -795,6 +840,28 @@ if (!function_exists('premium_calculation_manager'))
//GMC - Employees + Dependent Age band
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
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) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{
// echo $emp_data['name'];
$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']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$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,'.','');
$is_match_found = true;
break;
}
}
break;
case "7":
//GMC - Employees + Dependent Age + SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
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) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
@ -807,27 +874,7 @@ if (!function_exists('premium_calculation_manager'))
$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;
}
}
break;
case "7":
//GMC - Employees + Dependent Age + SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
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) && (($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']);
$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,'.','');
$is_match_found = true;
break;
}
}
@ -845,11 +892,11 @@ if (!function_exists('premium_calculation_manager'))
$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']);
$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']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$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,'.','');
$is_match_found = true;
break;
}
}
@ -866,11 +913,11 @@ if (!function_exists('premium_calculation_manager'))
$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']);
$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']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$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,'.','');
$is_match_found = true;
break;
}
}
@ -888,11 +935,11 @@ if (!function_exists('premium_calculation_manager'))
$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']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$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,'.',''));
$is_match_found = true;
break;
}
}
@ -917,11 +964,11 @@ if (!function_exists('premium_calculation_manager'))
$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']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = get_premium_for_si(slab_details: $slab_details,si_amount: $familiy_si_covered,band: $employee_received_band);
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days']);
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true;
break;
}
}
@ -942,11 +989,11 @@ if (!function_exists('premium_calculation_manager'))
$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']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$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,'.',''));
$is_match_found = true;
break;
}
}
@ -967,11 +1014,11 @@ if (!function_exists('premium_calculation_manager'))
$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']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$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,'.',''));
$is_match_found = true;
break;
}
}
@ -980,10 +1027,27 @@ if (!function_exists('premium_calculation_manager'))
default:
echo "Not a valid grid";
$this->myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found'));
}
// unset($emp_data['temp']);//remove temp data
if(!$is_match_found)
{
$log_message = '[ client_policy_id : ' .$emp_data['policy_details']['client_policy_id'].' - '. $emp_data['emp_code'].' - '.$emp_data['name'] .' - '. $emp_data['policy_details']['basic_cover_si'] . ' ]';
if($slab_details['slab_rates'][0]['premium_type'] == 1)
{
$log_message .= ' - skipping, calculating only self..!';
//reset emp si and others policy level data if premium only for self
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['basic_cover_si'] = 0;
$emp_data['policy_details']['premium'] = 0;
$emp_data['policy_details']['rata_premimum'] = 0;
$emp_data['policy_details']['gst'] = 0;
$emp_data['policy_details']['days'] = 0;
}
else { $log_message .= '- skipping, slab rate not found'; }
$myLogger->logme('error',$log_message);
// echo $log_message;
}
return $emp_data;
}
@ -1125,4 +1189,19 @@ if(!function_exists('replace_original_data'))
}
return $current_data;
}
}
if(!function_exists('get_premium_for_si'))
{
function get_premium_for_si(array $slab_details,string $si_amount,string $band)
{
foreach ($slab_details['slab_rates'] as $skey => $slab_value)
{
if($slab_value['si'] == $si_amount && $slab_value['grade'] == $band)
{
return $slab_value['premium'];
}
}
return 0;
}
}