From b6f3d97608453b187ad0cba4ba3cea5ec8b8447c Mon Sep 17 00:00:00 2001 From: sriramv Date: Wed, 17 Apr 2024 10:37:38 +0530 Subject: [PATCH 01/33] 'FEAT_EMP_MODULE_EXCEL_ERROR_DOWNLOAD_FULL_FILE_RV' --- app/Config/Routes.php | 2 + app/Controllers/EmpDataServiceController.php | 2 +- app/Controllers/EmployeeController.php | 143 ++++++++++++++++- app/Controllers/EmployeeServiceController.php | 3 +- app/Models/EmployeePolicyModel.php | 1 + app/Views/employee_upload.php | 149 +++++++++++------- app/Views/excel_errors.php | 7 + 7 files changed, 238 insertions(+), 69 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f516c231..fc3ee161 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -216,6 +216,8 @@ $routes->group("/util", ["filter" => "authMVC"], function($routes){ $routes->get("view-success-emp-list", "EmployeeController::viewUploadedEmployeeList/$1"); $routes->get("fetch-policy-for-policy-type", "ClientController::fetchPolicyDataForPolicyType/$1"); $routes->get("fetch-emp-count/(:any)", "EmployeeController::getEmpCount/$1"); + $routes->get("init-Emp-onboard/(:any)", "EmployeeController::initiateManualEmployeesOnboardProcess/$1"); + $routes->get("full-excel-error-file/(:any)", "EmployeeController::downloadFullExcelErrorFile/$1"); }); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 01216aa6..9e0e0517 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -490,7 +490,7 @@ class EmpDataServiceController extends BaseController try { - if ($value[15] === null) { + if ($value[15] === null || $value[16] === null) { $missing_id[] = $key + 1; } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index b3b0160d..6a3ba065 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -26,6 +26,8 @@ use App\Controllers\EmpDataServiceController; use CodeIgniter\API\ResponseTrait; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\IOFactory; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; class EmployeeController extends AdminController { @@ -248,6 +250,7 @@ class EmployeeController extends AdminController // Render views and capture output $result = $empServiceController->getExcelErrorData($file_id); + $result['file_id'] = $file_id; // echo '
';
         // print_r($result); die;
@@ -564,10 +567,21 @@ class EmployeeController extends AdminController
     // 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);
+    {   
+       $client_data = $this->clientPolicyModel->select('clients.client_name as client_name, policies.name as policy_name')
+       ->join('clients', 'clients.id = client_policy.client_id')
+       ->join('policies', 'policies.id = client_policy.policy_id')
+       ->where('client_policy.id', $client_policy_id)
+       ->first();
+
+       $empServiceController = new EmployeeServiceController();
+       $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => $client_policy_id]);
+       // dd($res);
+
+       $count = count($res);
+       $message =  $count . ' Employees are Initiate Onboard Process againts Client '. $client_data['client_name'] . ' and the Policy is ' . $client_data['policy_name'] ;
+       session()->setFlashdata('success1',  $message);
+       return redirect()->to(base_url('/employee/upload'));
     }
 
 
@@ -665,9 +679,9 @@ class EmployeeController extends AdminController
 
     public function getEmpCount($id = null){
 
-      $data = $this->employeeModel->select('employees.id')
-       ->join('clients', 'clients.id = employees.client_id')
-       ->where('employees.client_id', $id)
+      $data = $this->employeePolicyModel->select('employee_polices.id')
+       ->where('employee_polices.is_active', 1)
+       ->where('employee_polices.client_policy_id', $id)
        ->findAll();
 
        $emp_count = count($data);
@@ -683,5 +697,120 @@ class EmployeeController extends AdminController
 
 
     }
+
+    public function downloadFullExcelErrorFile($file_id = 137, $rowIndex = 1, $colIndex = 1)
+    {
+        // Get file data from the database
+        $file_data = $this->fileModel->find($file_id);
+
+       $error =  json_decode($file_data['reason']);
+    //    echo '
';
+    //    print_r($error); die;
+    //    dd($error);
+    
+        // Check if the file exists
+        if (!$file_data) {
+            $error_message = "File not found";
+            $this->myLogger->logme('error', $error_message . ' for file id ' . $file_id);
+            return $error_message;
+        }
+    
+        $fileName = $file_data['file_name'];
+        $filePath = WRITEPATH . '/uploads/excel/' . $fileName;
+    
+        // Check if the file exists
+        if (!file_exists($filePath)) {
+            $error_message = "File not found";
+            $this->myLogger->logme('error', $error_message . ' for file id ' . $file_id);
+            return $error_message;
+        }
+    
+        // Load the Excel file
+        $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath);
+        $sheet = $spreadsheet->getActiveSheet();
+
+        //  echo '
';
+
+        foreach ($error->error_data as $index => $error_data) {
+
+            $rowIndex = $index+1;
+
+            if( $error->error_type == 1 ){
+
+                foreach ($error_data as $key => $value) {
+               
+                    $colIndex = $value->col_idx+1;
+                    
+                    $originalValue = $sheet->getCell([$colIndex, $rowIndex])->getValue();
+        
+                    $newValue =  implode(', ',$value->error);
+                    $val = $originalValue . ' ( ' . $newValue . ' )';
+                    $sheet->setCellValue([$colIndex, $rowIndex],  $val);
+                
+                    $style = [
+                        'fill' => [
+                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
+                            'startColor' => ['rgb' => 'ffad99'] // Red color
+                        ]
+                    ];
+                    
+                    $sheet->getStyle([$colIndex, $rowIndex])->applyFromArray($style);
+    
+                }
+            }else if( $error->error_type == 2){
+
+
+                foreach ($error_data as $key => $value) {
+               
+                    
+                    $originalValue = $sheet->getCell([1, $rowIndex])->getValue();
+        
+                    $newValue =  implode(', ',$value->error);
+                    $val = $originalValue . ' ( ' . $newValue . ' )';
+                    $sheet->setCellValue([$colIndex, $rowIndex],  $val);
+                
+                    $style = [
+                        'fill' => [
+                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
+                            'startColor' => ['rgb' => 'ffad99'] // Red color
+                        ]
+                    ];
+                    $sheet->getStyle([$colIndex, $rowIndex])->applyFromArray($style);
+    
+                }
+
+            }
+
+       }
+    
+
+    
+        // Create a new filename for the modified Excel file
+        $newFileName = 'modified_' . $fileName;
+    
+        // Save the modified Excel file to a new location
+        $newFilePath = WRITEPATH . '/uploads/excel/' . $newFileName;
+        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
+        $writer->save($newFilePath);
+    
+        // Set headers to force download
+        $response = service('response');
+        $response->setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        $response->setHeader('Content-Disposition', 'attachment;filename="' . $newFileName . '"');
+        $response->setHeader('Cache-Control', 'max-age=0');
+        $response->setHeader('Content-Length', filesize($newFilePath));
+        $response->setBody(file_get_contents($newFilePath));
+    
+        // Delete the temporary file
+        unlink($newFilePath);
+    
+        // Return the response
+        return $response;
+    }
+    
+    
+    
+    
+    
     
 }
\ No newline at end of file
diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php
index 6007b717..581d659e 100644
--- a/app/Controllers/EmployeeServiceController.php
+++ b/app/Controllers/EmployeeServiceController.php
@@ -568,7 +568,8 @@ class EmployeeServiceController extends AdminController
 
             $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'];
+            // $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception'];
+            $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception','created_by' => get_session_userid()];
             // dd($this->employeeModel->getLastQuery());
             // Kint::dump($existing_famility_details);die();
              $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db');
diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php
index 084247bf..17f1c3f2 100644
--- a/app/Models/EmployeePolicyModel.php
+++ b/app/Models/EmployeePolicyModel.php
@@ -659,6 +659,7 @@ class EmployeePolicyModel extends Model
                          ->where('employee_polices.client_policy_id',$policy_id);
 
          $result->whereIn('employee_polices.status', ['draft', 'enrolled']);
+         $result->whereIn('emp.emp_status', ['draft', 'enrolled']);
          $result = $result->findAll();        
          return ($result);
     }
