CHANGE_ hr file upload : GWM

This commit is contained in:
Gowtham M 2025-08-22 14:32:50 +05:30
parent 9834fc4e7f
commit ca4101af91
5 changed files with 671 additions and 0 deletions

View File

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

View File

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

View File

@ -0,0 +1,34 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class HrFileUploadModel extends Model
{
protected $table = 'hr_file_upload';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
// Allowed fields
protected $allowedFields = [
'client_id',
'client_branch_id',
'policy_no',
'file_name',
'file_action',
'status',
'created_by',
'created_at',
'updated_by',
'updated_at'
];
// Automatically set timestamps
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
// Return type
protected $returnType = 'array';
}

View File

@ -0,0 +1,383 @@
<style>
.select2-container .select2-selection--multiple .select2-selection__choice {
padding: 5px 7px 5px 0 !important;
color: #000000;
}
</style>
<div class="tab-pane fade" id="HR-DOC-tab">
<div class="row">
<div class="col-xl-12">
<div id="accordion" class="mb-3">
<div class="card mb-1">
<h5 class="m-1">
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne" aria-expanded="true">
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</h5>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<!-- <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">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label>Client</label> <br />
<select name="client_id" class="form-control" id="client2" >
<option value="">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Branch</label> <br />
<select name="client_branch_id" class="form-control" id="client_branch_id2" >
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Policy</label> <br />
<select name="client_policy_id" class="form-control" id="policy2" >
<option value="">Select</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label>Event<span class="text-danger">*</span></label> <br />
<select name="file_action" class="form-control" id="event_type" required>
<option value="">Select</option>
<?php
if (isset($events) && count($events)) {
foreach ($events as $key => $action) {
echo "<option value='$key'" . ($key == "si_enhancement" ? " class='si-enhancement-option'" : "") . ">$action</option>";
}
}
?>
</select>
</div>
</div>
<div class="form-row" id="">
<div class="d-flex align-items-center justify-content-start" style="margin-top: 18px;">
<div class="form-group col-md-3">
<button type="submit" class="btn btn-primary waves-effect waves-light justify-content-end">Search</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row" id="hr_file_list">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="padding-bottom: 10px;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Files</h4>
</div>
</div>
<table class="table table-hover m-0 table-centered dt-responsive w-100" cellspacing="0"
id="hr_tickets_table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">SNO</th>
<th class="font-weight-medium">File name</th>
<th class="font-weight-medium">Client</th>
<th class="font-weight-medium">Client Branch</th>
<th class="font-weight-medium">Policy</th>
<th class="font-weight-medium">Event</th>
<th class="font-weight-medium">User/Time</th>
<th class="font-weight-medium">Status</th>
<th class="font-weight-medium">Action</th>
</tr>
</thead>
<tbody class="font-12">
<?php
if (isset($HRfileList)) { foreach ($fileList as $key => $file) { ?>
<tr>
<td><b><?php echo ($key + 1) ?></b></td>
<td title="<?php echo $file['file_name'] ?>">
<?php echo $file['file_name']?>
</td>
<td><?php echo $file['short_name'] ?></td>
<td><?php echo $file['branch_name'] ?></td>
<td><?php echo $file['policy_no'] ?></td>
<td><?php echo $file['file_action'] ?></td>
<td><?php echo change_date_format($file['created_at'],'Y-m-d H:i:s', 'd M Y h:i a') . ' by <strong>' . $file['first_name'] . '</strong>' ?></td>
<td><?php echo $file['status']; ?> </td>
<td> </td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
</div>
<!-- end row -->
</div>
<script>
var client_list = ''; // local variable for storing the client branch list
var branch_list = ''; // local variable for storing the client branch list
var policy_list = ''; // local variable for storing the client policy list
var branch_policy = '';
$(document).ready(function(){
//initialize the get client, branch, and policy
getClientAndBranchAndPolicy();
//client change to get the Client Branch
$('#client2').change(function(){
let client_id = $(this).val();
console.log('client_id', client_id);
if(branch_list != '') {
// console.log(branch_list[client_id]);
let data = branch_list[client_id];
appendBranch3(data);
}
})
//change the client branch than change the client policy
$('#client_branch_id2').change(function(){
let branch_id = $(this).val();
console.log("branch_id", branch_id);
if(policy_list != '' && branch_id != '') {
let data = policy_list[branch_id];
appendPolicy3(data);
}
});
})
$(document).ready(function() {
// Initialize select2
$("#client2").select2();
$("#policy2").select2();
$("#client_branch_id2").select2();
// Form submit event
$("#hr_file_upload_search").on("submit", function (e) {
e.preventDefault(); // stop normal form submit
let formData = $(this).serialize(); // serialize form with csrf
$.ajax({
url: "<?= base_url('hrFileList') ?>",
type: "POST",
data: formData,
dataType: "json",
beforeSend: function () {
// optional loader
$("#hr_tickets_table tbody").html(
"<tr><td colspan='9' class='text-center'>Loading...</td></tr>"
);
},
success: function (res) {
let tbody = "";
if (res.status === "success" && res.data.length > 0) {
$.each(res.data, function (index, file) {
tbody += `
<tr>
<td><b>${index + 1}</b></td>
<td id="${file.id}" class="reload truncate" title="${file.file_name}">${file.file_name}</td>
<td>${file.short_name ?? ""}</td>
<td>${file.branch_name ?? ""}</td>
<td>${file.policy_no ?? ""}</td>
<td>${file.file_action ?? ""}</td>
<td>${file.created_at} by <strong>${file.first_name ?? ""}</strong></td>
<td>${file.status}</td>
<td>
</td>
</tr>
`;
});
} else {
tbody = `<tr><td colspan="9" class="text-center">No records found</td></tr>`;
}
$("#hr_tickets_table tbody").html(tbody);
},
error: function (xhr, status, error) {
console.error("Error:", error);
$("#hr_tickets_table tbody").html(
`<tr><td colspan="9" class="text-center text-danger">Something went wrong</td></tr>`
);
},
});
});
});
// <div class="btn-group dropdown">
// <a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm"
// data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
// <div class="dropdown-menu dropdown-menu-right">
// <a href="${baseUrl}/hrFileUploadMasters?id=${file.id}" class="dropdown-item" style="color: #000;" aria-hidden="true" target="_blank" ><i class="mdi mdi-download mr-2 text-muted font-18 vertical-middle"></i>Download</a>
// </div>
// </div>
//featch client and branch and policy
function getClientAndBranchAndPolicy()
{
$.ajax({
url: '<?= base_url("/util/getClientAndBranchAndPolicy") ?>',
type: "GET",
dataType: 'json',
success: function(res) {
console.log('getClientAndBranchAndPolicy', res);
if(res.status == true){
client_list = res.client_data;
branch_list = res.branch_data;
policy_list = res.policy_data;
vehicle_list = res.vehicle_data;
unit_list = res.unit_data;
appendClients3(res.client_data);
}else{
console.log('No data found');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
// ------------ Append Functions are Below ----------------------------------------------------------------------------------
function appendClients3(data)
{
$('#client2').empty();
$('#client2').append($('<option>', {
value: '',
text: 'Select Client'
}));
$.each(data, function(index, item) {
let client_show_name = item.client_name;
if (item.client_type == 2) {
client_show_name = item.client_name + (item.dob ? ('- (' + item.dob + ' )' ) : '') + (item.pan ? ('- ' + item.pan ) : '');
// console.log(client_show_name);
}
var option = $('<option>', {
value: item.id,
text: client_show_name,
'data-cn': item.client_name,
'data-ct': item.client_type,
});
$('#client2').append(option);
});
}
function appendBranch3(data)
{
$('#client_branch_id2').empty();
$('#client_branch_id2').append($('<option>', {
value: '',
text: 'Select Branch'
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.branch_name
});
$('#client_branch_id2').append(option);
});
}
function appendPolicy3(data)
{
console.log('policy2', data);
console.log('policy2', $('#policy2'));
$('#policy2').empty();
$('#policy2').append($('<option>', {
value: '',
text: 'Select Policy',
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.policy_no,
text: item.policy_type + '-' + item.policy_no,
});
$('#policy2').append(option);
});
}
// ----------------------------------------------------------------------------------------------
$(document).ready(function() {
$('#hr_tickets_table').DataTable({
dom: "<'row'<'col-sm-0'f><'col-sm-9 text-right'B>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
"buttons": [{
"extend": 'csv',
"text": 'CSV',
"title": 'Employee-Upload-List',
"className": 'my_class',
"exportOptions": {
"columns": ':not(:last-child)'
},
}],
"initComplete": function(settings, json) {
$('.my_class').css({
"position": "relative",
"left": "79px"
});
},
language: {
search: "_INPUT_",
searchPlaceholder: "Search..."
},
paging: true,
});
});
</script>

View File

@ -25,10 +25,17 @@
<span class="d-none d-sm-inline-block">Insurer or TPA Data</span>
</a>
</li>
<li class="nav-item">
<a href="#HR-DOC-tab" data-toggle="tab" aria-expanded="true" class="nav-link px-3 py-2" id="hr_tab">
<span class="mr-1"><i class="fa fa-file"></i></span>
<span class="d-none d-sm-inline-block">HR Uploaded Files</span>
</a>
</li>
</ul>
<div class="tab-content">
<?php include('employee_upload.php'); ?>
<?php include('insurer_or_tpa_data.php'); ?>
<?php include('hr_file_upload.php'); ?>
</div>
</div>
</div>
@ -45,6 +52,11 @@
$('#kyc_tab').click();
}
if (window.location.hash === '#HR-DOC-tab') {
console.log('url hash :', window.location.hash)
$('#hr_tab').click();
}
})