diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index afeb733..1f1199c 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -3834,6 +3834,7 @@ class ClientController extends AdminController public function sendextraparam() { + helper('excel_util_helper'); // $batch_data = [ // 'client_id' => 17, // 'client_policy_id' => 30, @@ -3900,8 +3901,19 @@ class ClientController extends AdminController // $EmpDataServiceController->cashDepositCalculationForDeletion($array); - $employeeRestController = new EmployeeServiceController(); - $employeeRestController->employeesOnboardPreprocess(['file_id' => 756]); + // $employeeRestController = new EmployeeServiceController(); + // $employeeRestController->employeesOnboardPreprocess(['file_id' => 756]); + + // $employee_data = $this->employeeModel->getEmpFamilybyEmpCode(client_id: 159,client_policy_id: 336,emp_code: "6214",emp_status:[],policy_status:[]); + // dd(db_connect()->getLastQuery(), $employee_data); + // print_rr( $employee_data); die; + + // $data = update_si_with_auto_si(159, 336, "6214"); + // dd($data); + + // $EmployeeRestController = new EmployeeRestController(); + // $EmployeeRestController->calculatePremium(336, "6214", null, 126); + } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 42e8d53..f21e567 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -49,6 +49,8 @@ use Kreait\Firebase\Messaging\CloudMessage; use Kreait\Firebase\Messaging\Notification; use Kreait\Firebase\Exception\MessagingException; +use Kint\Kint; + class EmployeeRestController extends AdminController { @@ -2167,6 +2169,21 @@ class EmployeeRestController extends AdminController // print_r($slab_details);die(); $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); + // kint::dump($existing_famility_details); + + //get the Auto SI amount + $auto_si_data = update_si_with_auto_si($client_id, $client_policy_id, $emp_code, $client_branch_id, $existing_famility_details); + log_message('error', '----- Auto SI Amount : {data} -----', ['data' => $auto_si_data]); + + //Change the basic cover si to the auto si amount if the auto_si_amount is not null + if(!empty($auto_si_data)){ + foreach ($existing_famility_details as $emp_code => &$records) { + $records['basic_cover_si'] = $auto_si_data; + } + unset($record); + } + + // dd($existing_famility_details); if(!count($existing_famility_details) && $policy_type == 2)//top up addon only { @@ -2180,7 +2197,7 @@ class EmployeeRestController extends AdminController // dd($this->employeeModel->getLastQuery()); // print_r($existing_famility_details);die(); $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db'); - // print_r(($employee_data_group_by_family));//die(); + // print_rr(($employee_data_group_by_family));die(); $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $client_id,client_branch_id: $client_branch_id); @@ -2192,16 +2209,14 @@ class EmployeeRestController extends AdminController $data = calculate_premium_new(family_data: $transformed_famility_details,policy_terms:$policy_terms,slab_details:$slab_details,fileArr: $file,existing_units: $existing_units,default_si : $default_si); $employee_data_group_by_family[$emp_id] = $data; - } if($clientPolicyId != null && $empCode != null) - { - return $employee_data_group_by_family; + { // dd ($employee_data_group_by_family); + return $employee_data_group_by_family; }else{ // dd ($employee_data_group_by_family); - return $this->respond(['status' => 'success','code' => (count($employee_data_group_by_family) ? 200 : 404),'data' => [$employee_data_group_by_family] ], 200); - + return $this->respond(['status' => 'success','code' => (count($employee_data_group_by_family) ? 200 : 404),'data' => [$employee_data_group_by_family] ], 200); } } diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 2ab0273..c6e0a75 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -902,7 +902,7 @@ if (!function_exists('calculate_premium_new')) // dd($slab); $res = compare_incoming_family_slab_with_configured_slab($slab,$incoming_familiy_composition); // kint::dump($key); - kint::dump($res); + // kint::dump($res); if($res['is_applicable']) { @@ -942,7 +942,7 @@ if (!function_exists('calculate_premium_new')) $temp_slab_rates[$key]['is_applicable'] = false; } } - dd($family_data); + // dd($family_data); //4. if macthed then the current rack rate is applicable and find common variables link max age,max count,grade, basic pay,SI, self/acting self for current rack rate @@ -985,7 +985,7 @@ if (!function_exists('calculate_premium_new')) // // Final combined condition if ($conditions['isEmployeeSourceEnrollment'] || $conditions['isEmployeeSourceExcelFile'] || $primaryGridTypeCondition ) { - dd($transformed_familiy_member_data); + // dd($transformed_familiy_member_data); $transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$temp_slab_rates,$default_si); // dd($transformed_familiy_member_data); $result[] = $transformed_familiy_member_data; @@ -2177,39 +2177,104 @@ if(!function_exists('generate_family_floater_key')) } } +// --------AUTO SI Functions--------------------------------------------------------------------------------------- -if(!function_exists('update_si_with_auto_si')) +if (!function_exists('update_si_with_auto_si')) { - function update_si_with_auto_si($client_id, $client_policy_id, $client_branch_id, $emp_code) + function update_si_with_auto_si($client_id, $client_policy_id, $emp_code, $client_branch_id = null, $family_data_arr = []) { - $clientPolicy = new ClientPolicyModel(); $policy_data = $clientPolicy->getPolicyDetails($client_id, $client_policy_id); - if(empty($policy_data) || $policy_data['is_auto_si']){ + // check policy data is missing or Auto SI is enabled + if (empty($policy_data) || !empty($policy_data['is_auto_si'])) { return null; - }else{ - - $autoSiModel = new AutoSIModel(); - $auto_si_amounts = $autoSiModel - ->where('client_policy_id', $client_policy_id) - ->where('is_active', 1) - ->first(); - - $params = [ - 'auto_si' => $auto_si_amounts, - ]; - - $modified_si = modify_si_for_the_family($params); - return $modified_si; } + + $autoSiModel = new AutoSIModel(); + $auto_si_record = $autoSiModel + ->where('client_policy_id', $client_policy_id) + ->where('is_active', 1) + ->first(); + + // Check if Auto SI amounts exist + if (empty($auto_si_record) || empty($auto_si_record['family_composition'])) { + return null; + } + + $auto_si_amounts = json_decode($auto_si_record['family_composition'], true); + + $family_data = $family_data_arr; + if(empty($family_data_arr) && count($family_data_arr) == 0){ + + $employeeModel = new EmployeeModel(); + $family_data = $employeeModel->getEmpFamilybyEmpCode( + client_id: $client_id, + client_policy_id: $client_policy_id, + emp_code: $emp_code, + emp_status:['draft','enrolled'], + policy_status:['draft','enrolled'] + ); + } + + $params = [ + 'auto_si' => $auto_si_amounts, + 'family_data' => $family_data, + ]; + + $modified_si = modify_si_for_the_family($params); + return $modified_si; } } if(!function_exists('modify_si_for_the_family')) { function modify_si_for_the_family($params) - { + { + // print_rr($params); die; + // kint::dump($params); + $relationship_mapping = [ + "self" => ["self"], + "spouse" => ["spouse"], + "children" => ["son", "daughter"], + "elders" => ["father", "mother", "father-in-law", "mother-in-law"], + ]; + + if(empty($param) && !isset($params['auto_si']) && !isset($params['family_data']) && count($params['auto_si']) > 0 && count($params['family_data']) > 0){ + return null; + } + + $family_composition = ["self" => 0,"spouse" => 0,"children" => 0,"elders" => 0]; + + foreach ($params['family_data'] as $member) { + + $relationship = strtolower($member['relationship']); + $relationship = str_replace(' ', '-', $relationship); + + foreach ($relationship_mapping as $category => $relationships) { + if (in_array($relationship, $relationships)) { + $family_composition[$category]++; + break; + } + } + } + + $modified_si_amount = null; + + foreach ($params['auto_si'] as $auto_si_entry) { + $auto_si_pattern = array_diff_key($auto_si_entry, ['si' => 0]); + if ($family_composition == $auto_si_pattern) { + $modified_si_amount = $auto_si_entry['si']; + break; + } + } + + return $modified_si_amount; } -} \ No newline at end of file +} + +// --------AUTO SI Functions End--------------------------------------------------------------------------------------- + + +