From 06b3d4f0e8cc6a7aecf89c29d5a55decf29c3a79 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 20 Aug 2025 09:42:28 +0530 Subject: [PATCH] CHANGES_HR file upload changes : GWM --- app/Config/Routes.php | 2 +- app/Controllers/EmployeeController.php | 131 ------------------- app/Controllers/EmployeeRestController.php | 138 ++++++++++++++++++++- 3 files changed, 138 insertions(+), 133 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ed44377..601c3d8 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -498,7 +498,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("hrFileList", "EmployeeRestController::hrFileList"); $routes->get("hrFileUploadMasters", "EmployeeRestController::hrFileUploadMasters"); $routes->get("hrFileDownload", "EmployeeRestController::hrFileDownload"); - $routes->post("hrFileUpload", "RestAuthenticationController::hrFileUpload"); + $routes->post("hrFileUpload", "EmployeeRestController::hrFileUpload"); }); $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index b754828..c9a0298 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -2828,137 +2828,6 @@ class EmployeeController extends AdminController - //-------------------------------------------------------------------------------------------- - public function hrFileUpload() - { - try { - // Check file - $file = $this->request->getFile('file_name'); - if (!$file->isValid()) { - return $this->failValidationErrors(['file_name' => 'Invalid or missing file']); - } - - // Upload folder path - $uploadPath = WRITEPATH . 'uploads/hr_files/'; - - // If directory not exists, create it - if (!is_dir($uploadPath)) { - mkdir($uploadPath, 0777, true); - } - - // New file name with timestamp - $newFileName = time() . '_' . $file->getRandomName(); - - // Move file - $file->move($uploadPath, $newFileName); - - // Prepare data - $data = [ - 'client_id' => $this->request->getPost('client_id'), - 'client_branch_id' => $this->request->getPost('client_branch_id'), - 'policy_no' => $this->request->getPost('policy_no'), - 'file_name' => $newFileName, - 'file_action' => $this->request->getPost('file_action'), - 'status' => $this->request->getPost('status'), - 'created_by' => $this->request->getPost('created_by'), - 'updated_by' => $this->request->getPost('created_by'), - ]; - - // Save into DB - $this->hrFileUploadModel->insert($data); - - return $this->respondCreated([ - 'status' => true, - 'message' => 'File uploaded successfully', - 'data' => $data - ]); - - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); - } - - } - - public function hrFileDownload($id = null) - { - try { - - $file_id = $this->request->getFile('id') ?? $id; - - // Find record - $record = $this->hrFileUploadModel->find($file_id); - - if (!$record) { - return $this->failNotFound("File record not found"); - } - - $uploadPath = WRITEPATH . 'uploads/hr_files/'; - $filePath = $uploadPath . $record['file_name']; - - if (!file_exists($filePath)) { - return $this->failNotFound("File not found on server"); - } - - // Force file download - return $this->response->download($filePath, null) - ->setFileName($record['file_name']); - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); - } - } - - public function hrFileList() - { - try { - $request = service('request'); - $builder = $this->hrFileUploadModel; - - // Allowed filter keys - $filters = [ - 'client_id', - 'client_branch_id', - 'policy_no', - 'file_action', - 'status', - 'created_by' - ]; - - // Apply filters dynamically - foreach ($filters as $key) { - $value = $request->getGetPost($key); // supports both GET and POST - if (!empty($value)) { - $builder->where($key, $value); - } - } - - // Fetch results - $data = $builder->findAll(); - - return $this->respond([ - 'status' => true, - 'message' => 'File list fetched successfully', - 'data' => $data - ]); - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); - } - } - - public function hrFileUploadMasters() - { - try { - //for inception upload - $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; - - return $this->respond([ - 'status' => true, - 'message' => 'File inception upload masters', - 'data' => $data - ]); - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); - } - } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index e6371f0..ba01672 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -32,7 +32,7 @@ use App\Models\ClientBranchModel; use App\Models\AuditHistoryModel; use App\Models\SIMappingModel; use App\Models\InsurerModel; - +use App\Models\HrFileUploadModel; use App\Controllers\Jobs ; use App\Controllers\JobWorker ; @@ -79,6 +79,7 @@ class EmployeeRestController extends AdminController protected $siMappingModel; protected $employeeHelper; protected $insurerModel; + protected $hrFileUploadModel; public function __construct() @@ -106,6 +107,7 @@ class EmployeeRestController extends AdminController $this->siMappingModel = new SIMappingModel(); $this->employeeHelper = new EmployeeHelper(); $this->insurerModel = new InsurerModel(); + $this->hrFileUploadModel = new HrFileUploadModel(); } @@ -3494,4 +3496,138 @@ class EmployeeRestController extends AdminController } + //-------------------------------------------------------------------------------------------- + public function hrFileUpload() + { + try { + // Check file + $file = $this->request->getFile('file_name'); + if (!$file->isValid()) { + return $this->failValidationErrors(['file_name' => 'Invalid or missing file']); + } + + // Upload folder path + $uploadPath = WRITEPATH . 'uploads/hr_files/'; + + // If directory not exists, create it + if (!is_dir($uploadPath)) { + mkdir($uploadPath, 0777, true); + } + + // New file name with timestamp + $newFileName = time() . '_' . $file->getRandomName(); + + // Move file + $file->move($uploadPath, $newFileName); + + // Prepare data + $data = [ + 'client_id' => $this->request->getPost('client_id'), + 'client_branch_id' => $this->request->getPost('client_branch_id'), + 'policy_no' => $this->request->getPost('policy_no'), + 'file_name' => $newFileName, + 'file_action' => $this->request->getPost('file_action'), + 'status' => $this->request->getPost('status'), + 'created_by' => $this->request->getPost('created_by'), + 'updated_by' => $this->request->getPost('created_by'), + ]; + + // Save into DB + $this->hrFileUploadModel->insert($data); + + return $this->respondCreated([ + 'status' => true, + 'message' => 'File uploaded successfully', + 'data' => $data + ]); + + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + + } + + public function hrFileDownload($id = null) + { + try { + + $file_id = $this->request->getFile('id') ?? $id; + + // Find record + $record = $this->hrFileUploadModel->find($file_id); + + if (!$record) { + return $this->failNotFound("File record not found"); + } + + $uploadPath = WRITEPATH . 'uploads/hr_files/'; + $filePath = $uploadPath . $record['file_name']; + + if (!file_exists($filePath)) { + return $this->failNotFound("File not found on server"); + } + + // Force file download + return $this->response->download($filePath, null) + ->setFileName($record['file_name']); + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + public function hrFileList() + { + try { + $request = service('request'); + $builder = $this->hrFileUploadModel; + + // Allowed filter keys + $filters = [ + 'client_id', + 'client_branch_id', + 'policy_no', + 'file_action', + 'status', + 'created_by' + ]; + + // Apply filters dynamically + foreach ($filters as $key) { + $value = $request->getGetPost($key); // supports both GET and POST + if (!empty($value)) { + $builder->where($key, $value); + } + } + + // Fetch results + $data = $builder->findAll(); + + return $this->respond([ + 'status' => true, + 'message' => 'File list fetched successfully', + 'data' => $data + ]); + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + public function hrFileUploadMasters() + { + try { + //for inception upload + $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; + + return $this->respond([ + 'status' => true, + 'message' => 'File inception upload masters', + 'data' => $data + ]); + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + + } \ No newline at end of file