From 45afb0ec90e35e2307d8511812718be1872f8c20 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Mon, 18 Aug 2025 17:21:03 +0530 Subject: [PATCH] CHANGE_ HR file upload rest api : GWM --- app/Config/Routes.php | 5 + app/Controllers/EmployeeController.php | 142 +++++++++++++++++++++++++ app/Models/HrFileUploadModel.php | 34 ++++++ 3 files changed, 181 insertions(+) create mode 100644 app/Models/HrFileUploadModel.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4a21b1c..ed44377 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -495,6 +495,11 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); $routes->post("logHrActivity", "RestAuthenticationController::logHrActivity"); + $routes->get("hrFileList", "EmployeeRestController::hrFileList"); + $routes->get("hrFileUploadMasters", "EmployeeRestController::hrFileUploadMasters"); + $routes->get("hrFileDownload", "EmployeeRestController::hrFileDownload"); + $routes->post("hrFileUpload", "RestAuthenticationController::hrFileUpload"); + }); $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 28a76c4..b754828 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -27,6 +27,7 @@ use App\Models\ClientDepositModel; use App\Models\PolicyPremium2Model; use App\Models\AuditHistoryModel; use App\Models\UserModel; +use App\Models\HrFileUploadModel; @@ -73,6 +74,7 @@ class EmployeeController extends AdminController protected $PolicyPremium2Model; protected $auditHistory; protected $userModel; + protected $hrFileUploadModel; public function __construct() @@ -96,6 +98,7 @@ class EmployeeController extends AdminController $this->PolicyPremium2Model = new PolicyPremium2Model(); $this->auditHistory = new AuditHistoryModel(); $this->userModel = new userModel(); + $this->hrFileUploadModel = new HrFileUploadModel(); } public function list() @@ -2825,4 +2828,143 @@ 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/Models/HrFileUploadModel.php b/app/Models/HrFileUploadModel.php new file mode 100644 index 0000000..e5e2a22 --- /dev/null +++ b/app/Models/HrFileUploadModel.php @@ -0,0 +1,34 @@ +