PAYROLL NEW CHANGE AND REFRESH ISSSUE FIXED

This commit is contained in:
velz2020 2017-09-18 19:53:15 +05:30
parent 2a68e94d63
commit be9b1e6e70
4 changed files with 160 additions and 272 deletions

View File

@ -37,17 +37,7 @@ class payslip extends BaseController
}
/**
* This function used to load the first screen of the user
*/
public function viewUpload()
{
$this->global['pageTitle'] = 'Siddharth : Payroll Data Upload';
$this->loadViews("payslipupload", $this->global, null , NULL);
}
/**
* This function used to load the first screen of the user
@ -56,9 +46,10 @@ class payslip extends BaseController
{
$this->global['pageTitle'] = 'Siddharth : Payroll Data Upload2';
$data['userfile']='HI';
$data['month']='HI';
$this->loadViews("payslipupload2", $this->global, null , NULL);
$this->loadViews("payslipupload2", $this->global, $data , NULL);
}
/**
@ -228,147 +219,7 @@ function getEmployee()
/**
* This function used to upload the Excel file Details
*/
function uploadExcel(){
$FNAME = $this->input->post('FileName');
echo "HI" . $FNAME;
echo realpath($FNAME);die();
$PayrollFileName = '';
//Check whether user upload picture
if(!empty($_FILES['userfile']['name']))
{
echo 'inside if';
$pathinfo = pathinfo($_FILES['userfile']['name']);
$config['upload_path'] = 'uploads/files/';
$config['allowed_types'] = 'xls|xlsx|csv';
$config['file_name'] = $_FILES['userfile']['name'];
$config['overwrite'] = true;
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
&& $_FILES['userfile']['size'] > 0 )
{
if($this->upload->do_upload('userfile'))
{
$uploadData = $this->upload->data();
$PayrollFileName = $uploadData['file_name'];
}
else
{
$error = array('error' => $this->upload->display_errors());
$PayrollFileName = '';
}
$inputFileName = $_FILES['userfile']['tmp_name'];
require_once APPPATH .'third_party/PHPExcel/IOFactory.php';
$objTpl = PHPExcel_IOFactory::load($inputFileName);
$sheet = $objTpl->getActiveSheet(0) ;//->toArray(null, NULL, True, True);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$i = 8;
$dt = $sheet->getCell('PayOn')->getValue();
$stringDate = PHPExcel_Style_NumberFormat::toFormattedString($dt, 'YYYY-MM-DD');
$date = new DateTime($stringDate);
$PayOn = $date->format('m-Y');
$createdby = $this->session->userdata ( 'userId' );
$Totaldays = $sheet->getCell('I'.$i)->getValue();
$FileExists = $this->payroll_model->checkFileDetailsExists($PayOn);
if (count($FileExists)== 0)
{
$FileDetails = array('PayOn'=>$PayOn,'TotalNoofDays'=>$Totaldays,'FileName'=>$PayrollFileName,'CreatedBy'=>$createdby);
$result = $this->payroll_model->UploadFileName($FileDetails);
}
else
{
$FileDetailsupdate = array('TotalNoofDays'=>$Totaldays,'FileName'=>$PayrollFileName,'CreatedBy'=>$createdby);
$result = $this->payroll_model->UpdateFileName($FileDetailsupdate,$PayOn);
$this->payroll_model->deleteFileData($PayOn);
}
for($x=8; $x <= $highestRow; $x++)
{
$EmpId = $sheet->getCell('C'.$x)->getValue();
$BankAccountnumber = $sheet->getCell('E'.$x)->getValue();
$PFnumber = $sheet->getCell('F'.$x)->getValue();
$ESInumber = $sheet->getCell('G'.$x)->getValue();
$UAnumber = $sheet->getCell('H'.$x)->getValue();
$NoOfWorkingdays = $sheet->getCell('J'.$x)->getValue();
$LOP = $sheet->getCell('K'.$x)->getCalculatedValue();
$ActualSalary = $sheet->getCell('L'.$x)->getValue();
$PerDaySalary = $sheet->getCell('M'.$x)->getCalculatedValue();
$WorkedSalary =$sheet->getCell('N'.$x)->getCalculatedValue();
$BasicAndDA =$sheet->getCell('O'.$x)->getCalculatedValue();
$HRA =$sheet->getCell('P'.$x)->getCalculatedValue();
$OTWages = $sheet->getCell('Q'.$x)->getValue();
$OTPerHours =$sheet->getCell('R'.$x)->getValue();
$OTSalary =$sheet->getCell('S'.$x)->getCalculatedValue();
$GrosssSalary =$sheet->getCell('T'.$x)->getCalculatedValue();
$ESI = $sheet->getCell('U'.$x)->getCalculatedValue();
$PF =$sheet->getCell('V'.$x)->getCalculatedValue();
$ESIAndPF = $sheet->getCell('W'.$x)->getCalculatedValue();
$SalaryAsPerPF =$sheet->getCell('X'.$x)->getCalculatedValue();
$FoodAllowance = $sheet->getCell('Y'.$x)->getCalculatedValue();
$Incentive =$sheet->getCell('Z'.$x)->getValue();
$TotalSalary = $sheet->getCell('AA'.$x)->getCalculatedValue();
$Advance =$sheet->getCell('AB'.$x)->getValue();
$BalanceAdvance = $sheet->getCell('AC'.$x)->getValue();
$LessAdvance = $sheet->getCell('AD'.$x)->getCalculatedValue();
$Signature = $sheet->getCell('AE'.$x)->getValue();
//echo $EmpId ;
if( $EmpId != '')
{
$FileData = array('PayOn'=>$PayOn,'EmpID'=>$EmpId,'NoofDaysWorked'=>$NoOfWorkingdays,'ActualSalary'=>$ActualSalary,'PerDaySalary'=>$PerDaySalary,'WorkedSalary'=>$WorkedSalary,'BasicPlusDA'=>$BasicAndDA,'HRA'=>$HRA,'OTWages'=>$OTWages,'OTperHours'=>$OTPerHours,'OTSalary'=>$OTSalary,'ESIGrossSalary'=>$GrosssSalary,'EmployeeESI'=>$ESI,'PF'=>$PF,'TotalDeduction'=>$ESIAndPF,'SalaryAsPerPF'=>$SalaryAsPerPF,'FoodAllowance'=>$FoodAllowance,'Incentive'=>$Incentive,'TotalSalary'=>$TotalSalary,'Advance'=>$Advance,'BalanceAdvance'=>$BalanceAdvance,'LessAdvance'=>$LessAdvance,'Remarks'=>$Signature,'BankAccountNumber'=>$BankAccountnumber,'PFNumber'=>$PFnumber,'ESINumber'=>$ESInumber,'UANNO'=>$UAnumber,'LOP'=>$LOP);
$result = $this->payroll_model->UploadFileData($FileData);
}
}
$data['Success'] = "<script>alert('File Uploaded Successfully!');</script>";
$this->global['pageTitle'] = 'Siddharth : Payroll Data Upload';
$this->loadViews("payslipupload", $this->global, $data , NULL);
}
else
{
$data['Fail'] = "<script>alert('Please select valid Excel file to Upload!');</script>";
//echo "<script>alert('Please select valid Excel file to Upload!');</script>";
$this->global['pageTitle'] = 'Siddharth : Payroll Data Upload';
$this->loadViews("payslipupload", $this->global, $data , NULL);
}
}
else
{
$data['Fail'] = "<script>alert('Please select Excel file to Upload!');</script>";
//echo "<script>alert('Please select Excel file to Upload!');</script>";
$PayrollFileName = '';
$this->global['pageTitle'] = 'Siddharth : Payroll Data Upload';
$this->loadViews("payslipupload", $this->global, NULL , NULL);
}
}
/**
* This function used to upload the Excel file Details2
@ -377,11 +228,11 @@ function getEmployee()
$PayrollFileName = '';
//Check whether user upload picture
if(!empty($_FILES['userfile']['name']))
{
$pathinfo = pathinfo($_FILES['userfile']['name']);
$config['upload_path'] = 'uploads/files/';
$config['allowed_types'] = 'xls|xlsx|csv';
@ -443,8 +294,12 @@ function getEmployee()
$FileDetails = array('PayOn'=>$PayOn,'TotalNoofDays'=>$Totaldays,'FileName'=> $config['file_name'],'CreatedBy'=>$createdby);
$result = $this->payroll_model->UploadFileName($FileDetails);
$emplid=$this->payroll_model->getEmpID($q='');
$payEmpID=$this->payroll_model->getEmpIDfromPayData();
//print_r($payEmpID);die();
$nopaydata=0;
$nopayid='';
$nopayrowid='';
$Unknowncount=0;
$Unknown="";
$row="";
@ -454,44 +309,56 @@ function getEmployee()
for($x=8;$x<=$highestRow;$x++){
$EmpId = $sheet->getCell('A'.$x)->getValue();
//echo $EmpId;
/**** For Check Uploading EmpID existing in Employee Details(Valid or Not) *****/
$flag=0;
foreach($emplid as $e){
if(strtoupper($EmpId) == $e->EmpID){
$flag++;
// echo "<br>".$myvar.":- is valid empid";
}
}
if($flag==0){
//echo "<br>".$myvar.":- not a valid empid";
if($flag==0){
$Unknowncount++;
$Unknown.='-'.$EmpId;
$row.='-'.$x;
//$d.=$EmpId;
}
/***** For Check Uploading EmpID existing in Emp Pay Data Details(Whether master pay data available or not) *****/
if($flag != 0)
{
$flag2=0;
foreach($payEmpID as $p)
{
if(strtoupper($EmpId) == $p->EmpID)
{
$flag2++;
}
}
if($flag2==0)
{
$nopaydata++;
$nopayid.='-'.$EmpId;
$nopayrowid.='-'.$x;
}
}
$FileDataExists = $this->payroll_model->checkFileDetailsExists2($PayOn,$EmpId);
// echo $FileDataExists;
//die();
//echo $FileDataExists;
//die();
if ($FileDataExists=='' || $FileDataExists==0)
{
//$FileDetails = array('PayOn'=>$PayOn,'TotalNoofDays'=>$Totaldays,'FileName'=>$PayrollFileName,'CreatedBy'=>$createdby);
// $result = $this->payroll_model->UploadFileName($FileDetails);
//for($x=8; $x <= $highestRow; $x++)
//{
$EmpId = $sheet->getCell('A'.$x)->getValue();
$EmpId=strtoupper($EmpId);
@ -506,9 +373,8 @@ function getEmployee()
{
foreach($emplid as $e){
if($EmpId == $e->EmpID){
if($flag!=0 && $flag2!=0){
$FileData = array('Month_Year'=>$PayOn,'EmpID'=>$EmpId,'LOP_Days'=>$LOPDays,'OT_Hrs_Worked'=>$OTHoursWorked,'Loan_Recovered'=>$loanRecovered,'Incentives'=>$Incentive,'Other_Deductions'=>$Other_Deductions,'Created_By'=>$createdby,'Created_Time'=>date("Y-m-d h:i:sa"));
@ -516,24 +382,15 @@ function getEmployee()
$success++;
}
}
//}
// $data['Success'] = "<script>alert('File Uploaded Successfully!');</script>";
// echo "<script>alert('File Uploaded Successfully!');</script>";
// $this->global['pageTitle'] = 'Siddharth : Payroll Data Upload';
// $this->loadViews("payslipupload2", $this->global, $data , NULL);
}
//$data['Fail'] = "<script>alert('Duplicate Data Found!');</script>";
// $this->global['pageTitle'] = 'Siddharth : Payroll Data Upload';
// $this->loadViews("payslipupload2", $this->global, $data , NULL);
}
else{
@ -544,49 +401,40 @@ function getEmployee()
} //End of For Loop
// echo $success;
//echo $fail;
//$data['success'] = "<script>alert($fail + 'Duplicate Data Found!');</script>";
//echo "DONE";
echo "<script>alert('File Uploaded Successfully!');</script>";
echo "<script> alert($success +' Data Uploaded sucessfully and ' + $fail + ' Duplicate Data Found'); </script>";
echo "<script>alert($Unknowncount+'-data invalid, and data are'+'$Unknown'+'found at rows'+'$row');</script>";
$this->global['pageTitle'] = 'Siddharth : Payroll Data Upload';
$this->loadViews("payslipupload2", $this->global , NULL);
//redirect('payslip/viewUpload2');
echo "<script> alert($success +' - Data Uploaded sucessfully and ' + $fail + ' - Duplicate Data Found'); </script>";
echo "<script>alert($Unknowncount+'-data invalid, and data are'+'$Unknown'+'- found at rows'+'$row');</script>";
echo "<script>alert($nopaydata+'-data no have pay data, and data are'+'$nopayid'+'- found at rows'+'$nopayrowid');</script>";
echo "<script>window.location.href='ExcelUpload2';</script>";//redirect('payslip/viewUpload2');
} else
{
//$data['Fail'] = "<script>alert('Please select valid Excel file to Upload!');</script>";
//echo "<script>alert('Please select valid Excel file to Upload!');</script>";
// $this->global['pageTitle'] = 'Siddharth : Payroll Data Upload2';
// $this->loadViews("payslipupload2", $this->global, $data , NULL);
echo "<script>alert('Please select valid Excel file to Upload!');window.location.href='ExcelUpload2';</script>";
}
}
else
{
//$data['Fail'] = "<script>alert('Please select Excel file to Upload!');</script>";
//echo "<script>alert('Please select Excel file to Upload!');</script>";
// $PayrollFileName = '';
// $this->global['pageTitle'] = 'Siddharth : Payroll Data Upload2';
// $this->loadViews("payslipupload2", $this->global, NULL , NULL);
echo "<script>alert('Please select Excel file to Upload!');window.location.href='ExcelUpload2';</script>";
}
}
function updatepayroll()
function checkExistPay()
{
$this->global['pageTitle'] = 'Update Payroll';
$this->loadViews("payslipeditable", $this->global, NULL , NULL);
$empid = $this->input->post('employee');
$payon = $this->input->post('payon');
$result = $this->payroll_model->checkExistPayData($empid,$payon);
echo json_encode(count($result));
}
function pageNotFound()

