From 9960b714b9043e21d101b757d8459ee3fa1616b0 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Tue, 16 Apr 2024 13:24:04 +0530 Subject: [PATCH 1/8] CHANGE_in-empPolicyApi:GWM --- app/Controllers/EmployeeRestController.php | 95 +++++++++++++--------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index a6eb068b..09c8d9f7 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -339,8 +339,10 @@ class EmployeeRestController extends AdminController $result = []; foreach ($ClientPolicyData as $key => $value) { $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']); - if($value['is_addon'] == 1){ - $value['type'] = 'AddOn'; + if($value['is_addon'] == "2"){ + $value['type'] = 'SI-TopUp'; + }else if($value['is_addon'] == "3"){ + $value['type'] = 'Dependent-AddOn'; }else{ $value['type'] = $getSlabAndGridData['grid_master']['policy_type']; } @@ -854,6 +856,7 @@ class EmployeeRestController extends AdminController // $return_log = json_decode($return_log); // $this->myLogger->logme('info', "Email Status : {mail_status}, Sender Email:{email}", ['mail_status' => $return_log->status, 'email'=> $return_log->data]); } + return $this->respond(['status' => 'success', 'code' => 200, 'message' => "Success" ], 404); }else{ return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Client id and Client Policy id is Not Match!" ], 404); } @@ -882,7 +885,7 @@ public function getEmployeePolicy() $empPolicy = $this->employeeModel->getEmployeePolicy($id); // Retrieve employee and dependents data by passing the employee code $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('is_active', 1 )->where('is_addon_value',0)->findAll(); - + // dd($empPolicy); if ($empPolicy) { @@ -1099,24 +1102,24 @@ public function getAddOnPolicy() { $PolicyData = []; foreach ($clientPolicy as $key => $array) { - + $responce = []; $decodedArray = json_decode($array['policy_terms']); $policy_terms = $decodedArray; $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']); - if($array['is_addon'] == 1) - { - $responce['policy_name'] = $this->policesModel->where('id',$array['policy_id'])->get()->getRow()->name; - $responce['SlabRates'] = $getSlabAndGridData['slab_rates']; - $responce['GridMaster'] = $getSlabAndGridData['grid_master']; - $responce['client_id'] = $array['client_id']; - $responce['client_policy_id'] = $array['id']; - $responce['is_addon'] = $array['is_addon']; - $responce['open_for_enrollment'] = $array['open_for_enrollment']; - $responce['policy_terms'] = $decodedArray; - + $responce['policy_name'] = $this->policesModel->where('id',$array['policy_id'])->get()->getRow()->name; + $responce['SlabRates'] = $getSlabAndGridData['slab_rates']; + $responce['GridMaster'] = $getSlabAndGridData['grid_master']; + $responce['client_id'] = $array['client_id']; + $responce['client_policy_id'] = $array['id']; + $responce['is_addon'] = $array['is_addon']; + $responce['open_for_enrollment'] = $array['open_for_enrollment']; + $responce['policy_terms'] = $decodedArray; + if($array['is_addon'] == 3) + { + // Map family floaters that already exist in the employee table $familyFloates = $policy_terms->family_floaters; @@ -1213,40 +1216,52 @@ public function getAddOnPolicy() $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value; - $only_si_array = []; - $only_si_value = null; - $only_si_premium_value = null; - foreach ($GMCEmployeeData as $key => $value) { - - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); - if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } - if(isset($employee_policy->premium)){ $only_si_premium_value = $employee_policy->premium;} - $temp3['is_value_exist'] = true; - $temp3['data']['employee_id'] = $value['id']; - $temp3['data']['relationship'] = $value['relationship']; - $temp3['data']['name'] = $value['name']; - $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); - $temp3['data']['client_policy_id'] = $array['id']; - $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; - $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; - array_push($only_si_array,$temp3); - - } - - $responce['family_floaters_of_only_si_array'] = $only_si_array; - $responce['family_floaters_of_only_si_value'] = $only_si_value; - $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; + + if($this->request->getGet('policy') == 'GMC-DEPENDENT-ADDON'){ + return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_dependent_addon'=>$responce]], 200); + } + + //array_push($PolicyData, $responce); + }else if($array['is_addon'] == 2){ + + + $only_si_array = []; + $only_si_value = null; + $only_si_premium_value = null; + foreach ($GMCEmployeeData as $key => $value) { + + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); + if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->premium)){ $only_si_premium_value = $employee_policy->premium;} + $temp3['is_value_exist'] = true; + $temp3['data']['employee_id'] = $value['id']; + $temp3['data']['relationship'] = $value['relationship']; + $temp3['data']['name'] = $value['name']; + $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp3['data']['client_policy_id'] = $array['id']; + $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; + $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; + array_push($only_si_array,$temp3); + + } + + $responce['family_floaters_of_only_si_array'] = $only_si_array; + $responce['family_floaters_of_only_si_value'] = $only_si_value; + $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; + + if($this->request->getGet('policy') == 'GMC-SI-TOPUP'){ + return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_topup'=>$responce]], 200); + } - array_push($PolicyData, $responce); } } - return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200); + // return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200); }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); From 33fb5b8c50c410846835402f87fa723425177adf Mon Sep 17 00:00:00 2001 From: sriramv Date: Tue, 16 Apr 2024 14:21:20 +0530 Subject: [PATCH 2/8] 'FIX_EMP_MODULE_BATCH_LIST_AMOUNT' --- app/Config/Routes.php | 1 + app/Controllers/EmpDataServiceController.php | 2298 +++++++++--------- app/Controllers/EmployeeController.php | 43 +- app/Models/BatchFileModel.php | 1 + app/Views/batch_list.php | 2 + app/Views/employee_upload.php | 67 +- app/Views/errors/404.php | 175 ++ 7 files changed, 1431 insertions(+), 1156 deletions(-) create mode 100644 app/Views/errors/404.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 78167b47..57a4d3ea 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -215,6 +215,7 @@ $routes->group("/util", ["filter" => "authMVC"], function($routes){ $routes->get("featch-emp-list", "EmployeeController::featchEmpList/$1"); $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"); }); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index b723e8be..01216aa6 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -20,7 +20,7 @@ use App\Models\BatchFileModel; use App\Models\EmpEndorsementModel; use App\Models\ClientDepositModel; -use App\Controllers\Jobs ; +use App\Controllers\Jobs; use PhpOffice\PhpSpreadsheet\Spreadsheet; // use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; @@ -64,381 +64,390 @@ class EmpDataServiceController extends BaseController */ - public function batchFilesAndBatchListEntry($data, $objects) - { + public function batchFilesAndBatchListEntry($data, $objects) + { - $random_number_count = 4; - $data['batch_code'] = generate_random_string($random_number_count); - $data['created_by'] = get_session_userid(); + $random_number_count = 4; + $data['batch_code'] = generate_random_string($random_number_count); + $data['created_by'] = get_session_userid(); - $insert = $this->batchFileModel->insert($data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + $insert = $this->batchFileModel->insert($data); + $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); - if($insert){ - foreach($objects as $value){ - $batch_list_data['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_list_data['emp_policy_id'] = $value->primaryKey ?? $value->employee_policy_id ?? ''; - $batch_list_data['created_by'] = get_session_userid(); - $this->batchListModel->insert($batch_list_data); - } + if ($insert) { + foreach ($objects as $value) { + $batch_list_data['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_list_data['emp_policy_id'] = $value->primaryKey ?? $value->employee_policy_id ?? ''; + $batch_list_data['created_by'] = get_session_userid(); + $this->batchListModel->insert($batch_list_data); } - - return true; - } - + + return true; + } + /** * Generates an Excel file for Inception_Addititon_DependentAddititon, Correction, SI_Enhancement and Deletion events based on given export data. * * @param array $export_data An array containing export data such as - * client_policy_id, - * insurer_or_tpa, - * event_type, - * actions, - * file_name. + * client_policy_id, + * insurer_or_tpa, + * event_type, + * actions, + * file_name. * @return bool True if the Excel file is successfully generated and exported, otherwise false. */ - public function generateExcelForAdditionandInception($export_data) - { - // Fetch employee data for export from the database - $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); + public function generateExcelForAdditionandInception($export_data) + { + // Fetch employee data for export from the database + $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); + + $totals = 0; + foreach ($objects as $key => $value) { - // Log the count of exported data - $count = count($objects); - $export_data['count'] = $count; - $this->myLogger->logme('error', 'Inception export data count : {data}', ['data'=> $count ]); - - // If no data is found for export, return false - if($count == 0){ - return false; - } - - // Log the export file name - $this->myLogger->logme('error', 'Inception export file name : {data}', ['data'=> $export_data['file_name'] ]); - - // Transform retrieved objects to an array suitable for export - $data = transform_objects_to_array_for_inception($objects); - - // Define headers for the Excel file - $headers = [ - 'S.No', - 'NAME OF EMP/DEP', - 'EMP ID', - 'EMP/DEP TYPE', - 'RELATION', - 'DOB', - 'GENDER', - 'PRE EXISTING AILMENTS', - 'BASIC COVER SI', - 'DATE OF COVERAGE', - 'AGE', - 'RELATIONSHIP', - 'REMARKS', - 'POLICY END DATE', - 'NO OF DAYS', - 'TPA ID', - 'UHID', - 'PREMIUM', - 'PR0 RATA PREMIUM', - 'GST', - 'TOTAL' - ]; - - // Generate Excel file - $tempFile = tmpfile(); - $success = generate_excel($headers, $data, $tempFile, 1); - - // If Excel generation is successful - if ($success) { - // Batch files and list entry - $return = $this->batchFilesAndBatchListEntry($export_data, $objects); - - // If batch operation is successful - if ($return) { - // Set headers for Excel file download - header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); - header('Cache-Control: max-age=0'); - - // Output file contents - rewind($tempFile); - fpassthru($tempFile); - - // Close and remove temporary file - fclose($tempFile); - - return true; // Excel file successfully generated and exported - } else { - return false; // Batch operation failed - } - } - - return false; // Excel generation failed + $totals += $value->total; } - public function generateExcelForCorrection($export_data) - { - $ids = []; + // Log the count of exported data + $count = count($objects); + $export_data['count'] = $count; + $export_data['amount'] = $totals; - $objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data); - foreach ($objects as $obj) { - $ids[] = $obj->id; + $this->myLogger->logme('error', 'Inception export data count : {data}', ['data' => $count]); + + // If no data is found for export, return false + if ($count == 0) { + return false; + } + + // Log the export file name + $this->myLogger->logme('error', 'Inception export file name : {data}', ['data' => $export_data['file_name']]); + + // Transform retrieved objects to an array suitable for export + $data = transform_objects_to_array_for_inception($objects); + + // Define headers for the Excel file + $headers = [ + 'S.No', + 'NAME OF EMP/DEP', + 'EMP ID', + 'EMP/DEP TYPE', + 'RELATION', + 'DOB', + 'GENDER', + 'PRE EXISTING AILMENTS', + 'BASIC COVER SI', + 'DATE OF COVERAGE', + 'AGE', + 'RELATIONSHIP', + 'REMARKS', + 'POLICY END DATE', + 'NO OF DAYS', + 'TPA ID', + 'UHID', + 'PREMIUM', + 'PR0 RATA PREMIUM', + 'GST', + 'TOTAL' + ]; + + // Generate Excel file + $tempFile = tmpfile(); + $success = generate_excel($headers, $data, $tempFile, 1); + + // If Excel generation is successful + if ($success) { + // Batch files and list entry + $return = $this->batchFilesAndBatchListEntry($export_data, $objects); + + // If batch operation is successful + if ($return) { + // Set headers for Excel file download + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); + header('Cache-Control: max-age=0'); + + // Output file contents + rewind($tempFile); + fpassthru($tempFile); + + // Close and remove temporary file + fclose($tempFile); + + return true; // Excel file successfully generated and exported + } else { + return false; // Batch operation failed } - - // echo '
';
-            // print_r($objects); die;
+        }
 
-            $count = count($objects);
-            $export_data['count'] = $count;
-            $this->myLogger->logme('error','Correction export data count : {data}', ['data'=> $count ]);
+        return false; // Excel generation failed
+    }
 
