FEAT_COPY_POLICY
This commit is contained in:
parent
1231e28e99
commit
e1def8e953
@ -499,6 +499,8 @@ $routes->group("employeeRest", ['filter' => ['appSignature' , 'authJWT'] ], func
|
||||
$routes->get("hrFileDownload", "EmployeeRestController::hrFileDownload");
|
||||
$routes->post("hrFileUpload", "EmployeeRestController::hrFileUpload");
|
||||
|
||||
$routes->get("copyActiveEmployeeAndDependentDetails", "EmployeeRestController::copyActiveEmployeeAndDependentDetails");
|
||||
|
||||
});
|
||||
|
||||
$routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($routes) {
|
||||
|
||||
@ -3682,154 +3682,248 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
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' => $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
|
||||
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"
|
||||
]);
|
||||
|
||||
} 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->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());
|
||||
|
||||
// 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 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);
|
||||
|
||||
}
|
||||
|
||||
public function hrFileDownload($id = null)
|
||||
{
|
||||
try {
|
||||
|
||||
$file_id = $this->request->getGet('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());
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadSampleExcel()
|
||||
{
|
||||
$employeeController = new EmployeeController();
|
||||
$file_path = $employeeController->downloadSampleExcelFile('enrollment', 1);
|
||||
if(empty($file_path)){
|
||||
return $this->respond(['status' => "success", 'code' => 404, 'data' => "", "message" => "Sample file not avilable"], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => "success", 'code' => 200, 'data' => $file_path], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// copy the active enrolled employee data
|
||||
public function copyActiveEmployeeAndDependentDetails()
|
||||
{
|
||||
$received_payload = $this->request->getGet();
|
||||
$client_id = $received_payload['client_id'] ?? null;
|
||||
$emp_code = $received_payload['emp_code'] ?? null;
|
||||
$new_client_policy_id = $received_payload['new_client_policy_id'] ?? null;
|
||||
|
||||
if (empty($client_id)) {
|
||||
return $this->respond(['status' => "failed", 'code' => 404, 'message' => "client_id is required"], 200);
|
||||
}
|
||||
|
||||
if (empty($new_client_policy_id)) {
|
||||
return $this->respond(['status' => "failed", 'code' => 404, 'message' => "client_policy_id is required"], 200);
|
||||
}
|
||||
|
||||
if (empty($emp_code)) {
|
||||
return $this->respond(['status' => "failed", 'code' => 404, 'message' => "emp_code is required"], 200);
|
||||
}
|
||||
|
||||
$client_policy_data = $this->clientPolicyModel
|
||||
->where('is_active', 1)
|
||||
->where('client_id', $client_id)
|
||||
->where('id', $new_client_policy_id)
|
||||
->whereIn('policy_type_id', [2, 3, 4, 5])
|
||||
->first();
|
||||
|
||||
if (empty($client_policy_data)) {
|
||||
return $this->respond(['status' => "failed", 'code' => 404, 'message' => "Policy data not found", 'data' => []], 200);
|
||||
}
|
||||
|
||||
$policy_terms = $client_policy_data['policy_terms'] ?? null;
|
||||
|
||||
if (empty($policy_terms)) {
|
||||
return $this->respond(['status' => "failed", 'code' => 404, 'message' => "Policy terms not found", 'data' => []], 200);
|
||||
}
|
||||
|
||||
$policy_terms = json_decode($policy_terms, true);
|
||||
|
||||
$family_floaters = $policy_terms['family_floaters'];
|
||||
|
||||
$empData = $this->employeeModel
|
||||
->where('emp_code', $emp_code)
|
||||
->where('client_id', $client_id)
|
||||
->where('emp_status', 'enrolled')
|
||||
->where('is_active', 1)
|
||||
->findAll();
|
||||
|
||||
if (empty($empData)) {
|
||||
return $this->respond(['status' => "failed", 'code' => 404, 'message' => "employee data not found", 'data' => []], 200);
|
||||
}
|
||||
|
||||
$floters = $this->FloterConvertion($family_floaters);
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($floters as $familyFloatesValue) {
|
||||
|
||||
$dependent = preg_replace('/\d/', '', $familyFloatesValue);
|
||||
|
||||
if (count($empData)) {
|
||||
foreach ($empData as $key => $value) {
|
||||
if ($value['family_floater_key'] === $dependent) {
|
||||
|
||||
$temp['is_value_exist'] = true;
|
||||
$temp['data']['family_floater_key'] = $familyFloatesValue;
|
||||
$temp['data']['employee_id'] = $value['id'];
|
||||
$temp['data']['relationship'] = $value['relationship'];
|
||||
$temp['data']['name'] = $value['name'];
|
||||
$temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']);
|
||||
$temp['data']['client_policy_id'] = $new_client_policy_id;
|
||||
$temp['data']['form_type'] = $dependent;
|
||||
$temp['data']['basic_cover_si'] = null;
|
||||
|
||||
|
||||
$temp['data']['age_validation'] = $this->getAgeRange($policy_terms, $familyFloatesValue);
|
||||
|
||||
|
||||
array_push($data, $temp);
|
||||
unset($empData[$key]);
|
||||
$floters = array_diff($floters, [$familyFloatesValue]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadSampleExcel()
|
||||
{
|
||||
$employeeController = new EmployeeController();
|
||||
$file_path = $employeeController->downloadSampleExcelFile('enrollment', 1);
|
||||
if(empty($file_path)){
|
||||
return $this->respond(['status' => "success", 'code' => 404, 'data' => "", "message" => "Sample file not avilable"], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => "success", 'code' => 200, 'data' => $file_path], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!empty($data)){
|
||||
return $this->respond(['status' => "succese", 'code' => 200, 'data' => $data], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => "failed", 'code' => 404, 'message' => "No data found", 'data' => []], 200);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user