FEAT_EMP_MODULE_FILE_VALIDATIONS

This commit is contained in:
velz 2024-02-26 13:31:17 +05:30
parent d8a2ea435b
commit d5180f495f
7 changed files with 163 additions and 37 deletions

View File

@ -65,14 +65,15 @@ $routes->group("/client", ["filter" => "authMVC"], function($routes){
$routes->group("/employee", ["filter" => "authMVC"], function($routes){
$routes->get("list", "EmployeeController::list");
$routes->get("search", "EmployeeController::search");
$routes->get("bulk-event-uplod", "EmployeeController::employeesUplodWithEvents");
$routes->post("bulk-event-uplod", "EmployeeController::employeesUplodWithEvents");
$routes->get("upload", "EmployeeController::employeesUplodWithEvents");
$routes->post("upload", "EmployeeController::employeesUplodWithEvents");
});
$routes->group("/util", ["filter" => "authMVC"], function($routes){
$routes->get("clients-with-policies", "EmployeeController::getClientWithPolicies");
$routes->get("police-by-insurer/(:any)", "ClientController::getPolicesByInsurerId/$1");
$routes->get("get-file-error/(:any)", "EmployeeController::getUploadedFileError/$1");
});
$routes->cli('processjob', 'JobWorker::processJob');

View File

@ -15,6 +15,9 @@ use App\Models\FileModel;
use App\Controllers\Jobs ;
use App\Controllers\JobWorker ;
use App\Controllers\Jobs\SubJob;
use App\Controllers\EmployeeServiceController;
use CodeIgniter\API\ResponseTrait;
@ -69,6 +72,27 @@ class EmployeeController extends AdminController
}
}
public function getUploadedFileError()
{
$file_id = $this->request->uri->getSegment(3);
// dd($segments[2]);
// die();
// $file_id = $this->request->getGet();
// echo $file_id;die();
$file = $this->fileModel->find($file_id);
// print_r($result);die();
if(!isset($file))
{
return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'no data found'], 200);
}
else
{
return $this->respond(['dataStatus' => true,'code' => 200,'data' => $file['reason']], 200);
}
}
//handles employee & dependent bulk upload with events like inception,addition,deletion, correction and SI enhancements
public function employeesUplodWithEvents()
{
@ -85,13 +109,25 @@ class EmployeeController extends AdminController
// print_r($this->request->getPost('policies'));
// print_r($this->request->getPost('upload-action-type'));
// die();
// $empServiceController = new EmployeeServiceController();
// $res = $empServiceController->fileFormatValidationController('12');
// // dd($res);
// if(isset($res) && count($res))
// {
// $failure_reason = json_encode((json_encode($res)));
// $this->fileModel->where('id', '12')->set(['status' => 'failed','reason' => $failure_reason])->update();
// dd($failure_reason);
// }
if($this->request->getMethod() == 'post')
{
//validate uploaded file
$filename = '';
$validated = $this->validate([
'emplist' => [
'uploaded[emplist]',
'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/pdf]',
'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]',
'max_size[emplist,8192]',
],
]);
@ -116,13 +152,16 @@ class EmployeeController extends AdminController
$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]);
//die();
$this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]);
//start validation process
//en dof validation process
return $this->respond(['dataStatus' => true,'code' => 200,'data' => 'file upload success'], 200);
}
$data['actions'] = ['inception' => 'Inception','addition' => 'Addition','deletion' => 'Deletion','si_enhancement' =>'SI Enhancement'];
$data['actions'] = ['inception' => 'Inception','addition' => 'Addition','deletion' => 'Deletion','correction' =>'Correction','si_enhancement' =>'SI Enhancement'];
$data['fileList'] = $this->fileModel
->select(['files.*','up.emp_code','up.first_name'])
->join('user_profiles up','files.created_by = up.id')

View File

@ -21,5 +21,4 @@ class FileModel extends Model
];
}

View File