-            if($count == 0){                    
-                return false;
-            }  
 
-            $this->myLogger->logme('error','Correction export file name : {data}', ['data'=> $export_data['file_name'] ]);
+    public function generateExcelForCorrection($export_data)
+    {
+        $ids = [];
 
-            $correction_data = transform_objects_to_array_for_correction($objects);
+        $objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data);
 
-            $headers = [
-                'Emp Code', 
-                'RISK ID', 
-                'NAME OF EMP/DEP', 
-                'EMP/DEP TYPE', 
-                'RELATION', 
-                'DOB', 
-                'GENDER', 
-                'Wrong Data', 
-                'Correct Data', 
-                'Remarks', 
-                'Endorsement_Id'
-            ];
+        foreach ($objects as $obj) {
+            $ids[] = $obj->id;
+        }
 
-            // Create a temporary file in memory
-            $tempFile = tmpfile();
+        // echo '
';
+        // print_r($objects); die;
 
-            // Generate Excel file with the temporary file
-            $value = generate_excel($headers, $correction_data, $tempFile);
-    
-            if($value){
-                $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
-                if($return){
-    
-                    foreach ($ids as $key => $id) {
-                        $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
-                        if ($group_key) {
-                            $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
-                        }
+        $count = count($objects);
+        $export_data['count'] = $count;
+        $this->myLogger->logme('error', 'Correction export data count : {data}', ['data' => $count]);
+
+        if ($count == 0) {
+            return false;
+        }
+
+        $this->myLogger->logme('error', 'Correction export file name : {data}', ['data' => $export_data['file_name']]);
+
+        $correction_data = transform_objects_to_array_for_correction($objects);
+
+        $headers = [
+            'Emp Code',
+            'RISK ID',
+            'NAME OF EMP/DEP',
+            'EMP/DEP TYPE',
+            'RELATION',
+            'DOB',
+            'GENDER',
+            'Wrong Data',
+            'Correct Data',
+            'Remarks',
+            'Endorsement_Id'
+        ];
+
+        // Create a temporary file in memory
+        $tempFile = tmpfile();
+
+        // Generate Excel file with the temporary file
+        $value = generate_excel($headers, $correction_data, $tempFile);
+
+        if ($value) {
+            $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
+            if ($return) {
+
+                foreach ($ids as $key => $id) {
+                    $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
+                    if ($group_key) {
+                        $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
                     }
+                }
+
+
+                // Set the appropriate headers for Excel file download
+                header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+                header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
+                header('Cache-Control: max-age=0');
+
+                // Rewind the temporary file pointer
+                rewind($tempFile);
+
+                // Output the contents of the temporary file to the browser
+                fpassthru($tempFile);
+
+                // Close and remove the temporary file
+                fclose($tempFile);
+
+                return true;
+            } else {
+
+                return false;
+            }
+        }
+    }
+
+
+    public function generateExcelForSIEnhancement($export_data)
+    {
+        $ids = [];
+        $objects = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data);
+
+        
+        $totals = 0;
+        foreach ($objects as $obj) {
+            $ids[] = $obj->endorsement_primarykey;
+            $totals += $obj->total;
+        }
+        $rounded_totals = round($totals, 2);
+        // echo '
';
+        // print_r($ids); die;
+
+        $count = count($objects);
+        $export_data['count'] = $count;
+        $export_data['amount'] = $rounded_totals;
+
+        $this->myLogger->logme('error', 'SI_Enhancement export data count : {data}', ['data' => $count]);
+
+        if ($count == 0) {
+            return false;
+        }
+
+        $this->myLogger->logme('error', 'SI_Enhancement export file name : {data}', ['data' => $export_data['file_name']]);
+
+        $si_data = transform_objects_to_array_for_si_enhancement($objects);
+
+        $headers = [
+            'S.No',
+            'NAME OF EMP/DEP',
+            'EMP ID',
+            'EMP/DEP TYPE',
+            'RELATION',
+            'DOB',
+            'GENDER',
+            'PRE EXISTING AILMENTS',
+            'BASIC COVER SI',
+            'Old Sum Insured',
+            'Date of Coverage',
+            'Policy End Date',
+            'No Of Days',
+            'Old SI Premium',
+            'New SI premium',
+            'Difference premium',
+            'Pro Rata Premium',
+            'GST',
+            'Total',
+            'ENDORSEMENT_ID'
+        ];
+
+
+        // Create a temporary file in memory
+        $tempFile = tmpfile();
+
+        // Generate Excel file with the temporary file
+        $value = generate_excel($headers, $si_data, $tempFile);
+
+        if ($value) {
+            $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
+            if ($return) {
+
+                foreach ($ids as $key => $id) {
+                    $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
+                    if ($group_key) {
+                        $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
+                    }
+                }
+
+                // Set the appropriate headers for Excel file download
+                header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+                header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
+                header('Cache-Control: max-age=0');
+
+                // Rewind the temporary file pointer
+                rewind($tempFile);
+
+                // Output the contents of the temporary file to the browser
+                fpassthru($tempFile);
+
+                // Close and remove the temporary file
+                fclose($tempFile);
+
+                return true;
+            } else {
+                return false;
+            }
+        }
+    }
+
+
+    public function generateExcelForDeletion($export_data)
+    {
+        $ids = [];
+
+        $objects = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($export_data);
+
+        $totals = 0;
+        foreach ($objects as $obj) {
+            $ids[] = $obj->endorsement_primarykey;
+            $totals += $obj->total;
+        }
+        $rounded_totals = round($totals, 2);
+        // echo '
';
+        // print_r($ids); 
+        // print_r($objects); die;
+
+        $count = count($objects);
+        $export_data['count'] = $count;
+        $export_data['amount'] = $rounded_totals;
         
 
-                    // Set the appropriate headers for Excel file download
-                    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
-                    header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
-                    header('Cache-Control: max-age=0');
-    
-                    // Rewind the temporary file pointer
-                    rewind($tempFile);
-    
-                    // Output the contents of the temporary file to the browser
-                    fpassthru($tempFile);
-    
-                    // Close and remove the temporary file
-                    fclose($tempFile);
-
-                    return true;
-    
-                }else{
-
-                    return false;
-                }
-            }
+        $this->myLogger->logme('error', 'Deletion export data count : {data}', ['data' => $count]);
 
+        if ($count == 0) {
+            return false;
         }
-        
 
-        public function generateExcelForSIEnhancement($export_data)
-        {
-            $ids = [];
-            $objects = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data);
-            
-            foreach ($objects as $obj) {
-                $ids[] = $obj->endorsement_primarykey;
-            }
+        $this->myLogger->logme('error', 'Deletion export file name : {data}', ['data' => $export_data['file_name']]);
 
-            // echo '
';
-            // print_r($ids); die;
-            // dd($objects);
-            
-            $count = count($objects);
-            $export_data['count'] = $count;
+        $si_data = transform_objects_to_array_for_deletion($objects);
+        // dd($si_data);
+        $headers = [
+            'S.No',
+            'EMP ID',
+            'EMP NAME',
+            'DOB',
+            'GENDER',
+            'RELATIONSHIP',
+            'SUM INSURED',
+            'Date of Leaving',
+            'Policy End Date',
+            'No Of Days',
+            'Premium',
+            'Pro Rata Premium',
+            'GST',
+            'Total',
+            'Claim Status',
+            'ENDORSEMENT_ID'
+        ];
 
-            $this->myLogger->logme('error','SI_Enhancement export data count : {data}', ['data'=> $count ]);
 
-            if($count == 0){                    
-                return false;
-            }  
+        // Create a temporary file in memory
+        $tempFile = tmpfile();
 
-            $this->myLogger->logme('error','SI_Enhancement export file name : {data}', ['data'=> $export_data['file_name'] ]);
+        // Generate Excel file with the temporary file
+        $value = generate_excel($headers, $si_data, $tempFile, 2);
 
