diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 57a4d3ea..f516c231 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -238,6 +238,13 @@ $routes->group("/api", ["filter" => "authJWT"], function($routes){ + +$routes->get("/getEmployeeProfile", "EmployeeRestController::getEmployeeProfile/$1"); +$routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfile"); +$routes->post("/calculatePremium", "EmployeeRestController::calculatePremium"); + + + $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getEmployeeProfile", "EmployeeRestController::getEmployeeProfile"); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 942b5367..b3b0160d 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -159,7 +159,7 @@ class EmployeeController extends AdminController // $this->fileModel->where('id', '12')->set(['status' => 'failed','reason' => $failure_reason])->update(); // dd($failure_reason); // } - + if($this->request->getMethod() == 'post') { //validate uploaded file @@ -560,6 +560,17 @@ class EmployeeController extends AdminController } + // @param int $client_policy_id + // this funciton initiate Inception/adition/DA of employees data only form enrollment app when passing + // client_policy_id pull draft and enrolled status employees and proceed to calculatin and make entry in DB + public function initiateManualEmployeesOnboardProcess($client_policy_id) + { + $empServiceController = new EmployeeServiceController(); + $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => $client_policy_id]); + dd($res); + } + + public function downloadFileList($file_id = null) { // $actionType = $this->request->getGet(); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index a6eb068b..5245fcae 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -339,8 +339,10 @@ class EmployeeRestController extends AdminController $result = []; foreach ($ClientPolicyData as $key => $value) { $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']); - if($value['is_addon'] == 1){ - $value['type'] = 'AddOn'; + if($value['is_addon'] == "2"){ + $value['type'] = 'SI-TopUp'; + }else if($value['is_addon'] == "3"){ + $value['type'] = 'Dependent-AddOn'; }else{ $value['type'] = $getSlabAndGridData['grid_master']['policy_type']; } @@ -854,6 +856,7 @@ class EmployeeRestController extends AdminController // $return_log = json_decode($return_log); // $this->myLogger->logme('info', "Email Status : {mail_status}, Sender Email:{email}", ['mail_status' => $return_log->status, 'email'=> $return_log->data]); } + return $this->respond(['status' => 'success', 'code' => 200, 'message' => "Success" ], 404); }else{ return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Client id and Client Policy id is Not Match!" ], 404); } @@ -882,7 +885,7 @@ public function getEmployeePolicy() $empPolicy = $this->employeeModel->getEmployeePolicy($id); // Retrieve employee and dependents data by passing the employee code $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('is_active', 1 )->where('is_addon_value',0)->findAll(); - + // dd($empPolicy); if ($empPolicy) { @@ -1099,24 +1102,24 @@ public function getAddOnPolicy() { $PolicyData = []; foreach ($clientPolicy as $key => $array) { - + $responce = []; $decodedArray = json_decode($array['policy_terms']); $policy_terms = $decodedArray; $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']); - if($array['is_addon'] == 1) - { - $responce['policy_name'] = $this->policesModel->where('id',$array['policy_id'])->get()->getRow()->name; - $responce['SlabRates'] = $getSlabAndGridData['slab_rates']; - $responce['GridMaster'] = $getSlabAndGridData['grid_master']; - $responce['client_id'] = $array['client_id']; - $responce['client_policy_id'] = $array['id']; - $responce['is_addon'] = $array['is_addon']; - $responce['open_for_enrollment'] = $array['open_for_enrollment']; - $responce['policy_terms'] = $decodedArray; - + $responce['policy_name'] = $this->policesModel->where('id',$array['policy_id'])->get()->getRow()->name; + $responce['SlabRates'] = $getSlabAndGridData['slab_rates']; + $responce['GridMaster'] = $getSlabAndGridData['grid_master']; + $responce['client_id'] = $array['client_id']; + $responce['client_policy_id'] = $array['id']; + $responce['is_addon'] = $array['is_addon']; + $responce['open_for_enrollment'] = $array['open_for_enrollment']; + $responce['policy_terms'] = $decodedArray; + if($array['is_addon'] == 3) + { + // Map family floaters that already exist in the employee table $familyFloates = $policy_terms->family_floaters; @@ -1213,40 +1216,52 @@ public function getAddOnPolicy() $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value; - $only_si_array = []; - $only_si_value = null; - $only_si_premium_value = null; - foreach ($GMCEmployeeData as $key => $value) { - - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); - if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } - if(isset($employee_policy->premium)){ $only_si_premium_value = $employee_policy->premium;} - $temp3['is_value_exist'] = true; - $temp3['data']['employee_id'] = $value['id']; - $temp3['data']['relationship'] = $value['relationship']; - $temp3['data']['name'] = $value['name']; - $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); - $temp3['data']['client_policy_id'] = $array['id']; - $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; - $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; - array_push($only_si_array,$temp3); - - } - - $responce['family_floaters_of_only_si_array'] = $only_si_array; - $responce['family_floaters_of_only_si_value'] = $only_si_value; - $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; + + if($this->request->getGet('policy') == 'GMC-DEPENDENT-ADDON'){ + return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_dependent_addon'=>$responce]], 200); + } + + //array_push($PolicyData, $responce); + }else if($array['is_addon'] == 2){ + + + $only_si_array = []; + $only_si_value = null; + $only_si_premium_value = null; + foreach ($GMCEmployeeData as $key => $value) { + + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); + if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->premium)){ $only_si_premium_value = $employee_policy->premium;} + $temp3['is_value_exist'] = true; + $temp3['data']['employee_id'] = $value['id']; + $temp3['data']['relationship'] = $value['relationship']; + $temp3['data']['name'] = $value['name']; + $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp3['data']['client_policy_id'] = $array['id']; + $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; + $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; + array_push($only_si_array,$temp3); + + } + + $responce['family_floaters_of_only_si_array'] = $only_si_array; + $responce['family_floaters_of_only_si_value'] = $only_si_value; + $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; + + if($this->request->getGet('policy') == 'GMC-SI-TOPUP'){ + return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_topup'=>$responce]], 200); + } - array_push($PolicyData, $responce); } } - return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200); + // return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200); }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); @@ -1275,4 +1290,42 @@ public function iAgreeForAddOn() return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); } +//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()//family level +{ + helper('excel_util_helper'); + $client_policy_id = $this->request->getVar('client_policy_id'); + $emp_code = $this->request->getVar('emp_code'); + // 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_terms = (array) $policy_terms[0];// convert obj to array + + //get policy slab rates + $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); + + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['active'],policy_status:['active']); + + $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception']; + // dd($this->employeeModel->getLastQuery()); + // dd($existing_famility_details);die(); + $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db'); + // dd($employee_data_group_by_family); + foreach ($employee_data_group_by_family as $emp_id => $family) + { + $transformed_famility_details = transform_db_data_to_excel($family); + $data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file); + // dd($data); + $employee_data_group_by_family[$emp_id] = $data; + + } + + // 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); +} + } \ No newline at end of file diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index ac99a890..6007b717 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -349,7 +349,7 @@ class EmployeeServiceController extends AdminController //if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel if($file['action'] == 'dependent_addition') { - $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: 'active'); + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status:['active']); // dd($existing_famility_details); //transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites $existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file); @@ -531,7 +531,7 @@ class EmployeeServiceController extends AdminController //if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel if($file['action'] == 'dependent_addition') { - $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: 'active'); + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status:['active']); // dd($existing_famility_details); //transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites $existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file); @@ -566,7 +566,7 @@ class EmployeeServiceController extends AdminController //get policy slab rates $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); - $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_status: 'enrolled'); + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_status: ['enrolled','draft'],policy_status:['enrolled','draft']); $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception']; // dd($this->employeeModel->getLastQuery()); @@ -663,7 +663,7 @@ class EmployeeServiceController extends AdminController else { - $family = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $row[1],client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: 'active'); + $family = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $row[1],client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status: ['active']); // Kint::dump($family); foreach ($family as $key => $emp) { diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 5f2bd65f..50b0eadf 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -88,7 +88,7 @@ class EmployeeModel extends Model } - public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,string $emp_status = null) + public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = []) { $result = $this->select(['employees.id as emp_id', 'employees.client_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit']) ->join('employee_polices', 'employee_polices.employee_id = employees.id') @@ -98,17 +98,18 @@ class EmployeeModel extends Model }) ->where('employee_polices.is_active',1) - ->where('employees.emp_status', ($emp_status !== null ? $emp_status : 'active')) + // ->where('employees.emp_status', ($emp_status !== null ? $emp_status : 'active')) // ->where('employees.emp_code',$emp_code) ->when($emp_code, function($query) use ($emp_code){ return $query->where('employees.emp_code',$emp_code); }) - // ->when($emp_status, function($query) use ($emp_status){ - // $emp_status = ($emp_status !== null ? $emp_status : 'active'); - // dd($emp_status); - // return $query->where('employees.emp_status', $emp_status); - // }) + ->when(count($emp_status), function($query) use ($emp_status){ + return $query->whereIn('employees.emp_status', $emp_status); + }) + ->when(count($policy_status), function($query) use ($policy_status){ + return $query->whereIn('employee_polices.status', $policy_status); + }) ->when($client_id, function($query) use ($client_id){ return $query->where('employees.client_id',$client_id); })