@ -10,14 +10,14 @@
<div class="card">
<div class="card-body">
<!-- <div class="text-center"> -->
<form id="emp-upload-form" action="<?php echo base_url().'employee/bulk-event-uplod'?>" method="post">
<form id="emp-upload-form" action="<?php echo base_url().'employee/upload'?>" method="post">
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" id="csrf_token">
<div class="row">
<div class="col-md-4 col-xl-3">
<div class="form-group mb-3">
<label>Client</label> <br/>
<select name="client_id" class="form-control" id="client_id">
<option value="0">Select</option>
<select name="client_id" class="form-control" id="client_id" required>
<option value="">Select</option>
</select>
</div>
</div>
@ -25,7 +25,7 @@
<div class="form-group mb-3">
<label>Policy</label> <br/>
<select name="policy_id" class="form-control" id="policy_id">
<option value="0">Select</option>
<option value="">Select</option>
</select>
</div>
</div>
@ -33,8 +33,8 @@
<div class="col-md-4 col-xl-3">
<div class="form-group mb-3">
<label>Action</label> <br/>
<select name="upload-action-type" class="form-control" id="upload-action-type">
<option value="0">Select</option>
<select name="upload-action-type" class="form-control" id="upload-action-type" required>
<option value="">Select</option>
<?php
if(isset($actions) && count($actions))
{
@ -54,7 +54,7 @@
<div class="col-md-4 col-xl-3">
<div class="form-group mb-3">
<label>Choose file</label> <br/>
<input type="file" name="emplist" id="emplist">
<input type="file" name="emplist" id="emplist" accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet" required>
</div></div>
<div class="col-8" style="text-align: right;">
@ -94,9 +94,7 @@
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<h5>Overflowing text to show scroll behavior</h5>
<p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
</div>
</div>
</div><!-- /.modal-dialog -->
@ -115,35 +113,45 @@
//fetchClientPolicies();
//for modal pop up
$('#file-err-modal').on('show.bs.modal', function (event) {
// console.log(event.relatedTarget);
var myVal = $(event.relatedTarget).data('err');
$(this).find(".modal-body").text(myVal);
console.log(myVal);
var model_data = fetchFileError(myVal);
console.log('data received.');
console.log(model_data);
$(this).find(".modal-body").text(model_data);
});
//for form submit
$("#emp-upload-form").submit(function(event) {
event.preventDefault(); // Prevent default form submission
console.log('submit called');
// Check required fields
if (!$(this)[0].checkValidity()) {
// Form is invalid, handle error or notify user
console.log('failed');
var action_item = $('#upload-action-type').val();
var policy_id = $('#policy_id').val();
console.log('action_item - '+ action_item);
if(action_item != 'correction' && policy_id == "")
{
// $('#policy_id').attr('required', true);
// $('#policy_id').prop('title', 'plz choose policy');
// $('#policy_id').mouseover();
console.log('required');
alert('please choose policy for this uploaing event ');
return false;
}
console.log($(this));
console.log($(this)[0]);
else{
$('#policy_id').attr('required', false);
console.log('not required');
}
// Create FormData object
var formData = new FormData($(this)[0]);
for (var pair of formData.entries()) {
console.log(pair[0]+ ', ' + pair[1]);
}
// var formData = $("#emp-upload-form").serialize();
// var file = document.getElementById('emplist').files[0];
// formData.append('file', file);
console.log(pair[0]+ ', ' + pair[1]); }
console.log(formData);
// return false;
// AJAX request
$.ajax({
url: $(this).attr("action"),
type: "POST",
@ -156,9 +164,21 @@
},
success: function(response) {
// Request successful, handle response
$('#policy_id').attr('required', false);
console.log(response);
alert('success');
window.location.reload();
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
alert('sucess');
window.location.reload();
} else if(response.code === 404 && response.dataStatus === false){
console.error('no data found', response);
alert(response.message);
}
else
{
console.error('Something went wrong!');
alert('Something went wrong! Try later');
}
},
error: function(xhr, status, error) {
// Request failed, handle error
@ -223,6 +243,68 @@
}
function fetchFileError(file_id) {
$('#loader').show();
var apiURL = '<?php echo base_url();?>' + 'util/get-file-error/' + file_id;
console.log('fetchFileError');
console.log(apiURL);
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
// console.log(response.code);
// console.log(response.dataStatus);
// console.log(response.data);
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
try {
console.log(JSON.parse(JSON.parse(response.data)));
var file_error_data = JSON.parse(JSON.parse(response.data));
var file_error_html = "";
for (var rkey in file_error_data) {
// console.log(rkey);
var col = file_error_data[rkey]
console.log(col);
for (var ckey in col)
{
console.log(ckey);
console.log(col[ckey]);
var err_arr = col[ckey];
if(Array.isArray(err_arr)){
err_arr.forEach( function (item, index) {file_error_html += "Row "+ rkey +", "+ ckey+ " -" + item + "<br>"; } );
}
}
file_error_html += '-----------------------------------------------------------------------<br/>';
}
console.log(file_error_html);
$('#file-err-modal').find(".modal-body").html(file_error_html);
return file_error_html;
} catch (error)
{
console.error('Error parsing API response data:', error);
}
} else if(response.code === 404 && response.dataStatus === false){
console.error('no data found', response);
}
else
{
console.error('Something went wrong!');
}
},
error: function(xhr, status, error) {
console.error('Error fetching data from API:', error);
}
});
$('#loader').hide();
}
function appendClients(data) {
$.each(data, function(index, item) {
$('#client_id').append($('<option>', {
@ -234,7 +316,7 @@
function appendPolicies(data) {
$('#policy_id').empty();
$('#policy_id').append($('<option>', { value: '0',text: 'Select'}));
$('#policy_id').append($('<option>', { value: '',text: 'Select'}));
$.each(data, function(index, item) {
$('#policy_id').append($('<option>', {

View File

@ -21,15 +21,19 @@
<?php
if(isset($fileList))
{
foreach ($fileList as $key => $file) { ?>
foreach ($fileList as $key => $file) { //print_r((json_decode($file['reason'])));
// $reason = json_decode(($file['reason']));
// $reason = "{'date':'value data kbckl kcn/aksl'}";
// echo $reason;
?>
<tr>
<td><b><?php echo ($key + 1)?></b></td>
<td><?php echo $file['file_name']?></td>
<td><?php echo fancy_date_time_format($file['created_at']).' by <strong>'.$file['first_name'].'</strong>'?></td>
<td><?php echo $file['status']; if($file['status'] == 'failed')
{
echo '<span class="col-xl-3 col-lg-4 col-sm-6"> <i class="fe-alert-circle" data-toggle="modal" data-target="#file-err-modal" data-err="'.$file['reason'].'"></i></span>';
echo "<span class='col-xl-3 col-lg-4 col-sm-6'> <i class='fe-alert-circle' data-toggle='modal' data-target='#file-err-modal' data-err=".$file['id']."></i></span>";
}?></td>
</tr>
<?php }}?>

View File

@ -517,7 +517,7 @@
<a href="<?= base_url('/employee/list')?>">List</a>
</li>
<li>
<a href="<?= base_url('/employee/bulk-event-uplod')?>">Upload</a>
<a href="<?= base_url('/employee/upload')?>">Upload</a>
</li>
</ul>
</div>

View File

@ -16,6 +16,7 @@
"ext-mbstring": "*",
"google/apiclient": "^2.15.0",
"laminas/laminas-escaper": "^2.9",
"phpoffice/phpspreadsheet": "^2.0",
"psr/log": "^1.1"
},
"require-dev": {