CHANGES_HR file upload changes : GWM

This commit is contained in:
Gowtham M 2025-08-20 09:42:28 +05:30
parent cfbf7fada2
commit 06b3d4f0e8
3 changed files with 138 additions and 133 deletions

View File

@ -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");

View File

@ -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());
}
}

View File

@ -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());
}
}
}