From e5cdd231c2e1d91272c7c70a175b0c0f3fa9ec03 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 18 Apr 2024 15:57:31 +0530 Subject: [PATCH 01/10] CHANGE_addEmployeeAndDependenceAPI:GWM --- app/Config/Routes.php | 1 - app/Controllers/EmployeeRestController.php | 39 ++++++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index fc3ee161..b68ae6c3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -246,7 +246,6 @@ $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfi $routes->post("/calculatePremium", "EmployeeRestController::calculatePremium"); - $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getEmployeeProfile", "EmployeeRestController::getEmployeeProfile"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index e1814d9f..613bc1f8 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -170,7 +170,7 @@ class EmployeeRestController extends AdminController public function addEmployeeAndDependence() { - // try { + try { $data = $this->request->getJSON(); if ($data) { @@ -197,10 +197,6 @@ class EmployeeRestController extends AdminController $employee = $this->employeeModel->insert($item); if ($employee) { - if(!isset($item->is_addon_value)) - { - $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id); - } $Count++; } @@ -210,10 +206,16 @@ class EmployeeRestController extends AdminController if ($Count > 0) { - if(!isset($data[0]->is_addon_value)) + if(!isset($item->is_addon_value)) { - $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); + $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id); + }else{ + $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id,$item->basic_cover_si); } + + + $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); + $result = []; return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); @@ -222,18 +224,19 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404); } } - // } catch (\Exception $e) { - // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - // } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } } - public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id) + public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id,$basic_cover_si = null) { - + if($basic_cover_si != null){ $client_policy = $this->clientPolicyModel->where('id', $client_policy_id)->where('client_id', $client_id)->first(); $policy_terms = json_decode($client_policy['policy_terms']); $basic_cover_si = $policy_terms->sum_insured; + }else{ $basic_cover_si = $basic_cover_si; } $checkDataExist = $this->employeePolicyModel->where('employee_id',$employee_id)->where('client_policy_id',$client_policy_id)->first(); @@ -989,6 +992,7 @@ public function getEmployeePolicy() // Map family floaters that already exist in the employee table $familyFloates = $array->Policy_Terms->family_floaters; + // Generate Notes string based on familyFloates terms $array->notes = $this->FloterNotesConvertion($familyFloates); // Convert familyFloaters terms data to plain array @@ -1115,6 +1119,8 @@ public function FloterNotesConvertion($array){ $string = ucwords($string); $result .= ' + '.$string; }else if($value != 0 && $key ==='self') { + }else if($value != 0 && $key ==='childrens') { + if($value > 1){ $result .= ' + '.$value.' Children'; }else{ $result .= ' + '.$value.' Child'; } }else{ $string = str_replace('-', ' ', $key); $string = ucwords($string); @@ -1122,7 +1128,7 @@ public function FloterNotesConvertion($array){ } } } - + return $result; } @@ -1342,12 +1348,11 @@ public function iAgreeForAddOn() $this->employeeModel->where('emp_code', $emp_code ) ->where('is_active', 1 ) - ->set(array('emp_status'=>'Enrolled')) + ->set(array('emp_status'=>'enrolled')) ->update(); - $this->employeePolicyModel->where('client_id', $client_id ) - ->where('client_policy_id', $client_policy_id ) + $this->employeePolicyModel->where('client_policy_id', $client_policy_id ) ->where('is_active', 1 ) - ->set(array('status'=>'Enrolled')) + ->set(array('status'=>'enrolled')) ->update(); return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); } From 59ed66f84c39256b259b8dcb3547099a321076f2 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 18 Apr 2024 16:20:50 +0530 Subject: [PATCH 02/10] FIX_addEmployeeAndDependenceAPI:GWM --- app/Controllers/EmployeeRestController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index de4e0dec..4ec8de9d 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1063,9 +1063,9 @@ public function getEmployeePolicy() } - $result[] = $array; + // $result[] = $array; } - + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); }else{ @@ -1329,7 +1329,7 @@ public function getAddOnPolicy() } - // return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200); + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); From 6c99f547ab0ae8bd94d016799a8fba8b5548c818 Mon Sep 17 00:00:00 2001 From: sriramv Date: Thu, 18 Apr 2024 16:56:43 +0530 Subject: [PATCH 03/10] 'FIX_EMP_MODULE_ID_ISSUE_IN_RACK_RATE_RV' --- app/Controllers/ClientController.php | 18 +++++++++++++----- app/Controllers/EmpDataServiceController.php | 2 +- app/Models/EmployeePolicyModel.php | 7 +++---- app/Views/policy_grid.php | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 600d054e..baca94e2 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1048,11 +1048,19 @@ class ClientController extends AdminController ->where("employees.emp_status",'active') ->countAllResults(); - if($emp_count == 0){ - $emp_count = true; - }else{ - $emp_count = false; - } + + $data = $this->employeePolicyModel->select('employee_polices.id') + ->where('employee_polices.is_active', 1) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->findAll(); + + $emp_count = count($data); + + // if($emp_count == 0){ + // $emp_count = true; + // }else{ + // $emp_count = false; + // } $data = $this->policesModel->getPolicyPremium($record['policy_id']); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 36e3690c..6f82164a 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -1262,7 +1262,7 @@ class EmpDataServiceController extends BaseController $description = 'The following amount of Rs. ' . $amount->total_sum . '/- has been debited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.'; $data = [ - 'amount' => $amount->total_sum, + 'amount' => $amount->total_sum ?? 0, 'sub_type_id' => 4, 'client_id' => $arrayData['client_id'], 'insurer_id' => $insurer_id['insurer_id'], diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 82706219..9e817cd5 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -106,6 +106,7 @@ class EmployeePolicyModel extends Model { $client_policy_id = $ref_data['client_policy_id']; $insurer_or_tpa = $ref_data['insurer_or_tpa']; + $event = $ref_data['event_type']; if($insurer_or_tpa == 'tpa'){ @@ -150,13 +151,11 @@ class EmployeePolicyModel extends Model batch_files.batch_code as bf FROM batch_files LEFT JOIN batch_list ON batch_files.batch_code = batch_list.batch_code - WHERE batch_files.event_type = 'inception' + WHERE batch_files.event_type = '{$event}' AND batch_files.actions = 'export' AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' ) as batch_data ON employee_polices.id = batch_data.emp_policy_id - WHERE batch_data.bf IS NULL - AND batch_data.bl IS NULL - AND employee_polices.client_policy_id = '{$client_policy_id}' + WHERE employee_polices.client_policy_id = '{$client_policy_id}' AND (employee_polices.{$id} IS NULL OR employee_polices.{$id} = '') AND employee_polices.is_active = 1"; diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index 4a5a8f6c..372e5279 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -711,7 +711,7 @@ $('body').on('click', '.btnPolicyModel', function() { $('#nameOfThePolicy').html(' - ' + res.policy_name); $('#grid_emp_count').val(res.count); - if (res.count == false) { + if (res.count > 0) { console.log('count -- 2', res.count); $("#btnGridSubmit_2").hide(); } else { From d2f7729e78b1aa983b2dbe01b58b5017353130ff Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 18 Apr 2024 17:16:46 +0530 Subject: [PATCH 04/10] FIX_error in add dependent api : GWM --- app/Controllers/EmployeeRestController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 4ec8de9d..c51f62aa 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -172,7 +172,8 @@ class EmployeeRestController extends AdminController { try { $data = $this->request->getJSON(); - + + if ($data) { $Count = 0; @@ -206,11 +207,11 @@ class EmployeeRestController extends AdminController if ($Count > 0) { - if(!isset($item->is_addon_value)) + if(!isset($data[0]->is_addon_value)) { - $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id); + $this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id); }else{ - $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id,$item->basic_cover_si); + $this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si); } @@ -232,11 +233,13 @@ class EmployeeRestController extends AdminController public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id,$basic_cover_si = null) { - if($basic_cover_si != null){ + + if($basic_cover_si == null) + { $client_policy = $this->clientPolicyModel->where('id', $client_policy_id)->where('client_id', $client_id)->first(); $policy_terms = json_decode($client_policy['policy_terms']); $basic_cover_si = $policy_terms->sum_insured; - }else{ $basic_cover_si = $basic_cover_si; } + } $checkDataExist = $this->employeePolicyModel->where('employee_id',$employee_id)->where('client_policy_id',$client_policy_id)->first(); From 7e689904a962f99042f6fa8e8112c44afa5b3285 Mon Sep 17 00:00:00 2001 From: sriramv Date: Thu, 18 Apr 2024 19:36:42 +0530 Subject: [PATCH 05/10] 'FIX_INCEPTION_ID_UPDATE_ISSUE_RV' --- app/Controllers/EmpDataServiceController.php | 38 +++++++------------- app/Helpers/excel_import_export_helper.php | 4 +++ app/Models/EmployeePolicyModel.php | 2 ++ 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 6f82164a..18106a1d 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -108,6 +108,8 @@ class EmpDataServiceController extends BaseController // Fetch employee data for export from the database $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); + // dd($objects); + $totals = 0; foreach ($objects as $key => $value) { @@ -606,35 +608,21 @@ class EmpDataServiceController extends BaseController // dd($import_data, $empty_emp_tpa_uh_ids); + $tpa_id = []; + $uhid = []; + foreach ($data as $key => $value) { - - if (!empty($value)) { - - - if ($import_data['insurer_or_tpa'] == 'tpa') { - - $tpa_id = $value[15] !== null ? $value[15] : ''; - $uhid = $value[16] !== null ? $value[16] : ''; - - $data = ['tpa_id' => $tpa_id, 'uhid' => $uhid]; - } else if ($import_data['insurer_or_tpa'] == 'insurer') { - - $tpa_id = $value[15] !== null ? $value[15] : ''; - $uhid = $value[16] !== null ? $value[16] : ''; - $data = ['tpa_id' => $tpa_id, 'uhid' => $uhid]; - } - - foreach ($empty_emp_tpa_uh_ids as $id) { - - $this->employeePolicyModel->where('id', $id)->set($data)->update(); - } - } else { - - return 0; - } + $tpa_id[] = $value[15]; + $uhid[] = $value[16]; } + foreach ($empty_emp_tpa_uh_ids as $key => $id) { + $dataToUpdate = ['tpa_id' => $tpa_id[$key], 'uhid' => $uhid[$key]]; + $this->employeePolicyModel->where('id', $id) + ->set($dataToUpdate)->update(); + } + if($import_data['insurer_or_tpa'] == 'tpa'){ diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php index 95f164c8..5c29ce41 100644 --- a/app/Helpers/excel_import_export_helper.php +++ b/app/Helpers/excel_import_export_helper.php @@ -112,6 +112,10 @@ if (! function_exists('transform_objects_to_array_for_inception')) { // Iterate through each object foreach ($objects as $obj) { + + $TPAID = isset($obj->tpa_id) && $obj->tpa_id !== '' ? $obj->tpa_id : ''; + $UHID = isset($obj->uhid) && $obj->uhid !== '' ? $obj->uhid : ''; + // Extract all values for the object $rowData = [ $serialNumber++, // Serial Number diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 9e817cd5..b7e2f19d 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -130,6 +130,8 @@ class EmployeePolicyModel extends Model 'Has Define' as emp_type, employee_polices.id as primaryKey, + employee_polices.tpa_id, + employee_polices.uhid, employee_polices.pre_existing_alignments, employee_polices.basic_cover_si, employee_polices.date_coverage, From 63e4200281b5146850667584fe345f5974bc1cd3 Mon Sep 17 00:00:00 2001 From: sriramv Date: Mon, 22 Apr 2024 08:28:40 +0530 Subject: [PATCH 06/10] 'FIX_EMP_MODULE_EXPORT_IMPORT_INCEPTION_RV' --- app/Controllers/EmpDataServiceController.php | 11 +++++++++-- app/Controllers/EmployeeController.php | 10 ++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 18106a1d..80095b64 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -618,9 +618,16 @@ class EmpDataServiceController extends BaseController foreach ($empty_emp_tpa_uh_ids as $key => $id) { - $dataToUpdate = ['tpa_id' => $tpa_id[$key], 'uhid' => $uhid[$key]]; + $dataToUpdateTPAID = ['tpa_id' => $tpa_id[$key]]; + $dataToUpdateUHID = ['uhid' => $uhid[$key]]; + $this->employeePolicyModel->where('id', $id) - ->set($dataToUpdate)->update(); + ->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")') + ->set($dataToUpdateTPAID)->update(); + + $this->employeePolicyModel->where('id', $id) + ->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")') + ->set($dataToUpdateUHID)->update(); } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 1871fab0..4a029f00 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -351,8 +351,14 @@ class EmployeeController extends AdminController $return = $empDataServiceController->generateExcelForAdditionandInception($batch_data); if(!$return){ - session()->setFlashdata('error', 'No data found about this action'); - return redirect()->to(base_url('employee/upload')); + if($insurer_or_tpa == 'tpa'){ + session()->setFlashdata('error', "No data was found for this action. The TPA ID has already been updated."); + return redirect()->to(base_url('employee/upload')); + + }else if($insurer_or_tpa == 'insurer'){ + session()->setFlashdata('error', "No data was found for this action. The UHID has already been updated."); + return redirect()->to(base_url('employee/upload')); + } } else{ $this->myLogger->logme('error','Successfully exported Excel file in {data}.', ['data' => $event_type]); } From 37c1102181a0a072dd45758e29c42f329548a2b6 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Mon, 22 Apr 2024 16:02:46 +0530 Subject: [PATCH 07/10] FEATURE_newApi exportDataByClientPolicyId and getCashDepositData : GWM --- app/Config/Routes.php | 4 + app/Controllers/EmployeeRestController.php | 155 ++++++++++++++------- app/Models/ClientPolicyModel.php | 1 + 3 files changed, 110 insertions(+), 50 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index b68ae6c3..53f1eb4c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -246,6 +246,7 @@ $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfi $routes->post("/calculatePremium", "EmployeeRestController::calculatePremium"); + $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getEmployeeProfile", "EmployeeRestController::getEmployeeProfile"); @@ -263,6 +264,9 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getClientDetails", "EmployeeRestController::getClientDetails"); $routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy"); $routes->get("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); + + $routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId"); + $routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData"); }); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c51f62aa..6ac34fe0 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -384,6 +384,83 @@ class EmployeeRestController extends AdminController } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } + + } + + + public function exportDataByClientPolicyId() + { + try { + $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0); + + if(count($empData)) + { + // Define headers and map database fields to Excel fields + $headers = [ + 'Employee Code' => 'emp_code', + 'Name' => 'name', + 'Relationship' => 'relationship', + 'DOB' => 'dob', + 'Gender' => 'gender', + 'Mobile' => 'mobile', + 'Email' => 'email_corporate', + 'SI' => 'basic_cover_si', + 'Premium' => 'rata_premimum', + 'Policy Name' => 'policy_name', + 'Insurer Branch Name' => 'insurer_branch_name', + 'TPA Name' => 'tpa_name', + 'Status' => 'emp_status' + ]; + + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Add headers + $column = 'A'; + foreach ($headers as $header => $dbField) { + $sheet->setCellValue($column . '1', $header); + $column++; + } + + // Add data + $row = 2; + foreach ($empData as $employee) { + $column = 'A'; + foreach ($headers as $dbField) { + $sheet->setCellValue($column . $row, $employee[$dbField]); + $column++; + } + $row++; + } + + + // Set the header for download + $filename = $empData[0]['policy_name'].'-Enrollment.xlsx'; + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $filename . '"'); + header('Cache-Control: max-age=0'); + + // Save the Excel file to output + $writer = new Xlsx($spreadsheet); + $writer->save('php://output'); + exit; + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200); + + }else{ + + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200); + } + + + + } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); } @@ -1353,67 +1430,45 @@ public function iAgreeForAddOn() ->where('is_active', 1 ) ->set(array('emp_status'=>'enrolled')) ->update(); - $this->employeePolicyModel->where('client_policy_id', $client_policy_id ) - ->where('is_active', 1 ) - ->set(array('status'=>'enrolled')) - ->update(); + foreach ($client_policy_id as $key => $value) { + + $this->employeePolicyModel->where('client_policy_id', $value ) + ->where('is_active', 1 ) + ->set(array('status'=>'enrolled')) + ->update(); + } + 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($clientPolicyId = null , $empCode = null, $default_si = null)//family level -{ - helper('excel_util_helper'); - $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 - // dd($client_policy_id); +public function getCashDepositData() +{ - $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 + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name') + ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->groupBy('client_policy.insurer_id') + ->findAll(); + $result = []; - //get policy slab rates - $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); - // print_r($slab_details);die(); + foreach ($ClientPolicyData as $key => $value) { - $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']); - - 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: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); + $data['clientId'] = $value['clientId']; + $data['insurerId'] = $value['insurerId']; + $data['insurerName'] = $value['insurer_name']; + $data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']); + $data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0; + array_push($result,$data); + } + - $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'); - // dd($employee_data_group_by_family); - foreach ($employee_data_group_by_family as $emp_id => $family) + if($result) { - $transformed_famility_details = transform_db_data_to_excel($family); - $data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si); - // dd($data); - $employee_data_group_by_family[$emp_id] = $data; - - } - - if($clientPolicyId != null && $empCode != null) - { - return $employee_data_group_by_family; + return $this->respond(['status' => 'success','code' => (count($result) ? 200 : 404),'data' => $result ], 200); }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' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200); } } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 2c27280b..e5b4e591 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -185,6 +185,7 @@ class ClientPolicyModel extends Model ->where('cash_deposit.client_id', $clientId) ->where('cash_deposit.insurer_id', $insurerId) // Add this line to filter by insurer_id + ->orderBy('cash_deposit.id', 'DESC') ->get() ->getResult(); } From 68ca777e17ccb3a237847e2cd475993a55e8f505 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Mon, 22 Apr 2024 16:06:02 +0530 Subject: [PATCH 08/10] CHANGE_in calculatePremium : GWM --- app/Controllers/EmployeeRestController.php | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 6ac34fe0..e6ec0fa9 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1441,6 +1441,64 @@ 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($clientPolicyId = null , $empCode = null, $default_si = null)//family level +{ + helper('excel_util_helper'); + $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 + // 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']); + + 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: $client_policy_id,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'); + // 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,$default_si); + // dd($data); + $employee_data_group_by_family[$emp_id] = $data; + + } + + if($clientPolicyId != null && $empCode != null) + { + 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); + + } + +} + public function getCashDepositData() { From f05bb5d5f7c207b681cd44518134200f160f2630 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Tue, 23 Apr 2024 09:46:03 +0530 Subject: [PATCH 09/10] CHANGE_ iAgreeForAddOn API : GWM --- app/Config/Routes.php | 2 +- app/Controllers/EmployeeRestController.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 53f1eb4c..1252386c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -263,7 +263,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy"); $routes->get("getClientDetails", "EmployeeRestController::getClientDetails"); $routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy"); - $routes->get("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); + $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); $routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId"); $routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index e6ec0fa9..0fd22168 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1422,9 +1422,9 @@ public function getAddOnPolicy() public function iAgreeForAddOn() { - $emp_code = $this->request->getGet('emp_code'); - $client_policy_id = $this->request->getGet('client_policy_id'); - $client_id = $this->request->getGet('client_id'); + $emp_code = $this->request->getPost('emp_code'); + $client_policy_id = $this->request->getPost('client_policy_id'); + $client_id = $this->request->getPost('client_id'); $this->employeeModel->where('emp_code', $emp_code ) ->where('is_active', 1 ) From 11ecfce5c4e7ec6efb43947492918b3ef944f7e5 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Tue, 23 Apr 2024 12:07:52 +0530 Subject: [PATCH 10/10] CHANGE_cash deposit api :GWM --- app/Controllers/EmployeeRestController.php | 53 ++++++++++++++++++---- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0fd22168..fcac85ab 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1423,19 +1423,23 @@ public function iAgreeForAddOn() { $emp_code = $this->request->getPost('emp_code'); - $client_policy_id = $this->request->getPost('client_policy_id'); - $client_id = $this->request->getPost('client_id'); + $postData = json_decode($this->request->getBody(), true); + $client_policy_id = $postData['client_policy_id']; $this->employeeModel->where('emp_code', $emp_code ) ->where('is_active', 1 ) ->set(array('emp_status'=>'enrolled')) ->update(); - foreach ($client_policy_id as $key => $value) { - - $this->employeePolicyModel->where('client_policy_id', $value ) - ->where('is_active', 1 ) - ->set(array('status'=>'enrolled')) - ->update(); + + if (!is_null($client_policy_id) && is_array($client_policy_id)) + { + foreach ($client_policy_id as $key => $value) + { + $this->employeePolicyModel->where('client_policy_id', $value ) + ->where('is_active', 1 ) + ->set(array('status'=>'enrolled')) + ->update(); + } } return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); @@ -1517,6 +1521,39 @@ public function getCashDepositData() $data['insurerName'] = $value['insurer_name']; $data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']); $data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0; + + $data['policyDetails'] = []; + $ClientPolicyData =$this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id,policies.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon') + ->join('policies', 'client_policy.policy_id = policies.id', 'left') + ->where('client_policy.insurer_id', $value['insurerId'] ) + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->findAll(); + foreach ($ClientPolicyData as $key => $value) + { + $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']); + 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']; } + $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0); + $enrolledCount = 0; + $draftCount = 0; + if(count($employeeDetails)) + { + foreach ($employeeDetails as $item) { + if ($item['emp_status'] === 'enrolled') { + $enrolledCount++; + } elseif ($item['emp_status'] === 'draft') { + $draftCount++; + } + } + } + + $value['totalMembersCount'] = count($employeeDetails); + $value['membersCountOfEnrolled'] = $enrolledCount; + $value['membersCountOfDraft'] = $draftCount; + + array_push($data['policyDetails'],$value); + } + + array_push($result,$data); }