diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 77dfe5ba..f516c231 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 d07567c0..b3b0160d 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,8 +558,6 @@ class EmployeeController extends AdminController return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200); } } - - // @param int $client_policy_id @@ -572,22 +571,29 @@ class EmployeeController extends AdminController } - 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 @@ -596,7 +602,6 @@ class EmployeeController extends AdminController // You can return an error response here echo $errorMessage; } - } @@ -641,6 +646,7 @@ class EmployeeController extends AdminController $emp_data['tbody'] = $excel_data; $html = view('view_file_upload_emp_list', $emp_data); + } else { $html = '
No Data Found
'; @@ -657,5 +663,25 @@ 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) + ->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/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index bc9cb6f5..1631a100 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); 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