diff --git a/app/Views/employee_upload.php b/app/Views/employee_upload.php
index 959e1509..e6fccef7 100644
--- a/app/Views/employee_upload.php
+++ b/app/Views/employee_upload.php
@@ -1,3 +1,10 @@
+
 
 
@@ -124,7 +131,7 @@
@@ -152,6 +159,10 @@ $('#file_upload').hide(); $(document).ready(function() { + + has('success1')): ?> + toastr.success('getFlashdata('success1') ?>', 'success'); + // Initialize select2 $("#client_id").select2(); $("#policy_id").select2(); @@ -478,10 +489,10 @@ $(document).ready(function() { $('#client_id').on('change', function() { var selectedClient = $(this).val(); + console.log('selectedClient', selectedClient); // $('#selectedOptionInfo').text('Selected option: ' + selectedOption); - // Check if the selected option exists in apiData var foundPolicies = clientPolicies.find(function(item) { return item.id === selectedClient; @@ -489,64 +500,6 @@ $(document).ready(function() { console.log(foundPolicies.policies); appendPolicies(foundPolicies.policies); - var apiURL = '' + 'util/fetch-emp-count/' + selectedClient; - console.log(apiURL); - $.ajax({ - url: apiURL, - method: 'GET', - headers: { - "Content-Type": "application/json", - "X-Requested-With": "XMLHttpRequest" - }, - success: function(response) { - - console.log('responce data emp_count', response); - - if (response.code === 200 && response.dataStatus === true && response.data !== "") { - try { - console.log(response.emp_count.length) - if(response.emp_count > 0){ - - var select = document.getElementById("upload-action-type"); - for (var i = 0; i < select.options.length; i++) { - if (select.options[i].value === "inception") { - select.options[i].disabled = true; - break; - } - } - }else{ - - var select = document.getElementById("upload-action-type"); - for (var i = 0; i < select.options.length; i++) { - if (select.options[i].value === "inception") { - select.options[i].disabled = false; - break; - } - } - } - - } catch (error) { - console.error('Error parsing API response data:', error); - } - } else if (response.code === 404 && response.dataStatus === false) { - - console.error('no data found', response); - - } else { - console.error('Something went wrong!'); - } - }, - error: function(xhr, status, error) { - console.error('Error fetching data from API:', error); - var select = document.getElementById("upload-action-type"); - for (var i = 0; i < select.options.length; i++) { - if (select.options[i].value === "inception") { - select.options[i].disabled = false; - break; - } - } - } - }); }); }); @@ -637,6 +590,12 @@ document.getElementById('toggleIcon1').addEventListener('click', function() { $('#fetch_enrolled_data').click(function() { + var policy_id = $('#policy_id').val(); + var uri = '' + policy_id; + console.log(policy_id); + console.log(uri); + $('#fetch_btn').attr('href', uri); + $('#emp_data').empty(); var client_id = $('#client_id').val(); var policy_id = $('#policy_id').val(); @@ -700,5 +659,75 @@ $('#fetch_enrolled_data').click(function() }) +$(document).ready(function() { + + $('#policy_id').change(function(){ + + var selectedpolicy = $(this).val(); + console.log('selectedpolicy',selectedpolicy) + + var apiURL = '' + 'util/fetch-emp-count/' + selectedpolicy; + console.log(apiURL); + $.ajax({ + url: apiURL, + method: 'GET', + headers: { + "Content-Type": "application/json", + "X-Requested-With": "XMLHttpRequest" + }, + success: function(response) { + + console.log('responce data emp_count', response); + + if (response.code === 200 && response.dataStatus === true && response.data !== "") { + try { + console.log(response.emp_count.length) + if(response.emp_count > 0){ + + var select = document.getElementById("upload-action-type"); + for (var i = 0; i < select.options.length; i++) { + if (select.options[i].value === "inception") { + select.options[i].disabled = true; + break; + } + } + }else{ + + var select = document.getElementById("upload-action-type"); + for (var i = 0; i < select.options.length; i++) { + if (select.options[i].value === "inception") { + select.options[i].disabled = false; + break; + } + } + } + + } catch (error) { + console.error('Error parsing API response data:', error); + } + } else if (response.code === 404 && response.dataStatus === false) { + + console.error('no data found', response); + + } else { + console.error('Something went wrong!'); + } + }, + error: function(xhr, status, error) { + console.error('Error fetching data from API:', error); + var select = document.getElementById("upload-action-type"); + for (var i = 0; i < select.options.length; i++) { + if (select.options[i].value === "inception") { + select.options[i].disabled = false; + break; + } + } + } + }); + }) + +}) + + //-------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/app/Views/excel_errors.php b/app/Views/excel_errors.php index 0e8b070e..7c09353c 100644 --- a/app/Views/excel_errors.php +++ b/app/Views/excel_errors.php @@ -66,6 +66,7 @@ table.dataTable tbody td { +
@@ -118,6 +119,12 @@ $(document).ready(function() { extend: 'excel', text: 'Excel', // Set the title for the Excel button title: 'ExcelErrorData', // Set your custom title here + }, + { + text: 'Excel Error', // Set the text for the custom button + action: function (e, dt, node, config) { + window.location.href = ''; + } } ], paging: false, // Disable pagination From 7af224f0cfcdc7b9efc49930a053410a2599be5f Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 17 Apr 2024 10:55:19 +0530 Subject: [PATCH 02/33] CHANGE_ADDONPOILICYAPI:GWM --- app/Controllers/EmployeeRestController.php | 88 ++++++++++++++++------ 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 5245fcae..fcb784fa 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -170,16 +170,18 @@ class EmployeeRestController extends AdminController public function addEmployeeAndDependence() { - try { + // try { $data = $this->request->getJSON(); if ($data) { + $Count = 0; foreach ($data as $item) { if (isset($item->id)) { //update old data $id = $item->id; $item->family_floater_key = $this->RelationshipMap($item->relationship); + $item->gender = $this->GenderMap($item->relationship , $item->emp_code); $item->dob = $this->convertDateFormatYMD($item->dob); $item->emp_status = 'Draft'; $employee = $this->employeeModel->where('is_active', 1 )->update($id, (array)$item); @@ -189,9 +191,10 @@ class EmployeeRestController extends AdminController }else{ //create new data $item->family_floater_key = $this->RelationshipMap($item->relationship); + $item->gender = $this->GenderMap($item->relationship , $item->emp_code); $item->dob = $this->convertDateFormatYMD($item->dob); $item->emp_status = 'Draft'; - $employee = $this->employeeModel->where('is_active', 1 )->insert($item); + $employee = $this->employeeModel->insert($item); if ($employee) { if(!isset($item->is_addon_value)) @@ -206,6 +209,7 @@ class EmployeeRestController extends AdminController } if ($Count > 0) { + $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); $result = []; return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); } else { @@ -213,40 +217,57 @@ 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) { - - $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; - $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); - $SlabRatesArray = $getSlabAndGridData['slab_rates']; - $premium = $this->findPremiumAmount($SlabRatesArray, $basic_cover_si); - - - $data['employee_id']= $employee_id; $data['client_policy_id']= $client_policy_id; $data['basic_cover_si']= $basic_cover_si; - $data['premium']= $premium; + $data['status']= 'draft'; $this->employeePolicyModel->insert($data); - - return true; - - } + public function updatePremiumAmount($client_policy_id , $emp_code) + { + $response = $this->calculatePremium($client_policy_id , $emp_code); + + if(count($response[$emp_code])) + { + print_r($response[$emp_code]); + foreach ($response[$emp_code] as $key => $value) + { + + $checkIfExist = $this->employeePolicyModel->where('employee_id', $value['temp']['emp_id']) + ->where('client_policy_id', $value['policy_details']['client_policy_id']) + ->where('is_active', 1 ) + ->findAll(); + if($checkIfExist) + { + $this->employeePolicyModel + ->where('client_policy_id',$value['policy_details']['client_policy_id'] ) + ->where('employee_id' , $value['temp']['emp_id'] ) + ->where('is_active', 1 ) + ->set(array('premium'=> $value['policy_details']['premium'] )) + ->update(); + + } + } + } + } + + public function RelationshipMap($value){ if ($value === 'Mother' || $value === 'Father') { @@ -260,6 +281,19 @@ class EmployeeRestController extends AdminController } } + public function GenderMap($value,$empCode){ + + if ($value === 'Mother' || $value === 'Daughter' || $value === 'Mother in Law') { + return 'F'; + } else if($value === 'Son' || $value === 'Father' || $value === 'Father in Law'){ + return 'M'; + }else if($value === 'Spouse'){ + + $Gender = $this->employeeModel->where('emp_code',$empCode)->where('relationship','Self')->get()->getRow()->gender; + if($Gender == 'M'){ return 'F'; }else{ return 'M'; } + } +} + private function convertDateFormatYMD($dateString) { // Attempt to create a DateTime object from the provided date string @@ -1293,11 +1327,11 @@ public function iAgreeForAddOn() //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 +public function calculatePremium($clientPolicyId = null , $empCode = null)//family level { helper('excel_util_helper'); - $client_policy_id = $this->request->getVar('client_policy_id'); - $emp_code = $this->request->getVar('emp_code'); + $client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId; + $emp_code = $this->request->getVar('emp_code') ?? $empCode; // dd($client_policy_id); $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; @@ -1308,8 +1342,7 @@ public function calculatePremium()//family level //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']); - + $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()); // dd($existing_famility_details);die(); @@ -1324,8 +1357,15 @@ public function calculatePremium()//family level } - // dd ($employee_data_group_by_family); + 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); + + } + } } \ No newline at end of file From 334ce49bab1e38f8bf336696b9ea8025f73204f2 Mon Sep 17 00:00:00 2001 From: velz Date: Wed, 17 Apr 2024 16:00:29 +0530 Subject: [PATCH 03/33] CHANGE_PREMIUM_CALC_API --- app/Controllers/EmployeeRestController.php | 6 ++- app/Controllers/EmployeeServiceController.php | 2 +- app/Helpers/excel_util_helper.php | 45 +++++++++++-------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 1631a100..668c12f1 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1298,7 +1298,8 @@ 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); + $default_si = $this->request->getVar('si');// si amt which choosed in add on policy + // dd($default_si); $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; // get policy and rack details @@ -1307,6 +1308,7 @@ public function calculatePremium()//family level //get policy slab rates $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); + // dd($slab_details); $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']); @@ -1318,7 +1320,7 @@ public function calculatePremium()//family level 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); + $data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si); // dd($data); $employee_data_group_by_family[$emp_id] = $data; diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 6007b717..31f4fe58 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -568,7 +568,7 @@ class EmployeeServiceController extends AdminController $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']; + $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception','created_by' => get_session_userid()]; // dd($this->employeeModel->getLastQuery()); // Kint::dump($existing_famility_details);die(); $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db'); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 3d8b9421..34e36e46 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -509,7 +509,7 @@ if (!function_exists('generate_relationship_code')) if (!function_exists('calculate_premimum')) { - function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr) + function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr,$default_si = null) { // // dd($fileArr); @@ -558,7 +558,7 @@ if (!function_exists('calculate_premimum')) if( $fileArr['id'] == null || (in_array($grid_type,[10,11]) || $transformed_familiy_member_data['temp']['source'] == 'excel'))//if file id is null then data coming from enrollment (from DB) otherwise data coming from xcel, so calculate only data from excel (new entry) note: even data coming from excel for event dependet additon we fetch other dependts from db and calculate premium for whole family { - $transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details); + $transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details,$default_si); $result[] = $transformed_familiy_member_data; } @@ -630,7 +630,7 @@ if (!function_exists('transform_excel_data_to_db')) if (!function_exists('premium_calculation_manager')) { - function premium_calculation_manager($emp_data,$policy_terms,$slab_details) + function premium_calculation_manager($emp_data,$policy_terms,$slab_details,$default_si = null) { // grid type // 1 = premium => si @@ -639,11 +639,12 @@ if (!function_exists('premium_calculation_manager')) switch ($grid_type) { case "1": //GPA - Sum Insured (SI) * Multiplier - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { if($slab_value['si'] == $employee_received_si) { + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; @@ -658,11 +659,12 @@ if (!function_exists('premium_calculation_manager')) break; case "2": //GPA - Flat Rate for all SI - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { if($slab_value['si'] == $employee_received_si) { + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; @@ -676,11 +678,12 @@ if (!function_exists('premium_calculation_manager')) break; case "3": //GMC - SI - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { if($slab_value['si'] == $employee_received_si) { + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; @@ -694,13 +697,17 @@ if (!function_exists('premium_calculation_manager')) break; case "4": + //GMC - Employees Age band - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + // dd($employee_received_si); foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) { + // dd($slab_value); + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; @@ -714,13 +721,13 @@ if (!function_exists('premium_calculation_manager')) break; case "5": //GMC - Employees Age + SI - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) { - + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; @@ -734,13 +741,13 @@ if (!function_exists('premium_calculation_manager')) break; case "6": //GMC - Employees + Dependent Age band - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) { - + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; @@ -754,13 +761,13 @@ if (!function_exists('premium_calculation_manager')) break; case "7": //GMC - Employees + Dependent Age + SI - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) { - + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; @@ -776,14 +783,14 @@ if (!function_exists('premium_calculation_manager')) case "8": //GMC - SI as per Grade or Band $employee_received_band = $emp_data['temp']['band']; - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) { // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; - + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; @@ -798,13 +805,13 @@ if (!function_exists('premium_calculation_manager')) case "9": //GMC - Flat Rate for all $employee_received_band = $emp_data['temp']['band']; - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) { - // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; @@ -819,7 +826,7 @@ if (!function_exists('premium_calculation_manager')) case "10": //GMC - Maximum age of Dependents $max_age = $emp_data['temp']['maxage']; - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $emp_data['policy_details']['basic_cover_si'] = null; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { @@ -842,7 +849,7 @@ if (!function_exists('premium_calculation_manager')) //GMC - Maximum count per Family $max_count = $emp_data['temp']['maxcount']; $employee_received_band = $emp_data['temp']['band']; - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $emp_data['policy_details']['basic_cover_si'] = null; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { From 62054714e621b1c1015d551b3a74f698476c5c56 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 17 Apr 2024 16:51:18 +0530 Subject: [PATCH 04/33] CHANGE_siAmountUpdate:GWM --- app/Controllers/EmployeeRestController.php | 55 +++++++++++++++------- app/Models/EmployeePolicyModel.php | 2 +- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d1f7fbde..d0a70c30 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -183,7 +183,7 @@ class EmployeeRestController extends AdminController $item->family_floater_key = $this->RelationshipMap($item->relationship); $item->gender = $this->GenderMap($item->relationship , $item->emp_code); $item->dob = $this->convertDateFormatYMD($item->dob); - $item->emp_status = 'Draft'; + $item->emp_status = 'draft'; $employee = $this->employeeModel->where('is_active', 1 )->update($id, (array)$item); if ($employee) { $Count++; @@ -193,7 +193,7 @@ class EmployeeRestController extends AdminController $item->family_floater_key = $this->RelationshipMap($item->relationship); $item->gender = $this->GenderMap($item->relationship , $item->emp_code); $item->dob = $this->convertDateFormatYMD($item->dob); - $item->emp_status = 'Draft'; + $item->emp_status = 'draft'; $employee = $this->employeeModel->insert($item); if ($employee) { @@ -209,7 +209,12 @@ class EmployeeRestController extends AdminController } if ($Count > 0) { - $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); + + if(!isset($data[0]->is_addon_value)) + { + $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); + } + $result = []; return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); } else { @@ -230,12 +235,28 @@ class EmployeeRestController extends AdminController $policy_terms = json_decode($client_policy['policy_terms']); $basic_cover_si = $policy_terms->sum_insured; - $data['employee_id']= $employee_id; - $data['client_policy_id']= $client_policy_id; - $data['basic_cover_si']= $basic_cover_si; - $data['status']= 'draft'; - - $this->employeePolicyModel->insert($data); + $checkDataExist = $this->employeePolicyModel->where('employee_id',$employee_id)->where('client_policy_id',$client_policy_id)->first(); + + if($checkDataExist){ + + $this->employeePolicyModel + ->where('client_policy_id',$client_policy_id ) + ->where('employee_id' , $employee_id ) + ->where('is_active', 1 ) + ->set(array('basic_cover_si'=> $basic_cover_si )) + ->update(); + + }else{ + + $data['employee_id']= $employee_id; + $data['client_policy_id']= $client_policy_id; + $data['basic_cover_si']= $basic_cover_si; + $data['status']= 'draft'; + + $this->employeePolicyModel->insert($data); + + } + return true; } @@ -245,7 +266,7 @@ class EmployeeRestController extends AdminController if(count($response[$emp_code])) { - print_r($response[$emp_code]); + foreach ($response[$emp_code] as $key => $value) { @@ -543,27 +564,27 @@ class EmployeeRestController extends AdminController ->where('client_policy_id', $value->client_policy_id) ->where('is_active', 1 ) ->findAll(); - $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($value->client_policy_id,$value->client_id); - $SlabRatesArray = $getSlabAndGridData['slab_rates']; - $premium = $this->findPremiumAmount($SlabRatesArray, $value->basic_cover_si); + // dd($checkIfExist); if ($checkIfExist) { - $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si,$premium); + $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si); }else{ $data['employee_id']= $value->employee_id; $data['client_policy_id']= $value->client_policy_id; $data['basic_cover_si']= $value->basic_cover_si; - $data['premium']= $premium; - $data['status'] = 'Draft'; + $data['status'] = 'draft'; $this->employeePolicyModel->insert($data); } } - return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); + + $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code); + + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 17f1c3f2..f5577030 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -555,7 +555,7 @@ class EmployeePolicyModel extends Model // } - public function updateSiAndPremium( $client_policy_id, $employee_id,$basic_cover_si,$premium) + public function updateSiAndPremium( $client_policy_id, $employee_id,$basic_cover_si,$premium = 0) { From c1fcfee1d0e2526b0be165ba37118d9ec9b5f190 Mon Sep 17 00:00:00 2001 From: sriramv Date: Thu, 18 Apr 2024 09:41:24 +0530 Subject: [PATCH 05/33] 'FIX_EMP_MODULE_INCEPTION_IMPORT_EXPORT_VLD_AND_CHANGE_CLIENT_MODULE_RACK_RATE_RV' --- app/Controllers/ClientController.php | 76 +++++-- app/Controllers/EmpDataServiceController.php | 142 +++++++++---- app/Controllers/EmployeeController.php | 32 ++- app/Models/EmployeePolicyModel.php | 12 +- app/Models/PolicyPremium2Model.php | 1 + app/Views/policy_grid.php | 207 +++++++++++++++++-- 6 files changed, 378 insertions(+), 92 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 2b5354d5..600d054e 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -921,6 +921,39 @@ class ClientController extends AdminController } $data = $this->request->getPost(); $insert = true; + }else if($policy_grid_id == '12'){ + + $premium=$this->request->getPost('12_premium[]'); + $sum_insure =$this->request->getPost('12_si[]'); + $relationship =$this->request->getPost('12_relationship[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['relationship'] = $relationship[$i]; + + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '13'){ + + $premium=$this->request->getPost('13_premium[]'); + $sum_insure =$this->request->getPost('13_si[]'); + $age_from =$this->request->getPost('13_age_from[]'); + $age_to =$this->request->getPost('13_age_to[]'); + $relationship =$this->request->getPost('13_relationship[]'); + + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['age_from'] = $age_from[$i]; + $data['age_to'] = $age_to[$i]; + $data['relationship'] = $relationship[$i]; + + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; } if($insert){ @@ -1003,6 +1036,12 @@ class ClientController extends AdminController $family_floater=json_decode($record['policy_terms'])->family_floater; } + $policy_terms_data = json_decode($record['policy_terms']); + $self = ""; + if ($policy_terms_data !== null && isset($policy_terms_data->family_floaters)) { + $self = $policy_terms_data->family_floaters; + } + $emp_count = $this->employeeModel ->join('client_policy cp',"employees.client_id = cp.client_id") ->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id") ->where("employees.client_id",$record['client_id']) @@ -1054,26 +1093,25 @@ class ClientController extends AdminController if($search_term === 'GMC'){ $resultss = []; - if ($family_floater == 1) { + try { foreach ($results as $index => $record) { - if ($index == '8' || $index == '7') { - // Clearing the $results array - $resultss[$index] = $record; + if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0) { + if ($index == '0' || $index == '1' || $index == '2') { + $resultss[$index] = $record; + } + } else { + if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6' || $index == '8' || $index == '7' || $index == '9' || $index == '10') { + $resultss[$index] = $record; + } } } - }else if($family_floater == 0){ - foreach ($results as $index => $record) { - if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') { - // Clearing the $results array - $resultss[$index] = $record; - } - } - }else{ - foreach ($results as $index => $record) { - $resultss[$index] = $record; - } + } catch (\Exception $e) { + $resultss = $results; // Reset $resultss to an empty array if an exception occurs } + + + $premiumDataa =''; if ($family_floater == 0) { // print_r($premiumData);die; @@ -1086,7 +1124,7 @@ class ClientController extends AdminController else if($family_floater == 1){ if(count($premiumData) == 0){ $premiumDataa = $premiumData; - }else if ($premiumData[0]['policy_grid_id'] == '10' || $premiumData[0]['policy_grid_id'] == '11') { + }else if ($premiumData[0]['policy_grid_id'] == '10' || $premiumData[0]['policy_grid_id'] == '11' ) { $premiumDataa = $premiumData; } }else{ @@ -1103,15 +1141,15 @@ class ClientController extends AdminController // echo "hello"; // return json_encode($premiumData); - return $this->respond(['status' => true,'code' => 200,'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name,], 200); + return $this->respond(['status' => true,'code' => 200,'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); }else if($search_term === 'GPA'){ - return $this->respond(['status' => true,'code' => 200,'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name,], 200); + return $this->respond(['status' => true,'code' => 200,'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); }else{ - return $this->respond(['status' => false,'code' => 200,'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name,], 200); + return $this->respond(['status' => false,'code' => 200,'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); } } diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 9e0e0517..4ce78926 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -490,8 +490,19 @@ class EmpDataServiceController extends BaseController try { - if ($value[15] === null || $value[16] === null) { - $missing_id[] = $key + 1; + + if($import_data['insurer_or_tpa'] == 'tpa'){ + + if ($value[15] === null) { + $missing_id[] = $key + 1; + } + + }else if($import_data['insurer_or_tpa'] == 'insurer'){ + + if ( $value[16] === null) { + $missing_id[] = $key + 1; + } + } $emp_code = $value[2]; @@ -501,26 +512,32 @@ class EmpDataServiceController extends BaseController $db = \Config\Database::connect(); // Execute the query - $query = $db->table('employee_polices') - ->select('employee_polices.id') - ->join('employees', 'employees.id = employee_polices.employee_id') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employees.client_id', $client_id) - ->where('employees.name', $name) - ->where('employees.emp_code', $emp_code) - ->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")') - ->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")') - ->where('employee_polices.is_active', 1) - ->limit(1) - ->get(); + $query = $db->table('employee_polices'); + $query->select('employee_polices.id'); + $query->join('employees', 'employees.id = employee_polices.employee_id'); + $query->where('employee_polices.client_policy_id', $client_policy_id); + $query->where('employees.client_id', $client_id); + $query->where('employees.name', $name); + $query->where('employees.emp_code', $emp_code); + if($import_data['insurer_or_tpa'] == 'tpa'){ + + $query->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")'); + + }else if($import_data['insurer_or_tpa'] == 'insurer'){ + + $query->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")'); + + } + $query->where('employee_polices.is_active', 1); + $query->limit(1); // Get the result - $result = $query->getRowArray(); + $result = $query->get()->getRowArray(); if (isset($result['id']) && $result['id'] !== null) { $empty_emp_tpa_uh_ids[] = $result['id']; } } catch (\Exception $e) { - // Handle the exception here + return 0; } } @@ -529,17 +546,46 @@ class EmpDataServiceController extends BaseController $missing_id_count = count($missing_id); $empty_id_count = count($empty_emp_tpa_uh_ids); - // dd($count, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); - if ($missing_id_count != $count && $missing_id_count != 0) { + if($import_data['insurer_or_tpa'] == 'tpa'){ + + if ($empty_id_count == 0) { + + return 3; + } + + if ($missing_id_count != 0) { + + return 2; + } + + + }else if($import_data['insurer_or_tpa'] == 'insurer'){ + + if ($empty_id_count == 0) { + + return 5; + } + + if ($missing_id_count != 0) { + + return 4; + } - return 2; } - if ($empty_emp_tpa_uh_ids != $count && $empty_id_count == 0) { + // if ($missing_id_count != $count) { - return 3; - } + // return 2; + // } + + + // if ($empty_emp_tpa_uh_ids != $count) { + + // return 3; + // } + + // dd($empty_emp_tpa_uh_ids); @@ -559,18 +605,28 @@ class EmpDataServiceController extends BaseController foreach ($data as $key => $value) { - if (!empty($value) && (isset($value[15]) || isset($value[16]))) { + if (!empty($value)) { - $tpa_id = $value[15] !== null ? $value[15] : ''; - $uhid = $value[16] !== null ? $value[16] : ''; + + if($import_data['insurer_or_tpa'] == 'tpa'){ - foreach ($empty_emp_tpa_uh_ids as $id) { - // Update employee policies based on the ID - $this->employeePolicyModel->where('id', $id)->set(['tpa_id' => $tpa_id, 'uhid' => $uhid])->update(); + $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(); } - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
"; } else { @@ -580,17 +636,23 @@ class EmpDataServiceController extends BaseController - $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); - $depositeData = [ - 'employeeIds' => $empty_emp_tpa_uh_ids, - 'client_id' => $client_id, - 'client_policy_id' => $client_policy_id, - 'count' => $count, - 'event' => $import_data['event_type'], - 'policy_name' => $policy_name['policy_name'], - ]; + if($import_data['insurer_or_tpa'] == 'tpa'){ + + $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); + $depositeData = [ + 'employeeIds' => $empty_emp_tpa_uh_ids, + 'client_id' => $client_id, + 'client_policy_id' => $client_policy_id, + 'count' => $count, + 'event' => $import_data['event_type'], + 'policy_name' => $policy_name['policy_name'], + ]; + + $this->cashDepositCalculationForInception($depositeData); + + } + - $this->cashDepositCalculationForInception($depositeData); return 1; } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 6a3ba065..2676257c 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -401,16 +401,28 @@ class EmployeeController extends AdminController return redirect()->to(base_url('employee/upload')); }else if($return == 2){ - session()->setFlashdata('error', 'The TPA ID or UHID columns are empty.'); + session()->setFlashdata('error', 'The TPA ID column is either partially or entirely empty.'); return redirect()->to(base_url('employee/upload')); }else if($return == 0){ - session()->setFlashdata('error', 'Please upload the correct file, something went wrong.'); + session()->setFlashdata('error', 'Please upload the correct file.'); return redirect()->to(base_url('employee/upload')); + }else if($return == 3){ - session()->setFlashdata('error', 'File already uploaded'); + session()->setFlashdata('error', 'The following list of employees has already been updated with the TPA ID.'); return redirect()->to(base_url('employee/upload')); - } }else if($event_type == 'correction'){ + + }else if($return == 4){ + session()->setFlashdata('error', 'The UHID column is either partially or entirely empty.'); + return redirect()->to(base_url('employee/upload')); + + }else if($return == 5){ + session()->setFlashdata('error', 'The following list of employees has already been updated with the UHID.'); + return redirect()->to(base_url('employee/upload')); + + } + + }else if($event_type == 'correction'){ $return = $empDataServiceController->importExcelDataForCorrection($batch_data); if($return == 1){ @@ -422,7 +434,7 @@ class EmployeeController extends AdminController return redirect()->to(base_url('employee/upload')); }else if($return == 0){ - session()->setFlashdata('error', 'Please upload the correct file, something went wrong.'); + session()->setFlashdata('error', 'Please upload the correct file'); return redirect()->to(base_url('employee/upload')); }else if($return == 3){ session()->setFlashdata('error', 'File already uploaded'); @@ -441,7 +453,7 @@ class EmployeeController extends AdminController return redirect()->to(base_url('employee/upload')); }else if($return == 0){ - session()->setFlashdata('error', 'Please upload the correct file, something went wrong.'); + session()->setFlashdata('error', 'Please upload the correct file'); return redirect()->to(base_url('employee/upload')); }else if($return == 3){ session()->setFlashdata('error', 'File already uploaded'); @@ -460,7 +472,7 @@ class EmployeeController extends AdminController return redirect()->to(base_url('employee/upload')); }else if($return == 0){ - session()->setFlashdata('error', 'Please upload the correct file, something went wrong.'); + session()->setFlashdata('error', 'Please upload the correct file'); return redirect()->to(base_url('employee/upload')); }else if($return == 3){ session()->setFlashdata('error', 'File already uploaded'); @@ -704,9 +716,9 @@ class EmployeeController extends AdminController $file_data = $this->fileModel->find($file_id); $error = json_decode($file_data['reason']); - // echo '
';
-    //    print_r($error); die;
-    //    dd($error);
+        //    echo '
';
+        //    print_r($error); die;
+        //    dd($error);
     
         // Check if the file exists
         if (!$file_data) {
diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php
index 17f1c3f2..7c961144 100644
--- a/app/Models/EmployeePolicyModel.php
+++ b/app/Models/EmployeePolicyModel.php
@@ -107,6 +107,15 @@ class EmployeePolicyModel extends Model
         $client_policy_id = $ref_data['client_policy_id'];
         $insurer_or_tpa = $ref_data['insurer_or_tpa'];
 
+        if($insurer_or_tpa == 'tpa'){
+
+            $id = 'tpa_id';
+
+        }else if($insurer_or_tpa == 'insurer'){
+
+            $id = 'uhid';
+        }
+
         $sql = "
                 SELECT 
                 employees.name AS emp_name,
@@ -148,8 +157,7 @@ class EmployeePolicyModel extends Model
             WHERE batch_data.bf IS NULL
                 AND batch_data.bl IS NULL
                 AND employee_polices.client_policy_id = '{$client_policy_id}'
-                AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '')
-                AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '')
+                AND (employee_polices.{$id} IS NULL OR employee_polices.{$id} = '')
                 AND employee_polices.is_active = 1";
 
             // Get the result set
diff --git a/app/Models/PolicyPremium2Model.php b/app/Models/PolicyPremium2Model.php
index e390dcc7..85ee9972 100644
--- a/app/Models/PolicyPremium2Model.php
+++ b/app/Models/PolicyPremium2Model.php
@@ -24,6 +24,7 @@ class PolicyPremium2Model extends Model
         "updated_by",
         'is_active',  
         'premium_type',  
+        'relationship',  
         
     ];
 
diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php
index 89946fec..4a5a8f6c 100644
--- a/app/Views/policy_grid.php
+++ b/app/Views/policy_grid.php
@@ -27,12 +27,13 @@
                                 
                             
 
-                            
+ @@ -66,7 +67,7 @@ $('#btnGridSubmit').hide(); $('.close').click(function() { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -92,7 +93,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa if (dataIdValue == '1') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -164,7 +165,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
`; } else if (dataIdValue == '2') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -186,7 +187,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '3') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -211,7 +212,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '4') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } grid_html = ` @@ -245,7 +246,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '5') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -278,7 +279,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '6') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -313,7 +314,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '7') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -346,7 +347,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '8') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -376,7 +377,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '9') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -406,7 +407,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '10') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -438,7 +439,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '11') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -469,8 +470,91 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa `; + } else if (dataIdValue == '12') { + + for (var i = 1; i <= 13; i++) { + $('#grid_' + i).remove(); + } + + grid_html = ` + +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
`; + + } else if (dataIdValue == '13') { + + for (var i = 1; i <= 13; i++) { + $('#grid_' + i).remove(); + } + + grid_html = ` + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
`; + } else { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } grid_html = ''; @@ -597,6 +681,7 @@ $('body').on('click', '.btnPolicyModel', function() { $('.loader').fadeIn(); $('.loader-mask').fadeIn(); + $.ajax({ url: '', type: "GET", @@ -608,6 +693,12 @@ $('body').on('click', '.btnPolicyModel', function() { $('#GridForm')[0].reset(); + if(res.family_floater == 1){ + $('#premium_type').show(); + }else{ + $('#premium_type').hide(); + } + setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); @@ -634,7 +725,8 @@ $('body').on('click', '.btnPolicyModel', function() { } var policy_grid_id_value = ''; - if (res.premiumData && res.premiumData.length > 0 && res.premiumData[0].policy_grid_id) { + if (res.premiumData && res.premiumData.length > 0 && res.premiumData[0] + .policy_grid_id) { policy_grid_id_value = res.premiumData[0].policy_grid_id; } @@ -649,23 +741,26 @@ $('body').on('click', '.btnPolicyModel', function() { }); $('#grid').html(policeGridOptionHTML); - if(res.premiumData[0].hasOwnProperty('premium_type')){ + if (res.premiumData[0].hasOwnProperty('premium_type')) { if (res.premiumData[0].premium_type == '2') { $('#individual').prop('checked', true) $('#single').prop('checked', false) - } else if (res.premiumData[0].premium_type == '1') { + } else if (res.premiumData[0].premium_type == '1') { $('#single').prop('checked', true) $('#individual').prop('checked', false) + + } else { + $('#single').prop('checked', false) + $('#individual').prop('checked', false) } } - var si_or_bp_value = ''; if (res.premiumData && res.premiumData.length > 0) { @@ -1101,6 +1196,78 @@ function appendGridtHtml(ui_type = false, data = false, ) { `; + } else if (ui_type == '12') { + + html = ` +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
`; + } else if (ui_type == '13') { + + html = ` +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
`; } @@ -1113,8 +1280,6 @@ function appendGridtHtml(ui_type = false, data = false, ) { Count++ - - // Number to word $(document).keyup(function(event) { if (event.target) { From c671a1014981ca08bb44b918804fd6b3e589f05a Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 18 Apr 2024 10:13:29 +0530 Subject: [PATCH 06/33] CHANGE_addKeyGstInTopupPolicyAPI:GWM --- app/Controllers/EmployeeRestController.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c7591832..0efaafd6 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -280,7 +280,7 @@ class EmployeeRestController extends AdminController ->where('client_policy_id',$value['policy_details']['client_policy_id'] ) ->where('employee_id' , $value['temp']['emp_id'] ) ->where('is_active', 1 ) - ->set(array('premium'=> $value['policy_details']['premium'] )) + ->set(array('premium'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] )) ->update(); } @@ -1183,8 +1183,9 @@ public function getAddOnPolicy() $data = []; - $dependent_and_si_value = null; - $dependent_and_si_premium_value = null; + $dependent_and_si_value = 0; + $dependent_and_si_premium_value = 0; + $dependent_and_si_gst_value = 0; foreach ($floters as $familyFloatesValue) { $dependent = preg_replace('/\d/', '', $familyFloatesValue); if(count($addOnEmployeeData)){ @@ -1192,7 +1193,8 @@ public function getAddOnPolicy() if ($value['family_floater_key'] === $dependent) { $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)){ $dependent_and_si_value = $employee_policy->basic_cover_si; } - if(isset($employee_policy->premium)){ $dependent_and_si_premium_value = $employee_policy->premium;} + if(isset($employee_policy->premium)){ $dependent_and_si_premium_value = $dependent_and_si_premium_value + $employee_policy->premium;} + if(isset($employee_policy->gst)){ $dependent_and_si_gst_value = $dependent_and_si_gst_value + $employee_policy->gst;} $temp['is_value_exist'] = true; $temp['data']['family_floater_key'] = $familyFloatesValue; @@ -1269,6 +1271,7 @@ public function getAddOnPolicy() $responce['family_floaters_of_dependent_and_si_array'] = $data; $responce['family_floaters_of_dependent_and_si_value'] = $dependent_and_si_value; $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value; + $responce['family_floaters_of_dependent_and_gst_value'] = $dependent_and_si_gst_value; @@ -1283,13 +1286,15 @@ public function getAddOnPolicy() $only_si_array = []; - $only_si_value = null; - $only_si_premium_value = null; + $only_si_value = 0; + $only_si_premium_value = 0; + $only_si_gst_value = 0; 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;} + if(isset($employee_policy->premium)){ $only_si_premium_value = $only_si_premium_value + $employee_policy->premium;} + if(isset($employee_policy->gst)){ $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;} $temp3['is_value_exist'] = true; $temp3['data']['employee_id'] = $value['id']; $temp3['data']['relationship'] = $value['relationship']; @@ -1305,6 +1310,7 @@ public function getAddOnPolicy() $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; + $responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value; if($this->request->getGet('policy') == 'GMC-SI-TOPUP'){ return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_topup'=>$responce]], 200); From e3be92f2c0d8fd28d9e3f2222cbab57eff2b1488 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 18 Apr 2024 11:13:12 +0530 Subject: [PATCH 07/33] CHANGE_empFileUploadAPI:GWM --- app/Controllers/EmployeeRestController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0efaafd6..21652fe0 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -395,9 +395,9 @@ class EmployeeRestController extends AdminController 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'; + $value['type'] = 'SI TopUp'; }else if($value['is_addon'] == "3"){ - $value['type'] = 'Dependent-AddOn'; + $value['type'] = 'Dependent AddOn'; }else{ $value['type'] = $getSlabAndGridData['grid_master']['policy_type']; } @@ -680,7 +680,7 @@ class EmployeeRestController extends AdminController $extra = []; if (count($data[0]) == 10) { - $value = ['S.No','Emp Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI']; + $value = ['Sno','Emp_Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI']; $check_miss_match = []; for ($i=0; $i 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); + return $this->respond(['status' => 'success', 'code' => 200, 'message' => "Success" ], 200); }else{ return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Client id and Client Policy id is Not Match!" ], 404); } From 4174885042d1d70c8d563457e78d1b2cc1783e90 Mon Sep 17 00:00:00 2001 From: sriramv Date: Thu, 18 Apr 2024 11:35:29 +0530 Subject: [PATCH 08/33] 'FIX_EMP_MODULE_IMPORT_EXPORT_INCEPTION' --- app/Controllers/EmpDataServiceController.php | 86 +++++++++++--------- app/Controllers/EmployeeController.php | 4 +- 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 4ce78926..36e3690c 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -24,6 +24,10 @@ use App\Controllers\Jobs; use PhpOffice\PhpSpreadsheet\Spreadsheet; // use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; +use PhpOffice\PhpSpreadsheet\IOFactory; +use PhpOffice\PhpSpreadsheet\Reader\Exception as SpreadsheetReaderException; + +use function PHPUnit\Framework\returnSelf; class EmpDataServiceController extends BaseController { @@ -479,6 +483,12 @@ class EmpDataServiceController extends BaseController $file = $import_data['file']; $data = $this->readExcelToArray($file); + + if (!$data) { + + return 0; + } + unset($data[0]); array_pop($data); $count = count($data); @@ -491,18 +501,16 @@ class EmpDataServiceController extends BaseController try { - if($import_data['insurer_or_tpa'] == 'tpa'){ + if ($import_data['insurer_or_tpa'] == 'tpa') { if ($value[15] === null) { $missing_id[] = $key + 1; } + } else if ($import_data['insurer_or_tpa'] == 'insurer') { - }else if($import_data['insurer_or_tpa'] == 'insurer'){ - - if ( $value[16] === null) { + if ($value[16] === null) { $missing_id[] = $key + 1; } - } $emp_code = $value[2]; @@ -519,14 +527,12 @@ class EmpDataServiceController extends BaseController $query->where('employees.client_id', $client_id); $query->where('employees.name', $name); $query->where('employees.emp_code', $emp_code); - if($import_data['insurer_or_tpa'] == 'tpa'){ + if ($import_data['insurer_or_tpa'] == 'tpa') { $query->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")'); - - }else if($import_data['insurer_or_tpa'] == 'insurer'){ + } else if ($import_data['insurer_or_tpa'] == 'insurer') { $query->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")'); - } $query->where('employee_polices.is_active', 1); $query->limit(1); @@ -547,7 +553,7 @@ class EmpDataServiceController extends BaseController $empty_id_count = count($empty_emp_tpa_uh_ids); - if($import_data['insurer_or_tpa'] == 'tpa'){ + if ($import_data['insurer_or_tpa'] == 'tpa') { if ($empty_id_count == 0) { @@ -558,9 +564,7 @@ class EmpDataServiceController extends BaseController return 2; } - - - }else if($import_data['insurer_or_tpa'] == 'insurer'){ + } else if ($import_data['insurer_or_tpa'] == 'insurer') { if ($empty_id_count == 0) { @@ -571,7 +575,6 @@ class EmpDataServiceController extends BaseController return 4; } - } // if ($missing_id_count != $count) { @@ -585,7 +588,7 @@ class EmpDataServiceController extends BaseController // return 3; // } - + // dd($empty_emp_tpa_uh_ids); @@ -607,15 +610,14 @@ class EmpDataServiceController extends BaseController if (!empty($value)) { - - if($import_data['insurer_or_tpa'] == 'tpa'){ + + 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'){ + } else if ($import_data['insurer_or_tpa'] == 'insurer') { $tpa_id = $value[15] !== null ? $value[15] : ''; $uhid = $value[16] !== null ? $value[16] : ''; @@ -623,11 +625,9 @@ class EmpDataServiceController extends BaseController } foreach ($empty_emp_tpa_uh_ids as $id) { - + $this->employeePolicyModel->where('id', $id)->set($data)->update(); } - - } else { return 0; @@ -1532,34 +1532,42 @@ class EmpDataServiceController extends BaseController + public function readExcelToArray($file) { - if ($file->isValid() && !$file->hasMoved()) { $file = $file; + + try { - $reader = new Xlsx(); - $spreadsheet = $reader->load($file->getPathname()); - - // Get the active sheet - $sheet = $spreadsheet->getActiveSheet(); - - // Iterate through rows to read data - $data = []; - foreach ($sheet->getRowIterator() as $row) { - $rowData = []; - foreach ($row->getCellIterator() as $cell) { - $rowData[] = $cell->getValue(); + $reader = IOFactory::createReaderForFile($file->getPathname()); + $spreadsheet = $reader->load($file->getPathname()); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Iterate through rows to read data + $data = []; + foreach ($sheet->getRowIterator() as $row) { + $rowData = []; + foreach ($row->getCellIterator() as $cell) { + $rowData[] = $cell->getValue(); + } + $data[] = $rowData; } - $data[] = $rowData; + + return $data; + + } catch (SpreadsheetReaderException $e) { + + error_log('PhpSpreadsheet reader exception: ' . $e->getMessage()); + return false; } - - return $data; } else { - return false; } } + public function insertBatchFileAndBatchListForImportExcel($data, $ids) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 2676257c..1871fab0 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -409,7 +409,7 @@ class EmployeeController extends AdminController return redirect()->to(base_url('employee/upload')); }else if($return == 3){ - session()->setFlashdata('error', 'The following list of employees has already been updated with the TPA ID.'); + session()->setFlashdata('error', 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file'); return redirect()->to(base_url('employee/upload')); }else if($return == 4){ @@ -417,7 +417,7 @@ class EmployeeController extends AdminController return redirect()->to(base_url('employee/upload')); }else if($return == 5){ - session()->setFlashdata('error', 'The following list of employees has already been updated with the UHID.'); + session()->setFlashdata('error', 'The list of employees provided has already been updated with the UHID, or this is not the correct file'); return redirect()->to(base_url('employee/upload')); } From 0e2b4f3962e3809b162288619c076b2afe465ce2 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 18 Apr 2024 11:46:21 +0530 Subject: [PATCH 09/33] CHANGE_addColumnGradeInExcel:GWM --- app/Controllers/EmployeeRestController.php | 9 +++++---- app/Controllers/RestAuthenticationController.php | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 21652fe0..e1814d9f 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -679,8 +679,8 @@ class EmployeeRestController extends AdminController $file_data =$this->fileModel->insert($extractData); $extra = []; - if (count($data[0]) == 10) { - $value = ['Sno','Emp_Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI']; + if (count($data[0]) == 11) { + $value = ['Sno','Emp_Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI','Grade']; $check_miss_match = []; for ($i=0; $i respond(['status' => 'failed', 'code' => 404, 'message' => "Uploaded file row count is Not Match!" ], 200); } @@ -775,7 +775,8 @@ class EmployeeRestController extends AdminController 'email_corporate' => $extra['7'][$index], 'mobile'=> $extra['8'][$index], 'client_id' => $client_id, - 'emp_status'=>'draft' + 'emp_status'=>'draft', + 'band'=> $extra['10'][$index], ]; $basic_cover_si_value = null; diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index b283bc5a..4b14a8bd 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -130,6 +130,7 @@ class RestAuthenticationController extends AdminController try { $mobile_number = $this->request->getJSON()->mobile_number; $randomNumber = rand(100000, 999999); + $randomNumber = 123456; $HrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first(); if ($HrData) { From 053a74ff88d5c83fda7efc1971f4eb1f7a69dee2 Mon Sep 17 00:00:00 2001 From: velz Date: Thu, 18 Apr 2024 15:18:16 +0530 Subject: [PATCH 10/33] CHANGE_PREMIUM_CALC_API --- app/Controllers/EmployeeRestController.php | 20 +++--- app/Controllers/EmployeeServiceController.php | 2 +- app/Helpers/excel_util_helper.php | 58 +++++++++++++++ .../unit/GridType12PremiumCalculationTest.php | 72 +++++++++++++++++++ 4 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 tests/unit/GridType12PremiumCalculationTest.php diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 71ebec43..db0cfb55 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1330,12 +1330,6 @@ public function iAgreeForAddOn() 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'); - // $emp_code = $this->request->getVar('emp_code'); - - // dd($default_si); - $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 @@ -1345,17 +1339,27 @@ public function calculatePremium($clientPolicyId = null , $empCode = null, $defa $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); - // dd($slab_details); + // 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()); - // dd($existing_famility_details);die(); + // 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) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 808fa7a9..cc5cafeb 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -562,7 +562,7 @@ class EmployeeServiceController extends AdminController // 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->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 34e36e46..41fa05dd 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -873,6 +873,64 @@ if (!function_exists('premium_calculation_manager')) } break; + case "12": + //GMC - Employee + relationship + $max_count = $emp_data['temp']['maxcount']; + $employee_received_band = $emp_data['temp']['band']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + $emp_data['policy_details']['basic_cover_si'] = null; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + + if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + { + //calculate premium based on count + $familiy_si_covered = $employee_received_si * $max_count; + $familiy_si_covered = ($familiy_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $familiy_si_covered); + + $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $familiy_si_covered : null); + $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); + $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); + $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); + $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); + $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); + $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + + break; + } + } + break; + + case "13": + //GMC - Employee + relationship + age + $max_count = $emp_data['temp']['maxcount']; + $employee_received_band = $emp_data['temp']['band']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + $emp_data['policy_details']['basic_cover_si'] = null; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + + if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + { + //calculate premium based on count + $familiy_si_covered = $employee_received_si * $max_count; + $familiy_si_covered = ($familiy_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $familiy_si_covered); + + $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $familiy_si_covered : null); + $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); + $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); + $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); + $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); + $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); + $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + + break; + } + } + break; + + + default: echo "Not a valid grid"; } diff --git a/tests/unit/GridType12PremiumCalculationTest.php b/tests/unit/GridType12PremiumCalculationTest.php new file mode 100644 index 00000000..9b87a1d3 --- /dev/null +++ b/tests/unit/GridType12PremiumCalculationTest.php @@ -0,0 +1,72 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50000, 'max_si' => 0,'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 25000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 20000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'child'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 18000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 15000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 12,'policy_grid_type' => 'Employees + Relationship','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ + [1, 'Jane Doe', '1990-01-01', 'F', 'Spouse', 10000, '2024-01-01', '2020-01-01', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2, 'John Doe', '1990-01-01', 'M', 'Self', '', '', '', '', '', '', '', '', '', '', ''], + [3, 'Peter Doe', '1990-01-01', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4, 'Mary Doe', '1990-01-01', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5, 'Grace Doe', '1990-01-01', 'F', 'Mother-in-law', '', '', '', '', '', '', '', '', '', '', ''], + [6, 'George Doe', '1990-01-01', 'M', 'Father-in-law', '', '', '', '', '', '', '', '', '', '', ''], + [7, 'Alice Doe', '1995-02-02', 'F', 'Daughter', 8000, '2024-02-01', '2021-01-01', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8, 'Bob Doe', '1995-02-02', 'M', 'Son', '', '', '', '', '', '', '', '', '', '', ''], +]; + + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + // Sample action array + $actionArr = 'addition'; + + // Call the function + $result = check_dependent_conflict($family_data, $policy_terms, $actionArr); + Kint::dump($result); + // Assert that the status is true (no conflicts) + $this->assertTrue($result['status']); + } + + // public function testIsNull() + // { + // $i = null; + // $this->assertTrue($i); + + // } +} \ No newline at end of file From e5cdd231c2e1d91272c7c70a175b0c0f3fa9ec03 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 18 Apr 2024 15:57:31 +0530 Subject: [PATCH 11/33] 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 12/33] 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 13/33] '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 14/33] 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 15/33] '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 16/33] '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 17/33] 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 18/33] 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 19/33] 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 20/33] 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); } From 416f4e46b977335d170639ec3274e37fb39b13a8 Mon Sep 17 00:00:00 2001 From: velz Date: Wed, 24 Apr 2024 11:33:50 +0530 Subject: [PATCH 21/33] CHANGE_NEW_RACK_RATE_IMPLEMENTAIONS --- app/Controllers/EmployeeController.php | 6 +- app/Controllers/EmployeeRestController.php | 3 +- app/Controllers/EmployeeServiceController.php | 6 +- app/Helpers/excel_util_helper.php | 104 +++++----- .../unit/GridType11PremiumCalculationTest.php | 177 ++++++++++++++++++ .../unit/GridType12PremiumCalculationTest.php | 159 +++++++++++++--- .../unit/GridType13PremiumCalculationTest.php | 177 ++++++++++++++++++ 7 files changed, 547 insertions(+), 85 deletions(-) create mode 100644 tests/unit/GridType11PremiumCalculationTest.php create mode 100644 tests/unit/GridType13PremiumCalculationTest.php diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 1871fab0..0f685a7a 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -129,9 +129,9 @@ class EmployeeController extends AdminController // print_r($this->request->getPost('policies')); // print_r($this->request->getPost('upload-action-type')); // die(); - // $empServiceController = new EmployeeServiceController(); - // $res = $empServiceController->excelFileFormatValidation(['file_id' => '42']); - // dd($res); + $empServiceController = new EmployeeServiceController(); + $res = $empServiceController->excelFileFormatValidation(['file_id' => '42']); + dd($res); // $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->excelFileDataValidation(['file_id' => '38']); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index e93b2b2b..c93262b7 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1389,10 +1389,11 @@ public function calculatePremium($clientPolicyId = null , $empCode = null, $defa // 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); + // print_r(($employee_data_group_by_family));die(); foreach ($employee_data_group_by_family as $emp_id => $family) { $transformed_famility_details = transform_db_data_to_excel($family); + // print_r($transformed_famility_details);die(); $data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si); // dd($data); $employee_data_group_by_family[$emp_id] = $data; diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index cc5cafeb..ac2b2c86 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -35,7 +35,7 @@ class EmployeeServiceController extends AdminController protected $empEndorsementModel; protected $general_relationships = ['self' => ['name' => 'Self', 'gender' => 'M','age_min' => 18,'age_max' => null], 'spouse' => ['name' => 'Spouse', 'gender' => 'F','age_min' => 18,'age_max' => null], 'son' => ['name' => 'Son', 'gender' => 'M','age_min' => null,'age_max' => 25], 'daughter' => ['name' => 'Daughter', 'gender' => 'F','age_min' => null,'age_max' => 25], 'father' => ['name' => 'Father', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother' => ['name' => 'Mother', 'gender' => 'F','age_min' => 18,'age_max' => null], 'father-in-law' => ['name' => 'Father in Law', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother-in-law' => ['name' => 'Mother in Law', 'gender' => 'F','age_min' => 18,'age_max' => null]]; - protected $inception_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'dob'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'DOB','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_dob_diff','params'=>['row','relationship']],'gender'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Gender','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['M','F']],'relationship'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'RELATIONSHIP','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_relationship','params'=>['row','relationship','policy_terms']],'basic_cover_si'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'BASIC COVER SI','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'doc'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Date of Coverage','is_mandatory'=>['A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'params'=>['row']],'doj'=>['col_idx'=>8,'col_cell_name'=>'I','col_name'=>'DOJ','is_mandatory'=>false,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_doj','params'=>['row']],'basic_pay'=>['col_idx'=>9,'col_cell_name'=>'J','col_name'=>'Basic Pay','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_basic_pay','params'=>['row','policy_terms','slab_details']],'band_grade'=>['col_idx'=>10,'col_cell_name'=>'K','col_name'=>'Band/Grade','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_employee_band','params'=>['row','policy_terms','slab_details']],'designation'=>['col_idx'=>11,'col_cell_name'=>'L','col_name'=>'Designation','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'phone'=>['col_idx'=>12,'col_cell_name'=>'M','col_name'=>'Phone','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'email'=>['col_idx'=>13,'col_cell_name'=>'N','col_name'=>'Email','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'pre_existing_ailments'=>['col_idx'=>14,'col_cell_name'=>'O','col_name'=>'PRE EXISTING AILMENTS','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['0','1']],'change_event'=>['col_idx'=>15,'col_cell_name'=>'P','col_name'=>'Change event','is_mandatory'=>['A','DA','D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>16,'col_cell_name'=>'Q','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>17,'col_cell_name'=>'R','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; + protected $inception_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'dob'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'DOB','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_dob_diff','params'=>['row','relationship']],'gender'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Gender','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['M','F']],'relationship'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'RELATIONSHIP','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_relationship','params'=>['row','relationship','policy_terms']],'basic_cover_si'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'BASIC COVER SI','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'doc'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Date of Coverage','is_mandatory'=>['A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'params'=>['row']],'doj'=>['col_idx'=>8,'col_cell_name'=>'I','col_name'=>'DOJ','is_mandatory'=>false,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_doj','params'=>['row']],'basic_pay'=>['col_idx'=>9,'col_cell_name'=>'J','col_name'=>'Basic Pay','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_basic_pay','params'=>['row','policy_terms','slab_details']],'band_grade'=>['col_idx'=>10,'col_cell_name'=>'K','col_name'=>'Band/Grade','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_employee_band','params'=>['row','policy_terms','slab_details']],'designation'=>['col_idx'=>11,'col_cell_name'=>'L','col_name'=>'Designation','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'phone'=>['col_idx'=>12,'col_cell_name'=>'M','col_name'=>'Phone','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'email'=>['col_idx'=>13,'col_cell_name'=>'N','col_name'=>'Email','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'pre_existing_ailments'=>['col_idx'=>14,'col_cell_name'=>'O','col_name'=>'PRE EXISTING AILMENTS','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['0','1']],'change_event'=>['col_idx'=>15,'col_cell_name'=>'P','col_name'=>'Change event','is_mandatory'=>['A','DA','D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; protected $deletion_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'change_event'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'Change event','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; @@ -145,7 +145,7 @@ class EmployeeServiceController extends AdminController $policy_terms = json_decode($policy_terms[0]->policy_terms); $policy_terms = (array) $policy_terms;// convert obj to array // - // dd($policy_terms); + dd($policy_terms); //get policy slab rates $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); @@ -562,7 +562,7 @@ class EmployeeServiceController extends AdminController // 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->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 41fa05dd..6ed64b27 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -530,10 +530,13 @@ if (!function_exists('calculate_premimum')) // dd($transformed_familiy_member_data); //store emp id and emp band and attach it to their familiy members where band is always empty - $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = null; + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] : NULL; + + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : NULL; if(strtolower($transformed_familiy_member_data['relationship']) == 'self') { $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = $transformed_familiy_member_data['band']; + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = $transformed_familiy_member_data['policy_details']['basic_cover_si']; } //end of store emp id and emp band and attach it to their familiy members where band is always empty @@ -555,6 +558,7 @@ if (!function_exists('calculate_premimum')) $transformed_familiy_member_data['temp']['band'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']; $transformed_familiy_member_data['temp']['maxage'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage']; $transformed_familiy_member_data['temp']['maxcount'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount']; + $transformed_familiy_member_data['policy_details']['basic_cover_si'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']; if( $fileArr['id'] == null || (in_array($grid_type,[10,11]) || $transformed_familiy_member_data['temp']['source'] == 'excel'))//if file id is null then data coming from enrollment (from DB) otherwise data coming from xcel, so calculate only data from excel (new entry) note: even data coming from excel for event dependet additon we fetch other dependts from db and calculate premium for whole family { @@ -588,8 +592,8 @@ if (!function_exists('transform_excel_data_to_db')) $policy['basic_cover_si'] = $memArr[6]; $policy['pre_existing_alignments'] = $memArr[14]; - $policy['date_of_exit'] = isset($memArr[16]) ? change_date_format($memArr[16],'d-M-Y','Y-m-d') : NULL; - $policy['reason_for_exit'] = $memArr[17]; + // $policy['date_of_exit'] = isset($memArr[16]) ? change_date_format($memArr[16],'d-M-Y','Y-m-d') : NULL; + // $policy['reason_for_exit'] = $memArr[17]; $policy['client_policy_id'] = $actionArr['policy_id']; $policy['date_coverage'] = isset($memArr[7]) ? change_date_format($memArr[7],'d-M-Y','Y-m-d') : NULL;; $policy['policy_end_date'] = null; @@ -634,6 +638,8 @@ if (!function_exists('premium_calculation_manager')) { // grid type // 1 = premium => si + // dd($emp_data); + $slug = \Config\Services::slug(); $grid_type = $slab_details['grid_master']['ui_type']; switch ($grid_type) { @@ -745,7 +751,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -765,7 +771,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -787,7 +793,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -809,7 +815,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -831,15 +837,15 @@ if (!function_exists('premium_calculation_manager')) foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { - $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $employee_received_si : null); - $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); - $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); - $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); - $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); - $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); - $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']; + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']; + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } @@ -849,24 +855,26 @@ if (!function_exists('premium_calculation_manager')) //GMC - Maximum count per Family $max_count = $emp_data['temp']['maxcount']; $employee_received_band = $emp_data['temp']['band']; + // echo $employee_received_band; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $emp_data['policy_details']['basic_cover_si'] = null; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { //calculate premium based on count + // echo $emp_data['name']; $familiy_si_covered = $employee_received_si * $max_count; $familiy_si_covered = ($familiy_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $familiy_si_covered); - $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $familiy_si_covered : null); - $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); - $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); - $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); - $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); - $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); - $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + $emp_data['policy_details']['basic_cover_si'] = $familiy_si_covered; + $emp_data['policy_details']['date_coverage'] = (empty($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } @@ -875,26 +883,23 @@ if (!function_exists('premium_calculation_manager')) case "12": //GMC - Employee + relationship - $max_count = $emp_data['temp']['maxcount']; - $employee_received_band = $emp_data['temp']['band']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + $employee_relationship = $slug->slugify($emp_data['relationship']); + $employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship); $emp_data['policy_details']['basic_cover_si'] = null; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - - if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + if( $slab_value['si'] == $employee_received_si && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) ) { - //calculate premium based on count - $familiy_si_covered = $employee_received_si * $max_count; - $familiy_si_covered = ($familiy_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $familiy_si_covered); - $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $familiy_si_covered : null); - $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); - $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); - $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); - $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); - $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); - $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = (empty($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } @@ -903,26 +908,23 @@ if (!function_exists('premium_calculation_manager')) case "13": //GMC - Employee + relationship + age - $max_count = $emp_data['temp']['maxcount']; - $employee_received_band = $emp_data['temp']['band']; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + $employee_relationship = $slug->slugify($emp_data['relationship']); + $employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship); $emp_data['policy_details']['basic_cover_si'] = null; + $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - - if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) ) { - //calculate premium based on count - $familiy_si_covered = $employee_received_si * $max_count; - $familiy_si_covered = ($familiy_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $familiy_si_covered); - $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $familiy_si_covered : null); - $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); - $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); - $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); - $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); - $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); - $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = (empty($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } diff --git a/tests/unit/GridType11PremiumCalculationTest.php b/tests/unit/GridType11PremiumCalculationTest.php new file mode 100644 index 00000000..5c6a5ef1 --- /dev/null +++ b/tests/unit/GridType11PremiumCalculationTest.php @@ -0,0 +1,177 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 5000000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => 1, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 5000000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => 1, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', 'G', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); + } + + public function testType11PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 500000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => NULL, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 500000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => NULL, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '500000', '', '', '', 'C', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType11PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 500000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => NULL, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 500000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => NULL, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', '', '01-Jan-2024', '01-Jan-2020', 50000, '', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '500000', '', '', '', 'C', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + +} \ No newline at end of file diff --git a/tests/unit/GridType12PremiumCalculationTest.php b/tests/unit/GridType12PremiumCalculationTest.php index 9b87a1d3..8615a834 100644 --- a/tests/unit/GridType12PremiumCalculationTest.php +++ b/tests/unit/GridType12PremiumCalculationTest.php @@ -11,14 +11,14 @@ use Tests\Support\Libraries\ConfigReader; // use App\Helpers\excel_util_helper; use Kint\Kint; -class GridType12PremiumCalculationTest.php extends CIUnitTestCase +class GridType12PremiumCalculationTest extends CIUnitTestCase { - public function testType12PremiumCalculation() + public function testType12PremiumCalculationWithPremiumTypeOne() { helper('excel_util_helper'); $slab_details = [ 'slab_rates' =>[ - [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50000, 'max_si' => 0,'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, 'max_si' => 0,'premium_type' => 1, 'relationship' => 'self'], [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 25000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 20000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'child'], [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 18000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father'], @@ -29,18 +29,17 @@ class GridType12PremiumCalculationTest.php extends CIUnitTestCase 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 12,'policy_grid_type' => 'Employees + Relationship','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] ]; // Sample family data - $family_details = [ - [1, 'Jane Doe', '1990-01-01', 'F', 'Spouse', 10000, '2024-01-01', '2020-01-01', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], - [2, 'John Doe', '1990-01-01', 'M', 'Self', '', '', '', '', '', '', '', '', '', '', ''], - [3, 'Peter Doe', '1990-01-01', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], - [4, 'Mary Doe', '1990-01-01', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], - [5, 'Grace Doe', '1990-01-01', 'F', 'Mother-in-law', '', '', '', '', '', '', '', '', '', '', ''], - [6, 'George Doe', '1990-01-01', 'M', 'Father-in-law', '', '', '', '', '', '', '', '', '', '', ''], - [7, 'Alice Doe', '1995-02-02', 'F', 'Daughter', 8000, '2024-02-01', '2021-01-01', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], - [8, 'Bob Doe', '1995-02-02', 'M', 'Son', '', '', '', '', '', '', '', '', '', '', ''], + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], ]; - // Sample policy terms $policy_terms = [ 'family_floater' => true, @@ -53,20 +52,126 @@ class GridType12PremiumCalculationTest.php extends CIUnitTestCase ], ]; - // Sample action array - $actionArr = 'addition'; - - // Call the function - $result = check_dependent_conflict($family_data, $policy_terms, $actionArr); - Kint::dump($result); - // Assert that the status is true (no conflicts) - $this->assertTrue($result['status']); + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); } - // public function testIsNull() - // { - // $i = null; - // $this->assertTrue($i); - - // } + public function testType12PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, 'max_si' => 0,'premium_type' => NULL, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 25000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 20000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'child'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 18000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'father'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 15000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => NULL, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 12,'policy_grid_type' => 'Employees + Relationship','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType12PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, 'max_si' => 0,'premium_type' => 2, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 25000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 20000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'child'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 18000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'father'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 15000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 2, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 12,'policy_grid_type' => 'Employees + Relationship','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + } \ No newline at end of file diff --git a/tests/unit/GridType13PremiumCalculationTest.php b/tests/unit/GridType13PremiumCalculationTest.php new file mode 100644 index 00000000..24d7aaa3 --- /dev/null +++ b/tests/unit/GridType13PremiumCalculationTest.php @@ -0,0 +1,177 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); + } + + public function testType13PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => NULL, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType13PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => 2, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + +} \ No newline at end of file From 5ae2fcfdc42cc31d6c072728845afd029acd1151 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 24 Apr 2024 16:43:59 +0530 Subject: [PATCH 22/33] CHANGE_ family floter text : GWM --- app/Controllers/EmployeeRestController.php | 83 ++++++++++++---------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index fcac85ab..ffa655ba 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1075,6 +1075,11 @@ public function getEmployeePolicy() // Generate Notes string based on familyFloates terms $array->notes = $this->FloterNotesConvertion($familyFloates); + + if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) + { $array->family_floter_notes = 'For Family'; } + else{ $array->family_floter_notes = 'For Members'; } + // Convert familyFloaters terms data to plain array $floters = $this->FloterConvertion($familyFloates); @@ -1514,50 +1519,54 @@ public function getCashDepositData() ->findAll(); $result = []; - foreach ($ClientPolicyData as $key => $value) { + if(count($ClientPolicyData)) + { + foreach ($ClientPolicyData as $key => $value) { - $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; - - $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)) + $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; + + $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) { - foreach ($employeeDetails as $item) { - if ($item['emp_status'] === 'enrolled') { - $enrolledCount++; - } elseif ($item['emp_status'] === 'draft') { - $draftCount++; + $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); } - - $value['totalMembersCount'] = count($employeeDetails); - $value['membersCountOfEnrolled'] = $enrolledCount; - $value['membersCountOfDraft'] = $draftCount; - - array_push($data['policyDetails'],$value); + + + array_push($result,$data); + } - - - array_push($result,$data); - } - + + if($result) { From b34ebf686c1fc1c650f76789b63fa92bcfb156a7 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 24 Apr 2024 17:06:43 +0530 Subject: [PATCH 23/33] FEATURE_ exportCashDepositData New api : GWM --- app/Config/Routes.php | 1 + app/Controllers/EmployeeRestController.php | 70 +++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1252386c..f5bc674c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -267,6 +267,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId"); $routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData"); + $routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData"); }); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index f9b54af5..81a49040 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -398,7 +398,7 @@ class EmployeeRestController extends AdminController if(count($empData)) { - // Define headers and map database fields to Excel fields + // Define headers and map database fields to Excel fields $headers = [ 'Employee Code' => 'emp_code', 'Name' => 'name', @@ -1578,4 +1578,72 @@ public function getCashDepositData() } + + + +public function exportCashDepositData() +{ + + $CashDepositData = $this->clientPolicyModel->getdepositData($this->request->getGet('client_id'),$this->request->getGet('insurer_id')); + + // echo '
';print_r($CashDepositData); echo '
';die; + + if(count($CashDepositData)) + { + // Define headers and map database fields to Excel fields + $headers = [ + 'Date' => 'created_at', + 'Type' => 'transaction_type', + 'Amount' => 'amount', + 'Balance' => 'balance', + 'Description' => 'description', + 'Insurer Name' => 'insurer_name', + 'Client Name' => 'clientname' + ]; + + // 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 ($CashDepositData as $Cashvalue) { + $column = 'A'; + foreach ($headers as $dbField) { + $sheet->setCellValue($column . $row, $Cashvalue->$dbField); + $column++; + } + $row++; + } + + + // Set the header for download + $filename = $CashDepositData[0]->insurer_name.'-CashDeposit.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); + } + +} + } \ No newline at end of file From 787e452a10cf517a18d842d0413f9995bdad0315 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 25 Apr 2024 09:58:27 +0530 Subject: [PATCH 24/33] CHANGE_orderBy in getEmployeeAndDependenceByClientId API : GWM --- app/Models/EmployeePolicyModel.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index b7e2f19d..d2610c2b 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -79,13 +79,17 @@ class EmployeePolicyModel extends Model ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //tpab - tpa brach ->join('clients cm', 'cp.client_id = cm.id') //cm - client master ->where('emp.client_id',$client_id) - ->where('employee_polices.client_policy_id',$policy_id); + ->where('employee_polices.is_active',1) + ->where('emp.is_active',1) + ->where('employee_polices.client_policy_id',$policy_id) + ->orderBy('emp.emp_code','ASC')->orderBy('employee_polices.employee_id','ASC'); + if($status != 0 && !empty($status)){ $result->where('employee_polices.status', $status); } - $result = $result->findAll(); + $result = $result->findAll(); return ($result); } From 0015cc417dc18eb592e5deccaff9da77193c72e3 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 25 Apr 2024 10:06:51 +0530 Subject: [PATCH 25/33] CHANGE_ in floter_text_heading : GWM --- app/Controllers/EmployeeRestController.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 81a49040..c100b451 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1077,8 +1077,15 @@ public function getEmployeePolicy() $array->notes = $this->FloterNotesConvertion($familyFloates); if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) - { $array->family_floter_notes = 'For Family'; } - else{ $array->family_floter_notes = 'For Members'; } + { + $array->floter_text_heading = 'Floater Sum Insured'; + $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; + + }{ + $array->floter_text_heading = 'Sum Insured'; + $array->floter_text_description = ''; + + } // Convert familyFloaters terms data to plain array $floters = $this->FloterConvertion($familyFloates); From bfb18aa607f87d24a7af1ee7d2212b5c50fb5fb9 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 25 Apr 2024 10:10:22 +0530 Subject: [PATCH 26/33] CHANGE_ in floter_text_heading : GWM --- app/Controllers/EmployeeRestController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c100b451..c7597089 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1080,11 +1080,9 @@ public function getEmployeePolicy() { $array->floter_text_heading = 'Floater Sum Insured'; $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; - - }{ + }else{ $array->floter_text_heading = 'Sum Insured'; $array->floter_text_description = ''; - } // Convert familyFloaters terms data to plain array From ded7f75840dfc09f3ee85a3aae85ee24920a72a4 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 25 Apr 2024 12:03:19 +0530 Subject: [PATCH 27/33] CHANGE_ add floter sum insured text : GWM --- app/Controllers/EmployeeRestController.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c7597089..b957ff11 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1268,6 +1268,16 @@ public function getAddOnPolicy() $responce['is_addon'] = $array['is_addon']; $responce['open_for_enrollment'] = $array['open_for_enrollment']; $responce['policy_terms'] = $decodedArray; + + if(count($getSlabAndGridData['slab_rates'])){ + if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) + { + $responce['floter_text_heading'] = 'Floater Sum Insured'; + }else{ + $responce['floter_text_heading'] = 'Sum Insured'; + } + } + if($array['is_addon'] == 3) { From 850adec634aadaf2b92d5718789f0c62fafd3a71 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 25 Apr 2024 12:41:44 +0530 Subject: [PATCH 28/33] FEATURE_ removeEmpAndEmpPolicyData new API : GWM --- app/Config/Routes.php | 4 ++ app/Controllers/EmployeeRestController.php | 68 ++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f5bc674c..f906edbf 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -268,6 +268,10 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId"); $routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData"); $routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData"); + + $routes->get("removeEmpAndEmpPolicyData", "EmployeeRestController::removeEmpAndEmpPolicyData"); + + }); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index b957ff11..f25e56cf 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1661,4 +1661,72 @@ public function exportCashDepositData() } + +public function removeEmpAndEmpPolicyData() +{ + try { + + $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id'))->findAll(); + + if(count($clientPolicy)) + { + + + if($clientPolicy[0]['is_addon'] == 2)//Topup + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 0 )->findAll(); + if(count($empData)) + { + foreach ($empData as $key => $value) { + + $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) + ->where('employee_id', $value['id'] ) + ->set(array('is_active'=> 0 )) + ->update(); + + } + } + + } + else if($clientPolicy[0]['is_addon'] == 3)//Dependent addon + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 1 )->findAll(); + if(count($empData)) + { + foreach ($empData as $key => $value) { + + $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) + ->where('employee_id', $value['id'] ) + ->set(array('is_active'=> 0 )) + ->update(); + + } + + $this->employeeModel->where('emp_code', $this->request->getGet('emp_code') ) + ->where('is_active', 1 )->where('is_addon_value', 1 ) + ->set(array('is_active'=> 0 )) + ->update(); + } + + } + + + + return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200); + + }else{ + return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 404); + } + + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } + +} + + + } \ No newline at end of file From 788f74733cbcf47b9beaa2fd8402df8d68ef414e Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 25 Apr 2024 13:34:53 +0530 Subject: [PATCH 29/33] FIX_RACK_RATE_UI_ISSUE : RV --- app/Config/Routes.php | 3 + app/Controllers/ClientController.php | 2 +- app/Controllers/EmployeeController.php | 52 +- app/Controllers/EmployeeServiceController.php | 1 + app/Models/EmployeePolicyModel.php | 53 +- app/Views/id_card_view.php | 80 +++ app/Views/policy_grid.php | 31 +- app/Views/view_file_upload_emp_list.php | 2 +- composer.json | 1 + public/assets/images/1.jpg | Bin 0 -> 20109 bytes public/assets/images/1.svg | 471 ++++++++++++++++++ public/assets/images/2.jpg | Bin 0 -> 37844 bytes 12 files changed, 670 insertions(+), 26 deletions(-) create mode 100644 app/Views/id_card_view.php create mode 100644 public/assets/images/1.jpg create mode 100644 public/assets/images/1.svg create mode 100644 public/assets/images/2.jpg diff --git a/app/Config/Routes.php b/app/Config/Routes.php index b68ae6c3..82a48f37 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -218,6 +218,9 @@ $routes->group("/util", ["filter" => "authMVC"], function($routes){ $routes->get("fetch-emp-count/(:any)", "EmployeeController::getEmpCount/$1"); $routes->get("init-Emp-onboard/(:any)", "EmployeeController::initiateManualEmployeesOnboardProcess/$1"); $routes->get("full-excel-error-file/(:any)", "EmployeeController::downloadFullExcelErrorFile/$1"); + $routes->get("id-card", "EmployeeController::viewECard/$1"); + $routes->get('digital-id-card/(:segment)/(:segment)', 'EmployeeController::generateIDCardForEmployee/$1/$2'); + }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index baca94e2..96815f94 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1104,7 +1104,7 @@ class ClientController extends AdminController try { foreach ($results as $index => $record) { - if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0) { + if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0 && $family_floater == 0) { if ($index == '0' || $index == '1' || $index == '2') { $resultss[$index] = $record; } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 4a029f00..7261cec6 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -29,6 +29,8 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use Dompdf\Dompdf; + class EmployeeController extends AdminController { @@ -247,19 +249,23 @@ class EmployeeController extends AdminController { $file_id = $this->request->uri->getSegment(3); $empServiceController = new EmployeeServiceController(); - - // Render views and capture output - $result = $empServiceController->getExcelErrorData($file_id); $result['file_id'] = $file_id; - // echo '
';
-        // print_r($result); die;
-        if($result){
+        // Render views and capture output
+        $result = $empServiceController->getExcelErrorData($file_id);
+
+        if ($result != 0) {
+
             echo view('excel_errors', $result);
-        }else{
+        } else if ($result == 0) {
+
+            $data['message'] = 'File Not Found Physically';
+            return view('errors/404', $data);
+
+        } else {
+
             echo view('errors/html/production');
         }
-    
     }
 
     /**
@@ -673,6 +679,7 @@ class EmployeeController extends AdminController
             
                 $highestRowAndColumn = $sheet->getHighestRowAndColumn();
                 $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
+                // dd($excel_data);
                 $emp_data['thead'] = $excel_data[0];
                 unset($excel_data[0]);
                 $emp_data['tbody'] = $excel_data;
@@ -684,7 +691,7 @@ class EmployeeController extends AdminController
                 $html = '
No Data Found
'; } - return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $html, 'file_data' => $file_name], 200); + return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $html, 'file_data' => $file_name, 'excel_data' => $excel_data], 200); } catch (\Exception $e) { // Handle exception @@ -826,6 +833,33 @@ class EmployeeController extends AdminController return $response; } + public function generateIDCardForEmployee($emp_code, $client_policy_id) + { + $dompdf = new Dompdf(); + + $data['data'] = $this->employeePolicyModel->getECardDataUsingMd5($client_policy_id, $emp_code); + // $this->loadLayout('id_card_view', $data); exit; + + $html = view('id_card_view', $data); + // $html = str_replace('', '', $html); + + $dompdf->loadHtml($html); + + // (Optional) Setup the paper size and orientation + $dompdf->setPaper('A4', 'landscape'); + + // Render the HTML as PDF + $dompdf->render(); + + // Output the generated PDF to Browser + $dompdf->stream(); + + } + + public function viewECard() + { + $this->loadLayout('id_card_view'); + } diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index cc5cafeb..c7af743f 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -958,6 +958,7 @@ class EmployeeServiceController extends AdminController { $error_message = "File not found"; $this->myLogger->logme('error',($error_message . ' for file id ' . $file_id)); + return 0; } $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index b7e2f19d..105979be 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -674,7 +674,8 @@ class EmployeePolicyModel extends Model } - public function getViewEmpSuccessList($file_id){ + public function getViewEmpSuccessList($file_id) + { return $this->db->table('employees emp') ->select(['employee_polices.*','pm.name as policy_name','im.short_name as insurer_short_name','ib.branch_name as insurer_branch_name','ib.branch_code as insurer_branch_code','tpam.name as tpa_name','tpam.short_name as tpa_short_name','tpab.branch_code as tpa_branch_code','cm.client_name','cm.short_name as client_short_name','emp.relationship','emp.relationship_code','emp.change_event','emp.emp_code','emp.name','emp.email_corporate','emp.dob','emp.gender','emp.emp_status','emp.is_active as emp_is_active','emp.mobile as mobile']) ->join('employee_polices', 'employee_polices.employee_id = emp.id') @@ -689,5 +690,55 @@ class EmployeePolicyModel extends Model ->whereIn('employee_polices.status', ['draft', 'enrolled']) ->get()->getResultArray(); } + + public function getECardDataUsingMd5($client_policy_id, $emp_code){ + + $result = $this->db->table('employees e') + ->select('e.id, + e.name, e.mobile, + e.relationship, + e.relationship_code, + e.emp_code, + e.email_personal, + e.email_corporate, + e.gender, + e.dob, + e.doj, + e.band, + TIMESTAMPDIFF(YEAR, e.dob, CURDATE()) AS emp_age, + + ep.tpa_id, + ep.uhid, + ep.policy_end_date, + + clients.client_name, + clients.short_name AS client_short_name, + + policies.name AS policy_name, + + insurers.name AS insurer_name, + insurers.short_name AS insurer_short_name, + + tpa.name AS tpa_name, + tpa.short_name AS tpa_short_name' + ) + + ->join('employee_polices ep', 'ep.employee_id = e.id') + ->join('client_policy cp', 'cp.id = ep.client_policy_id') + ->join('clients', 'clients.id = cp.client_id') + ->join('policies', 'policies.id = cp.policy_id') + ->join('insurers', 'insurers.id = cp.insurer_id') + ->join('tpa', 'tpa.id = cp.tpa_id') + ->where('e.emp_status', 'active') + ->where('e.is_active', '1') + ->where('ep.status', 'active') + ->where('ep.is_active', '1') + ->where('MD5(e.emp_code)', $emp_code) + ->where('MD5(ep.client_policy_id)', $client_policy_id) + ->get() + ->getResultArray(); + + return $result; + } } \ No newline at end of file diff --git a/app/Views/id_card_view.php b/app/Views/id_card_view.php new file mode 100644 index 00000000..b646bb87 --- /dev/null +++ b/app/Views/id_card_view.php @@ -0,0 +1,80 @@ + + + + + + + Driving License ID Card + + + + +
+ + $value) { ?> + + + + + + +
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ +
+
+
+

Terms and Conditions

+

This card is non-transferable and is valid at network hospitals only.

+
    +
  • will enable Card Holder to avail cashless hospitalization only on the basis of +
  • +
  • In the case of photoless identity cards issued to beneficiaries, acceptable + proof
  • +
  • Notify the authorities in case of any changes to your personal information.
  • +
  • The mentioned covers are add-ons by paying additional premium and available only if opted by the policyholders.
  • +
+
+
+
+
+ + + button + + + + + \ No newline at end of file diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index 372e5279..289392f5 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -27,17 +27,17 @@
-
@@ -487,6 +487,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- + @@ -695,8 +696,10 @@ $('body').on('click', '.btnPolicyModel', function() { if(res.family_floater == 1){ $('#premium_type').show(); + $('#individual').prop('checked', true) }else{ $('#premium_type').hide(); + $('#individual').prop('checked', false) } setTimeout(function() { @@ -827,8 +830,8 @@ $('body').on('click', '.btnPolicyModel', function() { $('#grid').empty(); $('#nameOfThePolicy').html(''); $('#GridForm').hide(); - $('#no_data').html('The policy has no Policy Rac Rate'); - toastr.warning("The policy has no Policy Rac Rate", "Warning") + $('#no_data').html('The policy has no Policy Rack Rate'); + toastr.warning("The policy has no Policy Rack Rate", "Warning") } @@ -1208,7 +1211,7 @@ function appendGridtHtml(ui_type = false, data = false, ) {
-
+