myLogger = \Config\Services::mylogger(); $this->employeeModel = new EmployeeModel(); $this->employeePolicyModel = new EmployeePolicyModel(); $this->clientModel = new ClientModel(); $this->fileModel = new FileModel(); } public function list() { // $model = new UserModel(); $data = []; if(count($this->request->getGet())) { $filterData = $this->request->getGet(); $data['employees'] = $this->employeePolicyModel->getEmployeePolicy(client_id: $filterData['client_id'],policy_id: $filterData['policy_id']); } $this->myLogger->logme('error','list called'); $this->loadLayout('employee_list',$data); } public function getClientWithPolicies() { //echo $this->request->isAJAX();die(); $result = $this->clientModel->clientsWithPolicies(); // print_r($result);die(); if(!count($result)) { return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'no data found'], 200); } else { return $this->respond(['dataStatus' => true,'code' => 200,'data' => $result], 200); } } public function getUploadedFileError() { $file_id = $this->request->uri->getSegment(3); // dd($segments[2]); // die(); // $file_id = $this->request->getGet(); // echo $file_id;die(); $file = $this->fileModel->find($file_id); // print_r($result);die(); if(!isset($file)) { return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'no data found'], 200); } else { return $this->respond(['dataStatus' => true,'code' => 200,'data' => $file['reason']], 200); } } //handles employee & dependent bulk upload with events like inception,addition,deletion, correction and SI enhancements public function employeesUplodWithEvents() { // $job_details = new Jobs(); // $r = Jobs::addJob(['job_name' => 'add','payload' => ['a' => 10, 'b' => 35]]); // print_r($r);//die(); // // $jobWorker = new JobWorker(); // JobWorker::processJob($r); // die(); // echo $this->request->getMethod();die(); // print_r($this->request->getFiles('emplist'));print_r($this->request->getPost('emplist')); // print_r($this->request->getPost('clients')); // print_r($this->request->getPost('policies')); // print_r($this->request->getPost('upload-action-type')); // die(); // $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->excelFileFormatValidation(['file_id' => '38']); // dd($res); // $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->excelFileDataValidation(['file_id' => '38']); // dd($res); // $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: '2'); // dd($existing_famility_details); // $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->employeesSIEnhanceProcess(['file_id' => '38']); // dd($res); // $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->employeesCorrectionProcess(['file_id' => '37']); // // dd($res); // $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => '3']); // dd($res); // $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->employeeDisembark(['file_id' => '36']); // dd($res); // if(isset($res['error_summary']) && count($res['error_summary'])) // { // $res['error_summary'] = (array_count_values($res['error_summary'])); // $failure_reason = ((json_encode($res))); // // dd($failure_reason); // $this->fileModel->where('id', '12')->set(['status' => 'failed','reason' => $failure_reason])->update(); // dd($failure_reason); // } if($this->request->getMethod() == 'post') { //validate uploaded file $filename = ''; $validated = $this->validate([ 'emplist' => [ 'uploaded[emplist]', 'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]', 'max_size[emplist,8192]', ], ]); if ($validated) { $avatar = $this->request->getFile('emplist'); $is_moved = $avatar->move(WRITEPATH . 'uploads/excel/'); $filename = $avatar->getName(); } else { return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'invalid file'], 200); } //process post variable entry in file table $loggedInUserID = get_session_userid(); // $loggedInUserID = 8; $client_id = $this->request->getPost('client_id'); $policy_id = $this->request->getPost('policy_id'); $action = $this->request->getPost('upload-action-type'); $status = 'inprogress'; $file_id = $this->fileModel->insert(['file_name' => $filename,'client_id' => $client_id,'policy_id' => $policy_id,'created_by' => $loggedInUserID,'status' => $status,'action' => $action]);//here field policy_id have client_policy_id and not policy id from policy master $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); //start validation process $empServiceController = new EmployeeServiceController(); $result = $empServiceController->excelFileFormatValidation($file_id); //endof validation process if(isset($result['error_summary']) && count($result['error_summary'])) { return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'file rejected with errors'], 200); } return $this->respond(['dataStatus' => true,'code' => 200,'data' => 'file upload success'], 200); } $data['actions'] = ['inception' => 'Inception (Employee + Dependents)','addition' => 'Addition (Employee + Dependents)','dependent_addtion' => 'Dependent Addition (Only Dependents)','deletion' => 'Deletion','correction' =>'Correction','si_enhancement' =>'SI Enhancement']; $data['fileList'] = $this->fileModel ->select(['files.*','up.emp_code','up.first_name','pm.name as policy_name','c.short_name']) ->join('user_profiles up','files.created_by = up.id') ->join('client_policy cp','files.policy_id = cp.id') ->join('policies pm','cp.policy_id = pm.id') ->join('clients c','files.client_id = c.id and files.client_id = cp.client_id') ->where('files.created_by',get_session_userid())->orderBy('files.created_at','desc')->findAll(); // dd($data['fileList']);die(); if($this->request->getMethod() == "get") { $this->loadLayout('employee_upload',$data); } } public function getExcelFileErrors() { $file_id = $this->request->uri->getSegment(3); $file = $this->fileModel->find($file_id); $error_data = json_decode($file['reason']); $file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name']; //check the file exist or not if(!file_exists($file_name_with_path)) { $error_message = "File not found"; $this->myLogger->logme('error',($error_message . ' for file id ' . $file_id)); } $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); $sheet = $spreadsheet->getActiveSheet(); $highestRowAndColumn = $sheet->getHighestRowAndColumn(); $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); $data['excel_header'] = $excel_data[0]; unset($excel_data[0]); $data['excel_data'] = $excel_data; echo '
';

            // foreach ($error_data->error_data as $key => $value) {
            //     print_r($excel_data[$key]);
            //     foreach($value as $key2 => $value2){
            //         // echo '
';
            //         // print_r($excel_data[$key][$value2->col_idx]);
            //     }
                
            // }
            $finalArray = [];
            foreach ($error_data->error_data as $key => $value) {
                foreach($value as $key2 => $value2){
                    $error_data = $value2->error;

                    echo '
';
                    // print_r([$value2->col_idx]);
                    $excel_data[$key][$value2->col_idx] = $error_data;
                    // print_r($excel_data[$key]);
                   
                }
                // print_r($excel_data[$key]);
               // array_push($finalArray, $excel_data);
            }

            print_r($excel_data);

 die; 
           

        //  echo '###################################################################### 
'; // print_r($excel_data); // echo '######################################################################
'; // print_r($error_data->error_data); die; $headerData['page_name'] = 'Excel Error'; echo view('layout/header', $headerData); echo view('excel_errors', $data); echo view('layout/footer'); } }