payroll_model = new Payroll_model(); $this->monthlypay_model = new Monthlypay_model(); $this->session = session(); helper('form'); //$this->load->library('form_validation'); $this->isLoggedIn(); } function phpAlert($msg) { echo ''; } /** * This function used to call stored procedure named with final_payroll_data() */ public function callsp() { // $result = $this->payroll_model->model_sp($this->request->getPost('payon'), $this->request->getPost('employee')); // return $result; // die; $PayOn = $this->request->getPost('payon'); $EmpId = $this->request->getPost('employee'); $res = $this->payroll_model->getMonthlyPayDetails($EmpId, $PayOn); $result = $res[0]; $loan = []; $loanHistory = []; $loan_id = 0; $BalanceAdvance = 0; if(is_null($result->Loan_ID)){ }else{ if($result->Loan_Recovered > 0) { $loan_id = $result->Loan_ID; if($result->Remaining_Due - 1 == 0){ $is_Active = 0; }else{ $is_Active = 1; } $loan = [ 'Paid_Due' => $result->Paid_Due + 1, 'Remaining_Due' => $result->Remaining_Due - 1, 'Paid_Amount' => $result->Paid_Amount + $result->Loan_Recovered, 'is_Active' => $is_Active ]; $loanHistory = [ 'Loan_ID' => $loan_id, 'Due_Amount' => $result->Loan_Recovered, 'Balance_Amount' => $result->Loan_Amount - ($result->Paid_Amount + $result->Loan_Recovered), 'Due_Date' => $PayOn, ]; $BalanceAdvance = $result->Loan_Amount - ($result->Paid_Amount + $result->Loan_Recovered); } } // print_r($data);die; $data = [ 'PayOn' => $result->Month_Year, 'EmpID' => $result->EmpID, 'TotalCalDays' => $result->TotalCalDays, 'NoofDaysWorked' => $result->Days_worked, 'LOP' => $result->LOP_Days, 'Paid_Leave' => $result->Paid_leave, 'ActualSalary' => $result->ActualSalary, 'PerDaySalary' => $result->PerDaySalary, 'WorkedSalary' => $result->WorkedSalary, 'Basic' => $result->Basic, 'HRA' => $result->HRA, 'OT_Hrs_Worked' => $result->OT_Hrs_Worked, 'OTSalary' => $result->OTSalary, 'ESI' => $result->ESI, 'PF' => $result->PF, 'OtherDeductions' => $result->Other_Deductions, 'Festival_Bonus' => $result->Festival_Bonus, 'TotalSalary' => $result->Estimate, 'Advance' => $result->Loan_Recovered, 'BalanceAdvance' => $BalanceAdvance, 'LessAdvance' => 0, 'BankAccountNumber' => $result->BankAccountNo, 'PFNumber' => $result->PFNO, 'ESINumber' => $result->ESINO, 'UANNO' => $result->PFNO, ]; // print_r($result); // print_r($loan); // print_r($loanHistory); // print_r($data); // die; $insert = $this->payroll_model->insertPayroll($data); if($insert){ if(count($loan)){ $this->payroll_model->updateLoan($loan_id,$result->EmpID,$loan); } if(count($loanHistory)){ $this->payroll_model->insertLoanHistory($loanHistory); } } return $insert; } function loadBankreportScreen() { $Data['Payon'] = $this->payroll_model->getPayOn(); $Data['Bank'] = $this->payroll_model->getBankInfo(); $this->global['pageTitle'] = 'Bank Report Screen'; $this->loadViews("bankreport", $this->global, $Data, NULL); } function getBankReport() { $bank = $this->request->getPost('bank'); $payon = $this->request->getPost('month'); $chequeno = $this->request->getPost('chequeno'); $chequedate = format_date($this->request->getPost('chequedate')); $createdby = $this->session->get('userId'); $monthsoptions = array("01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr", "05" => "May", "06" => "June", "07" => "July", "08" => "Aug", "09" => "Sep", "10" => "Oct", "11" => "Nov", "12" => "Dec"); $m = substr((string)$payon, 0, 2); $y = substr((string)$payon, 3); $month = $monthsoptions[$m] . "-" . $y; $excel = $this->request->getPost('excel'); $HTML = ''; //echo $excel; // if(empty($excel)) // { // echo "PDF"; // } // else // { // echo "EXCEL"; // } // die(); $filename = ''; if ($this->request->getPost('Bank_Report')) { $data['result'] = $this->payroll_model->getReportforBank($bank, $payon); if ($chequeno != '' && $chequedate != '') { $empcount = count($data['result']); $cheque = array('ChequeNO' => $chequeno, 'ChequeDate' => $chequedate, 'BankName' => $bank, 'Monthyear' => $payon, 'Empcount' => $empcount, 'CreatedBy' => $createdby); $data['insertcheque'] = $this->payroll_model->ChequeDetails($cheque); } //print_r($data['result']);die(); $totamtwords = ''; $totalamt = 0.00; if (!empty($data['result'])) { foreach ($data['result'] as $amt) { $totalamt += $amt->LessAdvance; } } $totamtwords = $this->convertNumber($totalamt); $data['bankdetails'] = $this->payroll_model->getBankInfo($bank); $data['chequedetails'] = $this->payroll_model->getChequeInfo($bank, $payon); $data['Totalamount'] = $totalamt; $data['Totalamtwords'] = $totamtwords; $data['PayMonth'] = $month; $filename = 'Bank Report for' . $payon . 'pdf'; $HTML = view("bankreportprint", $data); } if ($this->request->getPost('PF_Report')) { $data['PFESI'] = $this->payroll_model->getReportforPFESI($payon); $data['PayMonth'] = $month; $data['companyinfo'] = $this->payroll_model->getCompanyInformation(); //print_r($data['companyinfo']);die(); $totamtwords = ''; $totalamt = 0.00; $totemppf = 0.00; $totemprpf = 0.00; if (!empty($data['PFESI'])) { foreach ($data['PFESI'] as $pf) { $totalamt += ($pf->PF + $pf->CompanyPF); $totemppf += ($pf->PF); $totemprpf += ($pf->CompanyPF); } } $data['Totalamount'] = $totalamt; $data['TotalEmployeeContribution'] = $totemppf; $data['TotalEmployerContribution'] = $totemprpf; $totamtwords = $this->convertNumber($totalamt); $data['Totalamtwords'] = $totamtwords; if (empty($excel)) { $filename = 'PF Report for' . $payon . 'pdf'; $HTML = view("pfreportprint", $data); // echo "PDF PART 1"; } else { // Create a new Spreadsheet object $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle('Employee PF Report ' . $data['PayMonth']); // Set headers $sheet->setCellValue('A1', 'Employee PF Report ' . $data['PayMonth']); $sheet->mergeCells('A1:H1'); $sheet->getStyle('A1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16); $sheet->getStyle('A1')->getFill()->getStartColor()->setARGB('#333'); // Set column headers $sheet->setCellValue('A4', 'S.No.'); $sheet->setCellValue('B4', 'Employee Name'); $sheet->setCellValue('C4', 'PF Account No'); $sheet->setCellValue('D4', 'Employee Contribution'); $sheet->setCellValue('E4', 'Employer Contribution'); $sheet->setCellValue('F4', 'No Of Days Worked'); $sheet->setCellValue('G4', 'OT Hrs Worked'); $sheet->setCellValue('H4', 'Total Amount'); // Style column headers for ($col = ord('A'); $col <= ord('H'); $col++) { $sheet->getColumnDimension(chr($col))->setAutoSize(true); $sheet->getStyle(chr($col))->getFont()->setSize(12); $sheet->getStyle(chr($col))->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); } // Populate data $i = 6; $j = 1; $overall = 0; $overallemp = 0; $overallemr = 0; foreach ($data['PFESI'] as $row) { $sheet->setCellValue('A' . $i, $j); $sheet->setCellValue('B' . $i, $row->FName . ' ' . $row->Lname); $sheet->setCellValue('C' . $i, $row->PFNO); $sheet->setCellValue('D' . $i, number_format($row->PF, 2, '.', '')); $sheet->setCellValue('E' . $i, number_format($row->CompanyPF, 2, '.', '')); $sheet->setCellValue('F' . $i, number_format($row->NoofDaysWorked, 2, '.', '')); $sheet->setCellValue('G' . $i, number_format($row->OTperHours, 2, '.', '')); $total = $row->PF + $row->CompanyPF; $overall += $total; $overallemp += $row->PF; $overallemr += $row->CompanyPF; $sheet->setCellValue('H' . $i, $total); $i++; $j++; } // Total $sheet->setCellValue('C' . $i, 'Total'); $sheet->setCellValue('D' . $i, $overallemp); $sheet->setCellValue('E' . $i, $overallemr); $sheet->setCellValue('H' . $i, $overall); // Protect the sheet $sheet->getProtection()->setSheet(true); $sheet->getProtection()->setSort(true); $sheet->getProtection()->setInsertRows(true); $sheet->getProtection()->setFormatCells(true); // Set the headers for file download // $filename = 'EmployeePFReport_' . date('Ymd_His') . '.xls'; $filename = 'EmployeePFReport' . $payon . 'xls'; header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $filename . '"'); header('Cache-Control: max-age=0'); // Write the file $writer = new Xlsx($spreadsheet); $writer->save('php://output'); } } if ($this->request->getPost('ESI_Report')) { $data['PFESI'] = $this->payroll_model->getReportforPFESI($payon); //print_r($data['PFESI']);die(); $data['PayMonth'] = $month; $data['companyinfo'] = $this->payroll_model->getCompanyInformation(); $totamtwords = ''; $totalamt = 0.00; $totemppf = 0.00; $totemprpf = 0.00; if (!empty($data['PFESI'])) { foreach ($data['PFESI'] as $pf) { $totalamt += ($pf->EmployeeESI + $pf->CompanyESI); $totemppf += ($pf->EmployeeESI); $totemprpf += ($pf->CompanyESI); } } $data['Totalamount'] = $totalamt; $totamtwords = $this->convertNumber($totalamt); $data['TotalEmployeeContribution'] = $totemppf; $data['TotalEmployerContribution'] = $totemprpf; $data['Totalamtwords'] = $totamtwords; if (empty($excel)) { $filename = 'ESI Report for' . $payon . 'pdf'; $HTML = view("esireportprint", $data); // echo "PDF PART 1"; } else { // Create a new Spreadsheet object $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle('Employee PF Report ' . $data['PayMonth']); // Set headers $sheet->setCellValue('A1', 'Employee PF Report ' . $data['PayMonth']); $sheet->mergeCells('A1:H1'); $sheet->getStyle('A1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16); $sheet->getStyle('A1')->getFill()->getStartColor()->setARGB('#333'); // Set column headers $sheet->setCellValue('A4', 'S.No.'); $sheet->setCellValue('B4', 'Employee Name'); $sheet->setCellValue('C4', 'PF Account No'); $sheet->setCellValue('D4', 'Employee Contribution'); $sheet->setCellValue('E4', 'Employer Contribution'); $sheet->setCellValue('F4', 'No Of Days Worked'); $sheet->setCellValue('G4', 'OT Hrs Worked'); $sheet->setCellValue('H4', 'Total Amount'); // Style column headers for ($col = ord('A'); $col <= ord('H'); $col++) { $sheet->getColumnDimension(chr($col))->setAutoSize(true); $sheet->getStyle(chr($col))->getFont()->setSize(12); $sheet->getStyle(chr($col))->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); } // Populate data $i = 6; $j = 1; $overall = 0; $overallemp = 0; $overallemr = 0; foreach ($data['PFESI'] as $row) { $sheet->setCellValue('A' . $i, $j); $sheet->setCellValue('B' . $i, $row->FName . ' ' . $row->Lname); $sheet->setCellValue('C' . $i, $row->PFNO); $sheet->setCellValue('D' . $i, number_format($row->PF, 2, '.', '')); $sheet->setCellValue('E' . $i, number_format($row->CompanyPF, 2, '.', '')); $sheet->setCellValue('F' . $i, number_format($row->NoofDaysWorked, 2, '.', '')); $sheet->setCellValue('G' . $i, number_format($row->OTperHours, 2, '.', '')); $total = $row->PF + $row->CompanyPF; $overall += $total; $overallemp += $row->PF; $overallemr += $row->CompanyPF; $sheet->setCellValue('H' . $i, $total); $i++; $j++; } // Total $sheet->setCellValue('C' . $i, 'Total'); $sheet->setCellValue('D' . $i, $overallemp); $sheet->setCellValue('E' . $i, $overallemr); $sheet->setCellValue('H' . $i, $overall); // Protect the sheet $sheet->getProtection()->setSheet(true); $sheet->getProtection()->setSort(true); $sheet->getProtection()->setInsertRows(true); $sheet->getProtection()->setFormatCells(true); // Set the headers for file download // $filename = 'EmployeePFReport_' . date('Ymd_His') . '.xls'; $filename = 'EmployeePFReport' . $payon . 'xls'; header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $filename . '"'); header('Cache-Control: max-age=0'); // Write the file $writer = new Xlsx($spreadsheet); $writer->save('php://output'); } } if (empty($excel)) { // Load the HTML content for the Header,footer $HtmlHeading = view('includes/bankreport_header', $data); $HTMLFooter = view('includes/bankreport_footer', $data); // Create an instance of mPDF $mpdf = new Mpdf([ 'mode' => 'utf-8', 'format' => 'A4-P', 'margin_left' => 10, 'margin_right' => 10, 'margin_top' => 38, 'margin_bottom' => 4, 'margin_header' => 10, 'margin_footer' => 6, ]); // Set document properties $mpdf->SetDisplayMode('fullpage'); $mpdf->SetHTMLHeader($HtmlHeading); // You need to define $HtmlHeading somewhere in your code $mpdf->SetHTMLFooter($HTMLFooter . 'Page {PAGENO} of {nb}'); $mpdf->SetTitle('Resicoindustries:PayrollReport'); // Configure mPDF settings $mpdf->list_indent_first_level = 1; $mpdf->setAutoTopMargin = 'stretch'; $mpdf->setAutoBottomMargin = 'stretch'; // Write HTML to PDF $mpdf->WriteHTML($HTML); // Output the PDF $filename = 'EmployeePayrollReport'; // Define your filename here $mpdf->Output($filename . '.pdf', 'D'); } } function loadLoanReport($param1 = null, $param2 = null) { $eid = $param1 ?? ''; $fyr = $param2 ?? ''; $currentyear = ''; $nxtyear = ''; if (!empty($eid) and !empty($fyr) and !is_numeric($eid) and !($fyr == 'Overall')) { //echo "EMPLOYEE WITH FINYEAR"; $currentyear = substr($fyr, 0, 4); $nxtyear = substr($fyr, 5, 4); $data['fyear'] = $currentyear . '-' . $nxtyear; $data['loanrecords'] = $this->payroll_model->getLoanReportforEmp($eid, $currentyear, $nxtyear, 'emp'); $data['selsource'] = $eid; } else if (!empty($eid) and !empty($fyr) and $fyr == 'Overall') { // echo "EMPLOYEE WITH OVERALL"; $data['fyear'] = "Overall"; $currentyear = ''; $nxtyear = ''; $data['loanrecords'] = $this->payroll_model->getLoanReportforEmp($eid, $currentyear, $nxtyear, 'emp'); $data['selsource'] = $eid; } else if (is_numeric($eid)) { //echo "LOAN HISTORY"; $currentyear = ''; $nxtyear = ''; $data['selsource'] = $eid; $data['fyear'] = $currentyear . '-' . $nxtyear; $data['childdata'] = $this->payroll_model->getLoanReportforEmp($eid, $currentyear = "", $nxtyear = "", 'history'); } else { if (empty($this->request->getPost('finyear'))) { //echo "DEFAULT LOAD"; $year = date("Y"); $month = date("m"); $currentyear = ''; $nxtyear = ''; $source = $this->request->getPost('source'); $data['selsource'] = 'Company'; } else { if (!empty($this->request->getPost('finyear'))) { //echo "FIN YEAR WITH SOURCE"; $source = $this->request->getPost('source'); $data['selsource'] = $source; $finyear = $this->request->getPost('finyear'); $currentyear = substr((string)$finyear, 0, 4); $nxtyear = substr((string)$finyear, 5, 4); $data['fyear'] = $currentyear . '-' . $nxtyear; } } // echo $currentyear.'-'.$nxtyear; // echo "Company"; $data['loanrecords'] = $this->payroll_model->getLoanReport($source, $currentyear, $nxtyear); // print_r($data['loanrecords']); } $data['loanemployees'] = $this->payroll_model->getEmpDetailsforLoan(); $this->global['pageTitle'] = 'Loan Reports'; $this->loadViews("loanreports", $this->global, $data, NULL); } public function leaveReport() { $fyr = get_financial_year(); if ($this->request->getMethod() == 'POST') { $fyr = $this->request->getPost('fyr'); } // $fiscalYears = get_financial_year_list(); $fiscalYears = get_financial_year_list(date('Y'), 8); $data['fiscalyears'] = $fiscalYears; $data['selectedfiscalyears'] = $fyr; $data['leaverecords'] = $this->payroll_model->getEmpDetailsforLeave($fyr); // echo ''; $this->global['pageTitle'] = 'Leave Reports'; $this->loadViews("leavereports", $this->global, $data, NULL); } function monthwiseLeaveReport($param1,$param2) { $EmployeeID = $param1; $Fin_year = $param2; $data['finyear'] = $Fin_year; $this->global['pageTitle'] = 'Monthwise Leave Reports'; $data['MonthwiseReport'] = $this->payroll_model->getMonthwiseEmpDetailsforLeave($Fin_year, $EmployeeID); $this->loadViews("leavereportsmonthwise", $this->global, $data, NULL); } /** * This function used to load the first screen of the user */ public function viewUpload2() { $this->global['pageTitle'] = 'Payroll Data Upload2'; $this->loadViews("payslipupload2", $this->global, NULL); } public function monthlyInputs() { $current = date("m-Y"); $data['month'] = $this->monthlypay_model->monthlyListing($current); $data['dropdownvalue'] = $current; $data['fresh'] = $this->monthlypay_model->getEmpPayDetailsforMonthInputs($current); $employeeSalary = []; $esi = []; $pf = []; $ot = []; foreach ($data['fresh'] as $value) { $NoofDays = $value->NoofDays; //Month day 30,31,28 $HRA_Amount = $value->HRA_Amount; $Basic_Pay = $value->Basic_Pay; $TotalSalary = $value->TotalSalary; $Days_worked = $value->Days_worked; // working day $Sunday = $value->sunday_count; // Sunday count $LOP_Days = $value->NoofDays - ($Days_worked + $Sunday); // not working day $Paid_leave = $value->Paid_leave; // leave day $OT_Hrs_Worked = $value->OT_Hrs_Worked; //OT hours $Monthly_Due = $value->Monthly_Due; // AUTO LOAN DUE $Loan_Recovered = $value->Loan_Recovered; //MANUAL LOAN DUE $due_start_date = $value->DueDate; $paydate = $current; //From POST parm $pmonth = substr($paydate, 0, 2); $pyear = substr($paydate, -4); $pday = cal_days_in_month(CAL_GREGORIAN, $pmonth, $pyear); $paymonth = $pyear . '-' . $pmonth . '-' . $pday; $Loan_amount = $value->Loan_Amount; $Paid_Amount = $value->Paid_Amount; $Balance_Amount = $Loan_amount - $Paid_Amount; $loan = 0; if ($Loan_Recovered == 'NA') { $loan = 0.00; } else if ($Loan_Recovered == 0.00) { if (strtotime($due_start_date) <= strtotime($paymonth)) { $loan = $Monthly_Due; } } else if ($Loan_Recovered >= 0.00) { if (strtotime($due_start_date) <= strtotime($paymonth)) { $loan = $Loan_Recovered; } } if ($Monthly_Due > $Balance_Amount) { $loan = $Balance_Amount; } $PF_Rate = $value->PF_Rate; $ESI_Rate = $value->ESI_Rate; $totalDaysWorked = ($Days_worked + $Sunday) + $Paid_leave; $dayBasic = $Basic_Pay / $NoofDays; $dayHra = $HRA_Amount / $NoofDays; $onehoursSalary = ($dayBasic + $dayHra) / 8; /**one hour salay ot calculation**/ if ($OT_Hrs_Worked != 0) { $totSalayOT = $OT_Hrs_Worked * $onehoursSalary; } else { $totSalayOT = 0; } //current day basic and hra salary if ($value->is_management_team == 1) { $currentDayBasic = $dayBasic * $NoofDays; $currentDayHra = $dayHra * $NoofDays; } else { $currentDayBasic = $dayBasic * $totalDaysWorked; $currentDayHra = $dayHra * $totalDaysWorked; } if ($value->esi_applicable == 1) { $esiAmount = $currentDayBasic * $ESI_Rate / 100; } else { $esiAmount = 0; } if ($value->pf_applicable == 1) { $pfAmount = $currentDayBasic * $PF_Rate / 100; } else { $pfAmount = 0; } /** pf amount per day**/ //echo $totalothour;die; $empSalaryAdd = $currentDayBasic + $currentDayHra + $totSalayOT; $empSalarySub = $esiAmount + $pfAmount + $loan; $salaryInCurrentday = $empSalaryAdd - $empSalarySub; // echo $esiAmount .'
'; // echo $pfAmount .'
'; // echo $loan .'
'; // echo $empSalarySub .'
'; // echo $empSalaryAdd .'
'; // echo $salaryInCurrentday .'
'; // die; $employeeSalary[] = round($salaryInCurrentday); $esi[] = number_format($esiAmount,2, '.', ''); $pf[] = number_format($pfAmount,2, '.', ''); $ot[] = number_format($totSalayOT,2, '.', ''); } $data['empSalary'] = $employeeSalary; $data['esi'] = $esi; $data['pf'] = $pf; $data['over_time'] = $ot; $this->global['pageTitle'] = 'Payroll Monthly Inputs'; $this->loadViews("monthlypayinputs", $this->global, $data, NULL); } function changeMonth() { $current = $this->request->getPost('monthyear'); $data['month'] = $this->monthlypay_model->monthlyListing($current); $data['dropdownvalue'] = $current; $data['fresh'] = $this->monthlypay_model->getEmpPayDetailsforMonthInputs($current); // dd($data['fresh']); $employeeSalary = []; $esi = []; $pf = []; $ot = []; foreach ($data['fresh'] as $value) { $NoofDays = $value->NoofDays; //Month day 30,31,28 $HRA_Amount = $value->HRA_Amount; $Basic_Pay = $value->Basic_Pay; $TotalSalary = $value->TotalSalary; $Days_worked = $value->Days_worked; // working day $Sunday = $value->sunday_count; // Sunday count $LOP_Days = $value->NoofDays - ($Days_worked + $Sunday); // not working day $Paid_leave = $value->Paid_leave; // leave day $OT_Hrs_Worked = $value->OT_Hrs_Worked; //OT hours $Monthly_Due = $value->Monthly_Due; // AUTO LOAN DUE $Loan_Recovered = $value->Loan_Recovered; //MANUAL LOAN DUE $due_start_date = $value->DueDate; $paydate = $current; //From POST parm if (strlen((string)$paydate) == 6) { $paydate = '0' . $paydate; } $pmonth = substr($paydate, 0, 2); $pyear = substr($paydate, -4); $pday = cal_days_in_month(CAL_GREGORIAN, $pmonth, $pyear); $paymonth = $pyear . '-' . $pmonth . '-' . $pday; $Loan_amount = $value->Loan_Amount; $Paid_Amount = $value->Paid_Amount; $Balance_Amount = $Loan_amount - $Paid_Amount; $loan = 0; if ($Loan_Recovered == 'NA') { $loan = 0.00; } else if ($Loan_Recovered == 0.00) { if (strtotime($due_start_date) <= strtotime($paymonth)) { $loan = $Monthly_Due; } } else if ($Loan_Recovered >= 0.00) { if (strtotime($due_start_date) <= strtotime($paymonth)) { $loan = $Loan_Recovered; } } if ($Monthly_Due > $Balance_Amount) { $loan = $Balance_Amount; } $PF_Rate = $value->PF_Rate; $ESI_Rate = $value->ESI_Rate; $totalDaysWorked = ($Days_worked + $Sunday) + $Paid_leave; $dayBasic = $Basic_Pay / $NoofDays; $dayHra = $HRA_Amount / $NoofDays; $onehoursSalary = ($dayBasic + $dayHra) / 8; /**one hour salay ot calculation**/ if ($OT_Hrs_Worked != 0) { $totSalayOT = $OT_Hrs_Worked * $onehoursSalary; } else { $totSalayOT = 0; } //current day basic and hra salary if ($value->is_management_team == 1) { $currentDayBasic = $dayBasic * $NoofDays; $currentDayHra = $dayHra * $NoofDays; } else { $currentDayBasic = $dayBasic * $totalDaysWorked; $currentDayHra = $dayHra * $totalDaysWorked; } //$totalSalary = $currentDayBasic + $currentDayHra + $totSalayOT; if ($value->esi_applicable == 1) { $esiAmount = $currentDayBasic * $ESI_Rate / 100; } else { $esiAmount = 0;} if ($value->pf_applicable == 1) { $pfAmount = $currentDayBasic * $PF_Rate / 100; } else { $pfAmount = 0;} /** pf amount per day**/ //echo $totalothour;die; $empSalaryAdd = $currentDayBasic + $currentDayHra + $totSalayOT; $empSalarySub = $esiAmount + $pfAmount + $loan; $salaryInCurrentday = $empSalaryAdd - $empSalarySub; // echo $esiAmount .'
'; // echo $pfAmount .'
'; // echo $loan .'
'; // echo $empSalarySub .'
'; // echo $empSalaryAdd .'
'; // echo $salaryInCurrentday .'
'; // die; $employeeSalary[] = round($salaryInCurrentday); $esi[] = number_format($esiAmount,2, '.', ''); $pf[] = number_format($pfAmount,2, '.', ''); $ot[] = number_format($totSalayOT,2, '.', ''); } $data['empSalary'] = $employeeSalary; $data['esi'] = $esi; $data['pf'] = $pf; $data['over_time'] = $ot; // dd($data); //echo sizeof($data['fresh'])."-".sizeof($data['empSalary']);die; $this->global['pageTitle'] = 'Payroll Monthly Inputs'; $this->loadViews("monthlypayinputs", $this->global, $data, NULL); } function saveMonthlyData() { $month = (string)$this->request->getPost('param2'); $jsondata = (string)$this->request->getPost('param1'); $json = json_decode($jsondata, true); $mon = ''; $year = ''; if (strlen($month) == 7) { //echo "SEVEN"; $mon = substr($month, 0, 2); $year = substr($month, 3); } else { //echo "NOT SEVEN"; $mon = substr($month, 0, 1); $year = substr($month, 2); if ((int)$mon < 10) { $mon = '0' . $mon; } } $month = $mon . "-" . $year; //echo $month;die(); $total = 0; $ErrorEmpId = ''; $TotalErrorFlag = 0; $i = sizeof($json); $len = $i - 2; foreach ($json as $index => $j) { if ($index <= $len) { $ErrorFlag = 0; $EmpID = $j['Emp ID']; //$Name = $j['Employee Name']; //echo $EmpID; die; $DaysWorked = $j['Days Worked']; $LOP_Days = $j['LOP Days']; $Paid_leave = $j['Paid Leave']; $OT_Hrs_Worked = $j['OT Hrs']; $Loan_Recovered = $j['Auto Loan Due ₹']; // $Incentives = $j['Incentives in ₹']; $Festival_Bonus = $j['Festival Bonus in ₹']; $Other_Deductions = $j['TDS Deductions in ₹']; $Estimate = $j['Estimate in ₹']; $Created_By = $this->session->get('userId'); if (!is_numeric($DaysWorked) || ($DaysWorked > 31) || (strlen((string)$DaysWorked)) > 5) { // echo $EmpID . "-LOP_Days Invalid Data!"; $ErrorFlag++; } if (!is_numeric($LOP_Days) || ($LOP_Days > 31) || (strlen((string)$LOP_Days)) > 5) { // echo $EmpID . "-LOP_Days Invalid Data!"; $ErrorFlag++; } if (!is_numeric($Paid_leave) || ($Paid_leave > 31) || (strlen((string)$Paid_leave)) > 5) { // echo $EmpID . "-Paid Leave Invalid Data!"; $ErrorFlag++; } $OT_Hrs_Worked_first = explode(".", $OT_Hrs_Worked); if (!is_numeric($OT_Hrs_Worked) || (strlen((string)$OT_Hrs_Worked)) > 6 || (strlen((string)$OT_Hrs_Worked_first[0])) >= 4) // || (strlen((string)$OT_Hrs_Worked_first[1]))> 3 ) { // echo $EmpID . "-OT Hrs Invalid Data!"; $ErrorFlag++; } if (is_numeric($Loan_Recovered)) { $Loan_Recovered_first = explode(".", $Loan_Recovered); if ((strlen((string)$Loan_Recovered)) > 8 || (strlen((string)$Loan_Recovered_first[0])) > 5) { // echo $EmpID . "-Loan Recoverd Invalid Data!"; $ErrorFlag++; } } else if (is_string($Loan_Recovered)) { // echo "STRING"; if (strcasecmp($Loan_Recovered, 'NA')) { // echo "NOT NA"; $ErrorFlag++; } } $Festivalbonus_first = explode(".", $Festival_Bonus); if (!is_numeric($Festival_Bonus) || (strlen((string)$Festival_Bonus)) > 8 || (strlen((string)$Festivalbonus_first[0])) > 5) { // echo $EmpID . "-Festival bonus Invalid Data!"; $ErrorFlag++; } $Other_Deductions_first = explode(".", $Other_Deductions); if (!is_numeric($Other_Deductions) || (strlen((string)$Other_Deductions)) > 8 || (strlen((string)$Other_Deductions_first[0])) > 5) { // echo $EmpID . "-Other Deductions Invalid Data!"; $ErrorFlag++; } $Estimate_first = explode(".", $Estimate); if (!is_numeric($Estimate) || (strlen((string)$Estimate)) > 8 || (strlen((string)$Estimate_first[0])) > 6) { // echo $Estimate_first[0]; // echo $EmpID . "-Estimate Invalid Data!"; $ErrorFlag++; } if ($ErrorFlag != 0) { //echo $EmpID ."- has Invalid Data!"; $ErrorEmpId = $ErrorEmpId . "|" . $EmpID; $TotalErrorFlag++; } else //if($ErrorFlag == 0) { //nothing } } } if ($TotalErrorFlag == 0) { foreach ($json as $index => $j) { $EmpID = $j['Emp ID']; $DaysWorked = $j['Days Worked']; $TotalCalDays = isset($j['Total Days']) ? $j['Total Days'] : 0.00 ; $ActualSalary = isset($j['Basic Salary']) ? $j['Basic Salary'] : 0.00 ; $WorkedSalary = isset($j['Worked Salary']) ? $j['Worked Salary'] : 0.00 ; $PerDaySalary = isset($j['Pre Day Salary']) ? $j['Pre Day Salary'] : 0.00 ; $Basic = isset($j['Basic Salary(0.7)']) ? $j['Basic Salary(0.7)'] : 0.00 ; $HRA = isset($j['HRA Salary(0.3)']) ? $j['HRA Salary(0.3)'] : 0.00 ; $OTSalary = isset($j['Over Time']) ? $j['Over Time'] : 0.00 ; $ESI = isset($j['ESI']) ? $j['ESI'] : 0.00 ; $PF = isset($j['PF']) ? $j['PF'] : 0.00 ; $LOP_Days = isset($j['LOP Days']) ? $j['LOP Days'] : 0.00; $Paid_leave = isset($j['Paid Leave']) ? $j['Paid Leave'] : 0.00; $OT_Hrs_Worked = isset($j['OT Hrs']) ? $j['OT Hrs'] : 0.00; $Loan_Recovered = isset($j['Auto Loan Due ₹']) ? $j['Auto Loan Due ₹'] : 0.00; $Festival_Bonus = isset($j['Festival Bonus in ₹']) ? $j['Festival Bonus in ₹'] : 0.00; $tds_Deductions = isset($j['TDS Deductions in ₹']) ? $j['TDS Deductions in ₹'] : 0.00; $Estimate = isset($j['Estimate in ₹']) ? $j['Estimate in ₹'] : 0.00; $Created_By = $this->session->get('userId'); $monthlypaydata = array( 'Month_Year' => $month, 'EmpID' => $EmpID, 'Days_worked' => $DaysWorked, 'LOP_Days' => $LOP_Days, 'Paid_leave' => $Paid_leave, 'OT_Hrs_Worked' => $OT_Hrs_Worked, 'Festival_Bonus' => $Festival_Bonus, 'Other_Deductions' => $tds_Deductions, 'Estimate' => $Estimate, 'Created_By' => $Created_By, 'Loan_Recovered' => $Loan_Recovered, 'TotalCalDays' => $TotalCalDays, 'ActualSalary' => $ActualSalary, 'WorkedSalary' => $WorkedSalary, 'PerDaySalary' => $PerDaySalary, 'Basic' => $Basic, 'HRA' => $HRA, 'OTSalary' => $OTSalary, 'ESI' => $ESI, 'PF' => $PF, ); // print_r($monthlypaydata); die; $result = $this->monthlypay_model->saveMonthlyData_model($monthlypaydata); $total = $total + $result; } } //echo ""; if (!empty($ErrorEmpId)) { echo $ErrorEmpId . "- are have Invalid Data!"; } echo $total . "- Employees Updated Successfully "; } function payslipLisiting() { $curr_year = date('Y'); $curr_month = date('m'); $curr_monthyear = $curr_month . '-' . $curr_year; $this->global['pageTitle'] = 'Payslip Listing'; $data['PayInfo'] = $this->payroll_model->GetPayslipdata(); $data['dropdownvalue'] = $curr_monthyear; $this->loadViews("paysliplist", $this->global, $data, NULL); } function reload_paysliplist() { $pre_monthyear = $this->request->getPost('month'); $this->global['pageTitle'] = 'Payslip Listing'; $data['PayInfo'] = $this->payroll_model->GetPayslipdata($pre_monthyear); $data['dropdownvalue'] = $pre_monthyear; $this->loadViews("paysliplist", $this->global, $data, NULL); } function editPayslip($EmpID, $PayOn) { $this->global['pageTitle'] = 'Edit Employee Payslip'; $data['PayInfo'] = $this->payroll_model->GetPayslipdata($PayOn, $EmpID); $this->loadViews("editPayslip", $this->global, $data, NULL); } public function viewGenerator() { $Data['Payon'] = $this->payroll_model->getPayOn(); $this->global['pageTitle'] = 'Payroll Generater'; $this->loadViews("payslipgenerate", $this->global, $Data, NULL); } /* Validation for Employee Dropdow */ public function Employee_validate(string $str, string &$error = null): bool { if ($str == '-1') { $error = 'Please Select Employee.'; return false; } return true; } function getEmployee() { $id = $this->request->getPost('id1'); $result = $this->payroll_model->getEmployeelist2($id); $HTML = ""; if (count($result) > 0) { foreach ($result as $list) { $HTML .= ""; } } echo $HTML; } /* Validation for PayOn Dropdown */ public function PayOn_validate(string $str, string &$error = null): bool { if ($str == '-1') { $error = 'Please Select PayOn.'; return false; } return true; } /** * This function used to load the first screen of the user */ public function PrintPdf() { // $EmpID = 'RIPL056'; // $Payon = '08-2024'; // $m = date("M", mktime(0, 0, 0, (int)$Payon, 10)); // $y = substr((string)$Payon, 3); // //echo "EmpID" . $EmpID; // $Data['PayDetails'] = $this->payroll_model->GetPayslipdata($Payon, $EmpID); // $fname = $Data['PayDetails'][0]->FName; // $filename = 'PayslipFor-' . $EmpID . ' ' . $fname . ' ' . $m . ' ' . $y; // $totalsalary = $Data['PayDetails'][0]->TotalSalary; // $totalsalaryinwords = $this->convertNumber(round($totalsalary)); // $Data['amtinwords'] = $totalsalaryinwords; // // dd ($Data); // echo view("payslipgenerateprint", $Data); // die; $filename = " "; $html = ""; $All = $this->request->getPost('All'); $Payon = $this->request->getPost('PayOn'); $m = date("M", mktime(0, 0, 0, (int)$Payon, 10)); $y = substr((string)$Payon, 3); if ($All != '') { $filename = 'PayslipFor-' . $m . '-' . $y; $result = $this->payroll_model->getEmpAll($Payon); if ($result > 0) { for ($i = 0; $i < count($result); $i++) { $EmpID = $result[$i]['EmpId']; $Data['PayDetails'] = $this->payroll_model->GetPayslipdata($Payon, $EmpID); $totalsalary = $Data['PayDetails'][0]->LessAdvance; $totalsalaryinwords = $this->convertNumber(round($totalsalary)); $Data['amtinwords'] = $totalsalaryinwords; $html .= view("payslipgenerateprint", $Data); } } } else { $EmpID = $this->request->getPost('Employee'); //echo "EmpID" . $EmpID; $Data['PayDetails'] = $this->payroll_model->GetPayslipdata($Payon, $EmpID); $fname = $Data['PayDetails'][0]->FName; $filename = 'PayslipFor-' . $EmpID . ' ' . $fname . ' ' . $m . ' ' . $y; $totalsalary = $Data['PayDetails'][0]->LessAdvance; $totalsalaryinwords = $this->convertNumber(round($totalsalary)); $Data['amtinwords'] = $totalsalaryinwords; // print_r ($Data); // exit(); $html = view("payslipgenerateprint", $Data); } $mpdf = new Mpdf([ 'mode' => 'utf-8', 'format' => 'A4-P', 'margin_left' => 10, 'margin_right' => 10, 'margin_top' => 10, 'margin_bottom' => 10, 'margin_header' => 10, 'margin_footer' => 6, 'setAutoTopMargin' => 'stretch', 'setAutoBottomMargin' => 'stretch' ]); $mpdf->SetDisplayMode('fullpage'); // $mpdf->SetHTMLHeader($HtmlHeading); $mpdf->setFooter("Page {PAGENO} of {nb}"); $mpdf->list_indent_first_level = 1; $mpdf->WriteHTML($html); $mpdf->SetTitle('Resico:Payslip'); $mpdf->Output("Payslip-" . $filename . ".pdf", 'D'); } function updatePayslip() { $paykey = $this->request->getPost("Key"); $EmpID = $this->request->getPost("EmpID"); $PayOn = $this->request->getPost("PayOn"); $otherallowence = $this->request->getPost("otherallowence"); $otherdeductions = $this->request->getPost("otherdeductions"); $incentive = $this->request->getPost("incentive"); $netpay = $this->request->getPost("netpay"); $esi = $this->request->getPost("txtesi"); $pf = $this->request->getPost("txtpf"); $basic = $this->request->getPost("txtbasicda"); $hra = $this->request->getPost("txthra"); $otsalary = $this->request->getPost("otsalary"); $Totaldeduction = $esi + $pf + $otherdeductions; $SalaryAsPerPF = ($basic + $hra + $otsalary) - $Totaldeduction; $userid = $this->session->get('userId'); $remarks = 'Manual Edit By' . $userid . " On " . get_current_date(); $paydetails = array('Key' => $paykey, 'EmpID' => $EmpID, 'PayOn' => $PayOn, 'Other_allowances' => $otherallowence, 'OtherDeductions' => $otherdeductions, 'Incentive' => $incentive, 'LessAdvance' => $netpay, 'TotalSalary' => $netpay, 'SalaryAsPerPF' => $SalaryAsPerPF, 'Totaldeduction' => $Totaldeduction, 'remarks' => $remarks); $monthdetails = array('Month_Year' => $PayOn, 'Other_Deductions' => $otherdeductions, 'Incentives' => $incentive); $result = $this->payroll_model->updateEmpPayslip($paydetails); $res = $this->monthlypay_model->editmonth($monthdetails, $EmpID); echo $result; } /** * This function used to upload the Excel file Details */ /** * This function used to upload the Excel file Details2 */ function uploadExcel2() { $path = ROOTPATH.'public/uploads/files/'; if(!is_dir($path)) { mkdir($path, 0777, true); } $PayrollFileName = ''; $file = $this->request->getFile('userfile'); if ($file && $file->isValid() && !$file->hasMoved()) { $pathinfo = pathinfo($file->getName()); $config['upload_path'] = $path; $config['allowed_types'] = 'xls|xlsx|csv'; $config['file_name'] = $_FILES['userfile']['name']; $config['overwrite'] = true; if (in_array($pathinfo['extension'], ['xlsx', 'xls']) && $file->getSize() > 0) { $file->move($config['upload_path'], $config['file_name']); $PayrollFileName = $file->getName(); $inputFileName = $path . $PayrollFileName; // $inputFileName = $_FILES['userfile']['tmp_name']; $spreadsheet = IOFactory::load($inputFileName); $sheet = $spreadsheet->getActiveSheet(); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); $x = 8; $month = $this->request->getPost('mon'); $year = $this->request->getPost('yr'); $PayOn = $month . "-" . $year; $createdby = $this->session->get('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); $Days_worked = $sheet->getCell('C' . $x)->getValue(); $LOPDays = $sheet->getCell('D' . $x)->getValue(); $Paid_leave = $sheet->getCell('E' . $x)->getValue(); $OTHoursWorked = $sheet->getCell('F' . $x)->getValue(); $LoanRecovered = $sheet->getCell('G' . $x)->getValue(); if (is_string($LoanRecovered)) { $LoanRecovered = strtoupper($LoanRecovered); } $Incentive = $sheet->getCell('G' . $x)->getValue(); $Other_Deductions = $sheet->getCell('H' . $x)->getValue(); if ($EmpId != '') { if ($flag != 0 && $flag2 != 0) { $FileData = array('Month_Year' => $PayOn, 'EmpID' => $EmpId, 'Days_worked' => $Days_worked, 'LOP_Days' => $LOPDays, 'Paid_leave' => $Paid_leave, '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 ""; echo ""; echo ""; echo ""; echo ""; //redirect('payslip/viewUpload2'); } else { echo ""; } } else { echo ""; } } function checkExistPay() { $empid = $this->request->getPost('employee'); $payon = $this->request->getPost('payon'); $result = $this->payroll_model->checkExistPayData($empid, $payon); echo json_encode(count($result)); } 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' => 'Fourty', '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; } function Bonusreport() { //echo"function in controller"; $this->global['pageTitle'] = 'Incentive and Bonus Reports'; $fin_year = $this->request->getPost('finyear'); //echo "values are,".$year.$fin_year; $data['finyear'] = $fin_year; $data['Reportvalue'] = $this->monthlypay_model->reportvalue($fin_year); $this->loadViews("Bonusreport", $this->global, $data, NULL); } function MonthwiseBonusreport() { //echo"in controller"; // $EmployeeID = $_GET['EID']; // $Fin_year = $_GET['Finyear']; $EmployeeID = $this->request->getGet('EID'); $Fin_year = $this->request->getGet('Finyear'); $data['finyear'] = $Fin_year; //echo $EmployeeID; //echo $Fin_year; $this->global['pageTitle'] = 'Monthwise Incentive and Bonus Reports'; $data['MonthwiseReport'] = $this->monthlypay_model->Monthwisereportvalue($Fin_year, $EmployeeID); //print_r($data['MonthwiseReport']); $this->loadViews("Bonusreportmonthwise", $this->global, $data, NULL); } function ValidationCheque() { $bank = $this->request->getPost("id1"); $payon = $this->request->getPost("id2"); $result = $this->payroll_model->getChequeInfo($bank, $payon); $count = count($result); echo $count; } }