-            $si_data = transform_objects_to_array_for_si_enhancement($objects);
+        if ($value) {
+            $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
+            if ($return) {
 
-            $headers = [
-                'S.No',
-                'NAME OF EMP/DEP',
-                'EMP ID',
-                'EMP/DEP TYPE',
-                'RELATION',
-                'DOB',
-                'GENDER',
-                'PRE EXISTING AILMENTS',
-                'BASIC COVER SI',
-                'Old Sum Insured',
-                'Date of Coverage',
-                'Policy End Date',
-                'No Of Days',
-                'Old SI Premium',
-                'New SI premium',
-                'Difference premium',
-                'Pro Rata Premium',
-                'GST',
-                'Total',
-                'ENDORSEMENT_ID'
-            ];
-            
-
-            // Create a temporary file in memory
-            $tempFile = tmpfile();
-
-            // Generate Excel file with the temporary file
-            $value = generate_excel($headers, $si_data, $tempFile);
-    
-            if($value){
-                $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
-                if($return){
-
-                    foreach ($ids as $key => $id) {
-                        $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
-                        if ($group_key) {
-                            $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
-                        }
+                foreach ($ids as $key => $id) {
+                    $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
+                    if ($group_key) {
+                        $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
                     }
-    
-                    // Set the appropriate headers for Excel file download
-                    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
-                    header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
-                    header('Cache-Control: max-age=0');
-    
-                    // Rewind the temporary file pointer
-                    rewind($tempFile);
-    
-                    // Output the contents of the temporary file to the browser
-                    fpassthru($tempFile);
-    
-                    // Close and remove the temporary file
-                    fclose($tempFile);
-
-                    return true;
-    
-                }else{
-                    return false;
                 }
-            }
 
-        }
+                // Set the appropriate headers for Excel file download
+                header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+                header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
+                header('Cache-Control: max-age=0');
 
+                // Rewind the temporary file pointer
+                rewind($tempFile);
 
-        public function generateExcelForDeletion($export_data)
-        {
-            $ids = [];
+                // Output the contents of the temporary file to the browser
+                fpassthru($tempFile);
 
-            $objects = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($export_data);
+                // Close and remove the temporary file
+                fclose($tempFile);
 
-            foreach ($objects as $obj) {
-                $ids[] = $obj->endorsement_primarykey;
-            }
-
-            // echo '
';
-            // print_r($ids); 
-            // print_r($objects); die;
-
-            $count = count($objects);
-            $export_data['count'] = $count;
-
-            $this->myLogger->logme('error','Deletion export data count : {data}', ['data'=> $count ]);
-
-            if($count == 0){                    
+                return true;
+            } else {
                 return false;
-            }  
-
-            $this->myLogger->logme('error','Deletion export file name : {data}', ['data'=> $export_data['file_name'] ]);
-
-            $si_data = transform_objects_to_array_for_deletion($objects);
-            // dd($si_data);
-            $headers = [
-                'S.No',
-                'EMP ID',
-                'EMP NAME',
-                'DOB',
-                'GENDER',
-                'RELATIONSHIP',
-                'SUM INSURED',
-                'Date of Leaving',
-                'Policy End Date',
-                'No Of Days',
-                'Premium',
-                'Pro Rata Premium',
-                'GST',
-                'Total',
-                'Claim Status',
-                'ENDORSEMENT_ID'
-            ];
-            
-
-            // Create a temporary file in memory
-            $tempFile = tmpfile();
-
-            // Generate Excel file with the temporary file
-            $value = generate_excel($headers, $si_data, $tempFile, 2);
-    
-            if($value){
-                $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
-                if( $return){
-
-                    foreach ($ids as $key => $id) {
-                        $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
-                        if ($group_key) {
-                            $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
-                        }
-                    }
-    
-                    // Set the appropriate headers for Excel file download
-                    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
-                    header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
-                    header('Cache-Control: max-age=0');
-    
-                    // Rewind the temporary file pointer
-                    rewind($tempFile);
-    
-                    // Output the contents of the temporary file to the browser
-                    fpassthru($tempFile);
-    
-                    // Close and remove the temporary file
-                    fclose($tempFile);
-
-                    return true;
-    
-                }else{
-                    return false;
-                }
             }
-
-
         }
+    }
 
 
 
@@ -461,455 +470,458 @@ class EmpDataServiceController extends BaseController
      *               - 2 if the file does not exist.
      *               - 0 if the provided data is incomplete or incorrect.
      */
-    
-        public function importExcelDataForInception($import_data)
-        {
 
-            $client_id = $import_data['client_id'];
-            $client_policy_id = $import_data['client_policy_id'];
-            $file = $import_data['file'];
+    public function importExcelDataForInception($import_data)
+    {
 
-            $data = $this->readExcelToArray($file);
-            unset($data[0]);
-            array_pop($data);
-            $count = count($data);
+        $client_id = $import_data['client_id'];
+        $client_policy_id = $import_data['client_policy_id'];
+        $file = $import_data['file'];
 
-            $missing_id = [];
-            $empty_emp_tpa_uh_ids = [];
-            foreach ($data as $key => $value) {
+        $data = $this->readExcelToArray($file);
+        unset($data[0]);
+        array_pop($data);
+        $count = count($data);
 
-                try {
+        $missing_id = [];
+        $empty_emp_tpa_uh_ids = [];
+        $totals = 0;
+        foreach ($data as $key => $value) {
 
-                    if ($value[15] === null) {
-                        $missing_id[] = $key + 1;
-                    }
+            try {
 
-                    $emp_code = $value[2];
-                    $name = $value[1];
+                if ($value[15] === null) {
+                    $missing_id[] = $key + 1;
+                }
 
-                    $db = \Config\Database::connect();
+                $emp_code = $value[2];
+                $name = $value[1];
+                $totals += $value[20];
 
-                    // Execute the query
-                    $query = $db->table('employee_polices')
+                $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();
+                    ->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();
 
-                    // Get the result
-                    $result = $query->getRowArray();
-                    if (isset($result['id']) && $result['id'] !== null) {
-                        $empty_emp_tpa_uh_ids[] = $result['id'];
-                    }
-                } catch (\Exception $e) {
-                    // Handle the exception here
-                    return 0;
+                // Get the result
+                $result = $query->getRowArray();
+                if (isset($result['id']) && $result['id'] !== null) {
+                    $empty_emp_tpa_uh_ids[] = $result['id'];
                 }
+            } catch (\Exception $e) {
+                // Handle the exception here
+                return 0;
             }
-
-            $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) {
-
-                return 2;
-            }
-
-            if ($empty_emp_tpa_uh_ids != $count  && $empty_id_count == 0) {
-
-                return 3;
-            }
-
-            // dd($empty_emp_tpa_uh_ids);
-
-            $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
-            $filename = $file->getName();
-            $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]);
-
-            $import_data['count'] = $count;
-            $import_data['file_name'] = $filename;
-
-
-            $this->insertBatchFileAndBatchListForImportExcel($import_data, $empty_emp_tpa_uh_ids);
-
-            // dd($import_data, $empty_emp_tpa_uh_ids);
-
-
-            foreach ($data as $key => $value) {
-
-                if (!empty($value) && (isset($value[15]) || isset($value[16]))) {
-
-                    $tpa_id = $value[15] !== null ? $value[15] : '';
-                    $uhid = $value[16] !== null ? $value[16] : '';
-            
-                    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();
-                    }
-            
-                    // $query = $this->employeePolicyModel->getLastQuery();
-                    // echo $query . "
"; - - } else { - - return 0; - } - } - - - - $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); - return 1; - } - public function importExcelDataForCorrection($import_data) - { + $missing_id_count = count($missing_id); + $empty_id_count = count($empty_emp_tpa_uh_ids); - $client_id = $import_data['client_id']; - $client_policy_id = $import_data['client_policy_id']; - $file = $import_data['file']; + // dd($count, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); - $data = $this->readExcelToArray($file); - unset($data[0]); - $count = count($data); + if ($missing_id_count != $count && $missing_id_count != 0) { - $missing_id = []; - $empty_emp_tpa_uh_ids = []; - foreach ($data as $key => $value) { + return 2; + } - try { + if ($empty_emp_tpa_uh_ids != $count && $empty_id_count == 0) { - if ($value[10] === null) { - $missing_id[] = $key + 1; - } + return 3; + } - $emp_code = $value[0]; - $uhid = $value[1]; - $endorsement_id = $value[10] != null ? $value[10] : ''; + // dd($empty_emp_tpa_uh_ids); - $db = \Config\Database::connect(); + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]); - // Execute the query - $query = $db->table('emp_endorsement') - ->select('emp_endorsement.id') - ->join('employees', 'employees.id = emp_endorsement.pk') - ->join('employee_polices', 'employee_polices.employee_id = employees.id') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employees.client_id', $client_id) - ->where('employee_polices.uhid', $uhid) - ->where('employees.emp_code', $emp_code) - ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') - ->groupBy('emp_endorsement.group_key') - ->limit(1); - - // Get the result - $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; - } - } - - $missing_id_count = count($missing_id); - $empty_id_count = count($empty_emp_tpa_uh_ids); - - // if($missing_id_count != $count){ - - // return 2; - // } - - if($missing_id_count != 0 ){ - - return 2; - } - - // if($empty_emp_tpa_uh_ids != $count){ - - // return 3; - // } - - if( $empty_id_count == 0){ - - return 3; - } - - // dd($count, $missing_id, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); - - - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); - - $this->myLogger->logme('error','Correction Import file name : {data}', ['data'=> $filename ]); - $random_number_count = 4; - $batch_code = generate_random_string($random_number_count); - $this->myLogger->logme('error','Correction Import BATCH CODE : {data}', ['data'=> $batch_code ]); + $import_data['count'] = $count; + $import_data['file_name'] = $filename; + $import_data['amount'] = $totals; - $import_data['batch_code'] = $batch_code; - $import_data['created_by'] = get_session_userid(); - $import_data['file_name'] = $filename; - $insert = $this->batchFileModel->insert($import_data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + $this->insertBatchFileAndBatchListForImportExcel($import_data, $empty_emp_tpa_uh_ids); - $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_code_for_batch_list['created_by'] = get_session_userid(); + // dd($import_data, $empty_emp_tpa_uh_ids); - $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; - if(!file_exists($file_name_with_path)) - { - return 2; + foreach ($data as $key => $value) { + + if (!empty($value) && (isset($value[15]) || isset($value[16]))) { + + $tpa_id = $value[15] !== null ? $value[15] : ''; + $uhid = $value[16] !== null ? $value[16] : ''; + + 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(); } - $data = read_excel_file_to_array($file_name_with_path); - unset($data[0]); - $count = count($data); - $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); - // dd($data); - foreach ($data as $key => $value) { + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; - if (!empty($value) && isset($value[10])) { + } else { - $emp_code = $value[0]; - $uhid = $value[1]; - $endorsement_id = $value[10] != null ? $value[10] : ''; - - $val = $this->employeePolicyModel - ->select('employees.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('employee_polices.uhid', $uhid) - ->where('employees.emp_code', $emp_code) - ->where('employees.is_active', 1) - ->first(); - - $batch_code_for_batch_list['emp_policy_id'] = $val['id']; - $this->batchListModel->insert($batch_code_for_batch_list); - - // $this->employeePolicyModel->updateCorrectionData($emp_code, $uhid, $endorsement_id); - - $queryData = $this->empEndorsementModel->select('emp_endorsement.*, employees.id as emp_id') - ->join('employees', 'employees.id = emp_endorsement.pk') - ->join('employee_polices', 'employee_polices.employee_id = employees.id') - ->where('employees.emp_code', $emp_code) - ->where('employees.client_id', $client_id) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employee_polices.uhid', $uhid) - ->get() - ->getResultArray(); - - // dd($queryData); - - foreach ($queryData as $endorsementData) { - - $emp_endoresment_id = $endorsementData['id']; - $emp_id = $endorsementData['emp_id']; - $field_name = $endorsementData['field_name']; - $new_value = $endorsementData['new_value']; - $endoresment_udate_data = [ - 'endorsement_id' => $endorsement_id, - 'status' => 'complete', - ]; - $this->empEndorsementModel->where('id', $emp_endoresment_id)->set($endoresment_udate_data)->update(); - $this->employeeModel->where('id', $emp_id)->set($field_name, $new_value)->update(); - } - - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
"; - }else{ - - return 0; - } - - } - - - return 1; - + return 0; + } } - public function importExcelDataForSIEnhancement($import_data) - { - $client_id = $import_data['client_id']; - $client_policy_id = $import_data['client_policy_id']; - $file = $import_data['file']; + $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'], + ]; - $data = $this->readExcelToArray($file); - unset($data[0]); - $count = count($data); + $this->cashDepositCalculationForInception($depositeData); + return 1; + } - $missing_id = []; - $empty_emp_tpa_uh_ids = []; - foreach ($data as $key => $value) { - try { - if ($value[19] === null) { - $missing_id[] = $key + 1; - } + public function importExcelDataForCorrection($import_data) + { - $emp_name = $value[1]; - $emp_code = $value[2]; - $endorsement_id = $value[19] != null ? $value[19] : ''; + $client_id = $import_data['client_id']; + $client_policy_id = $import_data['client_policy_id']; + $file = $import_data['file']; - $db = \Config\Database::connect(); + $data = $this->readExcelToArray($file); + unset($data[0]); + $count = count($data); - // Execute the query - $query = $db->table('emp_endorsement') + $missing_id = []; + $empty_emp_tpa_uh_ids = []; + foreach ($data as $key => $value) { + + try { + + if ($value[10] === null) { + $missing_id[] = $key + 1; + } + + $emp_code = $value[0]; + $uhid = $value[1]; + $endorsement_id = $value[10] != null ? $value[10] : ''; + + $db = \Config\Database::connect(); + + // Execute the query + $query = $db->table('emp_endorsement') + ->select('emp_endorsement.id') + ->join('employees', 'employees.id = emp_endorsement.pk') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employees.client_id', $client_id) + ->where('employee_polices.uhid', $uhid) + ->where('employees.emp_code', $emp_code) + ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') + ->groupBy('emp_endorsement.group_key') + ->limit(1); + + // Get the result + $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; + } + } + + $missing_id_count = count($missing_id); + $empty_id_count = count($empty_emp_tpa_uh_ids); + + // if($missing_id_count != $count){ + + // return 2; + // } + + if ($missing_id_count != 0) { + + return 2; + } + + // if($empty_emp_tpa_uh_ids != $count){ + + // return 3; + // } + + if ($empty_id_count == 0) { + + return 3; + } + + // dd($count, $missing_id, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); + + + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + + $this->myLogger->logme('error', 'Correction Import file name : {data}', ['data' => $filename]); + $random_number_count = 4; + $batch_code = generate_random_string($random_number_count); + $this->myLogger->logme('error', 'Correction Import BATCH CODE : {data}', ['data' => $batch_code]); + + + $import_data['batch_code'] = $batch_code; + $import_data['created_by'] = get_session_userid(); + $import_data['file_name'] = $filename; + $insert = $this->batchFileModel->insert($import_data); + $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + + $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_code_for_batch_list['created_by'] = get_session_userid(); + + $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name']; + + if (!file_exists($file_name_with_path)) { + return 2; + } + + $data = read_excel_file_to_array($file_name_with_path); + unset($data[0]); + $count = count($data); + $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); + foreach ($data as $key => $value) { + + if (!empty($value) && isset($value[10])) { + + $emp_code = $value[0]; + $uhid = $value[1]; + $endorsement_id = $value[10] != null ? $value[10] : ''; + + $val = $this->employeePolicyModel + ->select('employees.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('employee_polices.uhid', $uhid) + ->where('employees.emp_code', $emp_code) + ->where('employees.is_active', 1) + ->first(); + + $batch_code_for_batch_list['emp_policy_id'] = $val['id']; + $this->batchListModel->insert($batch_code_for_batch_list); + + // $this->employeePolicyModel->updateCorrectionData($emp_code, $uhid, $endorsement_id); + + $queryData = $this->empEndorsementModel->select('emp_endorsement.*, employees.id as emp_id') + ->join('employees', 'employees.id = emp_endorsement.pk') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code', $emp_code) + ->where('employees.client_id', $client_id) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.uhid', $uhid) + ->get() + ->getResultArray(); + + // dd($queryData); + + foreach ($queryData as $endorsementData) { + + $emp_endoresment_id = $endorsementData['id']; + $emp_id = $endorsementData['emp_id']; + $field_name = $endorsementData['field_name']; + $new_value = $endorsementData['new_value']; + $endoresment_udate_data = [ + 'endorsement_id' => $endorsement_id, + 'status' => 'complete', + ]; + $this->empEndorsementModel->where('id', $emp_endoresment_id)->set($endoresment_udate_data)->update(); + $this->employeeModel->where('id', $emp_id)->set($field_name, $new_value)->update(); + } + + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; + } else { + + return 0; + } + } + + + return 1; + } + + + public function importExcelDataForSIEnhancement($import_data) + { + + $client_id = $import_data['client_id']; + $client_policy_id = $import_data['client_policy_id']; + $file = $import_data['file']; + + $data = $this->readExcelToArray($file); + unset($data[0]); + $count = count($data); + + + $missing_id = []; + $empty_emp_tpa_uh_ids = []; + $totals = 0; + foreach ($data as $key => $value) { + + try { + if ($value[19] === null) { + $missing_id[] = $key + 1; + } + + $totals += $value[18]; + + $emp_name = $value[1]; + $emp_code = $value[2]; + $endorsement_id = $value[19] != null ? $value[19] : ''; + + $db = \Config\Database::connect(); + + // Execute the query + $query = $db->table('emp_endorsement') ->select('emp_endorsement.id') ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk') ->join('employees', 'employees.emp_code = emp_endorsement.emp_code') ->where('employees.emp_code', $emp_code) - ->where('employees.name', $emp_name) - ->where('employees.client_id', $client_id) - ->where('emp_endorsement.actions', 'si') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') - ->groupBy('emp_endorsement.group_key'); + ->where('employees.name', $emp_name) + ->where('employees.client_id', $client_id) + ->where('emp_endorsement.actions', 'si') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') + ->groupBy('emp_endorsement.group_key'); - // Get the result - $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; + // Get the result + $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; } - - $missing_id_count = count($missing_id); - $empty_id_count = count($empty_emp_tpa_uh_ids); + } + $rounded_totals = round($totals, 2); - // if($missing_id_count != $count){ + $missing_id_count = count($missing_id); + $empty_id_count = count($empty_emp_tpa_uh_ids); - // return 2; - // } - - if($missing_id_count != 0 ){ + // if($missing_id_count != $count){ - return 2; - } + // return 2; + // } - // if($empty_emp_tpa_uh_ids != $count){ + if ($missing_id_count != 0) { - // return 3; - // } + return 2; + } - if( $empty_id_count == 0){ + // if($empty_emp_tpa_uh_ids != $count){ - return 3; - } + // return 3; + // } - // dd($count, $missing_id, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); + if ($empty_id_count == 0) { - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); + return 3; + } - $this->myLogger->logme('error','SI_Enhancement Import file name : {data}', ['data'=> $filename ]); - $random_number_count = 4; - $batch_code = generate_random_string($random_number_count); - $this->myLogger->logme('error','SI_Enhancement Import BATCH CODE : {data}', ['data'=> $batch_code ]); + // dd($count, $missing_id, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); + + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + + $this->myLogger->logme('error', 'SI_Enhancement Import file name : {data}', ['data' => $filename]); + $random_number_count = 4; + $batch_code = generate_random_string($random_number_count); + $this->myLogger->logme('error', 'SI_Enhancement Import BATCH CODE : {data}', ['data' => $batch_code]); - $import_data['batch_code'] = $batch_code; - $import_data['created_by'] = get_session_userid(); - $import_data['file_name'] = $filename; - $insert = $this->batchFileModel->insert($import_data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + $import_data['batch_code'] = $batch_code; + $import_data['created_by'] = get_session_userid(); + $import_data['file_name'] = $filename; + $import_data['amount'] = $rounded_totals; + $insert = $this->batchFileModel->insert($import_data); + $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); - $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_code_for_batch_list['created_by'] = get_session_userid(); + $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_code_for_batch_list['created_by'] = get_session_userid(); - $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; + $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name']; - if(!file_exists($file_name_with_path)) - { - return 2; - } - - $data = read_excel_file_to_array($file_name_with_path); - unset($data[0]); - $count = count($data); - $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); - // dd($data); - $employeeIds = []; - foreach ($data as $key => $value) { + if (!file_exists($file_name_with_path)) { + return 2; + } - if (!empty($value) && isset($value[19])) { + $data = read_excel_file_to_array($file_name_with_path); + unset($data[0]); + $count = count($data); + $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); + $employeeIds = []; + foreach ($data as $key => $value) { - $emp_name = $value[1]; - $emp_code = $value[2]; - // echo $emp_name .'-'. $emp_code; die; - $endorsement_id = $value[19] != null ? $value[19] : ''; + if (!empty($value) && isset($value[19])) { - $updateData = [ - 'emp_code' =>$emp_code, - 'client_id' =>$client_id, - 'client_policy_id' =>$client_policy_id, - 'emp_name' =>$emp_name, - 'endorsement_id' =>$endorsement_id, - ]; + $emp_name = $value[1]; + $emp_code = $value[2]; + // echo $emp_name .'-'. $emp_code; die; + $endorsement_id = $value[19] != null ? $value[19] : ''; - $this->employeePolicyModel->updateEndoresmentIdForSIEnhancement($updateData); + $updateData = [ + 'emp_code' => $emp_code, + 'client_id' => $client_id, + 'client_policy_id' => $client_policy_id, + 'emp_name' => $emp_name, + 'endorsement_id' => $endorsement_id, + ]; - $queryData = $this->employeePolicyModel - ->select('employee_polices.*') - ->join('employees', 'employee_polices.employee_id = employees.id') - ->where('employees.emp_code', $emp_code) - ->where('employees.name', $emp_name) - ->where('employees.client_id', $client_id) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employee_polices.is_active', 1) - ->first(); + $this->employeePolicyModel->updateEndoresmentIdForSIEnhancement($updateData); - $queryData['is_active'] = 0; - $this->employeePolicyModel->save($queryData); + $queryData = $this->employeePolicyModel + ->select('employee_polices.*') + ->join('employees', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code', $emp_code) + ->where('employees.name', $emp_name) + ->where('employees.client_id', $client_id) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.is_active', 1) + ->first(); - unset($queryData['id']); - unset($queryData['created_by']); - unset($queryData['created_at']); - unset($queryData['updated_by']); - unset($queryData['updated_at']); - unset($queryData['is_active']); + $queryData['is_active'] = 0; + $this->employeePolicyModel->save($queryData); - $queryData['basic_cover_si'] = $value[8]; - $queryData['premium'] = $value[14]; - $queryData['si_enhancement_date'] = $value[10]; - $queryData['rata_premimum'] = $value[16]; - $queryData['gst'] = $value[17]; - $queryData['created_by'] = get_session_userid(); + unset($queryData['id']); + unset($queryData['created_by']); + unset($queryData['created_at']); + unset($queryData['updated_by']); + unset($queryData['updated_at']); + unset($queryData['is_active']); - //new insert - $this->employeePolicyModel->save($queryData); + $queryData['basic_cover_si'] = $value[8]; + $queryData['premium'] = $value[14]; + $queryData['si_enhancement_date'] = $value[10]; + $queryData['rata_premimum'] = $value[16]; + $queryData['gst'] = $value[17]; + $queryData['created_by'] = get_session_userid(); - $val = $this->employeePolicyModel + //new insert + $this->employeePolicyModel->save($queryData); + + $val = $this->employeePolicyModel ->select('employee_polices.id') ->join('employees', 'employees.id = employee_polices.employee_id') ->where('employee_polices.client_policy_id', $client_policy_id) @@ -919,246 +931,245 @@ class EmpDataServiceController extends BaseController ->where('employee_polices.is_active', 1) ->first(); - if ($val !== null) { - $id = $val['id']; - $batch_code_for_batch_list['emp_policy_id'] = $id; - $this->batchListModel->insert($batch_code_for_batch_list); - array_push($employeeIds, $id); - } - - }else{ - - return 0; + if ($val !== null) { + $id = $val['id']; + $batch_code_for_batch_list['emp_policy_id'] = $id; + $this->batchListModel->insert($batch_code_for_batch_list); + array_push($employeeIds, $id); } + } else { + return 0; } - - $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); - $depositeData = [ - 'employeeIds'=>$employeeIds, - 'client_id'=>$client_id, - 'client_policy_id'=>$client_policy_id, - 'count'=>$count, - 'event'=>$import_data['event_type'], - 'policy_name'=>$policy_name['policy_name'], - ]; - - // dd($depositeData); - $this->cashDepositCalculationForSIEnhancement($depositeData); - - return 1; } + $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); + $depositeData = [ + 'employeeIds' => $employeeIds, + 'client_id' => $client_id, + 'client_policy_id' => $client_policy_id, + 'count' => $count, + 'event' => $import_data['event_type'], + 'policy_name' => $policy_name['policy_name'], + ]; - public function importExcelDataForDeletion($import_data) - { + // dd($depositeData); + $this->cashDepositCalculationForSIEnhancement($depositeData); - $client_id = $import_data['client_id']; - $client_policy_id = $import_data['client_policy_id']; - $file = $import_data['file']; + return 1; + } - $data = $this->readExcelToArray($file); - unset($data[0]); - array_pop($data); - $count = count($data); + public function importExcelDataForDeletion($import_data) + { - $missing_id = []; - $empty_emp_tpa_uh_ids = []; - foreach ($data as $key => $value) { + $client_id = $import_data['client_id']; + $client_policy_id = $import_data['client_policy_id']; + $file = $import_data['file']; - try { - if ($value[15] === null) { - $missing_id[] = $key + 1; - } + $data = $this->readExcelToArray($file); + unset($data[0]); + array_pop($data); + $count = count($data); - $emp_name = $value[2]; //employee name - $emp_code = $value[1]; //employee code - $date_of_exit = $value[7]; // date of releving - $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id - $db = \Config\Database::connect(); + $missing_id = []; + $empty_emp_tpa_uh_ids = []; + $totals = 0 ; + foreach ($data as $key => $value) { - // Execute the query - $query = $db->table('emp_endorsement') - ->select('emp_endorsement.id') - ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk') - ->join('employees', 'employees.emp_code = emp_endorsement.emp_code') - ->where('employees.emp_code', $emp_code) - ->where('employees.name', $emp_name) - ->where('employees.client_id', $client_id) - ->where('emp_endorsement.actions', 'd') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') - ->groupBy('emp_endorsement.group_key'); + try { - $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; - } - } - - $missing_id_count = count($missing_id); - $empty_id_count = count($empty_emp_tpa_uh_ids); - - - // if($missing_id_count != $count){ - - // return 2; - // } - - if($missing_id_count != 0 ){ - - return 2; - } - - // if($empty_emp_tpa_uh_ids != $count){ - - // return 3; - // } - - if( $empty_id_count == 0){ - - return 3; + if ($value[15] === null) { + $missing_id[] = $key + 1; } - // dd($count, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); + $totals += $value[13]; - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); + $emp_name = $value[2]; //employee name + $emp_code = $value[1]; //employee code + $date_of_exit = $value[7]; // date of releving + $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id - $this->myLogger->logme('error','Deletion Import file name : {data}', ['data'=> $filename ]); - $random_number_count = 4; - $batch_code = generate_random_string($random_number_count); - $this->myLogger->logme('error','Deletion Import BATCH CODE : {data}', ['data'=> $batch_code ]); + $db = \Config\Database::connect(); + + // Execute the query + $query = $db->table('emp_endorsement') + ->select('emp_endorsement.id') + ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk') + ->join('employees', 'employees.emp_code = emp_endorsement.emp_code') + ->where('employees.emp_code', $emp_code) + ->where('employees.name', $emp_name) + ->where('employees.client_id', $client_id) + ->where('emp_endorsement.actions', 'd') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') + ->groupBy('emp_endorsement.group_key'); + + $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; + } + } + + $rounded_totals = round($totals, 2); + $missing_id_count = count($missing_id); + $empty_id_count = count($empty_emp_tpa_uh_ids); + + // if($missing_id_count != $count){ + + // return 2; + // } + + if ($missing_id_count != 0) { + + return 2; + } + + // if($empty_emp_tpa_uh_ids != $count){ + + // return 3; + // } + + if ($empty_id_count == 0) { + + return 3; + } + + // dd($count, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); + + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + + $this->myLogger->logme('error', 'Deletion Import file name : {data}', ['data' => $filename]); + $random_number_count = 4; + $batch_code = generate_random_string($random_number_count); + $this->myLogger->logme('error', 'Deletion Import BATCH CODE : {data}', ['data' => $batch_code]); - $import_data['batch_code'] = $batch_code; - $import_data['created_by'] = get_session_userid(); - $import_data['file_name'] = $filename; - $insert = $this->batchFileModel->insert($import_data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + $import_data['batch_code'] = $batch_code; + $import_data['created_by'] = get_session_userid(); + $import_data['file_name'] = $filename; + $import_data['amount'] = $rounded_totals; + $insert = $this->batchFileModel->insert($import_data); + $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); - $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_code_for_batch_list['created_by'] = get_session_userid(); + $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_code_for_batch_list['created_by'] = get_session_userid(); - $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; + $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name']; - if(!file_exists($file_name_with_path)) - { - return 2; + if (!file_exists($file_name_with_path)) { + return 2; + } + + $data = read_excel_file_to_array($file_name_with_path); + unset($data[0]); + array_pop($data); + + $count = count($data); + $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); + + $employeeIds = []; + foreach ($data as $key => $value) { + + if (!empty($value) && isset($value[15])) { + + $emp_name = $value[2]; //employee name + $emp_code = $value[1]; //employee code + $date_of_exit = $value[7]; // date of releving + + // echo $emp_name .'-'. $emp_code .'-'. $date_of_exit; die; + $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id + + $val = $this->employeePolicyModel + ->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', $emp_name) + ->where('employees.emp_code', $emp_code) + ->where('employee_polices.is_active', 1) + ->first(); + + + if ($val !== null) { + + $id = $val['id']; + $batch_code_for_batch_list['emp_policy_id'] = $id; + $this->batchListModel->insert($batch_code_for_batch_list); + array_push($employeeIds, $id); } - $data = read_excel_file_to_array($file_name_with_path); - unset($data[0]); - array_pop($data); + // $updateData = [ + // 'emp_code' =>$emp_code, + // 'client_id' =>$client_id, + // 'client_policy_id' =>$client_policy_id, + // 'emp_name' =>$emp_name, + // 'endorsement_id' =>$endorsement_id, + // ]; - $count = count($data); - $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); + // $this->employeePolicyModel->updateEndoresmentIdForDeletion($updateData); - $employeeIds = []; - foreach ($data as $key => $value) { + $deletionDataForEmployee = $this->empEndorsementModel + ->select('emp_endorsement.new_value, emp_endorsement.id as ee_id, employees.id') + ->join('employees', 'emp_endorsement.emp_code = employees.emp_code') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('emp_endorsement.emp_code', $emp_code) + ->where('employees.client_id', $client_id) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('emp_endorsement.name', $emp_name) + ->where('emp_endorsement.field_name', 'emp_status') + ->first(); - if (!empty($value) && isset($value[15])) { + $deletionDataForEmployee['updated_by'] = get_session_userid(); + $this->employeeModel->save($deletionDataForEmployee); - $emp_name = $value[2]; //employee name - $emp_code = $value[1]; //employee code - $date_of_exit = $value[7]; // date of releving + $e_Data = [ + 'endorsement_id' => $endorsement_id, + 'status' => 'complete', + ]; + $group_key = $this->empEndorsementModel->select('group_key')->where('id', $deletionDataForEmployee['ee_id'])->first(); + $this->empEndorsementModel->where('group_key', $group_key)->set($e_Data)->update(); - // echo $emp_name .'-'. $emp_code .'-'. $date_of_exit; die; - $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id - - $val = $this->employeePolicyModel - ->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', $emp_name) - ->where('employees.emp_code', $emp_code) - ->where('employee_polices.is_active', 1) - ->first(); - - - if ($val !== null) { - - $id = $val['id']; - $batch_code_for_batch_list['emp_policy_id'] = $id; - $this->batchListModel->insert($batch_code_for_batch_list); - array_push($employeeIds, $id); - } - - // $updateData = [ - // 'emp_code' =>$emp_code, - // 'client_id' =>$client_id, - // 'client_policy_id' =>$client_policy_id, - // 'emp_name' =>$emp_name, - // 'endorsement_id' =>$endorsement_id, - // ]; - - // $this->employeePolicyModel->updateEndoresmentIdForDeletion($updateData); - - $deletionDataForEmployee = $this->empEndorsementModel - ->select('emp_endorsement.new_value, emp_endorsement.id as ee_id, employees.id') - ->join('employees', 'emp_endorsement.emp_code = employees.emp_code') - ->join('employee_polices', 'employee_polices.employee_id = employees.id') - ->where('emp_endorsement.emp_code', $emp_code) - ->where('employees.client_id', $client_id) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('emp_endorsement.name', $emp_name) - ->where('emp_endorsement.field_name', 'emp_status') - ->first(); - - $deletionDataForEmployee['updated_by'] = get_session_userid(); - $this->employeeModel->save($deletionDataForEmployee); - - $e_Data = [ - 'endorsement_id'=> $endorsement_id, - 'status'=> 'complete', - ]; - $group_key = $this->empEndorsementModel->select('group_key')->where('id', $deletionDataForEmployee['ee_id'])->first(); - $this->empEndorsementModel->where('group_key', $group_key)->set($e_Data)->update(); - - $fetchData = [ - 'emp_code'=> $emp_code, - 'client_policy_id'=> $client_policy_id, - 'emp_name'=> $emp_name, - ]; - - $deletionDataForEmployeePolicy = $this->employeePolicyModel->fetchEmpEndorsementData($fetchData); - $deletionDataForEmployeePolicy['updated_by'] = get_session_userid(); - $this->employeePolicyModel->save($deletionDataForEmployeePolicy); - - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
"; - - }else{ - - return 0; - } - - } - - $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); - $depositeData = [ - 'employeeIds'=>$employeeIds, - 'client_id'=>$client_id, - 'client_policy_id'=>$client_policy_id, - 'count'=>$count, - 'event'=>$import_data['event_type'], - 'policy_name'=>$policy_name['policy_name'], + $fetchData = [ + 'emp_code' => $emp_code, + 'client_policy_id' => $client_policy_id, + 'emp_name' => $emp_name, ]; - $this->cashDepositCalculationForDeletion($depositeData); - return 1; + $deletionDataForEmployeePolicy = $this->employeePolicyModel->fetchEmpEndorsementData($fetchData); + $deletionDataForEmployeePolicy['updated_by'] = get_session_userid(); + $this->employeePolicyModel->save($deletionDataForEmployeePolicy); + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; + } else { + + return 0; + } } + $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); + $depositeData = [ + 'employeeIds' => $employeeIds, + 'client_id' => $client_id, + 'client_policy_id' => $client_policy_id, + 'count' => $count, + 'event' => $import_data['event_type'], + 'policy_name' => $policy_name['policy_name'], + ]; + + $this->cashDepositCalculationForDeletion($depositeData); + return 1; + } + /** @@ -1175,88 +1186,86 @@ class EmpDataServiceController extends BaseController * @return bool Returns true if the operation is successful, otherwise returns 0. */ - public function cashDepositCalculationForInception($arrayData) - { - if (!empty($arrayData)) { - - $amount = $this->employeePolicyModel->query(" + public function cashDepositCalculationForInception($arrayData) + { + if (!empty($arrayData)) { + + $amount = $this->employeePolicyModel->query(" SELECT SUM(rata_premimum + gst) AS total_sum FROM employee_polices WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ") ")->getRow(); - - $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first(); - $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, - 'sub_type_id' => 4, - 'client_id' => $arrayData['client_id'], - 'insurer_id' => $insurer_id['insurer_id'], - 'description' => $description, - 'transaction_type' => 'Debit', - 'updated_by' => get_session_userid(), - 'is_active' => 1, - ]; - $response = DepositHelper::saveDeposit($data, get_session_userid()); - return true; - // print_r($response); - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
"; + $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first(); + $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']) . '.'; - } else { - return 0; - } + $data = [ + 'amount' => $amount->total_sum, + 'sub_type_id' => 4, + 'client_id' => $arrayData['client_id'], + 'insurer_id' => $insurer_id['insurer_id'], + 'description' => $description, + 'transaction_type' => 'Debit', + 'updated_by' => get_session_userid(), + 'is_active' => 1, + ]; + $response = DepositHelper::saveDeposit($data, get_session_userid()); + return true; + // print_r($response); + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; - + } else { + return 0; } + } - public function cashDepositCalculationForSIEnhancement($arrayData) - { - if (!empty($arrayData)) { - - $amount = $this->employeePolicyModel->query(" + public function cashDepositCalculationForSIEnhancement($arrayData) + { + if (!empty($arrayData)) { + + $amount = $this->employeePolicyModel->query(" SELECT SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.si_enhancement_date)) / 365, 2) + ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.si_enhancement_date)) / 365) * 0.18, 2)) AS total_sum FROM employee_polices WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ") ")->getRow(); - $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first(); - $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.'; + $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first(); + $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.'; - $data = [ + $data = [ - 'amount' => $amount->total_sum, - 'sub_type_id' => 4, - 'client_id' => $arrayData['client_id'], - 'insurer_id' => $insurer_id['insurer_id'], - 'description' => $description, - 'transaction_type' => 'Debit', - 'updated_by' => get_session_userid(), - 'is_active' => 1, - ]; - $response = DepositHelper::saveDeposit($data, get_session_userid()); - return true; - // print_r($response); - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
"; + 'amount' => $amount->total_sum, + 'sub_type_id' => 4, + 'client_id' => $arrayData['client_id'], + 'insurer_id' => $insurer_id['insurer_id'], + 'description' => $description, + 'transaction_type' => 'Debit', + 'updated_by' => get_session_userid(), + 'is_active' => 1, + ]; + $response = DepositHelper::saveDeposit($data, get_session_userid()); + return true; + // print_r($response); + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; - } else { - return 0; - } + } else { + return 0; } + } - public function cashDepositCalculationForDeletion($arrayData) - { - // print_r($arrayData); - if (!empty($arrayData)) { - - // echo '
';
-                // print_r($arrayData); die;
-                $amount = $this->employeePolicyModel->query("
+    public function cashDepositCalculationForDeletion($arrayData)
+    {
+        // print_r($arrayData);   
+        if (!empty($arrayData)) {
+
+            // echo '
';
+            // print_r($arrayData); die;
+            $amount = $this->employeePolicyModel->query("
                 SELECT
                     SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365, 2) +
                         ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365) * 0.18, 2)) AS total_sum
@@ -1264,203 +1273,199 @@ class EmpDataServiceController extends BaseController
                 WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ")
                 ")->getRow();
 
-                $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();       
-                $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
+            $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
+            $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
 
-                $data = [
+            $data = [
 
-                    'amount' => $amount->total_sum,
-                    'sub_type_id' => 3,
-                    'client_id' => $arrayData['client_id'],
-                    'insurer_id' => $insurer_id['insurer_id'],
-                    'description' => $description,
-                    'transaction_type' => 'Credit',
-                    'updated_by' => get_session_userid(),
-                    'is_active' => 1,
-                ];
-                $response = DepositHelper::saveDeposit($data, get_session_userid());
-                return true;
-                // print_r($response);
-                // $query = $this->employeePolicyModel->getLastQuery();
-                // echo $query . "
"; - - } else { - return 0; - } + 'amount' => $amount->total_sum, + 'sub_type_id' => 3, + 'client_id' => $arrayData['client_id'], + 'insurer_id' => $insurer_id['insurer_id'], + 'description' => $description, + 'transaction_type' => 'Credit', + 'updated_by' => get_session_userid(), + 'is_active' => 1, + ]; + $response = DepositHelper::saveDeposit($data, get_session_userid()); + return true; + // print_r($response); + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; + } else { + return 0; } + } - /** - * Below function retrieves the policy name associated with a given client policy ID. - * - * @param int $client_policy_id The ID of the client policy. - * @return mixed Returns the policy name if found, otherwise null. - */ + /** + * Below function retrieves the policy name associated with a given client policy ID. + * + * @param int $client_policy_id The ID of the client policy. + * @return mixed Returns the policy name if found, otherwise null. + */ - public function getPolicyNameUsingClientPolicyId($client_policy_id) - { - return $this->clientPolicyModel->select('policies.name as policy_name') + public function getPolicyNameUsingClientPolicyId($client_policy_id) + { + return $this->clientPolicyModel->select('policies.name as policy_name') ->join('policies', 'policies.id = client_policy.policy_id') ->where('client_policy.id', $client_policy_id) ->first(); + } + + + + + /** + * Below function converts row data into column data format for SI enhancement. + * + * This function takes an array of data containing information about SI enhancement + * and calculates additional fields such as pro rata premium, GST, and total. + * + * @param array $data The array of data containing SI enhancement information. + * @return array Returns the converted data in column format. + */ + public function convertRowTColumnForSIEnhancement($data) + { + + $result = array(); + + foreach ($data as $obj) { + + $pro_rata_premium = round(($obj->difference_premium * $obj->no_of_days / 365), 2); + $gst = round(($pro_rata_premium * 18 / 100), 2); + $total = round(($pro_rata_premium + $gst), 2); + + $old_total = round(($obj->old_rata + $obj->old_gst), 2); + + + $result[] = array( + "field_name" => 'Basic Cover SI', + "old_value" => $obj->old_basic_cover_si, + "new_value" => $obj->new_basic_cover_si + ); + + $result[] = array( + "field_name" => 'Premium', + "old_value" => $obj->old_si_premium, + "new_value" => $obj->new_si_premium + ); + + $result[] = array( + "field_name" => 'SI Enhancement Date', + "old_value" => change_date_format($obj->old_date, 'Y-m-d', 'd-M-Y'), + "new_value" => change_date_format($obj->date_of_coverage, 'Y-m-d', 'd-M-Y') + ); + + $result[] = array( + "field_name" => 'Difference Premium', + "old_value" => ' --- ', + "new_value" => $obj->difference_premium + ); + + $result[] = array( + "field_name" => 'No of Days', + "old_value" => $obj->old_days, + "new_value" => $obj->no_of_days + ); + + $result[] = array( + "field_name" => 'Pro Rata Premium', + "old_value" => $obj->old_rata, + "new_value" => $pro_rata_premium + ); + + $result[] = array( + "field_name" => 'GST(18%)', + "old_value" => $obj->old_gst, + "new_value" => $gst + ); + + $result[] = array( + "field_name" => 'Total', + "old_value" => $old_total, + "new_value" => $total + ); } + return $result; + } - /** - * Below function converts row data into column data format for SI enhancement. - * - * This function takes an array of data containing information about SI enhancement - * and calculates additional fields such as pro rata premium, GST, and total. - * - * @param array $data The array of data containing SI enhancement information. - * @return array Returns the converted data in column format. - */ - public function convertRowTColumnForSIEnhancement($data) - { + /** + * Below function converts row data into column data format for deletion records. + * + * This function takes an array of data containing information about deletion records + * and converts it into a column format. It also calculates additional fields such as + * period of non-coverage, premium for non-coverage period, GST, total amount, and + * claim status based on the exist_reason field. + * + * @param array $data The array of data containing deletion records information. + * @return array Returns the converted data in column format. + */ + public function convertRowTColumnForDeletion($data) + { - $result = array(); + $result = array(); - foreach ($data as $obj) { - - $pro_rata_premium = round(($obj->difference_premium * $obj->no_of_days / 365), 2); - $gst = round(($pro_rata_premium * 18 / 100), 2); - $total = round(($pro_rata_premium + $gst), 2); + foreach ($data as $obj) { - $old_total = round(($obj->old_rata + $obj->old_gst), 2); + $old_total = round(($obj->old_rata + $obj->old_gst), 2); + $result[] = array( + "field_name" => 'Policy Period', + "data" => change_date_format($obj->start_date, 'Y-m-d', 'd-M-Y') . ' -
' . change_date_format($obj->end_date, 'Y-m-d', 'd-M-Y'), + ); + + $result[] = array( + "field_name" => 'Exit on', + "data" => change_date_format($obj->date_of_leaving, 'Y-m-d', 'd-M-Y'), + ); + + $result[] = array( + "field_name" => 'Reason', + "data" => $obj->exist_reason, + ); + + + + if ($obj->exist_reason != 'death') { $result[] = array( - "field_name" => 'Basic Cover SI', - "old_value" => $obj->old_basic_cover_si, - "new_value" => $obj->new_basic_cover_si + "field_name" => 'Period of non coverage', + "data" => $obj->no_of_days ); - + $result[] = array( - "field_name" => 'Premium', - "old_value" => $obj->old_si_premium, - "new_value" => $obj->new_si_premium + "field_name" => 'Premium for non coverage period', + "data" => $obj->pro_rata_premium ); - - $result[] = array( - "field_name" => 'SI Enhancement Date', - "old_value" => change_date_format($obj->old_date, 'Y-m-d', 'd-M-Y'), - "new_value" => change_date_format($obj->date_of_coverage, 'Y-m-d', 'd-M-Y') - ); - - $result[] = array( - "field_name" => 'Difference Premium', - "old_value" => ' --- ', - "new_value" => $obj->difference_premium - ); - - $result[] = array( - "field_name" => 'No of Days', - "old_value" => $obj->old_days, - "new_value" => $obj->no_of_days - ); - - $result[] = array( - "field_name" => 'Pro Rata Premium', - "old_value" => $obj->old_rata, - "new_value" => $pro_rata_premium - ); - + $result[] = array( "field_name" => 'GST(18%)', - "old_value" => $obj->old_gst, - "new_value" => $gst + "data" => $obj->gst ); - - $result[] = array( - "field_name" => 'Total', - "old_value" => $old_total, - "new_value" => $total - ); - - } - return $result; + $result[] = array( + "field_name" => 'Total Amount', + "data" => $obj->total + ); + + $result[] = array( + "field_name" => 'Claim', + "data" => '---', + ); + } } + return $result; + } - /** - * Below function converts row data into column data format for deletion records. - * - * This function takes an array of data containing information about deletion records - * and converts it into a column format. It also calculates additional fields such as - * period of non-coverage, premium for non-coverage period, GST, total amount, and - * claim status based on the exist_reason field. - * - * @param array $data The array of data containing deletion records information. - * @return array Returns the converted data in column format. - */ - public function convertRowTColumnForDeletion($data) - { - - $result = array(); - - foreach ($data as $obj) { - - $old_total = round(($obj->old_rata + $obj->old_gst), 2); - - $result[] = array( - "field_name" => 'Policy Period', - "data" => change_date_format($obj->start_date, 'Y-m-d', 'd-M-Y') . ' -
' . change_date_format($obj->end_date, 'Y-m-d', 'd-M-Y'), - ); - - $result[] = array( - "field_name" => 'Exit on', - "data" => change_date_format($obj->date_of_leaving, 'Y-m-d', 'd-M-Y'), - ); - - $result[] = array( - "field_name" => 'Reason', - "data" => $obj->exist_reason, - ); - - - - if($obj->exist_reason != 'death'){ - - $result[] = array( - "field_name" => 'Period of non coverage', - "data" => $obj->no_of_days - ); - - $result[] = array( - "field_name" => 'Premium for non coverage period', - "data" => $obj->pro_rata_premium - ); - - $result[] = array( - "field_name" => 'GST(18%)', - "data" => $obj->gst - ); - - $result[] = array( - "field_name" => 'Total Amount', - "data" => $obj->total - ); - - $result[] = array( - "field_name" => 'Claim', - "data" => '---', - ); - - } - - } - - return $result; - } - - // ----------------------------------------------------------------------------------- @@ -1469,30 +1474,29 @@ class EmpDataServiceController extends BaseController { if ($file->isValid() && !$file->hasMoved()) { - $file = $file; + $file = $file; - $reader = new Xlsx(); - $spreadsheet = $reader->load($file->getPathname()); + $reader = new Xlsx(); + $spreadsheet = $reader->load($file->getPathname()); - // Get the active sheet - $sheet = $spreadsheet->getActiveSheet(); + // 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; - } - - return $data; + // Iterate through rows to read data + $data = []; + foreach ($sheet->getRowIterator() as $row) { + $rowData = []; + foreach ($row->getCellIterator() as $cell) { + $rowData[] = $cell->getValue(); + } + $data[] = $rowData; + } - } else { + return $data; + } else { - return false; - } + return false; + } } @@ -1506,15 +1510,15 @@ class EmpDataServiceController extends BaseController $insert = $this->batchFileModel->insert($data); $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); - if($insert){ - foreach($ids as $id){ + if ($insert) { + foreach ($ids as $id) { $batch_list_data['batch_code'] = $batch_file_batch_code['batch_code']; $batch_list_data['emp_policy_id'] = $id; $batch_list_data['created_by'] = get_session_userid(); $this->batchListModel->insert($batch_list_data); } } - + return true; } } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index bb9f6a30..942b5367 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -77,6 +77,7 @@ class EmployeeController extends AdminController { //echo $this->request->isAJAX();die(); $result = $this->clientModel->clientsWithPolicies(); + // print_r($result);die(); if(!count($result)) { @@ -557,24 +558,31 @@ class EmployeeController extends AdminController return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200); } } - - public function downloadFileList($fileName = null) + + public function downloadFileList($file_id = null) { // $actionType = $this->request->getGet(); + $file_data = $this->fileModel->where('id', $file_id)->first(); + $fileName = $file_data['file_name']; + + $error_data = json_decode($file_data['reason']); + + $filePath = WRITEPATH . '/uploads/excel/' . $fileName; + try { - $filePath = WRITEPATH . '/uploads/excel/' . $fileName; - + // Check if the file exists if (file_exists($filePath)) { // Set the appropriate MIME type $mimeType = mime_content_type($filePath); - + // Send the file to the client for download return $this->response->download($filePath, null, $mimeType); } else { - throw new \CodeIgniter\Exceptions\PageNotFoundException(); + $data['message'] = 'The Physical File Not Found'; + echo view('errors/404', $data); } } catch (\Exception $e) { // Handle any exceptions @@ -583,7 +591,6 @@ class EmployeeController extends AdminController // You can return an error response here echo $errorMessage; } - } @@ -628,6 +635,7 @@ class EmployeeController extends AdminController $emp_data['tbody'] = $excel_data; $html = view('view_file_upload_emp_list', $emp_data); + } else { $html = '
No Data Found
'; @@ -643,5 +651,26 @@ class EmployeeController extends AdminController return $this->respond(['dataStatus' => false, 'code' => 500, 'data' => $html, 'file_data' => $file_name], 500); } } + + public function getEmpCount($id = null){ + + $data = $this->employeeModel->select('employees.id') + ->join('clients', 'clients.id = employees.client_id') + ->where('employees.client_id', $id) + ->findAll(); + + $emp_count = count($data); + + if($data){ + return $this->respond(['dataStatus' => true, 'code' => 200, 'emp_count' => $emp_count], 200); + + }else{ + + return $this->respond(['dataStatus' => false, 'code' => 404], 404); + + } + + + } } \ No newline at end of file diff --git a/app/Models/BatchFileModel.php b/app/Models/BatchFileModel.php index 119a73aa..5976d6a2 100644 --- a/app/Models/BatchFileModel.php +++ b/app/Models/BatchFileModel.php @@ -21,6 +21,7 @@ class BatchFileModel extends Model "created_by", "updated_by", "is_active", + "amount", ]; // Callbacks diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php index 3f252701..dea70840 100644 --- a/app/Views/batch_list.php +++ b/app/Views/batch_list.php @@ -26,6 +26,7 @@ Insurer/TPA Action Count + Amount @@ -46,6 +47,7 @@ + diff --git a/app/Views/employee_upload.php b/app/Views/employee_upload.php index c985b877..959e1509 100644 --- a/app/Views/employee_upload.php +++ b/app/Views/employee_upload.php @@ -478,15 +478,75 @@ $(document).ready(function() { $('#client_id').on('change', function() { var selectedClient = $(this).val(); - console.log(selectedClient); + 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; }); 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; + } + } + } + }); }); }); @@ -573,7 +633,9 @@ document.getElementById('toggleIcon1').addEventListener('click', function() { icon.classList.toggle('mdi-chevron-up'); }); -$('#fetch_enrolled_data').click(function() { + +$('#fetch_enrolled_data').click(function() +{ $('#emp_data').empty(); var client_id = $('#client_id').val(); @@ -637,5 +699,6 @@ $('#fetch_enrolled_data').click(function() { }); }) + //-------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/app/Views/errors/404.php b/app/Views/errors/404.php new file mode 100644 index 00000000..f271c312 --- /dev/null +++ b/app/Views/errors/404.php @@ -0,0 +1,175 @@ + + + + + + + <?= isset($page_name) ? $page_name : 'NHance'; ?> + + + + + + + /assets/images/Nhance_Favi.svg"> + + + + + + + + +
+
+
+

+
+
+
+ +
+ + + + \ No newline at end of file From 1c53d9d5ec9640c96e552048571d5396a372740d Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 16 Apr 2024 14:52:16 +0530 Subject: [PATCH 3/8] FIX_PREMIMUM_CALC_API --- app/Controllers/EmployeeRestController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 611f71d1..bc9cb6f5 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1293,7 +1293,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()); From 07955b0594b3f20baab4af10da6bb12c28850066 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Tue, 16 Apr 2024 17:20:52 +0530 Subject: [PATCH 4/8] FIX_CLIENT_POLICY : AADHAVAN --- app/Controllers/ClientController.php | 39 +++++++++- app/Views/client_policy.php | 38 ++++++++-- app/Views/policy_gmc_terms.php | 102 ++++++++++++++++++++------- 3 files changed, 145 insertions(+), 34 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 0e141e75..2b5354d5 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -610,7 +610,23 @@ class ClientController extends AdminController $policy_terms = $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first(); if ( $this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { - $data['policy_terms'] = $policy_terms['policy_terms']; + + if ($this->request->getPost('is_addon') == 3) { + $policyTerm = $policy_terms['policy_terms']; + $decoded_policyTerm = json_decode($policyTerm, true); + $decoded_policyTerm['family_floater'] =0; + $decoded_policyTerm['family_floaters']['self'] =0; + $decoded_policyTerm['family_floaters']['spouse'] =0; + $decoded_policyTerm['family_floaters']['childrens'] =0; + $decoded_policyTerm['family_floaters']['parents'] =0; + $decoded_policyTerm['family_floaters']['parents-in-law'] =0; + $decoded_policyTerm['family_floaters']['either-parents-pil'] =0; + + $data['policy_terms'] = json_encode($decoded_policyTerm); + }else{ + $data['policy_terms'] = $policy_terms['policy_terms']; + + } } @@ -679,7 +695,23 @@ class ClientController extends AdminController $policy_terms = $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first(); if ( $this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { - $data['policy_terms'] = $policy_terms['policy_terms']; + if ($this->request->getPost('is_addon') == 3) { + $policyTerm = $policy_terms['policy_terms']; + $decoded_policyTerm = json_decode($policyTerm, true); + $decoded_policyTerm['family_floater'] =0; + $decoded_policyTerm['family_floaters']['self'] =0; + $decoded_policyTerm['family_floaters']['spouse'] =0; + $decoded_policyTerm['family_floaters']['childrens'] =0; + $decoded_policyTerm['family_floaters']['parents'] =0; + $decoded_policyTerm['family_floaters']['parents-in-law'] =0; + $decoded_policyTerm['family_floaters']['either-parents-pil'] =0; + + $data['policy_terms'] = json_encode($decoded_policyTerm); + } else { + $data['policy_terms'] = $policy_terms['policy_terms']; + } + + } // dd($data); @@ -1259,6 +1291,7 @@ class ClientController extends AdminController ->where("employees.emp_status",'active') ->countAllResults(); + $emp_count_by_policy = $this->employeePolicyModel->where('client_policy_id',$client_policy_id)->where('is_active',1)->countAllResults(); if($emp_count == 0){ $emp_count = true; }else{ @@ -1266,7 +1299,7 @@ class ClientController extends AdminController } if ($record) { - return $this->respond(['Status' => true,'code' => 200,'data' => $record['policy_terms'], 'count' => $emp_count, 'policy_name' => $policy_name], 200); + return $this->respond(['Status' => true,'code' => 200,'data' => $record['policy_terms'], 'count' => $emp_count, 'policy_name' => $policy_name,'policy_addon' => $record['is_addon'], 'emp_count_by_policy'=>$emp_count_by_policy], 200); } else { return $this->respond(['Status' => false,'code' => 200,'message' => 'Record not found.', 'count' => $emp_count, 'policy_name' => $policy_name], 200); } diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index d211a9cf..dd2edd52 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -424,10 +424,26 @@ $(document).ready(function() { // console.log(res) var OptionsHTML = ''; OptionsHTML += ''; + $policy_type_value = $('#policy_type').val(); $.each(res.data, function(index, item) { - OptionsHTML += ''; + + if ($policy_type_value == 3) { + if (item.policy_type_id == 5 || item.policy_type_id == 3) { + OptionsHTML += ''; + } + }else if($policy_type_value == 2){ + if (item.policy_type_id == 4 ) { + OptionsHTML += ''; + } + }else{ + OptionsHTML += ''; + } }); $('#policy').html(OptionsHTML); @@ -1074,8 +1090,8 @@ $(document).ready(function(){ const queryString = objectToQueryString(queryParams); // var uri = '?' + queryString var uri = '' + client_policy_id - console.log('uri', uri) - console.log('queryString', queryString) + // console.log('uri', uri) + // console.log('queryString', queryString) $('.loader').fadeIn(); $('.loader-mask').fadeIn(); @@ -1102,11 +1118,19 @@ $(document).ready(function(){ var policeOptionHTML = ''; + $policy_type_value = $('#policy_type').val(); $.each(res.policy, function(index, item) { - console.log(item) - policeOptionHTML += ''; + // } + // } + }); $('#policy').html(policeOptionHTML); diff --git a/app/Views/policy_gmc_terms.php b/app/Views/policy_gmc_terms.php index f5b9b5ac..25b16341 100644 --- a/app/Views/policy_gmc_terms.php +++ b/app/Views/policy_gmc_terms.php @@ -105,8 +105,8 @@
- Yes - No + Yes + No
@@ -159,8 +159,8 @@
- Yes, waived off - No + Yes, waived off + No
@@ -206,8 +206,8 @@
- Yes, waived off - No
+ Yes, waived off + No
@@ -224,8 +224,8 @@
- Yes, waived off - No + Yes, waived off + No
@@ -235,8 +235,8 @@
- Yes, waived off - No + Yes, waived off + No
@@ -254,8 +254,8 @@
- Internal Covered - No
+ Internal Covered + No
@@ -324,8 +324,8 @@
- Yes - No + Yes + No
@@ -361,8 +361,8 @@
- Applicable - Not Applicable
+ Applicable + Not Applicable
@@ -370,8 +370,8 @@
- Yes - No
+ Yes + No
@@ -379,8 +379,8 @@
- Yes - No + Yes + No
@@ -398,8 +398,8 @@
- Yes - No + Yes + No
@@ -640,7 +640,7 @@ var grid_html = ''; var gmc_policy_type_id = $(this).attr('id'); - console.log(gmc_policy_type_id) + // console.log(gmc_policy_type_id) if(gmc_policy_type_id == 'GMC'){ @@ -657,7 +657,9 @@ var grid_html = ''; data: {client_policy_id: client_policy_id}, success: function(response) { console.log('response',response); - console.log('count', response.count); + + + // console.log('count', response.count); setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); @@ -684,6 +686,11 @@ var grid_html = ''; if (response) { + if ( response.emp_count_by_policy != 0) { + $('#btnGridSubmit1').hide(); + + $('#myButtonSpecialCondition').hide(); + } let jsonObject = JSON.parse(response.data); Object.keys(jsonObject).forEach(function(key) { if (key.includes("special_condition_label") || key.includes("special_condition_input")) { @@ -737,6 +744,53 @@ var grid_html = ''; } } + if(response.policy_addon == '3'){ + + $('.jodit-container').prop('disabled', true); + $('.waiverofpreexistingdiseases').prop('disabled', true); + $('#maternitycoverage').prop('disabled', true); + $('#twindelivery').prop('disabled', true); + $('#preandpostnatal').prop('disabled', true); + $('#babyday1cover').prop('disabled', true); + $('.9monthwaitingperiodwaived').prop('disabled', true); + $('#coverfromthedateofjoining').prop('disabled', true); + $('.waiverof1234thyearexclusions').prop('disabled', true); + $('.waiverof30dayswaitingperiod').prop('disabled', true); + $('#prehospitalizationcover').prop('disabled', true); + $('.congenitaldiseasesinternal').prop('disabled', true); + $('#copayzonewisecopay').prop('disabled', true); + $('#bioabsorbablestenttoriclensmultifocallens').prop('disabled', true); + $('#roomrentlimit').prop('disabled', true); + $('#proportionatedeductionclause').prop('disabled', true); + $('#nursingallowance').prop('disabled', true); + $('.ailmentcapping').prop('disabled', true); + $('#ambulancecharges').prop('disabled', true); + $('#airambulance').prop('disabled', true); + $('#familytransportationbenefit').prop('disabled', true); + $('.reasonableandcustomarycharges').prop('disabled', true); + $('.daycaretreatment').prop('disabled', true); + $('.ayudhtreatmentcover').prop('disabled', true); + $('#armdcovered').prop('disabled', true); + $('.suminsuredenhancement').prop('disabled', true); + $('#automaticsuminsuredreinstatement').prop('disabled', true); + $('#lasiksurgery').prop('disabled', true); + $('#midterminclusion').prop('disabled', true); + $('#capd').prop('disabled', true); + $('#organdonorexpenses').prop('disabled', true); + $('#moderntreatmentsasperirdai').prop('disabled', true); + $('#days_of_discharge').prop('disabled', true); + $('#days_from_dod').prop('disabled', true); + + setTimeout(function() { + var editor1 = new Jodit('#additionalsicknessbenefit'); + var editor2 = new Jodit('#Wellness'); + + editor1.setReadOnly(true); + editor2.setReadOnly(true); + + }, 3000); + } + } From 49c61d4e5dc510b999b17cd18fe5a91a9d47d7ae Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Wed, 17 Apr 2024 08:21:30 +0530 Subject: [PATCH 5/8] FIX_CLIENT_POLICY_DEPENDENT_ADDON_ALERT : AADHAVAN --- app/Views/client_policy.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index dd2edd52..908612fe 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -1005,6 +1005,10 @@ $('#policy_type').change(function() { $('#end_date').val(''); $('#base_policy').val('0'); + if($(this).val() == 3){ + toastr.warning('Please Change the Policy Terms after Submit the Policy!', 'warning'); + } + if ($(this).val() != '1' && $(this).val() != '0') { $('#base_policy_id').show(); @@ -1027,7 +1031,6 @@ $('#policy_type').change(function() { $('#base_policy_id').hide(); $('#base_policy').prop('required', false); } - }) From b6f3d97608453b187ad0cba4ba3cea5ec8b8447c Mon Sep 17 00:00:00 2001 From: sriramv Date: Wed, 17 Apr 2024 10:37:38 +0530 Subject: [PATCH 6/8] '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 7/8] 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 8/8] 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) {