2088 lines
66 KiB
PHP
Executable File
2088 lines
66 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
use CodeIgniter\Validation\Exceptions\ValidationException;
|
|
|
|
// require APPPATH . '/third_party/mpdf/mpdf.php';
|
|
|
|
use App\Models\Monthlypay_model;
|
|
use App\Models\Payroll_model;
|
|
use App\Models\Driver_model;
|
|
use Mpdf\Mpdf;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
|
|
|
|
/**
|
|
* Module : Payslip
|
|
* Payslip Class to control all payslip related operations.
|
|
* @author : Gandhimathi
|
|
* @version : 1.1
|
|
* @since : 07 Apr 2017
|
|
* @example : Revised at 15th april 2024
|
|
*/
|
|
class Payslip extends BaseController
|
|
{
|
|
protected $payroll_model;
|
|
protected $monthlypay_model;
|
|
protected $driver_model;
|
|
protected $session;
|
|
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->payroll_model = new Payroll_model();
|
|
$this->monthlypay_model = new Monthlypay_model();
|
|
$this->driver_model = new Driver_model();
|
|
$this->session = session();
|
|
helper('form'); //$this->load->library('form_validation');
|
|
$this->isLoggedIn();
|
|
|
|
}
|
|
|
|
function phpAlert($msg)
|
|
{
|
|
echo '<script type="text/javascript">alert("' . $msg . '")</script>';
|
|
}
|
|
|
|
|
|
/**
|
|
* 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);
|
|
|
|
$this->payroll_model->updatePaySlipGeneration($EmpId, $PayOn);
|
|
|
|
|
|
|
|
$result = $res[0];
|
|
|
|
if($result->is_payslip_generated == 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;
|
|
|
|
|
|
|
|
$loan = [
|
|
'Paid_Due' => $result->Paid_Due + 1,
|
|
'Remaining_Due' => $result->Remaining_Due - 1,
|
|
'Paid_Amount' => $result->Paid_Amount + $result->Loan_Recovered,
|
|
|
|
];
|
|
|
|
$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;
|
|
|
|
|
|
}
|
|
|
|
|
|
public function monthlyInputs()
|
|
{
|
|
$current = $this->request->getPost('monthyear') ? $this->request->getPost('monthyear') :date("m-Y");
|
|
|
|
$data['month'] = $this->monthlypay_model->monthlyListing($current);
|
|
$data['dropdownvalue'] = $current;
|
|
$data['fresh'] = $this->monthlypay_model->getEmpPayDetailsforMonthInputs($current);
|
|
// dd($data['fresh']);
|
|
$data['drivermonthinputs'] = $this->driverMonthlyPayInputs($current);
|
|
// $leavedate = $this->monthlypay_model->employeeLeaveDates($current);
|
|
|
|
$employeeSalary = [];
|
|
$esi = [];
|
|
$pf = [];
|
|
$ot = [];
|
|
foreach ($data['fresh'] as $value) {
|
|
|
|
$is_driver = $value->is_driver;
|
|
$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); // not working day
|
|
$Paid_leave = $value->Paid_leave; // leave day
|
|
if ($value->is_management_team == 1)
|
|
{
|
|
$OT_Hrs_Worked = 0; //OT hours
|
|
$value->OT_Hrs_Worked = 0;
|
|
} else {
|
|
$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);
|
|
|
|
$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 + $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 + $currentDayHra) * $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;
|
|
|
|
$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);
|
|
}
|
|
|
|
public function exportMonthlyPayInputs1($value)
|
|
{
|
|
$headlines = [
|
|
'company_name' => 'Resico Solutions',
|
|
'file_name' => 'Resico_Salary_'.$value.'.xls',
|
|
'type' => 1,
|
|
'header1' => ['Emp ID', 'Name', 'Department', 'Salary'], // example headers
|
|
'header2' => [],
|
|
'footer' => false,
|
|
];
|
|
|
|
$xldata = [
|
|
['E001', 'Arun', 'HR', 25000],
|
|
['E002', 'Meena', 'Finance', 28000],
|
|
];
|
|
|
|
helper('excel');
|
|
generate_excel($headlines, $xldata);
|
|
}
|
|
|
|
|
|
public function exportMonthlyPayInputs($value){
|
|
|
|
helper('excel');
|
|
$monthyear = get_date_time_dynamical_format('n-Y','m-Y',"$value");
|
|
$employee = [];$i=0; $j=0;
|
|
$company_info = $this->payroll_model->getCompanyInformation();
|
|
$employee_monthinputs_info = $this->monthlypay_model->getEmpPayDetailsforMonthInputs($monthyear);
|
|
$driver_monthinputs_info = $this->driverMonthlyPayInputs($monthyear);
|
|
// $headlines_main = ['S. No','Emp ID','Employees Name','Date of Joining','Destingnation','Total Days' ,'Days Worked','Leave','Basic Salary','Per day Salary','Worked Salary','Per Hours Salary','Earned Salary', '70% BASIC','30% HRA','Gross Salary','Esi 0.75%','Pf 12%','Esi + Pf (Ee`s)' ,'Over Time','Feb-25 Advance','TDS 92B','Refuned PF Nov24','Net Salary','Gross Salary','Over Time','Gross Net Salary','Esi (0)','Pf (0)','Sep-24 Advance','TDS 92B','Refuned PF Nov24','Net Salary','Diff'];
|
|
$headlines_main = ['S. No','Emp ID','Employees Name','Date of Joining','Destingnation','Total','Days','Leave','Basic','Per day','Worked','Per Hours','Earned','70%','30%','Gross','Esi','Pf','Esi + Pf','Over Time','Feb-25 Advance','TDS 92B','Refuned PF Nov24','Net Salary','Gross','Over Time','Gross Net','Esi','Pf','Sep-24 Advance','TDS 92B','Refuned PF Nov24','Net Salary','Diff'];
|
|
|
|
$headlines_sub = ['', '', '', '', '', 'Days','Worked','', 'Salary','Salary','Salary','Salary','Salary', 'BASIC','HRA','Salary','0.75%','12%','Ee`s','','','','','','Salary','','Salary',' 0','0','','','','',''];
|
|
|
|
$dum = [];
|
|
foreach ($employee_monthinputs_info as $key => $rec) {
|
|
// echo $rec->EmpID;
|
|
// print_r($dum);die;
|
|
$dum[$rec->EmpID] = $rec;
|
|
}
|
|
$employee_monthinputs_info = array_values($dum);
|
|
|
|
|
|
foreach ($employee_monthinputs_info as $value) {
|
|
|
|
$employee[$i]['SNO'] = $i+1;
|
|
$employee[$i]['ID'] = $value->EmpID;
|
|
$employee[$i]['Name'] = $value->FirstName;
|
|
$employee[$i]['DOJ'] = get_date_time_dynamical_format('Y-m-d H:i:s','d-m-Y',"$value->DateofJoining");
|
|
$employee[$i]['Designation'] = $value->Designation ;
|
|
$NoofDays = $value->NoofDays; // Month day 30,31,28
|
|
$employee[$i]['NoofDays'] = round($NoofDays);
|
|
$Days_worked = $value->Days_worked; // Work day
|
|
$employee[$i]['Days_worked'] = round($Days_worked);
|
|
$employee[$i]['Leave'] = round($value->NoofDays - ($Days_worked)); // Absent Days LOP
|
|
$Basic_Pay = $value->Basic_Pay;
|
|
// $employee[$i]['Basic_Pay'] = $Basic_Pay;
|
|
$TotalSalary = $value->TotalSalary;
|
|
$employee[$i]['TotalSalary'] = number_format($TotalSalary, 2, '.', '');
|
|
$PerDaySalary = $value->TotalSalary / $NoofDays;
|
|
$employee[$i]['PerDaySalary'] = number_format($PerDaySalary, 2, '.', '');
|
|
|
|
$WorkedSalary = $PerDaySalary * ($Days_worked);
|
|
$employee[$i]['WorkedSalary'] = number_format($WorkedSalary, 2, '.', '');
|
|
$PerHrSalary = $PerDaySalary / 8;
|
|
$employee[$i]['PerHrSalary'] = number_format($PerHrSalary, 2, '.', '');
|
|
$employee[$i]['EarnedSalary'] = number_format($WorkedSalary, 2, '.', '');
|
|
|
|
$BasicWorked = $WorkedSalary * 70 / 100;
|
|
$employee[$i]['BasicWorked'] = number_format($BasicWorked, 2, '.', '');
|
|
$HraWorked = $WorkedSalary * 30 / 100;
|
|
$employee[$i]['HraWorked'] = number_format($HraWorked, 2, '.', '');
|
|
$employee[$i]['GrossSalary'] = number_format($BasicWorked + $HraWorked, 2, '.', '');
|
|
if ($value->is_management_team == 1)
|
|
{
|
|
$OT_Hrs_Worked = 0; //OT hours
|
|
$value->OT_Hrs_Worked = 0;
|
|
} else {
|
|
$OT_Hrs_Worked = $value->OT_Hrs_Worked; //OT hours
|
|
}
|
|
$totSalayOT = ($OT_Hrs_Worked != 0) ? $OT_Hrs_Worked * $PerHrSalary : 0;
|
|
|
|
$HRA_Amount = $value->HRA_Amount;
|
|
$Paid_leave = $value->Paid_leave; // leave day
|
|
$Monthly_Due = $value->Monthly_Due; // AUTO LOAN DUE
|
|
$Loan_Recovered = $value->Loan_Recovered; //MANUAL LOAN DUE
|
|
$due_start_date = $value->DueDate;
|
|
|
|
if (strlen((string)$monthyear) == 6) {
|
|
$monthyear = '0' . $monthyear;
|
|
}
|
|
$pmonth = substr($monthyear, 0, 2);
|
|
$pyear = substr($monthyear, -4);
|
|
|
|
$pmonth = substr($monthyear, 0, 2);
|
|
$pyear = substr($monthyear, -4);
|
|
$pday = cal_days_in_month(CAL_GREGORIAN, $pmonth, $pyear);
|
|
$payfulldate = $pyear . '-' . $pmonth . '-' . $pday;
|
|
$totalDaysWorked = $Days_worked + $Paid_leave;
|
|
$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($payfulldate)) {
|
|
$loan = $Monthly_Due;
|
|
}
|
|
} else if ($Loan_Recovered >= 0.00) {
|
|
if (strtotime($due_start_date) <= strtotime($payfulldate)) {
|
|
$loan = $Loan_Recovered;
|
|
}
|
|
}
|
|
|
|
if ($Monthly_Due > $Balance_Amount) {
|
|
$loan = $Balance_Amount;
|
|
}
|
|
|
|
$PF_Rate = $value->PF_Rate;
|
|
$ESI_Rate = $value->ESI_Rate;
|
|
|
|
$dayHra = $HRA_Amount / $NoofDays;
|
|
$dayBasic = $Basic_Pay / $NoofDays;
|
|
|
|
//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 + $currentDayHra) * $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;
|
|
|
|
$employee[$i]['ESI'] = number_format($esiAmount, 2, '.', '');
|
|
$employee[$i]['PF'] = number_format($pfAmount, 2, '.', '');
|
|
$employee[$i]['ESI_PF'] = number_format($esiAmount + $pfAmount, 2, '.', '');
|
|
$employee[$i]['OT'] = number_format($totSalayOT, 2, '.', '');
|
|
|
|
$employee[$i]['Feb_25_Advance'] = "-";
|
|
$employee[$i]['TDS_92B'] ="-";
|
|
$employee[$i]['Refuned_PF_Nov24'] ="-";
|
|
$employee[$i]['NetSalary'] = round($salaryInCurrentday);
|
|
|
|
$employee[$i]['GrossSalary2'] = "-";
|
|
$employee[$i]['OT2'] = "-";
|
|
$employee[$i]['GrossNetSalary'] = "-";
|
|
$employee[$i]['ESI2'] ="-";
|
|
$employee[$i]['PF2'] ="-";
|
|
$employee[$i]['Sep_24_Advance'] = "-";
|
|
$employee[$i]['TDS_92B'] = "-";
|
|
$employee[$i]['Refuned_PF_Nov24'] = "-";
|
|
$employee[$i]['Net_Salary'] = "-";
|
|
$employee[$i]['Diff'] = "-";
|
|
$employee[$i]['work_location'] = $value->work_location;
|
|
$employee[$i]['tds_applicable'] = $value->tds_applicable;
|
|
$employee[$i]['pf_applicable'] = $value->pf_applicable;
|
|
$employee[$i]['esi_applicable'] = $value->esi_applicable;
|
|
$i++;
|
|
|
|
}
|
|
$j = $i;
|
|
foreach($driver_monthinputs_info as $record ){
|
|
$hra_worked = $record->hra_worked;
|
|
$basic_worked = $record->basic_worked;
|
|
$sum_of_amount = ($record->driver_salary+$record->driver_shed+$record->driver_diesel);
|
|
|
|
$employee[$j]['SNO'] = $j+1;
|
|
$employee[$j]['ID'] = $record->EmpID;
|
|
$employee[$j]['Name'] = $record->FirstName;
|
|
$employee[$j]['DOJ'] = get_date_time_dynamical_format('Y-m-d H:i:s','d-m-Y',"$record->DateofJoining");
|
|
$employee[$j]['Designation'] = $record->Designation;
|
|
$employee[$j]['NoofDays'] = round($record->total_cal_days);
|
|
$employee[$j]['Days_worked'] = round($record->unique_days);
|
|
$employee[$j]['Leave'] = round($record->total_cal_days - $record->unique_days);
|
|
// number_format(0.00, 2, '.', ''); // paid leave
|
|
// number_format(0.00, 2, '.', ''); //ot hours
|
|
$employee[$j]['TotalSalary'] = number_format($sum_of_amount, 2, '.', '');
|
|
$worked_amt = $sum_of_amount / $record->total_cal_days ;
|
|
$employee[$j]['PerDaySalary'] = number_format($worked_amt, 2, '.', '');
|
|
$employee[$j]['WorkedSalary'] = number_format($worked_amt, 2, '.', '');
|
|
$hr_amt = $worked_amt/8;
|
|
$employee[$j]['PerHrSalary'] = number_format($hr_amt, 2, '.', '');
|
|
$employee[$j]['EarnedSalary'] = number_format($sum_of_amount, 2, '.', '');
|
|
$employee[$j]['BasicWorked'] = number_format($basic_worked, 2, '.', '');
|
|
$employee[$j]['HraWorked'] = number_format($hra_worked, 2, '.', '');
|
|
$employee[$j]['GrossSalary'] = number_format($basic_worked + $hra_worked, 2, '.', '');
|
|
|
|
$employee[$j]['ESI'] = number_format($record->esi_amount, 2, '.', '');
|
|
$employee[$j]['PF'] = number_format($record->pf_amount, 2, '.', '');
|
|
$employee[$j]['ESI_PF'] = number_format($record->esi_amount + $record->pf_amount, 2, '.', '');
|
|
$employee[$j]['OT'] = number_format(0, 2, '.', '');
|
|
$estTotal = ($basic_worked + $hra_worked + $record->Festival_Bonus)-($record->Monthly_Due+$record->esi_amount+$record->pf_amount);
|
|
|
|
$employee[$j]['Feb_25_Advance'] = "-";
|
|
$employee[$j]['TDS_92B'] ="-";
|
|
$employee[$j]['Refuned_PF_Nov24'] ="-";
|
|
$employee[$j]['NetSalary'] = round($estTotal);
|
|
|
|
$employee[$j]['GrossSalary2'] = "-";
|
|
$employee[$j]['OT2'] = "-";
|
|
$employee[$j]['GrossNetSalary'] = "-";
|
|
$employee[$j]['ESI2'] ="-";
|
|
$employee[$j]['PF2'] ="-";
|
|
$employee[$j]['Sep_24_Advance'] = "-";
|
|
$employee[$j]['TDS_92B'] = "-";
|
|
$employee[$j]['Refuned_PF_Nov24'] = "-";
|
|
$employee[$j]['Net_Salary'] = "-";
|
|
$employee[$j]['Diff'] = "-";
|
|
$employee[$j]['work_location'] = $record->work_location;
|
|
$employee[$j]['tds_applicable'] = $record->tds_applicable;
|
|
$employee[$j]['pf_applicable'] = $record->pf_applicable;
|
|
$employee[$j]['esi_applicable'] = $record->esi_applicable;
|
|
$j++;
|
|
}
|
|
$finalFooter[] = $employee;
|
|
// do not try chatgpt please.
|
|
$location_info = [];
|
|
foreach ($employee as $key => $value)
|
|
{
|
|
if (isset($value['work_location']) && $value['work_location'] == "Thiruvenkadu") {
|
|
array_push($location_info,$value);
|
|
unset($employee[$key]);
|
|
}
|
|
}
|
|
|
|
$tds_info = [];
|
|
foreach ($employee as $key => $value)
|
|
{
|
|
if (isset($value['tds_applicable']) && (int)$value['tds_applicable'] == 1) {
|
|
array_push($tds_info,$value);
|
|
unset($employee[$key]);
|
|
}
|
|
}
|
|
|
|
$esi_or_pf_info = [];
|
|
foreach ($employee as $key => $value)
|
|
{
|
|
if (isset($value['pf_applicable']) && (int)$value['pf_applicable'] == 1 || isset($value['esi_applicable']) && (int)$value['esi_applicable'] == 1) {
|
|
array_push($esi_or_pf_info,$value);
|
|
unset($employee[$key]);
|
|
}
|
|
}
|
|
|
|
$keysToRemove = ['work_location','tds_applicable','pf_applicable','esi_applicable'];
|
|
foreach ($tds_info as &$t_item) {
|
|
foreach ($keysToRemove as $key) {
|
|
unset($t_item[$key]);
|
|
}
|
|
}
|
|
unset($t_item);
|
|
|
|
foreach ($esi_or_pf_info as &$e_item) {
|
|
foreach ($keysToRemove as $key) {
|
|
unset($e_item[$key]);
|
|
}
|
|
}
|
|
unset($e_item);
|
|
|
|
foreach ($location_info as &$l_item) {
|
|
foreach ($keysToRemove as $key) {
|
|
unset($l_item[$key]);
|
|
}
|
|
}
|
|
unset($l_item);
|
|
|
|
foreach ($employee as &$o_item) {
|
|
foreach ($keysToRemove as $key) {
|
|
unset($o_item[$key]);
|
|
}
|
|
}
|
|
unset($o_item);
|
|
|
|
foreach ($finalFooter as &$topLevelArray) {
|
|
if (is_array($topLevelArray)) {
|
|
foreach ($topLevelArray as &$employeeArray) { // Changed from $finalFooter to $employeeArray
|
|
if (is_array($employeeArray)) { // Check $employeeArray instead of $x
|
|
foreach ($keysToRemove as $key) {
|
|
if (array_key_exists($key, $employeeArray)) {
|
|
unset($employeeArray[$key]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
unset($employeeArray); // Break the reference
|
|
}
|
|
}
|
|
unset($topLevelArray); // Break the reference
|
|
|
|
$xl[] = array_values($tds_info);
|
|
$xl[] = array_values($esi_or_pf_info);
|
|
$xl[] = array_values($location_info);
|
|
$xl[] = array_values($employee);
|
|
|
|
// dd($xl);
|
|
|
|
$headlines['company_name'] = isset($company_info[0]->CompanyName) ? $company_info[0]->CompanyName : "Resico India Pvt Ltd";
|
|
$headlines['header1'] = $headlines_main;
|
|
$headlines['header2'] = $headlines_sub;
|
|
$headlines['type'] = 2;
|
|
$headlines['header2'] = $headlines_sub;
|
|
$headlines['merge_end_column'] = 7;
|
|
$headlines['file_name'] = 'ResicoSalary'.$pmonth.'-'.$pyear.'.xls';
|
|
$headlines['final_Footer'] = $finalFooter;
|
|
|
|
generate_excel($headlines,$xl);
|
|
|
|
|
|
// dd($employee);
|
|
|
|
}
|
|
|
|
public function driverMonthlyPayInputs($current)
|
|
{
|
|
|
|
list($month, $year) = explode('-', $current);
|
|
|
|
$month_in_number = get_date_time_dynamical_format('n','m',"$month");// refer helper
|
|
|
|
$get_last_date_of_the_month = cal_days_in_month(CAL_GREGORIAN, $month_in_number, $year);
|
|
|
|
$from_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m-d',"01-$month_in_number-$year");
|
|
$to_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m-d',"$get_last_date_of_the_month-$month_in_number-$year");
|
|
|
|
// $data['monthinputs']
|
|
$load_driver_data = $this->driver_model->driverAttendanceForMonthlyPayInputs($from_mysql_date,$to_mysql_date);
|
|
// dd($load_driver_data);
|
|
|
|
|
|
$format_month_year = get_date_time_dynamical_format('n-Y','m-Y',"$current");
|
|
|
|
$monthly_pay_data = $this->driver_model->driverMonthlyPayInputs($format_month_year);
|
|
|
|
|
|
|
|
// both foreach refer with chatgpt array data replacement....
|
|
$monthly_pay_array = [];
|
|
foreach ($monthly_pay_data as $row) {
|
|
$monthly_pay_array[$row->driver_id] = $row;
|
|
}
|
|
|
|
for ($i = 0; $i < count((array)$load_driver_data); $i++) {
|
|
$driver_id = $load_driver_data[$i]->driver_id;
|
|
if (isset($monthly_pay_array[$driver_id])) {
|
|
|
|
$PF_Rate = $load_driver_data[$i]->PF_Rate;
|
|
$ESI_Rate = $load_driver_data[$i]->ESI_Rate;
|
|
|
|
$monthly_salary_amount = isset($load_driver_data[$i]->monthly_salary_amount) ? (int)$load_driver_data[$i]->monthly_salary_amount : 0;
|
|
$monthly_food_amount = isset($load_driver_data[$i]->monthly_food_amount) ? (int)$load_driver_data[$i]->monthly_food_amount : 0;
|
|
$final_salary_amount = $monthly_salary_amount+$monthly_food_amount;
|
|
|
|
$shed = isset($load_driver_data[$i]->shed_amount) ? (int)$load_driver_data[$i]->shed_amount : 0;
|
|
$diesel = isset($load_driver_data[$i]->diesel_amount) ? (int)$load_driver_data[$i]->diesel_amount : 0;
|
|
|
|
$load_driver_data[$i]->driver_salary = $final_salary_amount;
|
|
$load_driver_data[$i]->driver_shed = $shed;
|
|
$load_driver_data[$i]->driver_diesel = $diesel;
|
|
|
|
$Monthly_Due = $load_driver_data[$i]->Monthly_Due; // AUTO LOAN DUE
|
|
$Loan_Recovered = $load_driver_data[$i]->Loan_Recovered; //MANUAL LOAN DUE
|
|
$loan = 0;
|
|
$due_start_date = $load_driver_data[$i]->DueDate;
|
|
$paydate = $current; //From POST parm
|
|
if ($Loan_Recovered == 'NA') {
|
|
$loan = 0.00;
|
|
} else if ($Loan_Recovered == 0.00) {
|
|
if (strtotime($due_start_date) <= strtotime($to_mysql_date)) {
|
|
$loan = $Monthly_Due;
|
|
}
|
|
} else if ($Loan_Recovered >= 0.00) {
|
|
if (strtotime($due_start_date) <= strtotime($to_mysql_date)) {
|
|
$loan = $Loan_Recovered;
|
|
}
|
|
}
|
|
|
|
$Loan_amount = $load_driver_data[$i]->Loan_Amount;
|
|
$Paid_Amount = $load_driver_data[$i]->Paid_Amount;
|
|
$Balance_Amount = $Loan_amount - $Paid_Amount;
|
|
if ($Monthly_Due > $Balance_Amount) {
|
|
$loan = $Balance_Amount;
|
|
}
|
|
|
|
$empSalaryAdd = $final_salary_amount;
|
|
$empSalarySub = $loan;
|
|
// $salaryInCurrentday = $empSalaryAdd - $empSalarySub;
|
|
// $load_driver_data[$i]->driver_final_payment = $salaryInCurrentday;
|
|
|
|
$load_driver_data[$i]->payroll_id = $monthly_pay_array[$driver_id]->payroll_id;
|
|
$load_driver_data[$i]->Festival_Bonus = $monthly_pay_array[$driver_id]->Festival_Bonus;
|
|
|
|
$basic = ($final_salary_amount+$shed+$diesel) * 70 / 100;
|
|
$hra = ($final_salary_amount+$shed+$diesel) * 30 / 100;
|
|
|
|
$load_driver_data[$i]->basic_worked = $basic;
|
|
$load_driver_data[$i]->hra_worked = $hra;
|
|
|
|
$load_driver_data[$i]->esi_amount = ($load_driver_data[$i]->esi_applicable == 1) ? ($basic) * $ESI_Rate / 100 : 0;
|
|
$load_driver_data[$i]->pf_amount = ($load_driver_data[$i]->pf_applicable == 1) ? ($basic) * $PF_Rate / 100 : 0;
|
|
$load_driver_data[$i]->total_cal_days = $get_last_date_of_the_month;
|
|
|
|
}else {
|
|
$PF_Rate = $load_driver_data[$i]->PF_Rate;
|
|
$ESI_Rate = $load_driver_data[$i]->ESI_Rate;
|
|
|
|
$monthly_salary_amount = isset($load_driver_data[$i]->monthly_salary_amount) ? (int)$load_driver_data[$i]->monthly_salary_amount : 0;
|
|
$monthly_food_amount = isset($load_driver_data[$i]->monthly_food_amount) ? (int)$load_driver_data[$i]->monthly_food_amount : 0;
|
|
$final_salary_amount = $monthly_salary_amount+$monthly_food_amount;
|
|
$shed = isset($load_driver_data[$i]->shed_amount) ? (int)$load_driver_data[$i]->shed_amount : 0;
|
|
$diesel = isset($load_driver_data[$i]->diesel_amount) ? (int)$load_driver_data[$i]->diesel_amount : 0;
|
|
|
|
$load_driver_data[$i]->driver_salary = $final_salary_amount;
|
|
$load_driver_data[$i]->driver_shed = $shed;
|
|
$load_driver_data[$i]->driver_diesel = $diesel;
|
|
|
|
$load_driver_data[$i]->payroll_id = '';
|
|
$load_driver_data[$i]->Festival_Bonus = 0;
|
|
|
|
$basic = ($final_salary_amount+$shed+$diesel) * 70 / 100;
|
|
$hra = ($final_salary_amount+$shed+$diesel) * 30 / 100;
|
|
$load_driver_data[$i]->basic_worked = $basic;
|
|
$load_driver_data[$i]->hra_worked = $hra;
|
|
|
|
$load_driver_data[$i]->esi_amount = ($load_driver_data[$i]->esi_applicable == 1) ? ($basic) * $ESI_Rate / 100 : 0;
|
|
$load_driver_data[$i]->pf_amount = ($load_driver_data[$i]->pf_applicable == 1) ? ($basic) * $PF_Rate / 100 : 0;
|
|
|
|
|
|
$Monthly_Due = $load_driver_data[$i]->Monthly_Due; // AUTO LOAN DUE
|
|
$Loan_Recovered = $load_driver_data[$i]->Loan_Recovered; //MANUAL LOAN DUE
|
|
$loan = 0;
|
|
$due_start_date = $load_driver_data[$i]->DueDate;
|
|
$paydate = $current; //From POST parm
|
|
if ($Loan_Recovered == 'NA') {
|
|
$loan = 0.00;
|
|
} else if ($Loan_Recovered == 0.00) {
|
|
if (strtotime($due_start_date) <= strtotime($to_mysql_date)) {
|
|
$loan = $Monthly_Due;
|
|
}
|
|
} else if ($Loan_Recovered >= 0.00) {
|
|
if (strtotime($due_start_date) <= strtotime($to_mysql_date)) {
|
|
$loan = $Loan_Recovered;
|
|
}
|
|
}
|
|
|
|
$Loan_amount = $load_driver_data[$i]->Loan_Amount;
|
|
$Paid_Amount = $load_driver_data[$i]->Paid_Amount;
|
|
$Balance_Amount = $Loan_amount - $Paid_Amount;
|
|
if ($Monthly_Due > $Balance_Amount) {
|
|
$loan = $Balance_Amount;
|
|
}
|
|
|
|
$empSalaryAdd = $final_salary_amount;
|
|
$empSalarySub = $loan;
|
|
// $salaryInCurrentday = $empSalaryAdd - $empSalarySub;
|
|
// $load_driver_data[$i]->driver_final_payment = $salaryInCurrentday+$shed+$diesel;
|
|
$load_driver_data[$i]->total_cal_days = $get_last_date_of_the_month;
|
|
|
|
}
|
|
}
|
|
// dd($load_driver_data);
|
|
return $load_driver_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
$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['Net Salary ₹'];
|
|
$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)) > 10 || (strlen((string)$Estimate_first[0])) > 8) {
|
|
// 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'];
|
|
$is_driver = $this->driver_model->getDriverName($EmpID,1);
|
|
$DaysWorked = $j['Days Worked'];
|
|
// $NoTrips = isset($j['Number Of Trips']) ? $j['Number Of Trips'] : 0.00 ;
|
|
$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['Net Salary ₹']) ? $j['Net Salary ₹'] : 0.00;
|
|
$Created_By = $this->session->get('userId');
|
|
|
|
if($is_driver == 0){
|
|
|
|
|
|
$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);
|
|
|
|
}else{
|
|
|
|
$get_last_date_of_the_month = cal_days_in_month(CAL_GREGORIAN, $mon, $year);
|
|
$from_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m-d',"01-$mon-$year");
|
|
$to_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m-d',"$get_last_date_of_the_month-$mon-$year");
|
|
$load_driver_data = $this->driver_model->driverAttendanceForMonthlyPayInputs($from_mysql_date,$to_mysql_date);
|
|
$Food = isset($load_driver_data[0]->monthly_food_amount) ? (int)$load_driver_data[0]->monthly_food_amount : 0;
|
|
$Shed = isset($load_driver_data[0]->shed_amount) ? (int)$load_driver_data[0]->shed_amount : 0;
|
|
$Diesel = isset($load_driver_data[0]->diesel_amount) ? (int)$load_driver_data[0]->diesel_amount : 0;
|
|
|
|
$drivermonthlypaydata = array(
|
|
'month_year'=>$month,
|
|
'driver_id'=>$EmpID,
|
|
'TotalCalDays' => $TotalCalDays,
|
|
'monthly_food_amount'=>$Food,
|
|
'total_diesel_amount'=>$Diesel,
|
|
'total_shed_amount'=>$Shed,
|
|
'monthly_salary_amount'=>($Basic+$Food),
|
|
'final_payment'=>$Estimate,
|
|
'BASIC'=>$Basic,
|
|
'HRA'=>$HRA,
|
|
'ESI'=>$ESI,
|
|
'PF'=>$PF,
|
|
'Festival_Bonus'=>$Festival_Bonus,
|
|
'Loan_Recovered'=>$Loan_Recovered,
|
|
'created_by'=>$Created_By,
|
|
'updated_by'=>$Created_By
|
|
|
|
);
|
|
|
|
$result = $this->driver_model->saveMonthlyData($drivermonthlypaydata);
|
|
|
|
}
|
|
$total = $total + $result;
|
|
}
|
|
}
|
|
|
|
//echo "<script> alert($ErrorEmpId + '- are have Invalid Data!'); </script>";
|
|
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');
|
|
|
|
$employee = $this->payroll_model->getEmployeelist2($id);
|
|
$driver = $this->driver_model->getDriverlist2($id);
|
|
|
|
$result = array_merge($employee, $driver);
|
|
|
|
|
|
$HTML = "";
|
|
|
|
if (count($result) > 0) {
|
|
|
|
foreach ($result as $list) {
|
|
|
|
$HTML .= "<option value='" . $list->EmpId . "'>" . $list->EmpId . "-" . $list->FullName . "</option>";
|
|
}
|
|
}
|
|
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 condition for all while checkbox is checked means.
|
|
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]->TotalSalary;
|
|
$totalsalaryinwords = $this->convertNumberToWords(round($totalsalary));
|
|
$Data['amtinwords'] = $totalsalaryinwords;
|
|
|
|
|
|
$html .= view("payslipgenerateprint", $Data);
|
|
|
|
|
|
}
|
|
}
|
|
} else {
|
|
$EmpID = $this->request->getPost('Employee');
|
|
// $EmpID = "RIPL136";
|
|
$is_driver = $this->driver_model->getDriverName($EmpID,1);
|
|
// print_r($is_driver);die;
|
|
if($is_driver == "1"){
|
|
$Data['PayDetails'] = $this->driver_model->GetPayslipdata($Payon, $EmpID);
|
|
|
|
$name = $Data['PayDetails'][0]->driver_name;
|
|
$filename = 'PayslipFor-' . $EmpID . ' ' . $name . ' ' . $m . ' ' . $y;
|
|
|
|
$totalsalary = $Data['PayDetails'][0]->final_payment;
|
|
$totalsalaryinwords = $this->convertNumberToWords(round($totalsalary));
|
|
$Data['amtinwords'] = $totalsalaryinwords;
|
|
$currentDayBasic = isset($Data['PayDetails'][0]->monthly_salary_amount) ? $Data['PayDetails'][0]->monthly_salary_amount : 0;
|
|
$PF_Rate = $Data['PayDetails'][0]->PF_Rate;
|
|
$ESI_Rate = $Data['PayDetails'][0]->ESI_Rate;
|
|
// $Data['esi_amount'] = ($Data['PayDetails'][0]->esi_applicable == 1) ? $currentDayBasic * $ESI_Rate / 100 : 0;
|
|
// $Data['pf_amount'] = ($Data['PayDetails'][0]->pf_applicable == 1) ? $currentDayBasic * $PF_Rate / 100 : 0;
|
|
$Data['esi_amount'] = ($Data['PayDetails'][0]->esi_applicable == 1) ? $Data['PayDetails'][0]->ESI : 0;
|
|
$Data['pf_amount'] = ($Data['PayDetails'][0]->pf_applicable == 1) ? $Data['PayDetails'][0]->PF : 0;
|
|
$html = view("driverPayslipGeneratePrint", $Data);
|
|
}else{
|
|
//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->convertNumberToWords(round($totalsalary));
|
|
$Data['amtinwords'] = $totalsalaryinwords;
|
|
// print_r ($Data);
|
|
// exit();
|
|
// echo view("payslipgenerateprint", $Data);die;
|
|
$html = view("payslipgenerateprint", $Data);
|
|
}
|
|
|
|
}
|
|
// echo $html;die;
|
|
|
|
$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($filename . ".pdf", 'D');
|
|
|
|
}
|
|
|
|
function convertNumberToWords($number) {
|
|
$numberWords = [
|
|
0 => "Zero",
|
|
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"
|
|
];
|
|
|
|
if ($number == 0) {
|
|
return $numberWords[0];
|
|
}
|
|
|
|
$word = '';
|
|
|
|
if ($number >= 10000000) {
|
|
$crore = floor($number / 10000000);
|
|
if ($crore > 0) {
|
|
$word .= $this->convertNumberToWords($crore) . " Crore ";
|
|
}
|
|
$number %= 10000000;
|
|
}
|
|
|
|
if ($number >= 100000) {
|
|
$lakh = floor($number / 100000);
|
|
if ($lakh > 0) {
|
|
$word .= $this->convertNumberToWords($lakh) . " Lakh ";
|
|
}
|
|
$number %= 100000;
|
|
}
|
|
|
|
if ($number >= 1000) {
|
|
$thousand = floor($number / 1000);
|
|
if ($thousand > 0) {
|
|
$word .= $this->convertNumberToWords($thousand) . " Thousand ";
|
|
}
|
|
$number %= 1000;
|
|
}
|
|
|
|
if ($number >= 100) {
|
|
$hundred = floor($number / 100);
|
|
if ($hundred > 0) {
|
|
$word .= $this->convertNumberToWords($hundred) . " Hundred ";
|
|
}
|
|
$number %= 100;
|
|
}
|
|
|
|
if ($number > 0) {
|
|
if ($word !== '') {
|
|
$word .= "and ";
|
|
}
|
|
if ($number <= 20) {
|
|
$word .= $numberWords[$number];
|
|
} else {
|
|
$word .= $numberWords[floor($number / 10) * 10];
|
|
if ($number % 10 > 0) {
|
|
$word .= " " . $numberWords[$number % 10];
|
|
}
|
|
}
|
|
}
|
|
|
|
return trim($word);
|
|
}
|
|
|
|
|
|
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 "<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->request->getPost('employee');
|
|
$payon = $this->request->getPost('payon');
|
|
$is_driver = $this->driver_model->getDriverName($empid,1);
|
|
if($is_driver){
|
|
$result = $this->driver_model->checkDriverExistPay($empid, $payon);
|
|
$data['count'] = count($result);
|
|
$data['path'] = "driverPayslip";
|
|
echo json_encode($data);
|
|
}else{
|
|
$result = $this->payroll_model->checkExistPayData($empid, $payon);
|
|
$data['count'] = count($result);
|
|
$data['path'] = "payslip/callsp";
|
|
echo json_encode($data);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
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 = '';
|
|
|
|
|
|
|
|
$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()
|
|
{
|
|
|
|
$report = [];
|
|
|
|
if ($this->request->getMethod(true) === 'POST' && $this->request->getPost('btn_submit')) {
|
|
|
|
|
|
$data['from_date'] = $this->request->getPost('from_date');
|
|
$data['to_date'] = $this->request->getPost('to_date');
|
|
$data['EmpID'] = $this->request->getPost('emp');
|
|
|
|
|
|
|
|
$report = $this->monthlypay_model->leave_report($data['from_date'], $data['to_date'], $data['EmpID']);
|
|
|
|
|
|
}
|
|
|
|
$data['EmpData'] = $this->monthlypay_model->getActiveEmployee();
|
|
|
|
|
|
$data['data'] = $report;
|
|
// dd($data);
|
|
// Load the view
|
|
|
|
$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);
|
|
}
|
|
}
|