CHANGE_HR_CHANGES

This commit is contained in:
VENKATESHWARAN 2026-01-05 14:45:20 +05:30
parent 3c5aef6563
commit 24bd1ef63d
9 changed files with 380 additions and 131 deletions

View File

@ -188,7 +188,7 @@ class EmployeeController extends AdminController
}
//handles employee & dependent bulk upload with events like inception,addition,deletion, correction and SI enhancements
public function employeesUplodWithEvents()
public function employeesUplodWithEvents($post_data = null)
{
// $empDataServiceController = new EmpDataServiceController();
@ -242,64 +242,85 @@ class EmployeeController extends AdminController
// $this->truncateFileData(747, 5) ;
// print_rr($this->cloneWorksheet());
// die();
if ($this->request->getMethod() == 'post') {
if (!empty($post_data) || $this->request->is('post') == 'post') {
//validate uploaded file
$filename = '';
$fileSize = '';
$validated = $this->validate([
'emplist' => [
'uploaded[emplist]',
'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]',
'max_size[emplist,16384]',
],
]);
if ($validated)
{
$avatar = $this->request->getFile('emplist');
if (!$avatar) {
$this->myLogger->logme("error", 'File not found');
if (empty($post_data)) {
$validated = $this->validate([
'emplist' => [
'uploaded[emplist]',
'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]',
'max_size[emplist,16384]',
],
]);
} else {
$validated = validateExcelFile($post_data['file_name']);
}
if ($validated) {
$avatar = isset($post_data['file_name']) ? $post_data['file_name'] : $this->request->getFile('emplist');
if (!$avatar) {
$this->myLogger->logme("error", 'File not found');
if (!empty($post_data)) {
return ['status' => false, 'message' => 'File not found'];
} else {
return $this->respond(['dataStatus' => false, 'code' => 400, 'message' => 'File not found'], 400);
}
}
$is_moved = $avatar->move(WRITEPATH . 'uploads/excel/');
if ($is_moved) {
$filename = $avatar->getName();
$fileSize = $avatar->getSize(); // File size in bytes
$fileSize = $fileSize / (1024 * 1024); // Convert to MB
// Handle successful upload, e.g., log success or further processing
$this->myLogger->logme("error", 'File move successful');
$is_moved = $avatar->move(WRITEPATH . 'uploads/excel/');
if ($is_moved) {
$filename = $avatar->getName();
$fileSize = $avatar->getSize(); // File size in bytes
$fileSize = $fileSize / (1024 * 1024); // Convert to MB
// Handle successful upload, e.g., log success or further processing
$this->myLogger->logme("error", 'File move successful');
} else {
$this->myLogger->logme("error", 'File move failed');
if (!empty($post_data)) {
return ['status' => false, 'message' => 'File move failed'];
} else {
$this->myLogger->logme("error", 'File move failed');
return $this->respond(['dataStatus' => false, 'code' => 500, 'message' => 'File move failed'], 500);
}
}
} else {
$this->myLogger->logme("error", 'Upload failed Invalid file');
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'Invalid file'], 404);
if (!empty($post_data)) {
return ['status' => false, 'message' => 'Invalid file'];
} else {
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'Invalid file'], 404);
}
}
//process post variable entry in file table
$loggedInUserID = get_session_userid();
// dd($loggedInUserID);
// $loggedInUserID = 8;
$loggedInUserID = $post_data['created_by'] ?? get_session_userid();
$client_id = $this->request->getPost('client_id');
$policy_id = $this->request->getPost('policy_id');
$branch_id = $this->request->getPost('branch_id');
$hr_file_id = $this->request->getPost('hr_file_id') ?? null;
$action = $this->request->getPost('upload-action-type');
$status = 'inprogress';
$client_id = isset($post_data['client_id']) ? $post_data['client_id'] : $this->request->getPost('client_id');
$policy_id = isset($post_data['policy_id']) ? $post_data['policy_id'] : $this->request->getPost('policy_id');
$branch_id = isset($post_data['client_branch_id']) ? $post_data['client_branch_id'] : $this->request->getPost('branch_id');
$action = isset($post_data['file_action']) ? $post_data['file_action'] : $this->request->getPost('upload-action-type');
if(empty($post_data)){
$hr_file_id = $this->request->getPost('hr_file_id') ?? null;
}else{
$hr_file_id = $post_data['hr_file_id'] ?? null ;
}
$file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action, 'client_branch_id' => $branch_id,'uploaded_by' => 1, 'hr_file_id' => $hr_file_id]); //here field policy_id have client_policy_id and not policy id from policy master
$hr_id = $post_data['created_by'] ?? null;
$status = 'inprogress';
$file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action, 'client_branch_id' => $branch_id, 'uploaded_by' => 1, 'hr_file_id' => $hr_file_id, 'hr_id' => $hr_id]); //here field policy_id have client_policy_id and not policy id from policy master
$this->myLogger->logme("error", '{file_id} uploaded success', ['file_id' => $file_id]);
if ($action == "all") {
$r = Jobs::addJob(['job_name' => 'excelMultieventFileFormateValidation', 'payload' => ['file_id' => $file_id]]);
$this->myLogger->logme("error", '{file_id} is greather than 1MB, validating with job queue', ['file_id' => $file_id]);
} else {
//start validation process
if ($fileSize < 1) // if file size less than 1
@ -309,7 +330,11 @@ class EmployeeController extends AdminController
$this->myLogger->logme("error", '{file_id} is less than 1MB, validating on the fly', ['file_id' => $file_id]);
//endof validation process
if (isset($result['error_summary']) && count($result['error_summary'])) {
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'file rejected with errors'], 200);
if(!empty($post_data)){
return ['status' => true, 'message' => 'file rejected with errors', 'file_id' => $file_id];
}else{
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'file rejected with errors'], 200);
}
}
} else //if file size greater than 1 add the file as job
{
@ -319,7 +344,11 @@ class EmployeeController extends AdminController
}
}
return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => 'file upload success'], 200);
if (!empty($post_data)) {
return ['status' => true, 'message' => 'File upload successs, Data validation is in-progress', 'file_id' => $file_id];
} else {
return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => 'file upload success'], 200);
}
}
$data['tab_name'] = 'View Inception';
@ -350,7 +379,7 @@ class EmployeeController extends AdminController
->select([
'files.id','files.file_name','files.created_by','files.created_at','files.is_active','files.status','files.client_id','files.policy_id','files.client_branch_id','files.action','files.uploaded_by',
'up.emp_code',
'up.first_name',
// 'up.first_name',
'c.short_name',
'cb.branch_name',
'cp.id as client_policy_id',
@ -358,8 +387,22 @@ class EmployeeController extends AdminController
'"0" as total',
'policy_type.policy_type' ,
'cp.policy_no' ,
"CASE
WHEN files.hr_id IS NOT NULL THEN
CONCAT(
(
SELECT lc.name
FROM level_contect lc
WHERE lc.id = files.hr_id
LIMIT 1
),
' (HR)'
)
ELSE up.first_name
END AS first_name
"
])
->join('user_profiles up', 'files.created_by = up.id')
->join('user_profiles up', 'files.created_by = up.id', 'left')
->join('client_policy cp', 'files.policy_id = cp.id', 'left')
->join('client_branch cb', 'files.client_branch_id = cb.id', 'left')
->join('policy_type', 'policy_type.id = cp.policy_type_id')
@ -435,14 +478,22 @@ class EmployeeController extends AdminController
}
}
public function getExcelFileErrors()
public function getExcelFileErrors($file_id, $retun_type = null)
{
$file_id = $this->request->uri->getSegment(3);
// $file_id = $this->request->uri->getSegment(3);
$empServiceController = new EmployeeServiceController();
// Render views and capture output
$result = $empServiceController->getExcelErrorData($file_id);
if($retun_type == 'api'){
if(!empty($result)){
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Error data feteched successfully', 'data' => $result], 200);
}else{
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to fetch error data', 'data' => []], 200);
}
}
if ($result != 0) {
$result['file_id'] = $file_id;

View File

@ -159,9 +159,9 @@ class EmployeeRestController extends AdminController
->where('employees.client_branch_id', $client_branch_id)
->where('employees.is_active', 1)
->where('employees.relationship', $relationship)
->where('employee_polices.status', ['active'])
->whereIn('employee_polices.status', ['active', 'expired'])
->where('employees.is_active', 1)
->where('employees.emp_status', ['active'])
->whereIn('employees.emp_status', ['active', 'expired'])
->first();
if (null !== $this->request->getGet('client_policy_id')) {
@ -4434,57 +4434,105 @@ 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'),
$post_data = [
'client_id' => $this->request->getPost('client_id') ?? null,
'client_branch_id' => $this->request->getPost('client_branch_id'),
'policy_id' => $this->request->getPost('policy_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'),
'file_name' => $this->request->getFile('file_name')
];
// print_r($post_data); die;
// Save into DB
$result = $this->hrFileUploadModel->insert($data);
if ($result) {
$this->giveNotificationToClientsAccountManager($data);
if(empty($post_data['client_id'])){
return $this->respondCreated(['status' => false, 'message' => 'Client is required', 'data' => []]);
}
return $this->respondCreated([
$client_data = $this->clientModel->where('id', $post_data['client_id'])->first();
// print_r($client_data); die;
if($client_data['hr_file_processed_by'] == 1){
$responce = $this->fileUploadInFilesTable($post_data);
}else{
$responce = $this->fileUploadInHrFileUploadTable($post_data);
}
return $this->respondCreated($responce);
} catch (\Exception $e) {
// return $this->failServerError($e->getMessage());
return $this->respondCreated(['status' => false, 'message' => $e->getMessage(), 'data' => []]);
}
}
public function fileUploadInHrFileUploadTable($post_data)
{
// Check file
$file = $post_data['file_name'];
if (!$file) {
return [
'status' => false,
'message' => "Invalid file or file not uploaded.",
'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_id' => $this->request->getPost('policy_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
$result = $this->hrFileUploadModel->insert($data);
if ($result) {
$this->giveNotificationToClientsAccountManager($data);
$response = [
'status' => true,
'message' => 'File uploaded successfully',
'data' => $data
]);
} catch (\Exception $e) {
return $this->failServerError($e->getMessage());
];
return $response;
}
}
public function fileUploadInFilesTable($post_data)
{
$employeeController = new EmployeeController();
$responce = $employeeController->employeesUplodWithEvents($post_data);
// print_r($responce); die;
if($responce['status']){
$file_data = $this->getDataFromHrFilesTable(['file_id' => $responce['file_id']]);
$responce['data'] = $file_data;
return $responce;
}else{
$responce['data'] = [];
return $responce;
}
}
@ -4643,17 +4691,48 @@ class EmployeeRestController extends AdminController
public function hrFileList()
{
try {
$request = service('request');
$search_data = $request->getGetPost() ?? []; // supports both GET and POST
$table = "";
// 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');
if(isset($search_data['hr_file_type']) && $search_data['hr_file_type'] == "CRM"){
$data = $this->getDataFromHrFileUploadTable($search_data);
$table = "hr_file_upload";
}else{
$client_data = $this->clientModel->where('id', $search_data['client_id'])->first();
if($client_data['hr_file_processed_by'] == 1){
$data = $this->getDataFromHrFileUploadTable($search_data);
$table = "hr_file_upload 2";
}else{
$data = $this->getDataFromHrFilesTable($search_data);
$table = "files";
}
}
$builder = $this->hrFileUploadModel
->select('
return $this->respond([
'status' => "success",
'message' => 'File list fetched successfully',
'data' => $data,
'table' => $table
]);
} catch (\Exception $e) {
return $this->failServerError($e->getMessage());
}
}
public function getDataFromHrFileUploadTable($search_data)
{
// 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');
$builder = $this->hrFileUploadModel
->select("
hr_file_upload.id,
hr_file_upload.client_id,
hr_file_upload.client_branch_id,
@ -4672,51 +4751,112 @@ class EmployeeRestController extends AdminController
WHEN f.status IS NULL
THEN hr_file_upload.status
ELSE CONCAT(UCASE(LEFT(f.status, 1)), LCASE(SUBSTRING(f.status, 2)))
END AS status
', false)
->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')
->join(
'(SELECT f1.*
END AS status,
'1' as file_error_status
", false)
->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')
->join(
'(SELECT f1.*
FROM files f1
WHERE f1.is_active = 1
ORDER BY f1.id DESC
LIMIT 1) f',
'f.hr_file_id = hr_file_upload.id',
'left'
);
'f.hr_file_id = hr_file_upload.id',
'left'
);
// Allowed filter keys
$filters = [
'client_id',
'client_branch_id',
'policy_id',
'policy_no',
'file_action',
'status',
'created_by'
];
// Allowed filter keys
$filters = [
'client_id',
'client_branch_id',
'policy_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);
}
// Apply filters dynamically
foreach ($filters as $key) {
$value = $search_data[$key] ?? null; // 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());
}
// Execute query
$data = $builder->get()->getResultArray();
if(!empty($data)){
return $data;
}
return [];
}
public function getDataFromHrFilesTable($search_data)
{
$file_download_base = base_url('util/download-file-list/');
$builder = $this->fileModel
->select("
files.id,
files.client_id,
files.client_branch_id,
files.policy_id,
cp.policy_no,
files.file_name,
files.action,
files.created_at,
files.created_by,
files.updated_at,
files.updated_by,
c.short_name,
cb.branch_name,
lc.name as first_name,
CONCAT(UCASE(LEFT(files.status, 1)), LCASE(SUBSTRING(files.status, 2))) as status,
CASE
WHEN status = 'failed' THEN 1
ELSE 0
END AS file_error_status,
CONCAT('{$file_download_base}', files.id, '/api') AS file_download_link
", false)
->join('clients c', 'files.client_id = c.id AND c.is_active = 1', 'left')
->join('client_branch cb', 'files.client_branch_id = cb.id AND cb.is_active = 1', 'left')
->join('client_policy cp', 'files.policy_id = cp.id AND cp.is_active = 1', 'left')
->join('level_contacts lc', 'files.hr_id = lc.id AND lc.contact_type = "client" AND lc.is_active = 1', 'left');
if (isset($search_data['policy_id']) && !empty($search_data['policy_id'])) {
$builder->where("files.policy_id", $search_data['policy_id']);
}
if (isset($search_data['created_by']) && !empty($search_data['created_by'])) {
$builder->where("files.hr_id", $search_data['created_by']);
}
if (isset($search_data['policy_no']) && !empty($search_data['policy_no'])) {
$builder->where("cp.policy_no", $search_data['policy_no']);
}
if (isset($search_data['client_id']) && !empty($search_data['client_id'])) {
$builder->where("files.client_id", $search_data['client_id']);
}
if (isset($search_data['file_id']) && !empty($search_data['file_id'])) {
$builder->where("files.id", $search_data['file_id']);
}
// Execute query
$data = $builder->get()->getResultArray();
if (!empty($data)) {
return $data;
}
return [];
}
public function hrFileUploadMasters()

View File

@ -940,6 +940,28 @@ if (!function_exists('getMimeTypeByFileName')) {
}
}
if (!function_exists('validateExcelFile')) {
function validateExcelFile($file)
{
$allowed = [
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.oasis.opendocument.spreadsheet'
];
// if ($file->getError() !== UPLOAD_ERR_OK) return 'Upload error';
// if ($file->getSize() > (16 * 1024 * 1024)) return 'File too large';
// if (!in_array($file->getClientMimeType(), $allowed, true)) return 'Invalid file type';
if ($file->getError() !== UPLOAD_ERR_OK) return false;
if ($file->getSize() > (16 * 1024 * 1024)) return false;
if (!in_array($file->getClientMimeType(), $allowed, true)) return false;
return true;
}
}
if (!function_exists('generate_ecard_download_link_based_on_tpa')) {
function generate_ecard_download_link_based_on_tpa($params) {

View File

@ -42,6 +42,7 @@ class ClientModel extends Model
"addon_subheading",
"parent_client_id",
"otp",
"hr_file_processed_by",
];

View File

@ -23,6 +23,7 @@ class FileModel extends Model
"updated_by",
"hr_file_id",
"is_comparison_skipped",
"hr_id",
];

View File

@ -142,6 +142,32 @@ input:checked + .slider:before {
</select>
</div>
<div class="form-group col-md-4">
<label>HR File Processed By <span class="text-danger">*</span></label>
<div class="d-flex align-items-center">
<div class="form-check form-check-inline mb-0" style="margin-right: -356px;">
<input class="form-check-input"
type="radio"
name="hr_file_processed_by"
id="hr_processed"
value="1" <?php echo(isset($client['hr_file_processed_by']) && $client['hr_file_processed_by'] == 1) ? 'checked' : '' ?>>
<label class="form-check-label" for="hr_processed">HR</label>
</div>
<div class="form-check form-check-inline mb-0">
<input class="form-check-input"
type="radio"
name="hr_file_processed_by"
id="account_manager_processed"
value="2"
<?php echo(isset($client['hr_file_processed_by']) && $client['hr_file_processed_by'] == 2) ? 'checked' : '' ?>>
<label class="form-check-label" for="account_manager_processed">Account Manager</label>
</div>
</div>
</div>
</div>
<hr>
</div>

View File

@ -851,4 +851,11 @@
}
$('#tickets-table tbody').on('click', 'td', function () {
const colIndex = this.cellIndex;
const rowIndex = this.parentElement.rowIndex - 1; // minus header
console.log('Row:', rowIndex, 'Column:', colIndex);
init();
});
</script>

View File

@ -622,7 +622,7 @@ function fetchFileError(file_id) {
file_error_html += (file_error_html != "" ?
"<a href ='<?php echo base_url()?>" +
"employee/excel_error/" + file_id +
"' target=_blank class='text-center'>click here to more details...</a>" : "");
"' target=_blank class='text-center'>Click here to more details...</a>" : "");
}
// console.log(file_error_html);
@ -1106,7 +1106,7 @@ function checkWellnessOnboardStatus(event)
console.log('check wellness response', response);
if(response.data && response.data != 0)
{
var btn_txt = 'click here to onboard ('+ response.data +') employees to Visit wellness';
var btn_txt = 'Click here to onboard ('+ response.data +') employees to Visit wellness';
$("#on_board_btn_txt").attr("data-id", response.data);
$('#on_board_btn_txt').text(btn_txt);
$('#onboard_div').show();

View File

@ -37,7 +37,8 @@
<!-- <div class="text-center"> -->
<form class="parsley-examples" id="hr_file_upload_search" >
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" id="csrf_token">
<input type="hidden" name="hr_file_type" value="CRM">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">