siddharth_application/application/controllers/payslip.php
2017-09-20 07:50:39 +00:00

517 lines
16 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : Employee (Employee Controller)
* User Class to control all user related operations.
* @author : Gandhimathi
* @version : 1.1
* @since : 07 Apr 2017
*/
class payslip extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('payroll_model');
$this->load->library('form_validation');
$this->isLoggedIn();
}
/**
* This function used to call stored procedure named with final_payroll_data()
*/
public function callsp(){
$payon = $this->input->post('payon');
$employee = $this->input->post('employee');
$result = $this->payroll_model->model_sp($payon,$employee);
// $result = $this->db->last_query();
return $result;
//$this->db->call_function('model_sp');
}
/**
* This function used to load the first screen of the user
*/
public function viewUpload2()
{
$this->global['pageTitle'] = 'Siddharth : Payroll Data Upload2';
$this->loadViews("payslipupload2", $this->global, NULL);
}
/**
* This function used to load the first screen of the user
*/
public function viewGenerator()
{
//echo 'inside funtion';
$Data['Payon'] = $this->payroll_model->getPayOn();
//$Data['Emplist'] = $this->payroll_model->getEmployeelist();
$this->global['pageTitle'] = 'Siddharth : Payroll Generater';
$this->loadViews("payslipgenerate", $this->global, $Data , NULL);
}
/* Validation for Employee Dropdown
*/
function Employee_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if($selectValue == '-1')
{
$this->form_validation->set_message('Employee_validate', 'Please Select Employee.');
return false;
}
else // user picked something
{
return true;
}
}
function getEmployee()
{
$id = $this->input->post('id1');
$result = $this->payroll_model->getEmployeelist2($id );
$HTML="";
if($result->num_rows() > 0){
foreach($result->result() as $list){
$HTML.="<option value='".$list->EmpId."'>".$list->EmpId."-".$list->Fname."</option>";
}
}
echo $HTML;
}
/* Validation for PayOn Dropdown
*/
function PayOn_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if($selectValue == '-1')
{
$this->form_validation->set_message('PayOn_validate', 'Please Select PayOn.');
return false;
}
else // user picked something
{
return true;
}
}
/**
* This function used to load the first screen of the user
*/
public function PrintPdf()
{
$All = $this->input->post('All');
if($All == '')
{
$this->form_validation->set_rules('Employee','Employee','trim|callback_Employee_validate');
}
$this->form_validation->set_rules('PayOn','PayOn','trim|callback_PayOn_validate');
if($this->form_validation->run() == FALSE)
{
$this->viewGenerator();
}
else
{
$Payon = $this->input->post('PayOn');
if($All != '')
{
$result = $this->payroll_model->getEmpAll($Payon);
//print_r($result);
//echo "-----------------------------------------";
if($result > 0 )
{
for($i=0;$i <count($result) ;$i++ )
{
$EmpID = $result[$i]['EmpId'];
$Data['PayDetails'] = $this->payroll_model->GetPayslipdata($Payon,$EmpID);
//print_r($Data['PayDetails']);//die();
$totalsalary =$Data['PayDetails'][0]->LessAdvance;
$totalsalaryinwords = $this->convertNumber(round($totalsalary));
$Data['amtinwords']=$totalsalaryinwords;
//$Data['Count'] = $i;
$this->load->View("payslipgenerateprint", $Data );
}
}
}
else
{
$EmpID = $this->input->post('Employee');
$Data['PayDetails'] = $this->payroll_model->GetPayslipdata($Payon,$EmpID);
$totalsalary =$Data['PayDetails'][0]->LessAdvance;
$totalsalaryinwords = $this->convertNumber(round($totalsalary));
$Data['amtinwords']=$totalsalaryinwords;
$this->load->View("payslipgenerateprint", $Data );
}
$php = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
if($All != '')
{
$filename = 'Payslip-'.$Payon.'.pdf' ;
}
else
{
$filename = 'Payslip-'.$EmpID . '-' .$Payon.'.pdf' ;
}
require_once(APPPATH .'third_party/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->set_paper('A4', 'portrait');
$dompdf->load_html($php);
$dompdf->render();
// add the header
$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "bold");
// the same call as in my previous example
$canvas->page_text(72, 18, "Page: {PAGE_NUM} of {PAGE_COUNT}",
$font, 6, array(0,0,0));
$dompdf->stream($filename);
}
}
/**
* This function used to upload the Excel file Details
*/
/**
* This function used to upload the Excel file Details2
*/
function uploadExcel2(){
$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';
$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();
$x = 8;
$month=$this->input->post('mon');
$year=$this->input->post('yr');
$PayOn= $month . "-" . $year;
$createdby = $this->session->userdata ( 'userId' );
if($month=='01' || $month=='03' || $month=='05' || $month=='07' || $month=='08' || $month=='10' || $month=='12')
{
$Totaldays = 31;
}
else if($month=='04' || $month=='06' || $month=='09' || $month=='11'){
$Totaldays = 30;
}
else{
$Totaldays = 28;
}
// $Totaldays = 0;
//echo $highestRow;
$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="";
$d=array("-1"=>"");
$fail=0;
$success=0;
for($x=8;$x<=$highestRow;$x++){
$EmpId = $sheet->getCell('A'.$x)->getValue();
/**** For Check Uploading EmpID existing in Employee Details(Valid or Not) *****/
$flag=0;
foreach($emplid as $e){
if(strtoupper($EmpId) == $e->EmpID){
$flag++;
}
}
if($flag==0){
$Unknowncount++;
$Unknown.='-'.$EmpId;
$row.='-'.$x;
}
/***** 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);
if ($FileDataExists=='' || $FileDataExists==0)
{
$EmpId = $sheet->getCell('A'.$x)->getValue();
$EmpId=strtoupper($EmpId);
$LOPDays = $sheet->getCell('C'.$x)->getValue();
$OTHoursWorked =$sheet->getCell('D'.$x)->getValue();
$loanRecovered=$sheet->getCell('E'.$x)->getValue();
//$loanBalance=$sheet->getCell('E'.$x)->getValue();
$Incentive =$sheet->getCell('F'.$x)->getValue();
$Other_Deductions =$sheet->getCell('G'.$x)->getValue();
if( $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"));
$result = $this->payroll_model->UploadFileData2($FileData);
$success++;
}
//}
}
}
else{
$fail++;}
} //End of For Loop
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>";
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
{
echo "<script>alert('Please select valid Excel file to Upload!');window.location.href='ExcelUpload2';</script>";
}
}
else
{
echo "<script>alert('Please select Excel file to Upload!');window.location.href='ExcelUpload2';</script>";
}
}
function checkExistPay()
{
$empid = $this->input->post('employee');
$payon = $this->input->post('payon');
$result = $this->payroll_model->checkExistPayData($empid,$payon);
echo json_encode(count($result));
}
function pageNotFound()
{
$this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
function convertNumber($amt){
$ShowPaise='0';
$totalAmt=explode(".",$amt);
$number = $totalAmt[0];
$no = $number;
if(!empty($totalAmt[1]) && $totalAmt[1]!=0){
$point = $totalAmt[1];
$ShowPaise='1';
}
else{
$point=0;
$ShowPaise='0';
}
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$words = array('0' => '', '1' => 'One', '2' => 'Two',
'3' => 'Three', '4' => 'Four', '5' => 'Five', '6' => 'Six',
'7' => 'Seven', '8' => 'Eight', '9' => 'Nine',
'10' => 'Ten', '11' => 'Eleven', '12' => 'Twelve',
'13' => 'Thirteen', '14' => 'Fourteen',
'15' => 'Fifteen', '16' => 'Sixteen', '17' => 'Seventeen',
'18' => 'Eighteen', '19' =>'Nineteen', '20' => 'Twenty',
'30' => 'Thirty', '40' => 'Forty', '50' => 'Fifty',
'60' => 'Sixty', '70' => 'Seventy',
'80' => 'Eighty', '90' => 'Ninety');
$digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
while ($i < $digits_1) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += ($divider == 10) ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 1) ? 's' : null;
$hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
$str [] = ($number < 21) ? $words[$number] .
" " . $digits[$counter] . $plural . " " . $hundred
:
$words[floor($number / 10) * 10]
. " " . $words[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else $str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ?
" " . $words[$point / 10] . " " .
$words[$point = $point % 10] : '';
if($ShowPaise=='0'){
$amountInWords = "Rupees " . $result." Only";
}
else{
$amountInWords = "Rupees " . $result ." Paise ". $points." Only";
}
return $amountInWords;
}
}
?>