Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
af6f5eb087
@ -73,8 +73,8 @@ $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");
|
||||
});
|
||||
|
||||
|
||||
@ -152,9 +152,10 @@ $routes->group("/master", ["filter" => "authMVC"], function($routes){
|
||||
|
||||
|
||||
$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("kyc-other-docs-delete/(:any)", "ClientController::deleteClientKycOtherDocs/$1");
|
||||
$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->get("kyc-other-docs-delete/(:any)", "ClientController::deleteClientKycOtherDocs/$1");
|
||||
$routes->get("policy-premium", "ClientController::getpolicyGridData/$1");
|
||||
});
|
||||
|
||||
|
||||
@ -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')
|
||||
|
||||
188
app/Controllers/EmployeeServiceController.php
Normal file
188
app/Controllers/EmployeeServiceController.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
||||
use App\Models\EmployeeModel;
|
||||
use App\Models\EmployeePolicyModel;
|
||||
use App\Models\ClientModel;
|
||||
use App\Models\FileModel;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
|
||||
class EmployeeServiceController extends AdminController
|
||||
{
|
||||
|
||||
protected $myLogger;
|
||||
protected $employeeModel;
|
||||
protected $employeePolicyModel;
|
||||
protected $clientModel;
|
||||
protected $fileModel;
|
||||
protected $general_relationships = ['self' => ['name' => 'Self', 'sex' => 'M','age_min' => 18,'age_max' => null], 'spouse' => ['name' => 'Spouse', 'sex' => 'F','age_min' => 18,'age_max' => null], 'son' => ['name' => 'Son', 'sex' => 'M','age_min' => null,'age_max' => 25], 'daughter' => ['name' => 'Daughter', 'sex' => 'F','age_min' => null,'age_max' => 25], 'father' => ['name' => 'Father', 'sex' => 'M','age_min' => 18,'age_max' => null], 'mother' => ['name' => 'Mother', 'sex' => 'F','age_min' => 18,'age_max' => null], 'father-in-law' => ['name' => 'Father in Law', 'sex' => 'M','age_min' => 18,'age_max' => null], 'mother-in-law' => ['name' => 'Mother in Law', 'sex' => 'F','age_min' => 18,'age_max' => null]];
|
||||
|
||||
protected $inception_excel_columns = ['sno' => ['col_idx' => 0,'col_cell_name' => 'A','col_name' => 'S.No','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'emp_id' => ['col_idx' => 1,'col_cell_name' => 'B','col_name' => 'EMP ID','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'name_of_emp_dep' => ['col_idx' => 2,'col_cell_name' => 'C','col_name' => 'NAME OF EMP/DEP','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'dob' => ['col_idx' => 3,'col_cell_name' => 'D','col_name' => 'DOB','is_mandatory' => true,'data_type' => 'str','format' => 'd-M-Y','allowed_values' => null,'custom' => 'check_dob_diff','params' => ['row','relationship']],'sex' => ['col_idx' => 4,'col_cell_name' => 'E','col_name' => 'SEX','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => ['M','F']],'relationship' => ['col_idx' => 5,'col_cell_name' => 'F','col_name' => 'RELATIONSHIP','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_relationship','params' => ['row','relationship']],'basic_cover_si' => ['col_idx' => 6,'col_cell_name' => 'G','col_name' => 'BASIC COVER SI','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'doj' => ['col_idx' => 7,'col_cell_name' => 'H','col_name' => 'DOJ','is_mandatory' => 'custom','data_type' => 'str','format' => 'd-M-Y','allowed_values' => null,'custom' => 'check_doj','params' => ['row']],'basic_pay' => ['col_idx' => 8,'col_cell_name' => 'I','col_name' => 'Basic Pay','is_mandatory' => 'custom','data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_basic_pay','params' => ['row']],'band_grade' => ['col_idx' => 9,'col_cell_name' => 'J','col_name' => 'Band/Grade','is_mandatory' => 'custom','data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_employee_band','params' => ['row']],'designation' => ['col_idx' => 10,'col_cell_name' => 'K','col_name' => 'Designation','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'phone' => ['col_idx' => 11,'col_cell_name' => 'L','col_name' => 'Phone','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'email' => ['col_idx' => 12,'col_cell_name' => 'M','col_name' => 'Email','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'pre_existing_ailments' => ['col_idx' => 13,'col_cell_name' => 'N','col_name' => 'PRE EXISTING AILMENTS','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => ['0','1']]];
|
||||
public function __construct()
|
||||
{
|
||||
// helper('utility');
|
||||
set_session_context('EmployeeService');
|
||||
$this->myLogger = \Config\Services::mylogger();
|
||||
$this->employeeModel = new EmployeeModel();
|
||||
$this->employeePolicyModel = new EmployeePolicyModel();
|
||||
$this->clientModel = new ClientModel();
|
||||
$this->fileModel = new FileModel();
|
||||
}
|
||||
|
||||
public function fileFormatValidationController($file_id)
|
||||
{
|
||||
helper('excel_util_helper');
|
||||
//get file name
|
||||
// check_dob_diff('4-APr-1990');die();
|
||||
$file = $this->fileModel->find($file_id);
|
||||
// dd($file);
|
||||
$return = [];
|
||||
if(!isset($file))
|
||||
{
|
||||
//file not found in DB
|
||||
return array('status' => false, 'msg' => 'file not found in DB');
|
||||
}
|
||||
$file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name'];
|
||||
|
||||
//check physical file
|
||||
if(!file_exists($file_name_with_path))
|
||||
{
|
||||
//file not found update status and reason
|
||||
$this->fileModel->where('id', $file_id)->set(['status' => 'failed','reason' => 'file not found'])->update();
|
||||
return array('status' => false, 'msg' => 'file not found');
|
||||
}
|
||||
|
||||
//start validation process
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
|
||||
// $highestRow = $sheet->getHighestDataRow(); // 1048576, should be 2
|
||||
// $highestColumn = $sheet->getHighestDataColumn(); // L, should be B
|
||||
// print_r($highestRowAndColumn);
|
||||
// echo $highestRow;echo ' - ' . $highestColumn;
|
||||
$excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
|
||||
// $data = array_filter($data);
|
||||
// echo '<pre>';
|
||||
// dd($excel_data);
|
||||
// echo "</pre>";die();
|
||||
// foreach ($excel_data as $key => $value)
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
|
||||
$columns_to_check = [];
|
||||
if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; }
|
||||
|
||||
//check no of columns in excel
|
||||
$total_defined_columns = count($columns_to_check);
|
||||
$excel_columns = ($excel_data[0]);
|
||||
// var_dump($excel_columns);die();
|
||||
$excel_columns_count = count($excel_columns);
|
||||
if($total_defined_columns != $excel_columns_count)
|
||||
{
|
||||
//columns count mismatch
|
||||
$message = "columns count mismatch. Expected - $total_defined_columns and received - $excel_columns";
|
||||
echo $message;
|
||||
$this->myLogger->logme('error',($message . ' for file id ' . $file_id));
|
||||
//$model->where('id', $file_id)->set(['status' => 'failed','reason' => $message])->update();
|
||||
return array('status' => false, 'msg' => $message);
|
||||
}
|
||||
|
||||
|
||||
//check columns order in excel
|
||||
$column_count_res = check_columns_count($columns_to_check,$excel_columns);
|
||||
|
||||
if(isset($column_count_res) && count($column_count_res))
|
||||
{
|
||||
//columns count mismatch
|
||||
$message = implode("\n", $column_count_res);
|
||||
echo $message;
|
||||
$this->myLogger->logme('error',($message . ' for file id ' . $file_id));
|
||||
// $model->where('id', $file_id)->set(['status' => 'failed','reason' => $message])->update();
|
||||
return array('status' => false, 'msg' => $message);
|
||||
}
|
||||
|
||||
//start other checks
|
||||
$result = [];
|
||||
$keys = array_keys($this->inception_excel_columns);
|
||||
// print_r($keys);die();
|
||||
|
||||
//remove header
|
||||
unset($excel_data[0]);
|
||||
$relationship = $this->general_relationships;
|
||||
foreach ($excel_data as $row_key => $row)
|
||||
{
|
||||
|
||||
//1. avoid empty rows
|
||||
if(check_row_is_empty_or_null($row))
|
||||
{
|
||||
break;
|
||||
}
|
||||
//iterate each row
|
||||
foreach ($row as $col_key => $col)
|
||||
{
|
||||
//mandatory check
|
||||
if(isset($this->inception_excel_columns[$keys[$col_key]]['custom']))
|
||||
{
|
||||
$custom_function = $this->inception_excel_columns[$keys[$col_key]]['custom'];
|
||||
// echo $custom_function;
|
||||
|
||||
$binding_params = $this->inception_excel_columns[$keys[$col_key]]['params'];
|
||||
|
||||
//convert string params into PHP variables
|
||||
// Create an array of variables to pass custom helper funcitons
|
||||
$param_values = [];
|
||||
foreach($binding_params as $bkey => $bparam) { $param_values[] = ($$bparam); }
|
||||
// dd(($param_values));//die();
|
||||
$res = call_user_func_array($custom_function,$param_values);
|
||||
// print_r($res['status']);die();
|
||||
if($res['status'] === false) { $result[$row_key][$keys[$col_key]][] = $res['error']; }
|
||||
|
||||
}
|
||||
|
||||
if($this->inception_excel_columns[$keys[$col_key]]['is_mandatory'] === true)
|
||||
{
|
||||
if($col == "" || $col == NULL) { $result[$row_key][$keys[$col_key]][] = 'value is mandatory'; }
|
||||
}
|
||||
|
||||
//format check
|
||||
if(isset($this->inception_excel_columns[$keys[$col_key]]['format']))
|
||||
{
|
||||
$format_error = check_excel_date_format($col,$this->inception_excel_columns[$keys[$col_key]]['format']);
|
||||
if(!$format_error['status'])
|
||||
{
|
||||
$result[$row_key][$keys[$col_key]][] = $format_error['error'];
|
||||
}
|
||||
}
|
||||
|
||||
//allowed values check
|
||||
if(isset($this->inception_excel_columns[$keys[$col_key]]['allowed_values']) && is_array($this->inception_excel_columns[$keys[$col_key]]['allowed_values']))
|
||||
{
|
||||
$allowed_values = $this->inception_excel_columns[$keys[$col_key]]['allowed_values'];
|
||||
if(!in_array($col,$allowed_values))
|
||||
{
|
||||
$result[$row_key][$keys[$col_key]][] = "Value not allowed: Expected ".implode(",",$allowed_values)." and received $col";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
159
app/Helpers/excel_util_helper.php
Normal file
159
app/Helpers/excel_util_helper.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
if (!function_exists('check_columns_count')) {
|
||||
function check_columns_count($definedColumns,$excelColumns)
|
||||
{
|
||||
$mismatchedColumns = [];
|
||||
|
||||
foreach ($definedColumns as $colName => $definedCol) {
|
||||
$definedColIdx = $definedCol['col_idx'];
|
||||
$definedColName = $definedCol['col_name'];
|
||||
|
||||
if ($excelColumns[$definedColIdx] !== $definedColName) {
|
||||
$mismatchedColumns[] = "Column order conflict. Column order no ".($definedColIdx + 1)." expected : ".$definedColName." and received : ".$excelColumns[$definedColIdx];
|
||||
}
|
||||
}
|
||||
|
||||
return $mismatchedColumns;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('check_row_is_empty_or_null')) {
|
||||
|
||||
function check_row_is_empty_or_null($arr) {
|
||||
unset($arr[0]);// unset SNO in the array, becoz we need to check only datapoints are empty not SNo, it may added by accidentally
|
||||
foreach ($arr as $item) {
|
||||
if ($item !== null && !empty($item)) {
|
||||
return false; // If any item is not empty or not null, return false
|
||||
}
|
||||
}
|
||||
return true; // If all items are empty or null, return true
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_excel_date_format')) {
|
||||
|
||||
function check_excel_date_format($dateString,$format)
|
||||
{
|
||||
|
||||
if($dateString == ""){ return array('status' => true); }
|
||||
$date = DateTime::createFromFormat('d-M-Y', $dateString);
|
||||
|
||||
if ($date !== false && !is_array($date::getLastErrors())) {
|
||||
return array('status' => true);
|
||||
} else {
|
||||
return array('status' => false,'error' => "wrong date format: Expected 'd-M-Y' and received $dateString");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!function_exists('check_relationship'))
|
||||
{
|
||||
function check_relationship($row,$relationship)
|
||||
{
|
||||
// print_r($col);print_r($relationship);
|
||||
// echo '<br>';
|
||||
if($row[5] != null && $row[4] != null)
|
||||
{
|
||||
$slug = \Config\Services::slug();
|
||||
$col = $slug->slugify($row[5]);
|
||||
// echo $col;die();
|
||||
if($col != 'self' && $col != 'spouse')
|
||||
{
|
||||
if($relationship[ $col ]['sex'] != $row[4])
|
||||
{
|
||||
$error = "Gender relationship conflict: Expected ".$relationship[ $col ]['sex'].", received $row[4]";
|
||||
return array('status' => false,'error' => $error);
|
||||
}
|
||||
|
||||
}
|
||||
return array('status' => true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array('status' => false,'error' => 'Rule Conflict: Both Relationship or Gender required');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!function_exists('check_doj'))
|
||||
{
|
||||
function check_doj($row)
|
||||
{
|
||||
$slug = \Config\Services::slug();
|
||||
$relationship = $slug->slugify($row[5]);
|
||||
// echo $relationship;echo $row[7];
|
||||
if($relationship == 'self' && $row[7] == "") { return array('status' => false,'error' => "DOJ mandantory for self"); }
|
||||
return array('status' => true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!function_exists('check_employee_band'))
|
||||
{
|
||||
function check_employee_band($row)
|
||||
{
|
||||
$slug = \Config\Services::slug();
|
||||
$relationship = $slug->slugify($row[5]);
|
||||
// echo $relationship;echo $row[7];
|
||||
if($relationship == 'self' && $row[9] == "") { return array('status' => false,'error' => "Band mandantory for self"); }
|
||||
return array('status' => true);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('check_basic_pay'))
|
||||
{
|
||||
function check_basic_pay($row)
|
||||
{
|
||||
$slug = \Config\Services::slug();
|
||||
$relationship = $slug->slugify($row[5]);
|
||||
// echo $relationship;echo $row[7];
|
||||
if($relationship == 'self' && $row[8] == "") { return array('status' => false,'error' => "Basic pay mandantory for self"); }
|
||||
return array('status' => true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('check_dob_diff'))
|
||||
{
|
||||
function check_dob_diff($row,$relationships) {
|
||||
// echo 'called';
|
||||
if($row[3] != null && $row[5] != null)
|
||||
{
|
||||
$dob = change_date_format($row[3],'d-M-Y','Y-m-d');
|
||||
// echo $row[3].' - '.$dob;echo '<br>';
|
||||
$currentDateTime = new DateTime();//die();
|
||||
$passedDateTime = new DateTime($dob);
|
||||
$interval = $currentDateTime->diff($passedDateTime);
|
||||
|
||||
$slug = \Config\Services::slug();
|
||||
$relationship = $slug->slugify($row[5]);
|
||||
$age_min = $relationships[$relationship]['age_min'];
|
||||
$age_max = $relationships[$relationship]['age_max'];
|
||||
// echo $relationship.','.$age_min.'-'.$age_max;
|
||||
if($age_min !== null && $age_min > $interval->y)
|
||||
{
|
||||
return array('status' => false,'error' => "Age conflict : minimum $age_min yrs allowed, received $interval->y");
|
||||
}
|
||||
if($age_max !== null && $age_max < $interval->y)
|
||||
{
|
||||
return array('status' => false,'error' => "Age conflict : maximum $age_max yrs allowed, received $interval->y");
|
||||
}
|
||||
return array('status' => true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array('status' => false,'error' => 'Rule Conflict: Both DOB or Relationship required');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -21,5 +21,4 @@ class FileModel extends Model
|
||||
];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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>', {
|
||||
|
||||
@ -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 }}?>
|
||||
|
||||
@ -540,7 +540,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>
|
||||
|
||||
@ -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": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user