From e3768fd3d7c334f6d3821313674519b7de5bce8a Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Wed, 8 Apr 2026 12:23:09 +0530 Subject: [PATCH 1/7] FEAT_HADLE_OPD_AS_GMC_TOP_UP --- app/Controllers/ClientController.php | 172 ++++++++- app/Controllers/EmployeeRestController.php | 366 +++++++++---------- app/Views/client_policy.php | 8 +- app/Views/other_policy_terms.php | 399 ++++++++++++++++++++- public/2026-04-08.md | 27 ++ public/policy_type_72_alignment_plan.md | 124 +++++++ 6 files changed, 874 insertions(+), 222 deletions(-) create mode 100644 public/2026-04-08.md create mode 100644 public/policy_type_72_alignment_plan.md diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 3d989a0..d8c4243 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1260,7 +1260,7 @@ class ClientController extends AdminController $data['is_addon'] = 1; // Base Policy - } else if ($policy_type_id == 4 || $policy_type_id == 5) { + } else if ($policy_type_id == 4 || $policy_type_id == 5 || $policy_type_id == 72) { $data['is_addon'] = 2; // SI TOPUP @@ -1416,7 +1416,7 @@ class ClientController extends AdminController $data['is_addon'] = 1; // Base Policy - } else if ($policy_type_id == 4 || $policy_type_id == 5) { + } else if ($policy_type_id == 4 || $policy_type_id == 5 || $policy_type_id == 72) { $data['is_addon'] = 2; // SI TOPUP @@ -2108,7 +2108,7 @@ class ClientController extends AdminController $subject = $record['policy_type']; $policy_type_id = $record['policy_type_id']; - if (preg_match($gmc_pattern, $subject)) { + if (preg_match($gmc_pattern, $subject) || $policy_type_id == 72) { $search_term = 'GMC'; } else if (preg_match($gpa_pattern, $subject) || $policy_type_id == 6 || $policy_type_id == 7) { $search_term = 'GPA'; @@ -3330,20 +3330,119 @@ class ClientController extends AdminController $client_policy_id = $this->request->getPost("client_policy_id"); $policy_terms = $this->request->getPost("policy_terms"); - - if (!empty($policy_terms)) { - $policy_terms = json_decode($policy_terms, true); - $policy_terms['is_payable_employee']['self'] = 0; - $policy_terms = json_encode($policy_terms); - } - - + $policy_terms = json_decode($policy_terms, true); $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); + if (empty($policy_terms)) { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Policy terms data could not be empty', 'formdata' => $this->request->getPost()], 200); + } + if ($record) { + $data = []; - $update = $this->clientPolicyModel->where('id', $client_policy_id)->set('policy_terms', $policy_terms)->update(); + if ((int)$record['policy_type_id'] === 72) { + $data['sum_insured'] = $policy_terms['sum_insured'] ?? 0; + $data['multiple_sum_insured'] = $policy_terms['multiple_sum_insured'] ?? []; + $data['family_floater'] = $policy_terms['family_floater'] ?? 0; + $data['family_floaters'] = $policy_terms['family_floaters'] ?? []; + $data['age_ratio']['self']['min'] = $policy_terms['self_min_age'] ?? 0; + $data['age_ratio']['self']['max'] = $policy_terms['self_max_age'] ?? 0; + $data['age_ratio']['spouse']['min'] = $policy_terms['spouse_min_age'] ?? 0; + $data['age_ratio']['spouse']['max'] = $policy_terms['spouse_max_age'] ?? 0; + $data['age_ratio']['child']['min'] = $policy_terms['child_min_age'] ?? 0; + $data['age_ratio']['child']['max'] = $policy_terms['child_max_age'] ?? 0; + $data['age_ratio']['elders']['min'] = $policy_terms['other_member_min_age'] ?? 0; + $data['age_ratio']['elders']['max'] = $policy_terms['other_member_max_age'] ?? 0; + + $temp_family_floaters = $data['family_floaters']; + $data['family_floaters'] = []; + $data['family_floaters']['self'] = in_array("self", $temp_family_floaters) ? 1 : 0; + $data['family_floaters']['spouse'] = in_array("spouse", $temp_family_floaters) ? 1 : 0; + + if (count($temp_family_floaters)) { + $children_index = 0; + $elders_index = 1; + if (count($temp_family_floaters) == 3) { + $children_index = 1; + $elders_index = 2; + } else if (count($temp_family_floaters) >= 4) { + $children_index = 2; + $elders_index = 3; + } + + $data['family_floaters']['childrens'] = (int)($temp_family_floaters[$children_index] ?? 0); + $elders_type = $temp_family_floaters[$elders_index] ?? '0'; + + if ($elders_type == '1P') { + $data['family_floaters']['parents'] = 1; + $data['family_floaters']['parents-in-law'] = 0; + $data['family_floaters']['either-parents-pil'] = 0; + } else if ($elders_type == '2P') { + $data['family_floaters']['parents'] = 2; + $data['family_floaters']['parents-in-law'] = 0; + $data['family_floaters']['either-parents-pil'] = 0; + } else if ($elders_type == '1PIL') { + $data['family_floaters']['parents'] = 0; + $data['family_floaters']['parents-in-law'] = 1; + $data['family_floaters']['either-parents-pil'] = 0; + } else if ($elders_type == '2PIL') { + $data['family_floaters']['parents'] = 0; + $data['family_floaters']['parents-in-law'] = 2; + $data['family_floaters']['either-parents-pil'] = 0; + } else if ($elders_type == '2EPORPIL') { + $data['family_floaters']['parents'] = 0; + $data['family_floaters']['parents-in-law'] = 0; + $data['family_floaters']['either-parents-pil'] = 2; + } else if ($elders_type == 'EPORPIL') { + $data['family_floaters']['parents'] = 0; + $data['family_floaters']['parents-in-law'] = 0; + $data['family_floaters']['either-parents-pil'] = 1; + } else if ($elders_type == '4EPORPIL') { + $data['family_floaters']['parents'] = 2; + $data['family_floaters']['parents-in-law'] = 2; + $data['family_floaters']['either-parents-pil'] = 0; + } else { + $data['family_floaters']['parents'] = 0; + $data['family_floaters']['parents-in-law'] = 0; + $data['family_floaters']['either-parents-pil'] = 0; + } + } + + $data['family_floaters']['elders_count'] = $this->request->getPost("elder_member_count") ? $this->request->getPost("elder_member_count") : 0; + $data['mode_of_serviceability'] = $policy_terms['mode_of_serviceability'] ?? ''; + $data['eligibility'] = $policy_terms['eligibility'] ?? ''; + $data['total_sum_insured_limit'] = $policy_terms['total_sum_insured_limit'] ?? 'INR 15000'; + $data['in_person_doctor_consultation'] = $policy_terms['in_person_doctor_consultation'] ?? ''; + $data['prescribed_lab_test_pathology_radiology'] = $policy_terms['prescribed_lab_test_pathology_radiology'] ?? ''; + $data['prescribed_pharmacy'] = $policy_terms['prescribed_pharmacy'] ?? ''; + $data['dental'] = $policy_terms['dental'] ?? ''; + $data['vision'] = $policy_terms['vision'] ?? ''; + $data['vaccination_for_children_and_adults'] = $policy_terms['vaccination_for_children_and_adults'] ?? ''; + $data['special_condition_label'] = $policy_terms['special_condition_label'] ?? []; + $data['special_condition_input'] = $policy_terms['special_condition_input'] ?? []; + $data['enrollment_display_key'] = $this->otherPolicyTermsDisplayKeyConstruct($policy_terms); + $data['is_payable_employee'] = [ + 'self' => $this->request->getPost('is_payable_employee_for_self') ? 1 : 0, + 'spouse' => $this->request->getPost('is_payable_employee_for_spouse') ? 1 : 0, + 'childern' => $this->request->getPost('is_payable_employee_for_child') ? 1 : 0, + 'elders' => $this->request->getPost('is_payable_employee_for_elders') ? 1 : 0, + ]; + } else { + foreach ($policy_terms as $key => $value) { + if (str_ends_with($key, '_display')) { + $original_key = substr($key, 0, -8); + $newKey = implode(' ', array_map('ucfirst', explode('_', $original_key))); + $data['enrollment_display_key'][$newKey] = $policy_terms[$original_key] ?? " "; + } else { + $data[$key] = $value; + } + } + $data['is_payable_employee']['self'] = 0; + } + + $policy_terms_json = json_encode($data); + $update = $this->clientPolicyModel->where('id', $client_policy_id)->set('policy_terms', $policy_terms_json)->update(); if ($update) { return $this->respond(['status' => true, 'code' => 200, 'message' => 'Data updated successfully', 'client_policy_id' => $client_policy_id], 200); } else { @@ -3355,6 +3454,49 @@ class ClientController extends AdminController } } + public function otherPolicyTermsDisplayKeyConstruct($data) + { + $labels = $data['special_condition_label'] ?? []; + $values = $data['special_condition_input'] ?? []; + $special_conditions = []; + $display_fields = []; + + foreach ($labels as $i => $label) { + $value = $values[$i] ?? ''; + if (trim((string)$label) === '' || trim((string)$value) === '') { + continue; + } + $special_conditions[$label] = $value; + } + + $labelMap = [ + 'mode_of_serviceability' => 'Mode Of Serviceability', + 'eligibility' => 'Eligibility', + 'total_sum_insured_limit' => 'Total Sum Insured Limit', + 'in_person_doctor_consultation' => 'In Person Doctor Consultation', + 'prescribed_lab_test_pathology_radiology' => 'Prescribed Lab Test Pathology Radiology', + 'prescribed_pharmacy' => 'Prescribed Pharmacy', + 'dental' => 'Dental', + 'vision' => 'Vision', + 'vaccination_for_children_and_adults' => 'Vaccination For Children And Adults', + ]; + + foreach ($data as $key => $value) { + if (!str_ends_with($key, '_display') || empty($value)) { + continue; + } + $baseKey = substr($key, 0, -8); + $baseValue = $data[$baseKey] ?? ''; + if (trim((string)$baseValue) === '') { + continue; + } + $label = $labelMap[$baseKey] ?? ucwords(str_replace('_', ' ', $baseKey)); + $display_fields[$label] = $baseValue; + } + + return array_merge($display_fields, $special_conditions); + } + public function checkPolicyType($policy_type_id, $client_branch_id, $client_id) { @@ -4128,7 +4270,7 @@ class ClientController extends AdminController $payable_arr = ["self" => 1,"spouse" => 1,"childern" => 1,"elders" => 1,]; - } else if (in_array($data[$i]['policy_type_id'], [4, 5])) { + } else if (in_array($data[$i]['policy_type_id'], [4, 5, 72])) { $payable_arr = ["self" => 1,"spouse" => 1,"childern" => 1,"elders" => 1,]; } @@ -4136,7 +4278,7 @@ class ClientController extends AdminController // Initialize an empty array for the ordered policy terms $orderedPolicyTerms = []; - if(in_array($data[$i]['policy_type_id'], [2,3,4,5])){ + if(in_array($data[$i]['policy_type_id'], [2,3,4,5,72])){ // Set default value of copayzonewisecopay to "empty" // $ans = isset($policyTerms['copayzonewisecopay']) ? $policyTerms['copayzonewisecopay'] : 'empty'; @@ -4239,7 +4381,7 @@ class ClientController extends AdminController } } - if(in_array($data[$i]['policy_type_id'], [2,3,4,5])){ + if(in_array($data[$i]['policy_type_id'], [2,3,4,5,72])){ if (!isset($policyTerms['waiver_of_90_days_waiting_period'])) { $policyTerms['waiver_of_90_days_waiting_period'] = ""; diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 302a569..b33bdfd 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -239,7 +239,7 @@ class EmployeeRestController extends AdminController ->where('is_active', 1) ->first(); - if(in_array($clientPolicyData['policy_type_id'], [3,4,5])){ + if(in_array($clientPolicyData['policy_type_id'], [3,4,5,72])){ $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($clientPolicyData['base_policy'], $data[0]->emp_code); }else{ $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($data[0]->client_policy_id, $data[0]->emp_code); @@ -610,7 +610,7 @@ class EmployeeRestController extends AdminController ->where('is_active', 1) ->first(); - if(in_array($clientPolicyData['policy_type_id'], [3,4,5])){ + if(in_array($clientPolicyData['policy_type_id'], [3,4,5,72])){ $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($clientPolicyData['base_policy'], $requestData[0]->emp_code); }else{ $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($requestData[0]->client_policy_id, $requestData[0]->emp_code); @@ -2790,7 +2790,7 @@ class EmployeeRestController extends AdminController ->where('is_active', 1) ->first(); - if(in_array($clientPolicyData['policy_type_id'], [3,4,5])){ + if(in_array($clientPolicyData['policy_type_id'], [3,4,5,72])){ $policy = $this->findThePolicyIsOpenForEnrollment($clientPolicyData['base_policy'], $emp_code); }else{ $policy = $this->findThePolicyIsOpenForEnrollment($value, $emp_code); @@ -2906,205 +2906,193 @@ class EmployeeRestController extends AdminController //Post method - which receives client_policy id and empcode of the family. //Pull records againest emp code and calculate premium // retun array - public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null , $client_branch_id = null)//family level + public function calculatePremium($clientPolicyId = null, $empCode = null, $default_si = null, $client_branch_id = null) //family level { - // dd($clientPolicyId, $empCode, $default_si, $client_branch_id); - helper('excel_util_helper'); - - if($this->request){ // - $client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId; - $emp_code = $this->request->getVar('emp_code') ?? $empCode; - $default_si = $this->request->getVar('si') ?? $default_si;// si amt which choosed in add on policy - $client_branch_id = $this->request->getVar('client_branch_id') ?? $client_branch_id; - }else{ - //Cli and enrollment - $client_policy_id = $clientPolicyId; - $emp_code = $empCode; - $default_si = $default_si;// si amt which choosed in add on policy - $client_branch_id =$client_branch_id; - } - // dd($client_policy_id); - - - $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; - // get policy and rack details - $policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id); - $policy_type = $policy_terms[0]->is_addon; - $base_policy = $policy_terms[0]->base_policy; - $policy_terms = (array) $policy_terms[0];// convert obj to array - - //get policy slab rates - $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); - // 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_decalculatePremiumtails); - - //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 - { - //get basepolicy id then pull emplist from base policy if only current policy is DA addon policy and emplist is zero - // echo 'inside'; - // $client_policy_id = $base_policy; - $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $base_policy,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); - } - - $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception']; - // 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_rr(($employee_data_group_by_family));die(); - - - $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $client_id,client_branch_id: $client_branch_id); - - foreach ($employee_data_group_by_family as $emp_id => $family) - { - $transformed_famility_details = transform_db_data_to_excel($family); - - $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); - // print_r($data); - $employee_data_group_by_family[$emp_id] = $data; - - foreach ($data as $value) { + // dd($clientPolicyId, $empCode, $default_si, $client_branch_id); + helper('excel_util_helper'); - if(!empty($value)){ - $newData = []; - $newData['employee_id'] = $value['temp']['emp_id']; - $newData['client_policy_id'] = $value['policy_details']['client_policy_id']; - $newData['status'] = "draft"; - $newData['basic_cover_si'] = $value['policy_details']['basic_cover_si']; - $newData['date_coverage'] = $value['policy_details']['date_coverage']; - $newData['policy_end_date'] = $value['policy_details']['policy_end_date']; - $newData['days'] = $value['policy_details']['days']; - + if ($this->request) { // + $client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId; + $emp_code = $this->request->getVar('emp_code') ?? $empCode; + $default_si = $this->request->getVar('si') ?? $default_si; // si amt which choosed in add on policy + $client_branch_id = $this->request->getVar('client_branch_id') ?? $client_branch_id; + } else { + //Cli and enrollment + $client_policy_id = $clientPolicyId; + $emp_code = $empCode; + $default_si = $default_si; // si amt which choosed in add on policy + $client_branch_id = $client_branch_id; + } + // dd($client_policy_id); - $isExistingEmpAndPolicy = $this->employeePolicyModel->where('employee_id',$value['temp']['emp_id'])->where('client_policy_id',$value['policy_details']['client_policy_id'])->where('is_active', 1)->get()->getRow(); - if($isExistingEmpAndPolicy) - { - $this->employeePolicyModel->where('employee_id',$value['temp']['emp_id'])->where('client_policy_id',$value['policy_details']['client_policy_id'])->where('is_active', 1)->set($newData)->update(); - }else{ - $this->employeePolicyModel->insert($newData); + + $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; + // get policy and rack details + $policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id, $client_policy_id); + $policy_type = $policy_terms[0]->is_addon; + $base_policy = $policy_terms[0]->base_policy; + $policy_terms = (array) $policy_terms[0]; // convert obj to array + + //get policy slab rates + $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id, $client_id); + 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_decalculatePremiumtails); + + //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(empty($clientPolicyId)){ - if(isset($policy_terms['policy_terms'])){ - $policyTermsJson = json_decode($policy_terms['policy_terms'], true); - // print_r($employee_data_group_by_family);die(); - - foreach ($employee_data_group_by_family[$emp_code] as $key => &$value) { - - if(!empty($value)){ - - if(strtolower($value['relationship']) == 'self' && $policyTermsJson['is_payable_employee']['self'] == 0){ - $value['policy_details']['rata_premimum'] = 0; - $value['policy_details']['premium'] = 0; - $value['policy_details']['gst'] = 0; - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['self']; - - }else if(strtolower($value['relationship']) == 'self' && $policyTermsJson['is_payable_employee']['self'] == 1){ - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['self']; - } - - if(strtolower($value['relationship']) == 'spouse' && $policyTermsJson['is_payable_employee']['spouse'] == 0){ - $value['policy_details']['rata_premimum'] = 0; - $value['policy_details']['premium'] = 0; - $value['policy_details']['gst'] = 0; - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['spouse']; - - }else if(strtolower($value['relationship']) == 'spouse' && $policyTermsJson['is_payable_employee']['spouse'] == 1){ - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['spouse']; - } - - if((strtolower($value['relationship']) == 'son' || strtolower($value['relationship']) == 'daughter') && $policyTermsJson['is_payable_employee']['childern'] == 0){ - $value['policy_details']['rata_premimum'] = 0; - $value['policy_details']['premium'] = 0; - $value['policy_details']['gst'] = 0; - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['childern']; - - }else if((strtolower($value['relationship']) == 'son' || strtolower($value['relationship']) == 'daughter') && $policyTermsJson['is_payable_employee']['childern'] == 1){ - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['childern']; - } - - if((strtolower($value['relationship']) == 'father in law' || strtolower($value['relationship']) == 'mother in law' || strtolower($value['relationship']) == 'father' || strtolower($value['relationship']) == 'mother' ) && $policyTermsJson['is_payable_employee']['elders'] == 0){ - $value['policy_details']['rata_premimum'] = 0; - $value['policy_details']['premium'] = 0; - $value['policy_details']['gst'] = 0; - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['elders']; - - }else if((strtolower($value['relationship']) == 'father in law' || strtolower($value['relationship']) == 'mother in law' || strtolower($value['relationship']) == 'father' || strtolower($value['relationship']) == 'mother' ) && $policyTermsJson['is_payable_employee']['elders'] == 1){ - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['elders']; - } - - }else{ - unset($employee_data_group_by_family[$emp_code][$key]); - } - } - unset($value); - - $employee_data_group_by_family[$emp_code] = array_values($employee_data_group_by_family[$emp_code]); + if (!count($existing_famility_details) && $policy_type == 2) //top up addon only + { + //get basepolicy id then pull emplist from base policy if only current policy is DA addon policy and emplist is zero + // echo 'inside'; + // $client_policy_id = $base_policy; + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id, client_policy_id: $base_policy, emp_code: $emp_code, emp_status: ['draft', 'enrolled'], policy_status: ['draft', 'enrolled']); } - }else{ - if(isset($policy_terms['policy_terms'])){ - $policyTermsJson = json_decode($policy_terms['policy_terms'], true); + $file = ['id' => null, 'client_id' => $client_id, 'policy_id' => $client_policy_id, 'action' => 'inception']; + // 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_rr(($employee_data_group_by_family));die(); - foreach ($employee_data_group_by_family[$emp_code] as $key => &$value) { - if(!empty($value)){ - if(strtolower($value['relationship']) == 'self'){ - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['self']; + $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $client_id, client_branch_id: $client_branch_id); + + foreach ($employee_data_group_by_family as $emp_id => $family) { + $transformed_famility_details = transform_db_data_to_excel($family); + + $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); + // print_r($data); + $employee_data_group_by_family[$emp_id] = $data; + + foreach ($data as $value) { + + if (!empty($value)) { + $newData = []; + $newData['employee_id'] = $value['temp']['emp_id']; + $newData['client_policy_id'] = $value['policy_details']['client_policy_id']; + $newData['status'] = "draft"; + $newData['basic_cover_si'] = $value['policy_details']['basic_cover_si']; + $newData['date_coverage'] = $value['policy_details']['date_coverage']; + $newData['policy_end_date'] = $value['policy_details']['policy_end_date']; + $newData['days'] = $value['policy_details']['days']; + + + $isExistingEmpAndPolicy = $this->employeePolicyModel->where('employee_id', $value['temp']['emp_id'])->where('client_policy_id', $value['policy_details']['client_policy_id'])->where('is_active', 1)->get()->getRow(); + if ($isExistingEmpAndPolicy) { + $this->employeePolicyModel->where('employee_id', $value['temp']['emp_id'])->where('client_policy_id', $value['policy_details']['client_policy_id'])->where('is_active', 1)->set($newData)->update(); + } else { + $this->employeePolicyModel->insert($newData); } - - if(strtolower($value['relationship']) == 'spouse'){ - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['spouse']; - } - - if((strtolower($value['relationship']) == 'son' || strtolower($value['relationship']) == 'daughter')){ - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['childern']; - } - - if((strtolower($value['relationship']) == 'father in law' || strtolower($value['relationship']) == 'mother in law' || strtolower($value['relationship']) == 'father' || strtolower($value['relationship']) == 'mother' )){ - $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['elders']; - } - }else{ - unset($employee_data_group_by_family[$emp_code][$key]); - } + } } - unset($value); - $employee_data_group_by_family[$emp_code] = array_values($employee_data_group_by_family[$emp_code]); + if (empty($clientPolicyId)) { + if (isset($policy_terms['policy_terms'])) { + $policyTermsJson = json_decode($policy_terms['policy_terms'], true); + // print_r($employee_data_group_by_family);die(); + + foreach ($employee_data_group_by_family[$emp_code] as $key => &$value) { + + if (!empty($value)) { + + if (strtolower($value['relationship']) == 'self' && $policyTermsJson['is_payable_employee']['self'] == 0) { + $value['policy_details']['rata_premimum'] = 0; + $value['policy_details']['premium'] = 0; + $value['policy_details']['gst'] = 0; + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['self']; + } else if (strtolower($value['relationship']) == 'self' && $policyTermsJson['is_payable_employee']['self'] == 1) { + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['self']; + } + + if (strtolower($value['relationship']) == 'spouse' && $policyTermsJson['is_payable_employee']['spouse'] == 0) { + $value['policy_details']['rata_premimum'] = 0; + $value['policy_details']['premium'] = 0; + $value['policy_details']['gst'] = 0; + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['spouse']; + } else if (strtolower($value['relationship']) == 'spouse' && $policyTermsJson['is_payable_employee']['spouse'] == 1) { + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['spouse']; + } + + if ((strtolower($value['relationship']) == 'son' || strtolower($value['relationship']) == 'daughter') && $policyTermsJson['is_payable_employee']['childern'] == 0) { + $value['policy_details']['rata_premimum'] = 0; + $value['policy_details']['premium'] = 0; + $value['policy_details']['gst'] = 0; + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['childern']; + } else if ((strtolower($value['relationship']) == 'son' || strtolower($value['relationship']) == 'daughter') && $policyTermsJson['is_payable_employee']['childern'] == 1) { + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['childern']; + } + + if ((strtolower($value['relationship']) == 'father in law' || strtolower($value['relationship']) == 'mother in law' || strtolower($value['relationship']) == 'father' || strtolower($value['relationship']) == 'mother') && $policyTermsJson['is_payable_employee']['elders'] == 0) { + $value['policy_details']['rata_premimum'] = 0; + $value['policy_details']['premium'] = 0; + $value['policy_details']['gst'] = 0; + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['elders']; + } else if ((strtolower($value['relationship']) == 'father in law' || strtolower($value['relationship']) == 'mother in law' || strtolower($value['relationship']) == 'father' || strtolower($value['relationship']) == 'mother') && $policyTermsJson['is_payable_employee']['elders'] == 1) { + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['elders']; + } + } else { + unset($employee_data_group_by_family[$emp_code][$key]); + } + } + unset($value); + + $employee_data_group_by_family[$emp_code] = array_values($employee_data_group_by_family[$emp_code]); + } + } else { + if (isset($policy_terms['policy_terms'])) { + + $policyTermsJson = json_decode($policy_terms['policy_terms'], true); + + foreach ($employee_data_group_by_family[$emp_code] as $key => &$value) { + if (!empty($value)) { + + if (strtolower($value['relationship']) == 'self') { + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['self']; + } + + if (strtolower($value['relationship']) == 'spouse') { + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['spouse']; + } + + if ((strtolower($value['relationship']) == 'son' || strtolower($value['relationship']) == 'daughter')) { + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['childern']; + } + + if ((strtolower($value['relationship']) == 'father in law' || strtolower($value['relationship']) == 'mother in law' || strtolower($value['relationship']) == 'father' || strtolower($value['relationship']) == 'mother')) { + $value['policy_details']['payable_employee'] = $policyTermsJson['is_payable_employee']['elders']; + } + } else { + unset($employee_data_group_by_family[$emp_code][$key]); + } + } + unset($value); + + $employee_data_group_by_family[$emp_code] = array_values($employee_data_group_by_family[$emp_code]); + } + } + } + // die(); + if ($clientPolicyId != null && $empCode != null) { + // 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 : 200), 'data' => [$employee_data_group_by_family]], 200); } - } - - - } - // die(); - if($clientPolicyId != null && $empCode != null) - { - // 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 : 200),'data' => [$employee_data_group_by_family] ], 200); - } - } @@ -4473,7 +4461,7 @@ class EmployeeRestController extends AdminController ->where('is_active', 1) ->first(); - if(in_array($clientPolicyData['policy_type_id'] ?? null, [3,4,5])){ + if(in_array($clientPolicyData['policy_type_id'] ?? null, [3,4,5,72])){ $policy = $this->employeePolicyModel ->select('employee_polices.enrollment_open_date, employee_polices.enrollment_close_date') @@ -4515,7 +4503,7 @@ class EmployeeRestController extends AdminController ( SELECT id FROM client_policy - WHERE policy_type_id = 4 + WHERE policy_type_id in (4, 72) AND base_policy = gmc_client_policy_id LIMIT 1 ) AS gmc_topup_policy_id diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index ad919af..ec60594 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -1141,7 +1141,7 @@ $('body').on('click', '.btnPolicyEdit', function() { // } - if (res.data.policy_type_id == '4' || res.data.policy_type_id == '5') { + if (res.data.policy_type_id == '4' || res.data.policy_type_id == '5' || res.data.policy_type_id == '72') { $('#base_policy_id').show(); $('#base_policy').prop('required', true); @@ -1645,7 +1645,7 @@ $('#policy_type').change(function() { }); - if ($(this).val() == 4 || $(this).val() == 5) { + if ($(this).val() == 4 || $(this).val() == 5 || $(this).val() == 72) { $("#insurer").next(".select2-container").css({ 'pointer-events': 'auto', @@ -1689,7 +1689,7 @@ $('#policy_type').change(function() { toastr.warning('Please Change the Policy Terms after Submit the Policy!', 'Info'); } - if ($(this).val() == '4' || $(this).val() == '5') { + if ($(this).val() == '4' || $(this).val() == '5' || $(this).val() == '72') { $('#base_policy_id').show(); $('#base_policy').prop('required', true); @@ -2189,7 +2189,7 @@ function getClientPolicyDataForEdit(client_policy_id) { $('#is_premium_summery').prop('checked', false); } - if (res.data.policy_type_id == '4' || res.data.policy_type_id == '5') { + if (res.data.policy_type_id == '4' || res.data.policy_type_id == '5' || res.data.policy_type_id == '72') { $('#base_policy_id').show(); $('#base_policy').prop('required', true); diff --git a/app/Views/other_policy_terms.php b/app/Views/other_policy_terms.php index c8ed3a4..22c092f 100755 --- a/app/Views/other_policy_terms.php +++ b/app/Views/other_policy_terms.php @@ -1,4 +1,128 @@