employeedetails_model = new Employeedetails_model();
$this->companydetailsmodel = new Companydetails_model();
$this->empFiles = new EmpFilesModel();
$this->appConfig = new AppConfigModel();
$this->emppaydate_model = new Emppaydate_model();
$this->session = session();
helper('form'); //$this->load->library('form_validation');
$this->isLoggedIn();
}
/**
* This function is used to load the Employee details
*/
public function index()
{
$data['userRecords'] = $this->employeedetails_model->employeeListing();
$this->global['pageTitle'] = 'Employee Listing';
$this->loadViews("employeeListing", $this->global, $data, NULL);
}
/*
Validation for Gender status Dropdown
*/
function Gender_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if ($selectValue == '-1') {
// $this->validator->setMessage('Gender_validate', 'Please Select Gender.');
echo "";
return false;
} else // user picked something
{
return true;
}
}
/*
Validation for Martial status Dropdown
*/
function Martial_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if ($selectValue == '-1') {
// $this->validator->setMessage('Martial_validate', 'Please Select Martial status.');
echo "";
return false;
} else // user picked something
{
return true;
}
}
/*
Validation for BloodGroup Dropdown
*/
function Blood_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if ($selectValue == '-1') {
// $this->validator->setMessage('Blood_validate', 'Please Select Blood Group.');
echo "";
return false;
} else // user picked something
{
return true;
}
}
/*
Validation for Qualification Dropdown
*/
function select_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if ($selectValue == '-1') {
// $this->validator->setMessage('select_validate', 'Supplier Record Not updated!');
echo "";
return false;
} else // user picked something
{
return true;
}
}
/*
Validation for Department Dropdown
*/
function Dep_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if ($selectValue == '-1') {
// $this->validator->setMessage('Dep_validate', 'Please Select Department.');
echo "";
return false;
} else // user picked something
{
return true;
}
}
/*
Validation for Desigination Dropdown
*/
function Des_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if ($selectValue == '-1') {
// $this->validator->setMessage('Des_validate', 'Please Select Desigination.');
echo "";
return false;
} else // user picked something
{
return true;
}
}
/* To Check the Pan Number is exists in the database or not */
function Pan_validate()
{
// alert('validation pan');
$PanNo = $this->request->getPost('panno');
$query = $this->employeedetails_model->checkPANExists($PanNo);
if (count($query) > 0) {
// $this->validator->setMessage('checkPanValidate', 'The Entered PAN Number is already exists in the Database.');
echo "";
return false;
} else {
return true;
}
}
/* To Check the Pan Number is exists in the database or not */
function Aadhar_validate()
{
$AadharNo = $this->request->getPost('aadharno');
$query = $this->employeedetails_model->checkAadharExists($AadharNo);
if (count($query) > 0) {
// $this->validator->setMessage('checkAadharValidate', 'The Entered Aadhar Number is already exists in the Database.');
echo "";
return false;
} else {
return true;
}
}
/**
* This function is used to save the new Employee form in the database
*/
/**
*/
function AddNewEmployee()
{
$photo = $this->request->getFile('photo');
$Picture = "";
if (isset($photo)) {
if ($photo->isValid() && !$photo->hasMoved()) {
$uploadDir = ROOTPATH . 'public/uploads/images/';
$allowedTypes = ['jpg', 'jpeg', 'png', 'gif'];
if (in_array($photo->getExtension(), $allowedTypes)) {
$newName = $photo->getRandomName();
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$photo->move($uploadDir, $newName);
$Picture = $newName;
}
else{
echo "Incorrect file format provided";
return false;
}
}
}
// $Profile = $this->request->getPost('photo');
$FirstName = $this->request->getPost('FirstName');
$FatherName = $this->request->getPost('FatherName');
$DateofBirth = $this->request->getPost('DateofBirth');
$ContactNumber = $this->request->getPost('ContactNumber');
$Gender = $this->request->getPost('gender');
$MartialStatus = $this->request->getPost('MartialStatus');
$CurrentAddress = $this->request->getPost('currentaddress');
$permanentaddress = $this->request->getPost('permanentaddress');
$desigination = $this->request->getPost('desigination');
$departmentCode = $this->request->getPost('departmentname');
$dateofjoining = $this->request->getPost('dateofjoining');
$pre_experience = $this->request->getPost('Previousexperience');
if ($pre_experience == '') {
$Previousexperience = null;
} else {
$Previousexperience = $pre_experience;
}
$eduqualifaction = $this->request->getPost('eduqualifaction');
$addqualification = $this->request->getPost('addqualification');
$referredby = $this->request->getPost('referredby');
$referrercontno = $this->request->getPost('referrercontno');
$accountno = $this->request->getPost('accountno');
$ifsccode = $this->request->getPost('ifsccode');
$bankbranchname = $this->request->getPost('bankbranchname');
$bankaddress = $this->request->getPost('bankaddress');
$aadharno = $this->request->getPost('aadharno');
$panno = $this->request->getPost('panno');
$panno = $panno !== null && is_string($panno) ? strtoupper($panno) : null;
$passportno = $this->request->getPost('passportno');
$passportno = $passportno !== null && is_string($passportno) ? strtoupper($passportno) : null;
$ValidTill = $this->request->getPost('ValidTill');
$addinfo = $this->request->getPost('addinfo');
$IsActive = '1';
$driverlicense = $this->request->getPost('driverlicense');
$driverlicense = $driverlicense !== null && is_string($driverlicense) ? strtoupper($driverlicense) : null;
$licenseExpiryDate = $this->request->getPost('licenseExpiryDate');
$VoterID = $this->request->getPost('voterID');
$VoterID = $VoterID !== null && is_string($VoterID) ? strtoupper($VoterID) : null;
$PFno = $this->request->getPost('pfno');
$ESIno = $this->request->getPost('esino');
$Nominee = $this->request->getPost('nomineename');
$createdby = $this->session->get('userId');
$is_management_team = $this->request->getPost('is_management_team');
$TDS_Rate = $this->request->getPost('TDS_Rate');
$tds_applicable=$this->request->getPost('tds_applicable');
$esi_applicable = $this->request->getPost('esi_applicable');
$pf_applicable = $this->request->getPost('pf_applicable');
$work_location = $this->request->getPost('work_location');
if ($licenseExpiryDate != '') {
//$License_ExpiryDate = get_date_format($licenseExpiryDate);
$License_ExpiryDate = get_date_time_format($licenseExpiryDate);
} else {
$License_ExpiryDate = null;
}
$DOB = get_date_time_format($DateofBirth);
$DOJ = get_date_time_format($dateofjoining);
if ($ValidTill != '') {
$Valid = get_date_time_format($ValidTill);
} else {
$Valid = null;
}
//echo $DOB;
$Employee = array(
'FirstName' => $FirstName,
'FatherName' => $FatherName,
'Gender' => $Gender,
'DateofBirth' => $DOB,
'ContactNumber' => $ContactNumber,
'MartialStatus' => $MartialStatus,
'DateofJoining' => $DOJ,
'PreviousYearsOfExp' => $Previousexperience,
'Designation' => $desigination,
'Departmentcode' => $departmentCode,
'PresentAddress' => $CurrentAddress,
'PermanentAddress' => $permanentaddress,
'Edu_Qualification' => $eduqualifaction,
'Additional_Qualification' => $addqualification,
'AadharNo' => $aadharno,
'PANNo' => $panno,
'BankAccountNo' => $accountno,
'IFSCCode' => $ifsccode,
'BankBranchName' => $bankbranchname,
'BankAddress' => $bankaddress,
'PassportNo' => $passportno,
'Passport_Valid_till' => $Valid,
'IsActive' => $IsActive,
'ProfilePic' => $Picture,
'Reference_Name' => $referredby,
'Reference_ContactNumber' => $referrercontno,
'Remarks' => $addinfo,
'CreatedBy' => $createdby,
'DriverLicense' => $driverlicense,
'LicenseValidtill' => $License_ExpiryDate,
'VoterID' => $VoterID,
'PFNO' => $PFno,
'ESI' => $ESIno,
'TDS_Rate' => $TDS_Rate,
'tds_applicable' => $tds_applicable,
'NomineeDetails' => $Nominee,
'is_management_team' => $is_management_team,
'esi_applicable' => $esi_applicable,
'pf_applicable' => $pf_applicable,
'work_location' => $work_location
);
//print_r($Employee);die();
$result = $this->employeedetails_model->addNewemployee($Employee);
if ($result) {
// Get the uploaded files
$files1 = $this->request->getFile('emp_file1');
$files2 = $this->request->getFile('emp_file2');
$files3 = $this->request->getFile('emp_file3');
$files4 = $this->request->getFile('emp_file4');
$files5 = $this->request->getFile('emp_file5');
$files=[$files1,$files2,$files3,$files4,$files5];
$fileName1 = $this->request->getPost('file_name1');
$fileName2 = $this->request->getPost('file_name2');
$fileName3 = $this->request->getPost('file_name3');
$fileName4 = $this->request->getPost('file_name4');
$fileName5 = $this->request->getPost('file_name5');
$fileNames=[$fileName1,$fileName2,$fileName3,$fileName4,$fileName5];
if (!empty($files)) {
foreach ($files as $index => $file) {
if ($file && $file->isValid() && !$file->hasMoved()) {
// Move the file to the desired directory
$newName = $file->getRandomName();
$file->move(ROOTPATH . 'public/uploads/images/emp_files', $newName);
$path = ROOTPATH . 'public/uploads/images/emp_files/' . $newName;
// Store the file information in the database
$this->empFiles->save([
'file_name' => $fileNames[$index], // User-entered file name
'emp_file' => $newName, // New file name
'emp_id' => $result['EmpID'],
'path' => $path
]);
}
}
}
$EmpID = $result['EmpID'];
$Total_Salary = $this->request->getPost('Total_salary');
$Basic_Pay = $this->request->getPost('Basic_Pay');
$HRA_Rate = $this->request->getPost('HRA_Rate');
$HRA_Amount = $this->request->getPost('HRA_Amount');
$PF_Rate = $this->request->getPost('PF_Rate');
$ESI_Rate = $this->request->getPost('ESI_Rate');
$CreateBy = $this->session->get('userId');
$emppay = array('EmpID' => $EmpID, 'TotalSalary' => $Total_Salary, 'Basic_Pay' => $Basic_Pay, 'HRA_Rate' => $HRA_Rate, 'HRA_Amount' => $HRA_Amount, 'PF_Rate' => $PF_Rate, 'ESI_Rate' => $ESI_Rate, 'Created_By' => $CreateBy);
$this->emppaydate_model->addNewemppay($emppay);
// $this->session->set_flashdata('Success', 'New Employee created successfully!');
$this->session->setFlashdata('success', 'New Employee created successfully!');
// return json_encode('true');
echo "";
} else {
// $this->session->set_flashdata('Error', 'New Employee details not saved');
$this->session->setFlashdata('error', 'Record Not Saved!');
// return json_encode('false');
echo "";
// redirect('employeeListing', 'refresh');
}
// return redirect()->route('employeeListing');
// }
}
function deleteEmployeeFile()
{
$id = $this->request->getPost('id');
$update = $this->empFiles->set(['is_active' => 0])->where('id', $id)->update();
if ($update) {
return true;
} else {
return false;
}
}
/**
* This function is used to load the add new Employee form with dropdown values */
function addemployee()
{
$GenderConfigID = 'C013';
$MartialConfigID = 'C012';
$QualificationConfigID = 'C014';
$DesignationConfigID = 'C010';
$LocationConfigID = 'C031';
$data['Gender'] = $this->employeedetails_model->getConfigValue($GenderConfigID);
$data['Martial'] = $this->employeedetails_model->getConfigValue($MartialConfigID);
$data['bankdetails'] = $this->employeedetails_model->getBankDetails();
$data['Qualification'] = $this->employeedetails_model->getConfigValue($QualificationConfigID);
$data['Designation'] = $this->employeedetails_model->getConfigValue($DesignationConfigID);
$data['Location'] = $this->employeedetails_model->getConfigValue($LocationConfigID);
$data['Department'] = $this->employeedetails_model->getDepartment();
$data['hra_rate'] = $this->appConfig->where('config_key', 1)->get()->getRow()->config_value;
$data['pf_rate'] = $this->appConfig->where('config_key', 2)->get()->getRow()->config_value;
$data['esi_rate'] = $this->appConfig->where('config_key', 3)->get()->getRow()->config_value;
$this->global['pageTitle'] = 'Add New Employee';
// if($this->role == ROLE_ADMIN || $this->DEPCode == HR)
// {
// $this->loadViews("addEmployee", $this->global, $data, NULL);
$this->loadViews("addEmployeenew", $this->global, $data, NULL);
// }
// else
// {
// $this->loadViews("access", $this->global, $data, NULL);
// }
}
/**
* This function is used to check whether the Employee is existing in the database or not */
function CheckEmail()
{
$emailId = $this->request->getPost('emailId');
//print_r($id);
$result = $this->employeedetails_model->checkMailExists($emailId);
$result = $result->getResultArray();
$response = [
"message" => "success",
"data" => $result
];
return $this->response->setJSON($response);
}
function checkPAN()
{
$panNo = $this->request->getPost('panNo');
//print_r($id);
$result = $this->employeedetails_model->checkPANExists($panNo);
$result = $result->getResultArray();
$response = [
"message" => "success",
"data" => $result
];
return $this->response->setJSON($response);
}
function checkAadharNo()
{
$aadharNo = $this->request->getPost('aadharNo');
//print_r($id);
$result = $this->employeedetails_model->checkAadharExists($aadharNo);
$result = $result->getResultArray();
$response = [
"message" => "success",
"data" => $result
];
return $this->response->setJSON($response);
}
/* To Check the Pan Number is exists in the database or not for the selected Supplier */
function Pan_validate_emp()
{
//print_r($PanNo);
$Empid = $this->request->getPost('employeeid');
$PanNo = $this->request->getPost('panno');
$query = $this->employeedetails_model->checkPANExists($PanNo, $Empid);
if (count($query) > 0) {
// $this->validator->setMessage('Pan_validate_emp', 'The Entered PAN Number is already exists in the Database.');
echo "";
return false;
} else {
return true;
}
}
// To Check the Aadhar Number is exists in the database or not for the selected Employee
function Aadhar_validate_emp()
{
$Empid = $this->request->getPost('employeeid');
$AadharNo = $this->request->getPost('aadharno');
$query = $this->employeedetails_model->checkAadharExists($AadharNo, $Empid);
if (count($query) > 0) {
// $this->validator->setMessage('Aadhar_validate_emp', 'The Entered Aadhar Number is exists in the Database.');
echo "";
return false;
} else {
return true;
}
}
public function add($photo)
{
$picture = '';
if ($photo->isValid() && !$photo->hasMoved()) {
// Define upload directory and allowed file types
$uploadDir = ROOTPATH . 'public/uploads/images/';
$allowedTypes = ['jpg', 'jpeg', 'png', 'gif'];
// Validate file type
if (in_array($photo->getExtension(), $allowedTypes)) {
// Generate unique file name
$newName = $photo->getRandomName();
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
// Move the uploaded file to the upload directory
$photo->move($uploadDir, $newName);
$picture = $newName;
} else {
// Handle invalid file type
$picture = '';
}
}
return $picture;
}
function ViewEmployee($EmpNO = '')
{
if ($EmpNO == '') {
$EmpID = $_GET['EmpID'];
} else {
$EmpID = $EmpNO;
}
$GenderConfigID = 'C013';
$MartialConfigID = 'C012';
$QualificationConfigID = 'C014';
$DesignationConfigID = 'C010';
$LocationConfigID = 'C031';
//print_r('hai');
$data['GenderList'] = $this->employeedetails_model->getConfigValue($GenderConfigID);
$data['MartialList'] = $this->employeedetails_model->getConfigValue($MartialConfigID);
$data['QualificationList'] = $this->employeedetails_model->getConfigValue($QualificationConfigID);
$data['DesignationList'] = $this->employeedetails_model->getConfigValue($DesignationConfigID);
$data['bankdetails'] = $this->employeedetails_model->getBankDetails();
$data['Location'] = $this->employeedetails_model->getConfigValue($LocationConfigID);
$data['DepartmentList'] = $this->employeedetails_model->getDepartment();
$data['EmpDetails'] = $this->employeedetails_model->viewemployee($EmpID);
$data['emp_data'] = $this->empFiles->where('emp_id', $EmpID)->where('is_active', 1)->findAll();
$data['empPay'] = $this->emppaydate_model->getEmpPayData($EmpID);
$this->global['pageTitle'] = 'View Employee';
$this->loadViews("editEmployeenew", $this->global, $data, NULL);
}
/* To Check the email exists in the database or not for the employee*/
function checkMailEmp()
{
$Empid = $this->request->getPost('employeeid');
$EmailId = $this->request->getPost('emailid');
$query = $this->employeedetails_model->checkMailExists($EmailId, $Empid);
if (count($query) > 0) {
// $this->validator->setMessage('checkMailEmp', 'The Entered Email id is exists in the Database.');
echo "";
return false;
} else {
return true;
}
}
/* To Update the employee details*/
function UpdateEmployee()
{
$EmpId = $this->request->getGet('empId');
//if it is empty it means the default image is selected
$oldPictureName = $this->request->getPost('oldImageName');
$Picture = "";
$photo = $this->request->getFile('photo');
if (isset($photo) && $photo->isValid() && !$photo->hasMoved()) {
$uploadDir = ROOTPATH . 'public/uploads/images/';
$allowedTypes = ['jpg', 'jpeg', 'png', 'gif'];
if (in_array($photo->getExtension(), $allowedTypes)) {
$newName = $photo->getRandomName();
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$photo->move($uploadDir, $newName);
$Picture = $newName;
}
}else{
$Picture=$oldPictureName;
}
$FirstName = $this->request->getPost('FirstName');
$LastName = $this->request->getPost('LastName');
$FatherName = $this->request->getPost('FatherName');
$DateofBirth = $this->request->getPost('DateofBirth');
// dd($DateofBirth);
$ContactNumber = $this->request->getPost('ContactNumber');
$Gender = $this->request->getPost('gender');
$MartialStatus = $this->request->getPost('MartialStatus');
$CurrentAddress = $this->request->getPost('currentaddress');
$permanentaddress = $this->request->getPost('permanentaddress');
$desigination = $this->request->getPost('desigination');
$departmentCode = $this->request->getPost('departmentname');
$dateofjoining = $this->request->getPost('dateofjoining');
// dd($dateofjoining);
//$Previousexperience = $this->request->getPost('Previousexperience');
$pre_experience = $this->request->getPost('Previousexperience');
if ($pre_experience == '') {
$Previousexperience = null;
} else {
$Previousexperience = $pre_experience;
}
$eduqualifaction = $this->request->getPost('eduqualifaction');
$addqualification = $this->request->getPost('addqualification');
$referredby = $this->request->getPost('referredby');
$referrercontno = $this->request->getPost('referrercontno');
$accountno = $this->request->getPost('accountno');
$ifsccode = $this->request->getPost('ifsccode');
$bankbranchname = $this->request->getPost('bankbranchname');
$bankaddress = $this->request->getPost('bankaddress');
$aadharno = $this->request->getPost('aadharno');
$panno = $this->request->getPost('panno');
$panno = $panno !== null && is_string($panno) ? strtoupper($panno) : null;
$passportno = $this->request->getPost('passportno');
$passportno = $passportno !== null && is_string($passportno) ? strtoupper($passportno) : null;
$ValidTill = $this->request->getPost('ValidTill');
$addinfo = $this->request->getPost('addinfo');
$driverlicense = $this->request->getPost('driverlicense');
// dd($driverlicense);
$driverlicense = $driverlicense !== null && is_string($driverlicense) ? strtoupper($driverlicense) : null;
$licenseExpiryDate = $this->request->getPost('LicenseExpiryDate');
$VoterID = $this->request->getPost('voterID');
//dd($VoterID);
$VoterID = $VoterID !== null && is_string($VoterID) ? strtoupper($VoterID) : null;
$pfno = $this->request->getPost('pfno');
$pfno = $pfno !== null && is_string($pfno) ? strtoupper($pfno) : null;
//$uano = $this->request->getPost('uano');
$esino = $this->request->getPost('esino');
$Nominee = $this->request->getPost('nomineename');
$chked = $this->request->getPost('isactive');
$is_management_team = $this->request->getPost('is_management_team');
$esi_applicable = $this->request->getPost('esi_applicable');
$pf_applicable = $this->request->getPost('pf_applicable');
$work_location = $this->request->getPost('work_location');
// echo 'chkvalue'. $chked ;
if ($chked != '') {
$IsActive = '1';
} else {
$IsActive = '0';
}
// echo 'chkvalue'. $IsActive ;
$UpdatedBY = $this->session->get('userId');
//$licenseExpiryDate = get_date_time_format($licenseExpiryDate);
$DOB = get_date_time_format($DateofBirth);
$DOJ = get_date_time_format($dateofjoining);
if ($ValidTill != '') {
$Valid = get_date_time_format($ValidTill);
} else {
$Valid = null;
}
if ($licenseExpiryDate != '') {
$License_ExpiryDate = get_date_time_format($licenseExpiryDate);
} else {
$License_ExpiryDate = null;
}
// echo $DOB;die;
$Employee = array(
'FirstName' => $FirstName,
'LastName' => $LastName,
'FatherName' => $FatherName,
'Gender' => $Gender,
'DateofBirth' => $DOB,
'ContactNumber' => $ContactNumber,
'MartialStatus' => $MartialStatus,
'DateofJoining' => $DOJ,
'PreviousYearsOfExp' => $Previousexperience,
'Designation' => $desigination,
'Departmentcode' => $departmentCode,
'PresentAddress' => $CurrentAddress,
'PermanentAddress' => $permanentaddress,
'Edu_Qualification' => $eduqualifaction,
'Additional_Qualification' => $addqualification,
'AadharNo' => $aadharno,
'PANNo' => $panno,
'BankAccountNo' => $accountno,
'IFSCCode' => $ifsccode,
'BankBranchName' => $bankbranchname,
'BankAddress' => $bankaddress,
'PassportNo' => $passportno,
'Passport_Valid_till' => $Valid,
'IsActive' => $IsActive,
'ProfilePic' => $Picture,
'Reference_Name' => $referredby,
'Reference_ContactNumber' => $referrercontno,
'Remarks' => $addinfo,
'UpdatedBY' => $UpdatedBY,
'DriverLicense' => $driverlicense,
'LicenseValidtill' => $License_ExpiryDate,
'VoterID' => $VoterID,
'PFNO' => $pfno,
'ESI' => $esino,
'NomineeDetails' => $Nominee,
'is_management_team' => $is_management_team,
'esi_applicable' => $esi_applicable,
'pf_applicable' => $pf_applicable,
'work_location' => $work_location
);
//print_r($Employee);die();
$result = $this->employeedetails_model->UpdateEmployee($Employee, $EmpId);
// Get the uploaded files
$files1 = $this->request->getFile('emp_file1');
$files2 = $this->request->getFile('emp_file2');
$files3 = $this->request->getFile('emp_file3');
$files4 = $this->request->getFile('emp_file4');
$files5 = $this->request->getFile('emp_file5');
$files=[$files1,$files2,$files3,$files4,$files5];
$fileName1 = $this->request->getPost('file_name1');
$fileName2 = $this->request->getPost('file_name2');
$fileName3 = $this->request->getPost('file_name3');
$fileName4 = $this->request->getPost('file_name4');
$fileName5 = $this->request->getPost('file_name5');
$fileNames=[$fileName1,$fileName2,$fileName3,$fileName4,$fileName5];
if (!empty($files)) {
foreach ($files as $index => $file) {
if ($file && $file->isValid() && !$file->hasMoved()) {
// Move the file to the desired directory
$newName = $file->getRandomName();
$file->move(ROOTPATH . 'public/uploads/images/emp_files', $newName);
$path = ROOTPATH . 'public/uploads/images/emp_files/' . $newName;
// Store the file information in the database
$this->empFiles->save([
'file_name' => $fileNames[$index], // User-entered file name
'emp_file' => $newName, // New file name
'emp_id' => $EmpId,
'path' => $path
]);
}
}
}
$Total_Salary = $this->request->getPost('Total_salary');
$Basic_Pay = $this->request->getPost('Basic_Pay');
$HRA_Rate = $this->request->getPost('HRA_Rate');
$HRA_Amount = $this->request->getPost('HRA_Amount');
$PF_Rate = $this->request->getPost('PF_Rate');
$ESI_Rate = $this->request->getPost('ESI_Rate');
$CreateBy = $this->session->get('userId');
$emppay = array('EmpID' => $EmpId, 'TotalSalary' => $Total_Salary, 'Basic_Pay' => $Basic_Pay, 'HRA_Rate' => $HRA_Rate, 'HRA_Amount' => $HRA_Amount, 'PF_Rate' => $PF_Rate, 'ESI_Rate' => $ESI_Rate, 'Created_By' => $CreateBy);
$empPayUpdate = $this->emppaydate_model->editemppay($emppay);
if ($result + $empPayUpdate > 0) {
$this->session->setFlashdata('success', 'You Have Successfully updated the Employee Record!');
return json_encode(true);
} else {
$this->session->setFlashdata('error', 'Record Not Updated!');
return json_encode(false);
}
// return redirect()->route('employeeListing');
}
function exportemployee()
{
$exportData = $this->employeedetails_model->export_excel();
$file_name = 'Employee_Details' . ' ' . '.xls'; //save our workbook as this file name
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->mergeCells('L3:S3');
$sheet->getStyle('L3')->getAlignment()->setHorizontal('center');
$sheet->setTitle('Employee details');
$headers = [
'L3' => 'RESICO Employee Details',
'A5' => 'EmpID',
'B5' => 'FirstName-LastName',
'C5' => 'FatherName',
'D5' => 'Gender',
'E5' => 'Date of Birth',
'F5' => 'ContactNumber',
'G5' => 'EmailId',
'H5' => 'BloodGroup',
'I5' => 'MartialStatus',
'J5' => 'DateofJoining',
'K5' => 'PreviousYearsOfExp',
'L5' => 'Designation',
'M5' => 'DepartmentName',
'N5' => 'PresentAddress',
'O5' => 'PermanentAddress',
'P5' => 'EmergencyContactName',
'Q5' => 'EmergencyContactNumber',
'R5' => 'Edu_Qualification',
'S5' => 'Additional_Qualification',
'T5' => 'Reference_Name',
'U5' => 'Reference_ContactNumber',
'V5' => 'BankStatemant',
'W5' => 'AadharNo',
'X5' => 'PANNo',
'Y5' => 'PassportNo',
'Z5' => 'Passport_Valid_till',
'AA5' => 'Voter ID',
'AB5' => 'Driving License',
'AC5' => 'Driving License Expiry Date',
'AD5' => 'Official Email ID',
'AE5' => 'IsActive',
'AF5' => 'PFNO',
'AG5' => 'ESI',
'AH5' => 'Nominee Details',
// 'AI5'=>'PF_Balance',
// 'AJ5'=>'PF_Bal_On',
'AI5' => 'Remarks',
'AJ5' => 'CreatedBy',
'AK5' => 'UpdatedBY'
];
foreach ($headers as $cell => $value) {
$sheet->setCellValue($cell, $value);
$sheet->getStyle($cell)->getFont()->setSize($cell == 'L3' ? 14 : 12);
$sheet->getStyle($cell)->getFont()->setBold(true);
}
if ($exportData) {
$i = 6;
$s = 1;
foreach ($exportData as $data) {
$rowData = [
'A' . $i,
$data['EmpID'],
'B' . $i => $data['FirstName'] . '-' . $data['LastName'],
'C' . $i => $data['FatherName'],
'D' . $i => $data['Gender'],
'E' . $i => $data['DateofBirth'],
'F' . $i => $data['ContactNumber'],
'G' . $i => $data['EmailId'],
'H' . $i => $data['BloodGroup'],
'I' . $i => $data['MartialStatus'],
'J' . $i => $data['DateofJoining'],
'K' . $i => $data['PreviousYearsOfExp'],
'L' . $i => $data['Designation'],
'M' . $i => $data['DepartmentName'],
'N' . $i => $data['PresentAddress'],
'O' . $i => $data['PermanentAddress'],
'P' . $i => $data['EmergencyContactName'],
'Q' . $i => $data['EmergencyContactNumber'],
'R' . $i => $data['Edu_Qualification'],
'S' . $i => $data['Additional_Qualification'],
'T' . $i => $data['Reference_Name'],
'U' . $i => $data['Reference_ContactNumber'],
'V' . $i => $data['BankAccountNo'] . '-' . $data['IFSCCode'] . '-' . $data['BankBranchName'] . $data['BankAddress'],
'W' . $i => $data['AadharNo'],
'X' . $i => $data['PANNo'],
'Y' . $i => $data['PassportNo'],
'Z' . $i => $data['Passport_Valid_till'],
'AA' . $i => $data['VoterID'],
'AB' . $i => $data['DriverLicense'],
'AC' . $i => $data['LicenseValidtill'],
'AD' . $i => $data['personalEmailId'],
'AE' . $i => $data['IsActive'],
'AF' . $i => $data['PFNO'],
'AG' . $i => $data['ESI'],
'AH' . $i => $data['NomineeDetails'],
// 'AI'. $i=>$data['PF_Balance'],
// 'AJ'. $i=>$data['PF_Bal_On'],
'AI' . $i => $data['Remarks'],
'AJ' . $i => $data['CreatedByName'],
'AK' . $i => $data['UpdatedByName'],
];
foreach ($rowData as $cell => $value) {
$sheet->setCellValue($cell, $value);
}
$i++;
$s++;
}
}
// $writer = new Xlsx($spreadsheet);
// $writer->save($file_name);
// header("Content-Type: application/vnd.ms-excel");
// header('Content-Disposition: attachment; filename="' . basename($file_name) . '"');
// header('Expires: 0');
// header('Cache-Control: must-revalidate');
// header('Pragma: public');
// header('Content-Length:' . filesize($file_name));
// flush();
// readfile($file_name);
// exit;
// Clear the output buffer to prevent any other output
ob_clean();
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $file_name . '"');
header('Cache-Control: max-age=0');
header('Expires: 0');
header('Pragma: public');
$writer->save('php://output');
exit;
}
}