View File

@ -61,6 +61,17 @@ class Payroll_model extends CI_Model
}
}
function checkExistPayData($empid,$payon)
{
$this->db->select('PayOn,EmpID');
$this->db->from('T_Payroll');
$this->db->where('PayOn',$payon);
$this->db->where('EmpID',$empid);
$query = $this->db->get();
return $query->result();
}
function checkFileDetailsExists2($PayOn,$EmpId)
{
//echo $EmpId;
@ -236,5 +247,16 @@ class Payroll_model extends CI_Model
$query = $this->db->get();
return $query->result();
}
function getEmpIDfromPayData()
{
$this->db->select('EmpID');
$this->db->from('T_Emp_Pay_Data');
$query = $this->db->get();
return $query->result();
}
}
?>

View File

@ -61,7 +61,7 @@ $(function() {
$("#Calculate").click(function(){
var count=0;
var payon = $('#PayOn').val();
var employee = $('#Employee').val();
@ -71,34 +71,53 @@ $(function() {
{
var check = $('#All').is(":checked");
if(check){
//alert(check);
var c=0;
$('#Employee').find('option').each(function() {
//alert($(this).val());
count++;
//AJAX STARTED
var employee=$(this).val();
$('#content').loader('show');
$.ajax({
data:{payon:payon,employee:employee},
type:"POST",
url:"<?php echo base_url();?>payslip/callsp",
url:"<?php echo base_url();?>payslip/checkExistPay",
success:function(result){
$('form#PayslipGenerator').submit();
success:function(result)
{
if(result == 1)
{
$('form#PayslipGenerator').submit();
$('#content').loader('hide');
//alert("Procedure Called Sucessfully!");
}
else{
c++;
$.ajax({
data:{payon:payon,employee:employee},
type:"POST",
url:"<?php echo base_url();?>payslip/callsp",
success:function(result){
$('form#PayslipGenerator').submit();
$('#content').loader('hide');
}
});
}
}
});
// CALCULATE PAY AJAX ENDED
});
});
alert("Employees Salary Added Successfully!");
alert(count + " Employees Salary Added Successfully!");
} // else for select all not selected
@ -109,13 +128,32 @@ $(function() {
$.ajax({
data:{payon:payon,employee:employee},
type:"POST",
url:"<?php echo base_url();?>payslip/callsp",
url:"<?php echo base_url();?>payslip/checkExistPay",
success:function(result) {
$('form#PayslipGenerator').submit();
$('#content').loader('hide');
alert("Employees Salary Added Successfully!");
if(result == 1)
{
$('form#PayslipGenerator').submit();
$('#content').loader('hide');
alert("Payslip Downloaded Successfully..!");
}
else{
$.ajax({
data:{payon:payon,employee:employee},
type:"POST",
url:"<?php echo base_url();?>payslip/callsp",
success:function(result){
$('form#PayslipGenerator').submit();
$('#content').loader('hide');
alert("Salary Calculated Successfully..!");
}
});
}
}

View File

@ -1,15 +1,4 @@
<?php
if(isset($Success)){
echo $Success;
}
if(isset($Fail)){
echo $Fail;
}
?>
<script>
function readURL(input) {
$('#FileName').val(input.files[0].name);
@ -58,12 +47,12 @@ function checkYearMonthAsEmpty()
<div class="col-md-8 col-md-offset-2" style="border:2px dotted;padding:2%;">
<form id="upload" method="post" action="<?php echo base_url() ?>FileUpload2"; role="form" enctype="multipart/form-data"> <div class="col-md-5 col-md-offset-2">
<span for="FileName">File Name</span>
<form id="upload" method="post" action="<?php echo base_url() ?>FileUpload2"; role="form" enctype="multipart/form-data"> <div class="col-md-5 col-md-offset-2">
<span for="FileName">File Name</span><?php //print_r($data);?>
<input type="text" class="form-control required" id="FileName" name="FileName" readonly>
</div>
<div class="box-header">
<input type="file" accept=".xlsx" onchange="readURL(this);" id="userfile" name="userfile"/>
<input type="file" accept=".xlsx" onchange="readURL(this);" id="userfile" name="userfile" />
<label for="photo">Select Excel File to upload<br/>(only .xls)</label>
@ -96,7 +85,7 @@ function checkYearMonthAsEmpty()
</div>
<br/>
<div class="col-md-1 col-md-offset-1">
<input type="button" class="btn btn-info" value="upload" onclick="save();"/>
<input type="submit" class="btn btn-info" value="upload" onclick="save();return false;"/>
</div>
</div>
@ -112,30 +101,21 @@ var x=checkYearMonthAsEmpty();
//alert(x);
if(x == 0)
{
//alert($('#userfile').val());
//$_FILES['userfile']['name']=
// $.ajax({
// data:$('#upload').serialize(),
// type:"POST",
// //enctype: 'multipart/form-data',
// url:"<?php echo base_url();?>payslip/uploadExcel2",
// success:function(result){
// $('#content').loader('hide');
// alert("File Uploaded Sucessfully!");
// alert(result);
// window.location="purchaseorderListing";
// //alert("redirect");
$('form#upload').submit();
//window.location="ExcelUpload2";
// }
//});
$('#userfile').val('');
$('#mon ').val('');
}else
{
alert("Please Provide All Information Correctly!");
return false;
}
}
</script>