CHANGE_EMPLOYEE_REST_API :AADHAVAN
This commit is contained in:
parent
9411d5d297
commit
755b1fc353
@ -211,9 +211,10 @@ $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfi
|
||||
$routes->get("/getEmployeePolicy", "EmployeeRestController::getEmployeePolicy");
|
||||
$routes->post("/employeeUpload", "EmployeeRestController::employeeUpload");
|
||||
|
||||
$routes->get("getEmployeeAndDependence", "EmployeeRestController::getEmployeeAndDependence");
|
||||
|
||||
$routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
|
||||
$routes->get("/relationshipList", "EmployeeRestController::relationshipList");
|
||||
$routes->get("relationshipList", "EmployeeRestController::relationshipList");
|
||||
$routes->get("getEmployeeAndDependence", "EmployeeRestController::getEmployeeAndDependence");
|
||||
$routes->post("editEmployeeAndDependence", "EmployeeRestController::editEmployeeAndDependence");
|
||||
$routes->post("addEmployeeAndDependence", "EmployeeRestController::addEmployeeAndDependence");
|
||||
|
||||
@ -13,8 +13,13 @@ use App\Models\EmployeePolicyModel;
|
||||
use App\Models\ClientModel;
|
||||
use App\Models\PolicesModel;
|
||||
use App\Models\RelationshipModel;
|
||||
use App\Models\FileModel;
|
||||
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@ -42,6 +47,7 @@ class EmployeeRestController extends AdminController
|
||||
$this->clientModel = new ClientModel();
|
||||
$this->policesModel = new PolicesModel();
|
||||
$this->relationshipModel = new RelationshipModel();
|
||||
$this->fileModel= new FileModel();
|
||||
}
|
||||
|
||||
|
||||
@ -144,26 +150,28 @@ class EmployeeRestController extends AdminController
|
||||
try {
|
||||
$data = $this->request->getJSON();
|
||||
|
||||
|
||||
if ($data) {
|
||||
$updatedCount = 0;
|
||||
$Count = 0;
|
||||
foreach ($data as $item) {
|
||||
$extractData['name'] = $item->name;
|
||||
$extractData['emp_code']= $item->emp_code;
|
||||
$extractData['email_corporate']=$item->email_corporate;
|
||||
$extractData['relationship_code']=$item->relationship_code;
|
||||
$extractData['mobile']=$item->mobile;
|
||||
$extractData['gender']=$item->gender;
|
||||
$extractData['dob']=$item->dob;
|
||||
$extractData['client_id']=$item->client_id;
|
||||
// print_r($extractData);die();
|
||||
$employee = $this->employeeModel->insert($extractData);
|
||||
if ($employee) {
|
||||
$updatedCount++;
|
||||
}
|
||||
if (isset($item->id)) {
|
||||
//update old data
|
||||
$id = $item->id;
|
||||
$employee = $this->employeeModel->update($id, (array)$item);
|
||||
if ($employee) {
|
||||
$Count++;
|
||||
}
|
||||
}else{
|
||||
//create new data
|
||||
$employee = $this->employeeModel->insert($item);
|
||||
if ($employee) {
|
||||
$Count++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($updatedCount > 0) {
|
||||
if ($Count > 0) {
|
||||
$result = [];
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
|
||||
} else {
|
||||
@ -233,51 +241,132 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
public function employeeUpload()
|
||||
{
|
||||
if ($this->request->getFile('file')) {
|
||||
// Load PHPExcel library
|
||||
require_once APPPATH . 'third_party/PHPExcel/PHPExcel.php';
|
||||
|
||||
// Load the uploaded file
|
||||
$file = $this->request->getFile('file');
|
||||
|
||||
// Load file into PHPExcel
|
||||
$inputFileType = PHPExcel_IOFactory::identify($file->getPathname());
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$objPHPExcel = $objReader->load($file->getPathname());
|
||||
|
||||
// Get the active sheet
|
||||
$sheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Get the highest row number
|
||||
$highestRow = $sheet->getHighestRow();
|
||||
|
||||
// Assuming your data starts from the second row (after headers)
|
||||
for ($row = 2; $row <= $highestRow; $row++) {
|
||||
// Get cell values
|
||||
$name = $sheet->getCellByColumnAndRow(0, $row)->getValue();
|
||||
$email = $sheet->getCellByColumnAndRow(1, $row)->getValue();
|
||||
// Assuming you have more columns, adjust indexes accordingly
|
||||
|
||||
// Store data into database (Example using CodeIgniter's database methods)
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
// Add more fields as necessary
|
||||
);
|
||||
// Insert data into the database table
|
||||
$this->db->insert('employees', $data);
|
||||
}
|
||||
|
||||
// Optionally, you can delete the uploaded file after processing
|
||||
unlink($file->getPathname());
|
||||
|
||||
// Optionally, you can redirect the user to a success page
|
||||
redirect('employee/success');
|
||||
} else {
|
||||
// Handle case when no file was uploaded
|
||||
echo 'No file uploaded!';
|
||||
|
||||
$file = $this->request->getFile('file');
|
||||
$client_id = $this->request->getPost('client_id');
|
||||
$policy_id = $this->request->getPost('policy_id');
|
||||
|
||||
|
||||
$is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
|
||||
$filename = $file->getName();
|
||||
|
||||
$file_name_with_path = WRITEPATH."/uploads/import_excel/".$filename;
|
||||
|
||||
//check the file exist or not
|
||||
if(!file_exists($file_name_with_path))
|
||||
{
|
||||
session()->setFlashdata('error', 'File not found');
|
||||
return redirect()->to(base_url('employee/upload'));
|
||||
}
|
||||
|
||||
// Load the Excel file
|
||||
$spreadsheet = IOFactory::load($file_name_with_path);
|
||||
|
||||
// Get the active sheet
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// Get the highest row and column numbers
|
||||
$highestRow = $sheet->getHighestRow();
|
||||
$highestColumn = $sheet->getHighestColumn();
|
||||
|
||||
$data = [];
|
||||
|
||||
// Iterate through each row
|
||||
for ($row = 1; $row <= $highestRow; $row++) {
|
||||
// Initialize the row data array
|
||||
$rowData = [];
|
||||
|
||||
// Iterate through each column in the row
|
||||
for ($col = 'A'; $col <= $highestColumn; $col++) {
|
||||
// Get the cell value
|
||||
$value = $sheet->getCell($col . $row)->getValue();
|
||||
|
||||
// Add the cell value to the row data array
|
||||
$rowData[] = $value;
|
||||
}
|
||||
|
||||
// Add the row data to the main data array
|
||||
$data[] = $rowData;
|
||||
}
|
||||
|
||||
$extractData['file_name']= $filename;
|
||||
$extractData['client_id']= $client_id;
|
||||
$extractData['status']= 'success';
|
||||
$extractData['policy_id']= $policy_id;
|
||||
$extractData['action']= 'enrollment';
|
||||
|
||||
// $extractData['created_by']=set_session_context('Employee');
|
||||
|
||||
$file_data =$this->fileModel->insert($extractData);
|
||||
|
||||
// print_r(count($data));
|
||||
$extra = [];
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if ($i == 0) {
|
||||
// Loop through the first row to extract keys
|
||||
for ($j = 0; $j < count($data[$i]); $j++) {
|
||||
$extra[$data[$i][$j]] = []; // Initialize keys with empty array
|
||||
}
|
||||
} else {
|
||||
// Loop through subsequent rows
|
||||
for ($j = 0; $j < count($data[$i]); $j++) {
|
||||
// Append values to corresponding keys in $extra
|
||||
if (isset($extra[$data[0][$j]])) {
|
||||
// Make sure the key exists in the $extra array
|
||||
$extra[$data[0][$j]][] = $data[$i][$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$dataToInsert = [];
|
||||
foreach ($extra['id'] as $index => $id) {
|
||||
$record = [
|
||||
// 'id' => $id,
|
||||
'emp_code' => $extra['emp_code'][$index],
|
||||
'name' => $extra['name'][$index],
|
||||
// Check if the 'doj' key exists before accessing it
|
||||
'doj' => isset($extra['doj'][$index]) ? $extra['doj'][$index] : null,
|
||||
'gender' => $extra['gender'][$index],
|
||||
'relationship' => $extra['relationship'][$index],
|
||||
'dob' => $extra['dob'][$index],
|
||||
'email' => $extra['Email'][$index],
|
||||
];
|
||||
$dataToInsert[] = $record;
|
||||
}
|
||||
|
||||
// print_r($dataToInsert);die();
|
||||
|
||||
for ($a=0; $a <count($dataToInsert) ; $a++) {
|
||||
|
||||
// print_r($dataToInsert[$a]);die();
|
||||
|
||||
// $emp_data = $this->employeeModel->insert($dataToInsert[$a]);
|
||||
|
||||
$employee = $this->employeeModel->checkExistingEmpEntrollment($dataToInsert[$a]);
|
||||
|
||||
// print_r($employee);die;
|
||||
if (count($employee)) {
|
||||
// $dataToInsert['id'] = $employee['id'];
|
||||
$this->employeeModel->update($dataToInsert[$a], ['id' => $employee['id']]);
|
||||
die();
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// $query = $this->employeePolicyModel->getLastQuery();
|
||||
// echo $query . "<br>";
|
||||
// Return the array containing data from the Excel file
|
||||
// return $data;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -45,4 +45,13 @@ class EmployeeModel extends Model
|
||||
->getResult();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// for EMP rest API process do not change
|
||||
public function checkExistingEmpEntrollment($arr)
|
||||
{
|
||||
return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->first();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -180,5 +180,14 @@ class EmployeePolicyModel extends Model
|
||||
}
|
||||
|
||||
|
||||
|
||||
//for emp onboard do not change
|
||||
public function checkExistingEmpPolicy($arr)
|
||||
{
|
||||
return $this->where('employee_id',$arr['employee_id'])
|
||||
->where('client_policy_id',$arr['client_policy_id'])
|
||||
->find();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@ -629,16 +629,26 @@
|
||||
// $("#sum_insured").trigger("keyup");
|
||||
// $("#premium").trigger("keyup");
|
||||
|
||||
// $('#basic_pay').trigger('keyup');
|
||||
$('#basic_pay').trigger('keyup');
|
||||
|
||||
$('input[name="si[]"]').each(function() {
|
||||
$(this).trigger('keyup');
|
||||
});
|
||||
|
||||
|
||||
|
||||
$('input[name="premium[]"]').each(function() {
|
||||
$(this).trigger('keyup');
|
||||
});
|
||||
|
||||
// $("input[name='si[]']").trigger("keyup");
|
||||
// $("input[name='premium[]']").trigger("keyup")
|
||||
|
||||
setTimeout(function() {
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
}, 1000);
|
||||
}, 1000);si
|
||||
|
||||
$('#basic_gpa_si').trigger('keyup');
|
||||
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
@ -1061,8 +1071,6 @@
|
||||
|
||||
function checkDuplicate()
|
||||
{
|
||||
// console.log($('#grid')[0].value);
|
||||
|
||||
if ($('#grid')[0].value === '3') {
|
||||
var siInputs = $('input[name="si[]"]');
|
||||
var premiumInputs = $('input[name="premium[]"]');
|
||||
@ -1504,17 +1512,17 @@
|
||||
|
||||
|
||||
|
||||
$("#gpa_si").on("keyup", function() {
|
||||
var inputNumber = $(this).val();
|
||||
if (inputNumber) {
|
||||
var result = convertCommaNumberToWords(inputNumber);
|
||||
$("#gpa_si_number_word").text(result);
|
||||
} else {
|
||||
$("#gpa_si_number_word").text("");
|
||||
}
|
||||
// $("#gpa_si").on("keyup", function() {
|
||||
// var inputNumber = $(this).val();
|
||||
// if (inputNumber) {
|
||||
// var result = convertCommaNumberToWords(inputNumber);
|
||||
// $("#gpa_si_number_word").text(result);
|
||||
// } else {
|
||||
// $("#gpa_si_number_word").text("");
|
||||
// }
|
||||
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
// $("#basic_gpa_premium").on("keyup", function() {
|
||||
// var inputNumber = $(this).val();
|
||||
@ -1527,26 +1535,26 @@
|
||||
// });
|
||||
|
||||
|
||||
$("#sum_insured").on("keyup", function() {
|
||||
var inputNumber = $(this).val();
|
||||
if (inputNumber) {
|
||||
var result = convertCommaNumberToWords(inputNumber);
|
||||
$("#sum_insured_number_word").text(result);
|
||||
} else {
|
||||
$("#sum_insured_number_word").text("");
|
||||
}
|
||||
});
|
||||
// $("#sum_insured").on("keyup", function() {
|
||||
// var inputNumber = $(this).val();
|
||||
// if (inputNumber) {
|
||||
// var result = convertCommaNumberToWords(inputNumber);
|
||||
// $("#sum_insured_number_word").text(result);
|
||||
// } else {
|
||||
// $("#sum_insured_number_word").text("");
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
$("#premium").on("keyup", function() {
|
||||
var inputNumber = $(this).val();
|
||||
if (inputNumber) {
|
||||
var result = convertCommaNumberToWords(inputNumber);
|
||||
$("#premium_number_word").text(result);
|
||||
} else {
|
||||
$("#premium_number_word").text("");
|
||||
}
|
||||
});
|
||||
// $("#premium").on("keyup", function() {
|
||||
// var inputNumber = $(this).val();
|
||||
// if (inputNumber) {
|
||||
// var result = convertCommaNumberToWords(inputNumber);
|
||||
// $("#premium_number_word").text(result);
|
||||
// } else {
|
||||
// $("#premium_number_word").text("");
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user