1300 lines
68 KiB
PHP
1300 lines
68 KiB
PHP
<?php
|
|
|
|
use App\Models\EmployeeModel;
|
|
use Kint\Kint;
|
|
|
|
|
|
if(!function_exists('calculate_days_bw_dates'))
|
|
{
|
|
function calculate_days_bw_dates(string $from_date = "", string $to_date ="")
|
|
{
|
|
if($to_date == ""){ $currentDateTime = new DateTime(); }
|
|
else{ $currentDateTime = new DateTime($to_date); }
|
|
if($from_date == ""){ $passedDateTime = new DateTime(); }
|
|
else{ $passedDateTime = new DateTime($from_date); }
|
|
|
|
return $interval = $currentDateTime->diff($passedDateTime);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('check_columns_name')) {
|
|
function check_columns_name($definedColumns,$excelColumns)
|
|
{
|
|
$mismatchedColumns = [];
|
|
|
|
foreach ($definedColumns as $colName => $definedCol) {
|
|
$definedColIdx = $definedCol['col_idx'];
|
|
$definedColName = $definedCol['col_name'];
|
|
|
|
if (strtolower(strip_tags(trim($excelColumns[$definedColIdx]))) !== strtolower($definedColName)) {
|
|
$mismatchedColumns[] = "Column order conflict. Column order no ".($definedColIdx + 1)." expected : ".$definedColName." and received : ".$excelColumns[$definedColIdx]."<br/>";
|
|
}
|
|
}
|
|
|
|
return $mismatchedColumns;
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('check_row_is_empty_or_null')) {
|
|
|
|
function check_row_is_empty_or_null($arr) {
|
|
unset($arr[0]);// unset SNO in the array, becoz we need to check only datapoints are empty not SNo, it may added by accidentally
|
|
foreach ($arr as $item) {
|
|
if ($item !== null && !empty($item)) {
|
|
return false; // If any item is not empty or not null, return false
|
|
}
|
|
}
|
|
return true; // If all items are empty or null, return true
|
|
}
|
|
}
|
|
|
|
if (!function_exists('check_excel_date_format')) {
|
|
|
|
function check_excel_date_format($dateString,$format)
|
|
{
|
|
|
|
if($dateString == ""){ return array('status' => true); }
|
|
$date = DateTime::createFromFormat('d-M-Y', $dateString);
|
|
|
|
if ($date !== false && !is_array($date::getLastErrors())) {
|
|
return array('status' => true);
|
|
} else {
|
|
return array('status' => false,'error' => "wrong date format: Expected 'd-M-Y' and received $dateString");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if(!function_exists('check_relationship'))
|
|
{
|
|
function check_relationship($row,$relationship,$policy_terms)
|
|
{
|
|
// print_r($relationship);
|
|
// echo '<br>';
|
|
if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available
|
|
{
|
|
if($row[5] != null && $row[4] != null)//$row[5] = relationship $row[4] = Gender
|
|
{
|
|
$slug = \Config\Services::slug();
|
|
$col = $slug->slugify($row[5]);
|
|
// echo $col;//die();
|
|
if($col != 'self' && $col != 'spouse')
|
|
{
|
|
if(!isset($relationship[ $col ]))
|
|
{
|
|
return array('status' => false,'error' => 'Rule Conflict: Unknown Relationship');
|
|
}
|
|
|
|
$family_floaters = isset($policy_terms['family_floaters']);
|
|
if($family_floaters)
|
|
{
|
|
if(isset($relationship[ $col ]) && $relationship[ $col ]['gender'] != $row[4])
|
|
{
|
|
$error = "Gender relationship conflict: Expected ".$relationship[ $col ]['gender'].", received $row[4]";
|
|
return array('status' => false,'error' => $error);
|
|
}
|
|
}
|
|
else // if family_floaters not set the its GPA, reject all other dependents
|
|
{
|
|
if($col != 'self')
|
|
{
|
|
$error = "Dependent(s) are not allowed";
|
|
return array('status' => false,'error' => $error);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
return array('status' => true);
|
|
}
|
|
else
|
|
{
|
|
return array('status' => false,'error' => 'Rule Conflict: Both Relationship and Gender required for check relationship conflict');
|
|
}
|
|
}
|
|
else { return array('status' => true); } // in else condition no need to check rule, just return true
|
|
}
|
|
}
|
|
|
|
|
|
if(!function_exists('check_doj'))
|
|
{
|
|
|
|
function check_doj($row)
|
|
{
|
|
if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available
|
|
{
|
|
$slug = \Config\Services::slug();
|
|
$relationship = $slug->slugify($row[5]);
|
|
// echo $relationship;echo $row[7];
|
|
if($relationship == 'self' && $row[8] == "") { return array('status' => false,'error' => "DOJ mandantory for self"); }
|
|
return array('status' => true);
|
|
}
|
|
else { return array('status' => true); } // in else condition no need to check rule, just return true
|
|
}
|
|
}
|
|
|
|
|
|
if(!function_exists('check_employee_band'))
|
|
{
|
|
function check_employee_band($row,$policy_terms,$slab_details)
|
|
{
|
|
if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available
|
|
{
|
|
$is_emp_band_needed = $slab_details['grid_master']['emp_band'];
|
|
if($slab_details['grid_master']['ui_type'] == 1) //gpa rack rate 1
|
|
{
|
|
if($slab_details['slab_rates'][0]['si_or_bp'] == 3)
|
|
{
|
|
$is_emp_band_needed = true;
|
|
}
|
|
}
|
|
$slug = \Config\Services::slug();
|
|
$relationship = $slug->slugify($row[5]);
|
|
// echo $relationship;echo $row[7];
|
|
if($is_emp_band_needed && $relationship == 'self' && $row[10] == "") { return array('status' => false,'error' => "Band mandantory for self"); }
|
|
else if($is_emp_band_needed && $relationship == 'self' && $row[10] != "")
|
|
{
|
|
$received_grade = $row[10];
|
|
$found = false;
|
|
foreach ($slab_details['slab_rates'] as $skey => $slab_value)
|
|
{
|
|
if($slab_value['grade'] == $received_grade)
|
|
{
|
|
$found = true;
|
|
break;
|
|
}
|
|
}
|
|
if(!$found) { return array('status' => false,'error' => "Emp band/Grade not found"); }
|
|
}
|
|
return array('status' => true);
|
|
}else { return array('status' => true); } // in else condition no need to check rule, just return true
|
|
}
|
|
}
|
|
|
|
|
|
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];
|
|
foreach ($slab_details['slab_rates'] as $skey => $slab_value)
|
|
{
|
|
if($is_si_found && $is_age_slab_found)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if(!$is_si_found && $slab_value['si'] == $received_si) //match si amount
|
|
{
|
|
$is_si_found = true;
|
|
}
|
|
|
|
// check age slab
|
|
if($row[3] != null && DateTime::createFromFormat('d-M-Y', $row[3]) !== false)// 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);
|
|
if(!$is_age_slab_found)
|
|
{
|
|
if(isset($slab_value['age_from']) && isset($slab_value['age_to']))
|
|
{
|
|
if($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;// send true if age slab found
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$is_age_slab_found = true;// send true if age conditin is not applicable
|
|
}
|
|
|
|
}
|
|
|
|
}//end of check age slab
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
if(!function_exists('check_basic_pay'))
|
|
{
|
|
function check_basic_pay($row,$policy_terms,$slab_details)
|
|
{
|
|
if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available
|
|
{
|
|
$is_basic_pay_needed = $slab_details['grid_master']['basicpay'];
|
|
$slug = \Config\Services::slug();
|
|
$relationship = $slug->slugify($row[5]);
|
|
// echo $relationship;echo $row[7];
|
|
if($is_basic_pay_needed && $relationship == 'self' && $row[9] == "") { return array('status' => false,'error' => "Basic pay mandantory for self"); }
|
|
return array('status' => true);
|
|
}else { return array('status' => true); } // in else condition no need to check rule, just return true
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('check_dob_diff'))
|
|
{
|
|
function check_dob_diff($row,$relationships,$default_age_ratio) {
|
|
// echo 'called';
|
|
if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available
|
|
{
|
|
if($row[3] != null && $row[5] != null)
|
|
{
|
|
if (DateTime::createFromFormat('d-M-Y', $row[3]) === false)
|
|
{
|
|
return array('status' => false,'error' => 'Not a valid Date');
|
|
}
|
|
// return array('status' => true);
|
|
$dob = change_date_format($row[3],'d-M-Y','Y-m-d');
|
|
// echo $row[3].' - '.$dob;echo '<br>';
|
|
$currentDateTime = new DateTime();//die();
|
|
// print_r($currentDateTime);
|
|
// die();
|
|
$passedDateTime = new DateTime($dob);
|
|
// print_r($passedDateTime);
|
|
|
|
$interval = $currentDateTime->diff($passedDateTime);
|
|
//remap default age ratio data into relationship array
|
|
if(count($default_age_ratio))
|
|
{
|
|
$relationships = remap_default_age_ratio_into_relationship($relationships,$default_age_ratio);
|
|
}
|
|
$slug = \Config\Services::slug();
|
|
$relationship = $slug->slugify($row[5]);
|
|
$age_min = isset($relationships[$relationship]['age_min']) ? $relationships[$relationship]['age_min'] : NULL;
|
|
$age_max = isset($relationships[$relationship]['age_max']) ? $relationships[$relationship]['age_max'] : NULL;
|
|
// echo $relationship.','.$age_min.'-'.$age_max;
|
|
if($age_min !== null && $age_min > $interval->y)
|
|
{
|
|
return array('status' => false,'error' => "Age conflict : minimum $age_min yrs allowed, received $interval->y");
|
|
}
|
|
if($age_max !== null && $age_max < $interval->y)
|
|
{
|
|
return array('status' => false,'error' => "Age conflict : maximum $age_max yrs allowed, received $interval->y");
|
|
}
|
|
return array('status' => true);
|
|
}
|
|
else
|
|
{
|
|
return array('status' => false,'error' => 'Rule Conflict: Both DOB and Relationship required for age check');
|
|
}
|
|
}else { return array('status' => true); } // in else condition no need to check rule, just return true
|
|
}
|
|
}
|
|
|
|
if (!function_exists('data_group_by_family'))
|
|
{
|
|
function data_group_by_family($emp_data,$data_source = 'excel')
|
|
{
|
|
$result = [];
|
|
// Kint::dump($emp_data);
|
|
foreach ($emp_data as $rkey => $row)
|
|
{
|
|
if($data_source == 'excel')
|
|
{
|
|
if(!check_row_is_empty_or_null($row))
|
|
{
|
|
if(strtolower($row[5]) == 'self' && isset($result[$row[1]]))
|
|
{
|
|
array_unshift($result[$row[1]],$row);
|
|
}else
|
|
{
|
|
$result[$row[1]][] = $row;
|
|
}
|
|
}
|
|
}else if($data_source = 'db')
|
|
{
|
|
if(strtolower($row['relationship']) == 'self' && isset($result[$row['emp_code']]))
|
|
{
|
|
array_unshift($result[$row['emp_code']],$row);
|
|
}else
|
|
{
|
|
$result[$row['emp_code']][] = $row;
|
|
}
|
|
}
|
|
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('name_dup_check_within_family'))
|
|
{
|
|
function name_dup_check_within_family($family_data)
|
|
{
|
|
$result = [];
|
|
$temp = [];
|
|
foreach ($family_data as $rkey => $row)
|
|
{
|
|
if(in_array($row[2],$temp))
|
|
{
|
|
array_push($result,$row[0]);
|
|
}
|
|
else
|
|
{
|
|
array_push($temp, $row[2]);
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
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
|
|
{
|
|
$is_self_found = true;
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
return ['is_self_found' => $is_self_found,'emp_code' => $family_data[0][1],'row_id' => $row_id_from_excel];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('name_and_empid_check_in_db'))
|
|
{
|
|
function name_and_empid_check_in_db($family_data,$actionArr)
|
|
{
|
|
$employeeModel = new EmployeeModel();
|
|
$result = ['del' => [],'i' => []];
|
|
$client_id = $actionArr['client_id'];
|
|
$policy_id = $actionArr['policy_id'];
|
|
$current_action = $actionArr['action'];
|
|
|
|
foreach ($family_data as $rkey => $row)
|
|
{
|
|
if(($current_action == 'inception' || $current_action == 'addition') || ($current_action == 'dependent_addition' && (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]);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('check_dependent_conflict'))
|
|
{
|
|
function check_dependent_conflict($family_data,$policy_terms,$actionArr)
|
|
{
|
|
$result = ['status' => true];
|
|
|
|
$self_gender = null;
|
|
$spouse_gender = null;
|
|
|
|
$allowed_spouse_count = 0;
|
|
$received_spouse_count = 0;
|
|
$allowed_child_count = 0;
|
|
$received_child_count = 0;
|
|
$allowed_parents_count = 0;
|
|
$received_parents_count = 0;
|
|
$allowed_parent_in_laws_count = 0;
|
|
$received_parent_in_laws_count = 0;
|
|
$overall_famility_relationships = [];
|
|
$self_emp_row_id = null;
|
|
$temp_counts = [2,3,4,5,6,7,8,9,10]; //temp variable for check relation repetaed count
|
|
$slug = \Config\Services::slug();
|
|
// dd($policy_terms);
|
|
if(isset($policy_terms['family_floater']) && !empty($policy_terms['family_floaters']))
|
|
{
|
|
|
|
// $temp_string = implode(" ",$policy_terms['family_floaters']);
|
|
$temp = $policy_terms['family_floaters'];
|
|
$temp = is_array($temp) ? $temp : (is_object($temp) ? (array)$temp : []);
|
|
$allowed_child_count = $temp['childrens'];
|
|
$allowed_spouse_count = $temp['spouse'];
|
|
$allowed_adults = $temp['either-parents-pil'];
|
|
$allowed_parents_count = $temp['either-parents-pil'] == 0 ? $temp['parents'] : 0;
|
|
$allowed_parent_in_laws_count = $temp['either-parents-pil'] == 0 ? $temp['parents-in-law'] : 0;
|
|
// dd($allowed_adults == 0);
|
|
foreach ($family_data as $key => $row)
|
|
{
|
|
// dd($family_data[0][0]);
|
|
$relationship = $slug->slugify($row[5]);
|
|
|
|
if($actionArr != 'deletion' && $relationship != 'son' && $relationship != 'daughter')
|
|
{
|
|
array_push($overall_famility_relationships, $relationship);
|
|
}
|
|
|
|
|
|
if($relationship == 'self')
|
|
{
|
|
$self_gender = $row[4];
|
|
$self_emp_row_id = $row[0];
|
|
}
|
|
if($relationship == 'spouse')
|
|
{
|
|
$spouse_gender = $row[4];
|
|
$received_spouse_count = $received_spouse_count + 1;
|
|
}
|
|
if($relationship == 'son' || $relationship == 'daughter')
|
|
{
|
|
$received_child_count = $received_child_count + 1;
|
|
}
|
|
if($relationship == 'father' || $relationship == 'mother')
|
|
{
|
|
$received_parents_count = $received_parents_count + 1;
|
|
}
|
|
if($relationship == 'father-in-law' || $relationship == 'mother-in-law')
|
|
{
|
|
$received_parent_in_laws_count = $received_parent_in_laws_count + 1;
|
|
}
|
|
|
|
}
|
|
|
|
// print_r($overall_famility_relationships);
|
|
// echo '<br/>';
|
|
if($actionArr != 'deletion')
|
|
{
|
|
$repeated_relationships_count = array_count_values($overall_famility_relationships);
|
|
// print_r($repeated_relationships_count);
|
|
// echo '<br/>';
|
|
$repeated_count = array_intersect($repeated_relationships_count,$temp_counts);
|
|
if(is_array($repeated_count) && count($repeated_count))
|
|
{
|
|
$result['status'] = false;
|
|
$result['error_data'][] = ['code' => 13,'col_name' => 'relationship','msg' => 'Rule conflict: Twofold relationship found within family','row_id' => $family_data[0][0]];
|
|
}
|
|
}
|
|
// print_r($repeated_count);
|
|
// echo "===============";
|
|
// echo "<br/>";
|
|
|
|
|
|
// print_r(array_values(array_count_values($overall_famility_relationships)));
|
|
// print_r(in_array(2,array_values(array_count_values($overall_famility_relationships))));
|
|
|
|
if($self_gender && $spouse_gender && $self_gender == $spouse_gender)
|
|
{
|
|
$result['status'] = false;
|
|
$result['error_data'][] = ['code' => 4,'col_name' => 'gender','msg' => 'Rule conflict: Self and Spouse cannot be same gender','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];
|
|
}
|
|
|
|
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: 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)
|
|
if($allowed_adults == 1 && $received_parents_count && $received_parent_in_laws_count )
|
|
{
|
|
$result['status'] = false;
|
|
$result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: Parents and Parents in law both not allowed','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];
|
|
|
|
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: 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
|
|
}
|
|
}
|
|
|
|
// var_dump($allowed_adults == 0);
|
|
// dd($allowed_adults == 0 && (($allowed_parents_count < $received_parents_count) || ($allowed_parent_in_laws_count < $received_parent_in_laws_count)));
|
|
if($allowed_adults == 0 && (($allowed_parents_count < $received_parents_count) || ($allowed_parent_in_laws_count < $received_parent_in_laws_count) ))
|
|
{
|
|
// dd($allowed_adults);
|
|
$result['status'] = false;
|
|
$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
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
$result['status'] = true;
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
}
|
|
|
|
if (!function_exists('generate_relationship_code'))
|
|
{
|
|
function generate_relationship_code($arr)
|
|
{
|
|
$gender = ['M' => 1,'F' => 2];
|
|
$relationship = ['self' => 1,'spouse' => 2,'son' => 3,'daughter' => 4,'father' => 5,'mother' => 6,'father-in-law' => 7,'mother-in-law' => 8];
|
|
$slug = \Config\Services::slug();
|
|
$relationship_code = $slug->slugify($arr['relationship']);
|
|
$relationship_code = $gender[ $arr['gender'] ] . $relationship[ $relationship_code ] ;
|
|
return $relationship_code;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('calculate_premimum'))
|
|
{
|
|
function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr,$default_si = null)
|
|
{
|
|
//
|
|
// dd($slab_details);
|
|
// grid type
|
|
// 1 = premium => si
|
|
$result = [];
|
|
$grid_type = $slab_details['grid_master']['ui_type'];
|
|
$fileArr['grid_type'] = $grid_type;
|
|
//this variable for store emp id and their band for emp band level premium calculation for all famility members (especially for grid type 9) also store max age and max count of a familiy for grid type 10,11
|
|
$emp_details_with_empband_max_age_max_count = [];
|
|
//max age amoung familiy
|
|
$max_age = max(array_map(function($item) {return calculate_days_bw_dates(from_date: $item[3])->y; }, $family_data));
|
|
|
|
foreach($family_data as $fkey => $member)
|
|
{
|
|
//transform as db row column
|
|
$transformed_familiy_member_data = transform_excel_data_to_db($member,$fileArr);
|
|
// 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'] = 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
|
|
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount'] =count($family_data);
|
|
|
|
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage'] = $max_age;
|
|
|
|
//generate relationship code
|
|
if($transformed_familiy_member_data['temp']['action'] != 'D' && $transformed_familiy_member_data['temp']['action'] != 'C' && $transformed_familiy_member_data['temp']['action'] != 'SI')
|
|
{
|
|
$transformed_familiy_member_data['relationship_code'] = generate_relationship_code($transformed_familiy_member_data);
|
|
}
|
|
|
|
//calculate primimum based on grid type
|
|
if($transformed_familiy_member_data['temp']['action'] != 'D' && $transformed_familiy_member_data['temp']['action'] != 'C' && $transformed_familiy_member_data['temp']['action'] != 'SI')
|
|
{
|
|
|
|
//before call premium_calculation_manager attach band,max age and max count into the array temporarly for grid 9,10 and 11
|
|
$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'] = 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 || $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);
|
|
|
|
$result[] = $transformed_familiy_member_data;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('transform_excel_data_to_db'))
|
|
{
|
|
function transform_excel_data_to_db($memArr,$actionArr)
|
|
{
|
|
|
|
$current_column_action = null;
|
|
if($actionArr['action'] == 'inception'){ $current_column_action = 'I'; }
|
|
else if($actionArr['action'] == 'addition'){ $current_column_action = 'A'; }
|
|
else if($actionArr['action'] == 'dependent_addition'){ $current_column_action = 'DA'; }
|
|
else if($actionArr['action'] == 'deletion'){ $current_column_action = 'D'; }
|
|
else if($actionArr['action'] == 'correction'){ $current_column_action = 'C'; }
|
|
else if($actionArr['action'] == 'si_enhancement'){ $current_column_action = 'SI'; }
|
|
|
|
if($actionArr['action'] == 'inception' || $actionArr['action'] == 'addition' || $actionArr['action'] == 'dependent_addition')
|
|
{
|
|
|
|
$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['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;
|
|
$policy['days'] = null;
|
|
$policy['premium'] = null;
|
|
$policy['rata_premimum'] = null;
|
|
$policy['gst'] = null;
|
|
|
|
|
|
$result['emp_code'] = $memArr[1];
|
|
$result['name'] = $memArr[2];
|
|
$result['dob'] = isset($memArr[3]) ? change_date_format($memArr[3],'d-M-Y','Y-m-d') : NULL;
|
|
$result['gender'] = $memArr[4];
|
|
$result['relationship'] = $memArr[5];
|
|
$result['relationship_code'] = $memArr[5];
|
|
$result['doj'] = isset($memArr[8]) ? change_date_format($memArr[8],'d-M-Y','Y-m-d') : NULL;
|
|
$result['basic_pay'] = $memArr[9];
|
|
$result['band'] = $memArr[10];
|
|
$result['designation'] = $memArr[11];
|
|
$result['mobile'] = $memArr[12];
|
|
$result['email_corporate'] = $memArr[13];
|
|
$result['file_id'] = $actionArr['id'];
|
|
$result['client_id'] = $actionArr['client_id'];
|
|
$result['change_event'] = $memArr[15];
|
|
$result['temp']['grid_type'] = $actionArr['grid_type'];
|
|
$result['temp']['action'] = isset($memArr['current_action']) ? $memArr['current_action'] : $current_column_action;
|
|
$result['temp']['source'] = isset($memArr['temp']['source']) ? $memArr['temp']['source'] : 'excel';
|
|
$result['temp']['emp_id'] = isset($memArr['temp']['emp_id']) ? $memArr['temp']['emp_id'] : null;
|
|
$result['temp']['emp_policy_id'] = isset($memArr['temp']['emp_policy_id']) ? $memArr['temp']['emp_policy_id'] : null;
|
|
$result['temp']['policy_status'] = isset($memArr['temp']['policy_status']) ? $memArr['temp']['policy_status'] : null;
|
|
$result['temp']['emp_status'] = isset($memArr['temp']['emp_status']) ? $memArr['temp']['emp_status'] : null;
|
|
$result['policy_details'] = $policy;
|
|
|
|
return $result;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
//check if the data comes from enrollment (DB) and status is draft then fetch original data of employee from
|
|
//audit history table then initiate calculation with it. so this data again get updated in emp table
|
|
|
|
//check emp records
|
|
if($emp_data['file_id'] == null && $emp_data['temp']['emp_status'] == 'draft' && $emp_data['temp']['policy_status'] == 'draft')
|
|
{
|
|
$original_emp_records = get_emp_records_from_audit_history($emp_data['temp']['emp_id']);
|
|
if(is_array($original_emp_records))
|
|
{
|
|
// Kint::dump($original_emp_records);
|
|
$emp_data = replace_original_data(original_data:$original_emp_records,current_data:$emp_data);
|
|
// Kint::dump($value);
|
|
}
|
|
}
|
|
|
|
//check emp policy records
|
|
if($emp_data['file_id'] == null && $emp_data['temp']['emp_status'] == 'draft' && $emp_data['temp']['policy_status'] == 'draft')
|
|
{
|
|
$original_emp_policy_records = get_emp_policy_records_from_audit_history($emp_data['temp']['emp_policy_id']);
|
|
if(is_array($original_emp_policy_records))
|
|
{
|
|
// Kint::dump($original_emp_records);
|
|
$emp_data['policy_details'] = replace_original_data(original_data:$original_emp_policy_records,current_data:$emp_data['policy_details']);
|
|
// Kint::dump($policy_data);
|
|
}
|
|
}
|
|
//end of fetching data from audit history table
|
|
|
|
//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
|
|
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
|
|
$employee_received_band = $emp_data['temp']['band'];
|
|
foreach ($slab_details['slab_rates'] as $skey => $slab_value)
|
|
{
|
|
if(($slab_value['si'] == $employee_received_si) || ($slab_value['grade'] != null && $slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si))
|
|
{
|
|
$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 "2":
|
|
//GPA - Flat Rate for all 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)
|
|
{
|
|
if($slab_value['si'] == $employee_received_si)
|
|
{
|
|
$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 "3":
|
|
//GMC - 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)
|
|
{
|
|
if($slab_value['si'] == $employee_received_si)
|
|
{
|
|
$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 "4":
|
|
|
|
//GMC - Employees Age band
|
|
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
|
|
// dd($employee_received_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))
|
|
{
|
|
// dd($slab_value);
|
|
$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 "5":
|
|
//GMC - Employees 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))
|
|
{
|
|
$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 "6":
|
|
//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) ))
|
|
{
|
|
$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 "8":
|
|
//GMC - SI as per Grade or Band
|
|
$employee_received_band = $emp_data['temp']['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)
|
|
{
|
|
|
|
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'];
|
|
$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 "9":
|
|
//GMC - Flat Rate for all
|
|
$employee_received_band = $emp_data['temp']['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)
|
|
{
|
|
|
|
if($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']);
|
|
$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 "10":
|
|
//GMC - Maximum age of Dependents
|
|
$max_age = $emp_data['temp']['maxage'];
|
|
$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['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'] = $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($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 "11":
|
|
//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) && (($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'] = $familiy_si_covered;
|
|
$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'] = 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;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case "12":
|
|
//GMC - Employee + relationship
|
|
|
|
$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['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) )
|
|
{
|
|
|
|
$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($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 "13":
|
|
//GMC - Employee + relationship + age
|
|
$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['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')) )
|
|
{
|
|
|
|
$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($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;
|
|
|
|
|
|
|
|
default:
|
|
$this->myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found'));
|
|
}
|
|
if(!$is_match_found)
|
|
{
|
|
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
|
|
$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'] . ', Age : '. $age.' ]';
|
|
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;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('calculate_pro_rata_premimum'))
|
|
{
|
|
function calculate_pro_rata_premimum($premium,$days)
|
|
{
|
|
return (float) number_format(($premium / 365) * $days,2,'.','');
|
|
}
|
|
}
|
|
|
|
//transform db columns into excel rows with indexs
|
|
if (!function_exists('transform_db_data_to_excel'))
|
|
{
|
|
function transform_db_data_to_excel($familiyArr,$actionArr = [])
|
|
{
|
|
// if($actionArr['action'] == 'dependent_addition')
|
|
// {
|
|
$return_data = [];
|
|
|
|
foreach ($familiyArr as $key => $value)
|
|
{
|
|
// dd($value);
|
|
$row = [];
|
|
$row[0] = ($key + 1);
|
|
$row[6] = $value['basic_cover_si'];
|
|
$row[14] = $value['pre_existing_alignments'];
|
|
$row[16] = isset($value['date_of_exit']) ? change_date_format($value['date_of_exit'], 'Y-m-d', 'd-M-Y') : NULL;
|
|
$row[17] = $value['reason_for_exit'];
|
|
|
|
|
|
$row[7] = isset($value['date_coverage']) ? change_date_format($value['date_coverage'], 'Y-m-d', 'd-M-Y') : NULL;
|
|
|
|
$row[1] = $value['emp_code'];
|
|
$row[2] = $value['name'];
|
|
$row[3] = isset($value['dob']) ? change_date_format($value['dob'], 'Y-m-d', 'd-M-Y') : NULL;
|
|
$row[4] = $value['gender'];
|
|
$row[5] = $value['relationship'];
|
|
|
|
$row[8] = isset($value['doj']) ? change_date_format($value['doj'], 'Y-m-d', 'd-M-Y') : NULL;
|
|
$row[9] = $value['basic_pay'];
|
|
$row[10] = $value['band'];
|
|
$row[11] = $value['designation'];
|
|
$row[12] = $value['mobile'];
|
|
$row[13] = $value['email_corporate'];
|
|
// $actionArr['id'] = $value['file_id'];
|
|
// $actionArr['client_id'] = $value['client_id'];
|
|
$row[15] = $value['change_event'];
|
|
$row['current_action'] = 'DA';
|
|
$row['temp']['source'] = 'db';
|
|
$row['temp']['emp_id'] = $value['emp_id'];
|
|
$row['temp']['emp_policy_id'] = $value['emp_policy_id'];
|
|
$row['temp']['emp_status'] = $value['emp_status'];
|
|
$row['temp']['policy_status'] = $value['status'];
|
|
|
|
array_push($return_data, ($row));
|
|
}
|
|
|
|
return $return_data;
|
|
// }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
//comparre excel cell names and return range of chars between them
|
|
if (!function_exists('compare_excel_cell_range'))
|
|
{
|
|
function compare_excel_cell_range($highestColumnAllowed, $highestColumnReceivedInExcel) {
|
|
$highestColumnAllowed = strtoupper($highestColumnAllowed);
|
|
$highestColumnReceivedInExcel = strtoupper($highestColumnReceivedInExcel);
|
|
|
|
if ($highestColumnAllowed < $highestColumnReceivedInExcel) {
|
|
$range = range($highestColumnAllowed, $highestColumnReceivedInExcel);
|
|
return $range;
|
|
}
|
|
return [];
|
|
}
|
|
}
|
|
|
|
if(!function_exists('get_emp_records_from_audit_history'))
|
|
{
|
|
function get_emp_records_from_audit_history($employee_id)
|
|
{
|
|
$db = db_connect();
|
|
$query = "SELECT min(id) as id,pk,table_name,field_name,old_value FROM venbaehn_nhance.auditing_history where pk = $employee_id and table_name = 'employees' and field_name in ('name','dob','gender','mobile','email_corporate','relationship') group by field_name order by id asc";
|
|
$res = $db->query($query);
|
|
// echo $db->getLastQuery();
|
|
$res = $res->getResultArray();
|
|
if(count($res))
|
|
{ $temp = [];
|
|
foreach($res as $row)
|
|
{
|
|
$temp[ $row['field_name'] ] = $row['old_value'];
|
|
}
|
|
return $temp;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
if(!function_exists('get_emp_policy_records_from_audit_history'))
|
|
{
|
|
function get_emp_policy_records_from_audit_history($emp_policy_id)
|
|
{
|
|
$db = db_connect();
|
|
$query = "SELECT min(id) as id,pk,table_name,field_name,old_value FROM venbaehn_nhance.auditing_history where pk = $emp_policy_id and table_name = 'employee_polices' and field_name in ('basic_cover_si','premium','gst') group by field_name order by id asc";
|
|
$res = $db->query($query);
|
|
// echo $db->getLastQuery();
|
|
$res = $res->getResultArray();
|
|
if(count($res))
|
|
{ $temp = [];
|
|
foreach($res as $row)
|
|
{
|
|
$temp[ $row['field_name'] ] = $row['old_value'];
|
|
}
|
|
return $temp;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if(!function_exists('replace_original_data'))
|
|
{
|
|
function replace_original_data(array $original_data,array $current_data)
|
|
{
|
|
foreach($original_data as $key => $data)
|
|
{
|
|
if(array_key_exists($key, $current_data))
|
|
{
|
|
$current_data [$key] = $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;
|
|
}
|
|
}
|
|
|
|
if(!function_exists('remap_default_age_ratio_into_relationship'))
|
|
{
|
|
function remap_default_age_ratio_into_relationship(array $general_relationships,array $default_age_ratio)
|
|
{
|
|
foreach ($default_age_ratio as $relationship => $age_ratio)
|
|
{
|
|
switch ($relationship) {
|
|
case 'child':
|
|
if (isset($general_relationships['son'])) {
|
|
$general_relationships['son']['age_min'] = $age_ratio['min'];
|
|
$general_relationships['son']['age_max'] = $age_ratio['max'];
|
|
}
|
|
if (isset($general_relationships['daughter'])) {
|
|
$general_relationships['daughter']['age_min'] = $age_ratio['min'];
|
|
$general_relationships['daughter']['age_max'] = $age_ratio['max'];
|
|
}
|
|
break;
|
|
case 'elders':
|
|
if (isset($general_relationships['father'])) {
|
|
$general_relationships['father']['age_min'] = $age_ratio['min'];
|
|
$general_relationships['father']['age_max'] = $age_ratio['max'];
|
|
}
|
|
if (isset($general_relationships['mother'])) {
|
|
$general_relationships['mother']['age_min'] = $age_ratio['min'];
|
|
$general_relationships['mother']['age_max'] = $age_ratio['max'];
|
|
}
|
|
if (isset($general_relationships['father-in-law'])) {
|
|
$general_relationships['father-in-law']['age_min'] = $age_ratio['min'];
|
|
$general_relationships['father-in-law']['age_max'] = $age_ratio['max'];
|
|
}
|
|
if (isset($general_relationships['mother-in-law'])) {
|
|
$general_relationships['mother-in-law']['age_min'] = $age_ratio['min'];
|
|
$general_relationships['mother-in-law']['age_max'] = $age_ratio['max'];
|
|
}
|
|
break;
|
|
default:
|
|
if (isset($general_relationships[$relationship])) {
|
|
$general_relationships[$relationship]['age_min'] = $age_ratio['min'];
|
|
$general_relationships[$relationship]['age_max'] = $age_ratio['max'];
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $general_relationships;
|
|
}
|
|
}
|
|
|
|
|
|
if(!function_exists('check_dup_mobileno'))
|
|
{
|
|
function check_dup_mobileno(array $row,array $existing_mobilenos)
|
|
{
|
|
foreach($existing_mobilenos as $k => $value)
|
|
{
|
|
if ($row['12'] == $value['mobile']) {
|
|
return array('status' => false,'error' => "Duplicate Mobile No");
|
|
// break;
|
|
}
|
|
}
|
|
return array('status' => true);
|
|
}
|
|
} |