myLogger = \Config\Services::mylogger(); $this->employeeModel = new EmployeeModel(); $this->employeePolicyModel = new EmployeePolicyModel(); $this->clientModel = new ClientModel(); $this->policesModel = new PolicesModel(); $this->relationshipModel = new RelationshipModel(); } public function getEmployeeProfile() { try { $emp_code = $this->request->getGet('emp_code'); if ($emp_code) { $relationship = 'self'; $employee = $this->employeeModel->where('emp_code', $emp_code) ->where('relationship', $relationship) ->first(); $result = $employee; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { $result = "No Match's"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } public function editEmployeeProfile() { try { $data = $this->request->getJSON(); if ($data) { $id = $data->id; $employee = $this->employeeModel->update($id, $data); if ($employee) { $result = []; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { $result = "No Match's"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); } } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } public function getEmployeeAndDependence() { try { $emp_code = $this->request->getGet('emp_code'); if ($emp_code) { $employee = $this->employeeModel->where('emp_code', $emp_code) ->findAll(); $result = $employee; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { $result = "No Match's"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } public function editEmployeeAndDependence() { try { $data = $this->request->getJSON(); if ($data) { $updatedCount = 0; foreach ($data as $item) { $id = $item->id; $employee = $this->employeeModel->update($id, (array)$item); if ($employee) { $updatedCount++; } } if ($updatedCount > 0) { $result = []; return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); } else { $result = "No Matches"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404); } } } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th], 500); } } public function addEmployeeAndDependence() { try { $data = $this->request->getJSON(); if ($data) { $updatedCount = 0; foreach ($data as $item) { $extractData['name'] = $item->name; $extractData['emp_code']= $item->emp_code; $extractData['email_corporate']=$item->email_corporate; $extractData['relationship_code']=$item->relationship_code; $extractData['mobile']=$item->mobile; $extractData['gender']=$item->gender; $extractData['dob']=$item->dob; $extractData['client_id']=$item->client_id; // print_r($extractData);die(); $employee = $this->employeeModel->insert($extractData); if ($employee) { $updatedCount++; } } if ($updatedCount > 0) { $result = []; return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); } else { $result = "No Matches"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404); } } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); } } public function getEmployeePolicy() { $id= 1; try { $keysToRemove = ["sum_insured","family_floater","corporatebuffer","family_floaters"]; $empPolicy = $this->employeeModel->getEmployeePolicy($id); if ($empPolicy) { $result = []; foreach ($empPolicy as $array) { $decodedArray = json_decode($array->Policy_Terms); $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove)); // $client_id =$array->ClientId; // $policy_id =$array->PolicyId; // $rackRate = $this->policesModel->getPolicySlabRatesForEmpOnboard($policy_id, $client_id); // $array->Policy_Terms = json_encode($refusingData); $array->Policy_Terms = $refusingData; $result[] = $array; } return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); } } public function relationshipList() { try { $relation_ships= $this->relationshipModel->findAll(); if(count($relation_ships) > 0){ return $this->respond(['status' => 'success','code' => 200,'data' => $relation_ships], 200); }else{ return $this->respond(['status' => 'success','code' => 200,'data' => "No Data..!"], 200); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); } } public function employeeUpload() { if ($this->request->getFile('file')) { // Load PHPExcel library require_once APPPATH . 'third_party/PHPExcel/PHPExcel.php'; // Load the uploaded file $file = $this->request->getFile('file'); // Load file into PHPExcel $inputFileType = PHPExcel_IOFactory::identify($file->getPathname()); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($file->getPathname()); // Get the active sheet $sheet = $objPHPExcel->getActiveSheet(); // Get the highest row number $highestRow = $sheet->getHighestRow(); // Assuming your data starts from the second row (after headers) for ($row = 2; $row <= $highestRow; $row++) { // Get cell values $name = $sheet->getCellByColumnAndRow(0, $row)->getValue(); $email = $sheet->getCellByColumnAndRow(1, $row)->getValue(); // Assuming you have more columns, adjust indexes accordingly // Store data into database (Example using CodeIgniter's database methods) $data = array( 'name' => $name, 'email' => $email, // Add more fields as necessary ); // Insert data into the database table $this->db->insert('employees', $data); } // Optionally, you can delete the uploaded file after processing unlink($file->getPathname()); // Optionally, you can redirect the user to a success page redirect('employee/success'); } else { // Handle case when no file was uploaded echo 'No file uploaded!'; } } }