diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 2377fc38..599236aa 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -182,6 +182,8 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->post('get_emp_history','EmployeeController::getEmpHistory'); }); + + $routes->group("/master", ["filter" => "authMVC"], function ($routes) { $routes->group("insurer", ["filter" => "authMVC"], function ($routes) { @@ -550,7 +552,16 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("claimView", "EmployeeRestController::claimView"); $routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData"); + //hr file upload api's + $routes->get("hrFileList", "EmployeeRestController::hrFileList"); + $routes->get("hrFileUploadMasters", "EmployeeRestController::hrFileUploadMasters"); + $routes->get("hrFileDownload", "EmployeeRestController::hrFileDownload"); + $routes->post("hrFileUpload", "EmployeeRestController::hrFileUpload"); + $routes->post("updateHrFileUploadData", "EmployeeRestController::updateHrFileUploadData"); + }); +$routes->get("hrFileUploadMasters", "EmployeeRestController::hrFileUploadMasters"); +$routes->post("hrFileList", "EmployeeRestController::hrFileList"); $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d8ec8b0e..6fc764b3 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -34,6 +34,7 @@ use App\Models\TicketMasterModel; use App\Models\TicketMessageModel; use App\Models\HRAccessControlModel; use App\Models\InsurerModel; +use App\Models\HrFileUploadModel; @@ -87,6 +88,7 @@ class EmployeeRestController extends AdminController protected $ticketController; protected $hrAccessControlModel; protected $insurerModel; + protected $hrFileUploadModel; public function __construct() @@ -118,6 +120,7 @@ class EmployeeRestController extends AdminController $this->ticketController = new TicketController(); $this->hrAccessControlModel = new HRAccessControlModel(); $this->insurerModel = new InsurerModel(); + $this->hrFileUploadModel = new HrFileUploadModel(); } @@ -3781,4 +3784,232 @@ class EmployeeRestController extends AdminController return $response->getBody(); } + + + //-------------------------------------------------------------------------------------------- + public function hrFileUpload() + { + try { + // Check file + $file = $this->request->getFile('file_name'); + if (!$file) { + return $this->response->setJSON([ + 'status' => false, + 'message' => "Invalid file or file not uploaded.", + 'data' => "No Data" + ]); + } + + // 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' => 'Yet to start', + '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 updateHrFileUploadData() + { + try { + $id = $this->request->getPost('id'); + + if (!$id) { + return $this->failValidationErrors('ID is required for update.'); + } + + // 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_action' => $this->request->getPost('file_action'), + 'status' => $this->request->getPost('status'), + 'updated_by' => $this->request->getPost('updated_by'), + ]; + + // Check if record exists + $record = $this->hrFileUploadModel->find($id); + if (!$record) { + return $this->failNotFound("Record with ID {$id} not found."); + } + + // Update record + $this->hrFileUploadModel->update($id, $data); + + return $this->respond([ + 'status' => true, + 'message' => 'File record updated successfully', + 'data' => $data + ], 200); + + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + + public function hrFileDownload($id = null) + { + try { + + $file_id = $this->request->getGet('id') ?? $id; + + // Find record + $record = $this->hrFileUploadModel->where('id',$file_id)->find(); + + // print_rr( $record);die; + + if (!$record) { + return $this->failNotFound("File record not found"); + } + + $uploadPath = WRITEPATH . 'uploads/hr_files/'; + $filePath = $uploadPath . $record[0]['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[0]['file_name']); + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + // public function hrFileList() + // { + // try { + // $request = service('request'); + // $builder = $this->hrFileUploadModel + // ->select('hr_file_upload.* , c.short_name , cb.branch_name , lc.name as first_name '); + + // // 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 + // $builder->join('clients c', 'c.id = hr_file_upload.client_id AND c.is_active = 1', 'left'); + // $builder->join('client_branch cb', 'cb.id = hr_file_upload.client_branch_id AND cb.is_active = 1', 'left'); + // $builder->join('level_contacts lc', 'lc.id = hr_file_upload.created_by AND lc.contact_type = "client" AND lc.is_active = 1', 'left'); + // $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 hrFileList() + { + try { + $request = service('request'); + + // Start builder from model + $builder = $this->hrFileUploadModel + ->select('hr_file_upload.* , c.short_name , cb.branch_name , lc.name as first_name') + ->join('clients c', 'c.id = hr_file_upload.client_id AND c.is_active = 1', 'left') + ->join('client_branch cb', 'cb.id = hr_file_upload.client_branch_id AND cb.is_active = 1', 'left') + ->join('level_contacts lc', 'lc.id = hr_file_upload.created_by AND lc.contact_type = "client" AND lc.is_active = 1', 'left'); + + // 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("hr_file_upload.$key", $value); + } + } + + // Execute query + $data = $builder->get()->getResultArray(); + + return $this->respond([ + 'status' => "success", + '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 diff --git a/app/Models/HrFileUploadModel.php b/app/Models/HrFileUploadModel.php new file mode 100644 index 00000000..e5e2a22b --- /dev/null +++ b/app/Models/HrFileUploadModel.php @@ -0,0 +1,34 @@ + + .select2-container .select2-selection--multiple .select2-selection__choice { + padding: 5px 7px 5px 0 !important; + color: #000000; + } + + +
| SNO | +File name | +Client | +Client Branch | +Policy | +Event | +User/Time | +Status | +Action | +
|---|---|---|---|---|---|---|---|---|
| + | + + | ++ | + | + | + | ' . $file['first_name'] . '' ?> | ++ | + |