diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php
index 10a0b636..733c2352 100755
--- a/app/Controllers/EmployeeRestController.php
+++ b/app/Controllers/EmployeeRestController.php
@@ -3841,7 +3841,8 @@ class EmployeeRestController extends AdminController
// 'Denial Review Awaited' => [66],
// 'Rejected' => [8, 49, 55, 60],
// ];
-
+
+ // construct the claim status
$client_claim_status = $this->getClaimStatusGrouped();
foreach ($ticket_data as $key => $value) {
diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php
index 4329388d..15f41462 100755
--- a/app/Helpers/excel_util_helper.php
+++ b/app/Helpers/excel_util_helper.php
@@ -1028,8 +1028,8 @@ if (!function_exists('transform_excel_data_to_db')) {
}
-if (!function_exists('premium_calculation_manager')) {
- function premium_calculation_manager($emp_data, $policy_terms, $slab_details, $default_si = null)
+if (!function_exists('premium_calculation_manager_old')) {
+ function premium_calculation_manager_old($emp_data, $policy_terms, $slab_details, $default_si = null)
{
// dd($emp_data,$policy_terms,$slab_details,$default_si);
@@ -1435,6 +1435,424 @@ if (!function_exists('premium_calculation_manager')) {
}
}
+if (!function_exists('premium_calculation_manager')) {
+ function premium_calculation_manager($emp_data, $policy_terms, $slab_details, $default_si = null)
+ {
+ // dd($emp_data,$policy_terms,$slab_details,$default_si);
+
+ $myLogger = \Config\Services::mylogger();
+ // grid type
+ // 1 = premium => si
+ // Kint::dump($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 = $emp_data['temp']['grid_id'];
+ $slab_index = isset($emp_data['temp']['grid_name']) ? $emp_data['temp']['grid_name'] : false;
+ // echo $emp_data['name'];
+ // kint::dump($slab_index);
+ if ($slab_index === false) {
+ // echo 'not set';
+ return false;
+ }
+ $temp_slab_rates = $slab_details[$slab_index]['slab_rates'];
+
+ //if curent action is dependent addition OR addition then pull insurer master to set whether add one day from employee date of coverage
+ if ($emp_data['temp']['action'] == 'DA' || $emp_data['temp']['action'] == 'A') {
+ $insurer = new InsurerModel();
+ $insurer = ($insurer->find($policy_terms['insurer_id']));
+ if (isset($insurer['addition_add_day']) && $insurer['addition_add_day'] == true) {
+ // $emp_data['policy_details']['date_coverage'] = (new DateTime($emp_data['policy_details']['date_coverage']))->modify('+1 day')->format('Y-m-d');
+
+ $emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) && $emp_data['policy_details']['date_coverage'] != '' && $emp_data['policy_details']['date_coverage'] != null ?
+ (new DateTime($emp_data['policy_details']['date_coverage']))->modify('+1 day')->format('Y-m-d') : null;
+ }
+ }
+ // dd($emp_data);
+ $is_match_found = false;
+ $gst = isset($policy_terms['gst']) && $policy_terms['gst'] != 0 ? $policy_terms['gst'] : 18;
+ 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 ($temp_slab_rates as $skey => $slab_value) {
+ if (($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit']) || ($slab_value['grade'] != null && $slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'])) {
+ $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', '');
+ $is_match_found = true;
+ break;
+ }
+ }
+ //auto calculate of SI and premium for basic pay type
+ if (!$is_match_found) {
+ if ($temp_slab_rates[0]['si_or_bp'] == 2) {
+ $temp_si = $emp_data['basic_pay'] * $temp_slab_rates[0]['basic_multiplier'];
+ $temp_premium = ($temp_si * $temp_slab_rates[0]['multiplier']) / 1000;
+
+ $emp_data['policy_details']['basic_cover_si'] = $temp_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 + 1);
+ $emp_data['policy_details']['premium'] = $temp_premium;
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', '');
+ $is_match_found = true;
+
+ $log_message = 'Pre defined SI not found. auto calc SI & premium for -' . $emp_data['emp_code'] . ' - ' . $emp_data['name'] . ' - ' . $temp_si . ' - ' . $temp_premium;
+ $myLogger->logme('error', $log_message);
+ }
+ }
+ 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 ($temp_slab_rates as $skey => $slab_value) {
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit']) {
+ $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 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 ($temp_slab_rates as $skey => $slab_value) {
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit']) {
+ $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 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);
+ $temp_date = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
+ $age = calculate_days_bw_dates(from_date: $emp_data['dob'], to_date: $temp_date)->y;
+
+ foreach ($temp_slab_rates as $skey => $slab_value) {
+
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', '');
+ $emp_data['policy_details']['age_band'] = $slab_value['age_from'] . '-' . $slab_value['age_to'];
+ $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;
+ $temp_date = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
+ $age = calculate_days_bw_dates(from_date: $emp_data['dob'], to_date: $temp_date)->y;
+ // kint::dump($age);
+ foreach ($temp_slab_rates as $skey => $slab_value) {
+ // dd($slab_value);
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', '');
+ $emp_data['policy_details']['age_band'] = $slab_value['age_from'] . '-' . $slab_value['age_to'];
+ $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;
+ $temp_date = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
+ $age = calculate_days_bw_dates(from_date: $emp_data['dob'], to_date: $temp_date)->y;
+ foreach ($temp_slab_rates as $skey => $slab_value) {
+
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) {
+ // echo $emp_data['name']; die;
+ $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', '');
+ $emp_data['policy_details']['age_band'] = $slab_value['age_from'] . '-' . $slab_value['age_to'];
+ $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;
+ $temp_date = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
+ $age = calculate_days_bw_dates(from_date: $emp_data['dob'], to_date: $temp_date)->y;
+ foreach ($temp_slab_rates as $skey => $slab_value) {
+
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', '');
+ $emp_data['policy_details']['age_band'] = $slab_value['age_from'] . '-' . $slab_value['age_to'];
+
+ $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 ($temp_slab_rates as $skey => $slab_value) {
+
+ if ($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si) {
+ // $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 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 ($temp_slab_rates as $skey => $slab_value) {
+
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit']) {
+ $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', '');
+ $is_match_found = true;
+ break;
+ }
+ }
+ break;
+ case "10":
+ //GMC - Maximum age of Dependents
+ $max_age = $emp_data['temp']['max_age'];
+ $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
+ // echo $emp_data['name'].'-'.$employee_received_si.'
';
+ // echo $emp_data['temp']['grid_type'].'
';
+ $emp_data['policy_details']['basic_cover_si'] = null;
+ foreach ($temp_slab_rates as $skey => $slab_value) {
+ // echo $slab_value['si'].'-'.$slab_value['age_from'].'-'.$slab_value['age_to'].'-'.$max_age.'
';
+ if (
+ $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age)
+ ) {
+ $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', ''));
+ $emp_data['policy_details']['age_band'] = $slab_value['age_from'] . '-' . $slab_value['age_to'];
+
+ $is_match_found = true;
+ break;
+ }
+ }
+ break;
+ case "11":
+ //GMC - Maximum count per Family
+ $max_count = $emp_data['temp']['max_count'];
+ $employee_received_band = $emp_data['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 ($temp_slab_rates as $skey => $slab_value) {
+
+ if ($slab_value['si'] == $employee_received_si && $slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit']) {
+ //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 + 1);
+ $emp_data['policy_details']['premium'] = get_premium_for_si(slab_details: $temp_slab_rates, si_amount: $familiy_si_covered, band: $employee_received_band, unit: $emp_data['unit']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 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 ($temp_slab_rates as $skey => $slab_value) {
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && $slab_value['relationship'] == $employee_relationship) {
+
+ $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], (calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days + 1));
+ $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 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;
+ $temp_date = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
+ $age = calculate_days_bw_dates(from_date: $emp_data['dob'], to_date: $temp_date)->y;
+ foreach ($temp_slab_rates as $skey => $slab_value) {
+ if ($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && $slab_value['relationship'] == $employee_relationship) {
+
+ $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 + 1);
+ $emp_data['policy_details']['premium'] = $slab_value['premium'];
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'], $emp_data['policy_details']['days'], calculate_days_bw_dates($policy_terms['policy_start_date'], $policy_terms['policy_end_date'])->days);
+ $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', ''));
+ $emp_data['policy_details']['age_band'] = $slab_value['age_from'] . '-' . $slab_value['age_to'];
+ $is_match_found = true;
+ break;
+ }
+ }
+ break;
+
+
+
+ default:
+ $myLogger->logme('error', ($emp_data['emp_code'] . '-' . $emp_data['name'] . ' - grid type not found'));
+ }
+
+ //this if condition for premium calculated & premium type 3 (familiy floater but premium calculated every individual implemented later) then remove si amount only for dependents (not self)
+ if ($is_match_found && strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 3 && $policy_terms['is_addon'] != 3) {
+ //set dependent si to 0
+ $emp_data['policy_details']['basic_cover_si'] = 0;
+ }
+ if (!$is_match_found) {
+ $temp_date = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
+ $age = calculate_days_bw_dates(from_date: $emp_data['dob'], to_date: $temp_date)->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 ($temp_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;
+ $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
+ } else {
+ $log_message .= '- skipping, slab rate not found';
+ }
+ $myLogger->logme('error', $log_message);
+ // echo $log_message;
+
+ }
+ // if the family floater case first self add first the process completed, after spouse or any dependent add the rata premium not added this change will handle this
+ if (strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 1 && $emp_data['temp']['action'] == 'DA') {
+ //set dependent si to 0
+ $emp_data['policy_details']['basic_cover_si'] = 0;
+ $emp_data['policy_details']['premium'] = 0;
+ }else if(strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 1 && ($emp_data['temp']['action'] == 'I' || $emp_data['temp']['action'] == 'A' || $emp_data['temp']['action'] == 'MI')){
+
+ $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;
+ $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
+ }
+
+ return $emp_data;
+ }
+}
+
if (!function_exists('calculate_pro_rata_premimum')) {
function calculate_pro_rata_premimum($premium, $employee_policy_coverage_days, $policy_coverage_days)