diff --git a/application/controllers/payslip.php b/application/controllers/payslip.php index b56e2d67..62ba759c 100755 --- a/application/controllers/payslip.php +++ b/application/controllers/payslip.php @@ -467,19 +467,166 @@ class payslip extends BaseController public function monthlyInputs() { $current = date("m-Y"); - $data['month'] = $this-> monthlypay_model->monthlyListing($current); - $data['fresh'] = $this-> monthlypay_model->getEmpPayDetailsforMonthInputs($current); - $data['dropdownvalue'] = $current; + $data['month'] = $this->monthlypay_model->monthlyListing($current); + $data['dropdownvalue'] = $current; + $data['fresh'] = $this->monthlypay_model->getEmpPayDetailsforMonthInputs($current); + $employeeSalary = []; + 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; + $Food_Allowances= $value->Food_Allowances; + $Days_worked = $value->Days_worked; // working day + $LOP_Days = $value->LOP_Days; // 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 + + $MasterIncentives=$value->MasterIncentives;//Master values get + // echo 'master'.$MasterIncentives; + + + $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) + { + + // current= Balance_Amount - autoLoan; + //alert('hi'); + $loan = $Balance_Amount; + + } + + + + + + + $Allowances =$value->Allowances; + $HRA_Rate=$value->HRA_Rate; + $PF_Rate=$value->PF_Rate; + $ESI_Rate=$value->ESI_Rate; + + $MonthIncentive = $value->MonthlyIncentives;//T_Monthly_Pay_Inputs,for change month + + $Incentive = 0; + + if(empty($MonthIncentive)) + { + + $Incentive = $MasterIncentives; + } + else + { + $Incentive = $MonthIncentive; + + } + // echo $Incentive; + + + + $daySalarys = $Days_worked + $Paid_leave; + + //echo "hra amount";print_r(array($HRA_Amount,$Basic_Pay,$totalsalary)); + //$Allowances = $allowances * $values; + $dayFood_Allowance = $Food_Allowances * $Days_worked; + + $daySalary = $Basic_Pay / $NoofDays; + /**per day salary working hour**/ + //echo $daySalary.'
'; + + $dayHra = $HRA_Amount / $NoofDays; + /** per day hra amount **/ + //echo $dayHra.'
'; + + $onehoursSalary = ($daySalary + $dayHra) / 8; + /**one hour salay ot calculation**/ + if ($OT_Hrs_Worked != 0) + { + $totSalayOT = $OT_Hrs_Worked * $onehoursSalary; + } + else + { + $totSalayOT = 0; + } + $currentDaySalary = $daySalary * $daySalarys; + /** current day salary working days calculation**/ + + + $currentDayHra = $dayHra * $daySalarys; + /** total working days hra calculations**/ + // echo $currentDayHra.'
'; + $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; + /** current date pf calculation**/ + if ($TotalSalary <= 20000) + { + + $esiAmount = $currentDatePF * $ESI_Rate/ 100; + /** esiamount not elgiable for 20000 **/ + } + else + { + $esiAmount = 0; + } + $pfAmount = $currentDaySalary * $PF_Rate/ 100; + /** pf amount per day**/ + + //echo $totalothour;die; + $empSalaryAdd = $currentDaySalary + $totSalayOT + $currentDayHra + $dayFood_Allowance + $Allowances + $Incentive; + $empSalarySub = $esiAmount + $pfAmount + $loan; + + $salaryInCurrentday= $empSalaryAdd - $empSalarySub; + + + $employeeSalary []= round($salaryInCurrentday); + + + +} +$data['empSalary'] = $employeeSalary; + //$this->global['pageTitle'] = 'Resico : Payroll Monthly Inputs'; $this->global['pageTitle'] = $this->CompanyName.' : Monthly Payroll Details'; $this->loadViews("monthlypayinputs", $this->global,$data,NULL); - - - } - - /** - * To Change the Month in payslip dropdown - */ + } function changeMonth() { @@ -489,15 +636,179 @@ class payslip extends BaseController // $data = json_encode(array_merge($month,$fresh)); // echo $data; $current = $this->input->post('monthyear'); - $data['month'] = $this-> monthlypay_model->monthlyListing($current); - $data['fresh'] = $this-> monthlypay_model->getEmpPayDetailsforMonthInputs($current); + + $data['month'] = $this->monthlypay_model->monthlyListing($current); $data['dropdownvalue'] = $current; + $data['fresh'] = $this->monthlypay_model->getEmpPayDetailsforMonthInputs($current); + + $employeeSalary = []; + + + foreach($data['fresh'] as $value){ + + //print_r($value); + //die(); + + $NoofDays=$value->NoofDays;//Month day 30,31,28 + $HRA_Amount = $value->HRA_Amount; + $Basic_Pay = $value->Basic_Pay; + $TotalSalary = $value->TotalSalary; + $Food_Allowances= $value->Food_Allowances; + $Days_worked = $value->Days_worked; // working day + $LOP_Days = $value->LOP_Days; // 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 + $due_start_date = $value->DueDate; + $paydate = $current;//From POST parm + + if(strlen($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_Recovered = $value->Loan_Recovered; //MANUAL LOAN DUE + + $MasterIncentives=$value->MasterIncentives;//Master values get + // echo 'master'.$MasterIncentives; + $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) + { + + // current= Balance_Amount - autoLoan; + //alert('hi'); + $loan = $Balance_Amount; + + } + + + + + + + $Allowances =$value->Allowances; + $HRA_Rate=$value->HRA_Rate; + $PF_Rate=$value->PF_Rate; + $ESI_Rate=$value->ESI_Rate; + + $MonthIncentive = $value->MonthlyIncentives;//T_Monthly_Pay_Inputs,for change month + + $Incentive = 0; + + if(empty($MonthIncentive)) + { + + $Incentive = $MasterIncentives; + } + else + { + $Incentive = $MonthIncentive; + + } + // echo $Incentive; + + + + $daySalarys = $Days_worked + $Paid_leave; + + //echo "hra amount";print_r(array($HRA_Amount,$Basic_Pay,$totalsalary)); + //$Allowances = $allowances * $values; + $dayFood_Allowance = $Food_Allowances * $Days_worked; + + $daySalary = $Basic_Pay / $NoofDays; + /**per day salary working hour**/ + //echo $daySalary.'
'; + + $dayHra = $HRA_Amount / $NoofDays; + /** per day hra amount **/ + //echo $dayHra.'
'; + + $onehoursSalary = ($daySalary + $dayHra) / 8; + /**one hour salay ot calculation**/ + if ($OT_Hrs_Worked != 0) + { + $totSalayOT = $OT_Hrs_Worked * $onehoursSalary; + } + else + { + $totSalayOT = 0; + } + $currentDaySalary = $daySalary * $daySalarys; + /** current day salary working days calculation**/ + + + $currentDayHra = $dayHra * $daySalarys; + /** total working days hra calculations**/ + // echo $currentDayHra.'
'; + $currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT; + /** current date pf calculation**/ + if ($TotalSalary <= 20000) + { + + $esiAmount = $currentDatePF * $ESI_Rate/ 100; + /** esiamount not elgiable for 20000 **/ + } + else + { + $esiAmount = 0; + } + $pfAmount = $currentDaySalary * $PF_Rate/ 100; + /** pf amount per day**/ + + //echo $totalothour;die; + $empSalaryAdd = $currentDaySalary + $totSalayOT + $currentDayHra + $dayFood_Allowance + $Allowances + $Incentive; + $empSalarySub = $esiAmount + $pfAmount + $loan; + + $salaryInCurrentday= $empSalaryAdd - $empSalarySub; + + + $employeeSalary []= round($salaryInCurrentday); + + + +} + $data['empSalary'] = $employeeSalary; + + //$this->global['pageTitle'] = 'Resico : Payroll Monthly Inputs'; $this->global['pageTitle'] = $this->CompanyName.' : Monthly Payroll Inputs'; $this->loadViews("monthlypayinputs", $this->global,$data,NULL); - - } +} /** * To Store the Month in payslip datas @@ -533,20 +844,26 @@ class payslip extends BaseController $total = 0; $ErrorEmpId = ''; $TotalErrorFlag = 0; - foreach($json as $j) + $i = sizeof($json); + $len = $i-2; + foreach($json as $index=>$j) { - $ErrorFlag = 0; + if($index<=$len){ + $ErrorFlag = 0; + + $Emp = $j['Employee']; + + $EmpID = substr($Emp,0,4); - $EmpID = $j['Employee Id']; - $Name = $j['Employee Name']; $DaysWorked = $j['Days Worked']; $LOP_Days = $j['LOP Days']; $Paid_leave = $j['Paid Leave']; - $OT_Hrs_Worked = $j['OT Hours Worked in Hrs']; - $Loan_Recovered = $j['Loan Recovered in ₹']; + $OT_Hrs_Worked = $j['OT Hrs']; + $Loan_Recovered = $j['Manual Loan Due ₹']; $Incentives = $j['Incentives in ₹']; $Festival_Bonus = $j['Festival Bonus in ₹']; $Other_Deductions = $j['Other Deductions in ₹']; + $Estimate =$j['Estimate in ₹']; $Created_By = $this->session->userdata ( 'userId' ); if(!is_numeric($DaysWorked) || ($DaysWorked > 31) || (strlen((string)$DaysWorked)) > 5 ) @@ -607,6 +924,12 @@ class payslip extends BaseController $ErrorFlag++; } + $Estimate_first = explode(".",$Estimate); + if(!is_numeric($Estimate) || (strlen((string)$Estimate))>8 || (strlen((string)$Estimate_first[0]))> 5) + { + //echo $EmpID . "-Loan Recoverd Invalid Data!"; + $ErrorFlag++; + } if($ErrorFlag != 0) { $ErrorEmpId = $ErrorEmpId ."|". $EmpID; @@ -617,18 +940,24 @@ class payslip extends BaseController //nothing } } + } if($TotalErrorFlag == 0) { - foreach($json as $j) + foreach($json as $index=>$j) { - $EmpID = $j['Employee Id']; - $Name = $j['Employee Name']; + // $EmpID = $j['Employee Id']; + // $Name = $j['Employee Name']; + $Emp = $j['Employee']; + + $EmpID = substr($Emp,0,4); + $DaysWorked = $j['Days Worked']; - $LOP_Days = $j['LOP Days']; + + $LOP_Days = $j['LOP Days']; $Paid_leave = $j['Paid Leave']; - $OT_Hrs_Worked = $j['OT Hours Worked in Hrs']; - $Loan_Recovered = $j['Loan Recovered in ₹']; + $OT_Hrs_Worked = $j['OT Hrs']; + $Loan_Recovered = $j['Manual Loan Due ₹']; if(is_string($Loan_Recovered)) { $Loan_Recovered = strtoupper($Loan_Recovered); @@ -636,14 +965,15 @@ class payslip extends BaseController $Incentives = $j['Incentives in ₹']; $Festival_Bonus = $j['Festival Bonus in ₹']; $Other_Deductions = $j['Other Deductions in ₹']; + $Estimate =$j['Estimate in ₹']; $Created_By = $this->session->userdata ( '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,'Loan_Recovered'=>$Loan_Recovered,'Incentives'=>$Incentives,'Festival_Bonus'=>$Festival_Bonus,'Other_Deductions'=>$Other_Deductions,'Created_By'=>$Created_By); + $monthlypaydata = array('Month_Year'=>$month,'EmpID'=>$EmpID,'Days_worked'=>$DaysWorked,'LOP_Days'=>$LOP_Days,'Paid_leave'=>$Paid_leave,'OT_Hrs_Worked'=>$OT_Hrs_Worked,'Loan_Recovered'=>$Loan_Recovered,'Incentives'=>$Incentives,'Festival_Bonus'=>$Festival_Bonus,'Other_Deductions'=>$Other_Deductions,'Estimate'=>$Estimate,'Created_By'=>$Created_By); $result = $this->monthlypay_model->saveMonthlyData_model($monthlypaydata); $total = $total + $result; } } - + $total = $total -1; if(!empty($ErrorEmpId)) { echo $ErrorEmpId . "- are have Invalid Data!"; @@ -668,6 +998,7 @@ class payslip extends BaseController function reload_paysliplist() { + $pre_monthyear = $this->input->post('month'); //$this->global['pageTitle'] = 'Resico : Payslip Listing'; @@ -1012,7 +1343,7 @@ class payslip extends BaseController $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(); + $LoanRecovered=$sheet->getCell('G'.$x)->getValue(); if(is_string($loanRecovered)) { $loanRecovered = strtoupper($loanRecovered); diff --git a/application/models/batchcard_model.php b/application/models/batchcard_model.php index c52f4f64..ae8a5b53 100755 --- a/application/models/batchcard_model.php +++ b/application/models/batchcard_model.php @@ -51,7 +51,7 @@ class batchcard_model extends CI_Model $this->db->select('MaterialCode,MaterialName,'); $this->db->from('T_MaterialMaster'); - $this->db->where('T_MaterialMaster.Category',Consumables); + $this->db->where('T_MaterialMaster.Category like','%Consumables%'); $supp = $this->db->get(); return $supp->result(); @@ -64,7 +64,7 @@ class batchcard_model extends CI_Model { $this->db->select('MaterialCode,MaterialName,'); $this->db->from('T_MaterialMaster'); - $this->db->where('T_MaterialMaster.Category',RawMaterial); + $this->db->where('T_MaterialMaster.Category like','%Raw Material%'); $supp = $this->db->get(); return $supp->result(); } @@ -76,7 +76,7 @@ class batchcard_model extends CI_Model { $this->db->select('MaterialCode,MaterialName,'); $this->db->from('T_MaterialMaster'); - $this->db->where('T_MaterialMaster.Category',Packingmaterial); + $this->db->where('T_MaterialMaster.Category like','%Packing%'); $supp = $this->db->get(); return $supp->result(); } diff --git a/application/models/monthlypay_model.php b/application/models/monthlypay_model.php index 117123fb..d4088aee 100755 --- a/application/models/monthlypay_model.php +++ b/application/models/monthlypay_model.php @@ -10,13 +10,18 @@ class monthlypay_model extends CI_Model */ function monthlyListing($current="") { + $month = $current; + if(strlen($month) == 6) + { + $month = '0'.$month; + } $curr_split = explode('-',$current); $month_val = $curr_split[0]; $year_val = $curr_split[1]; $date_val =cal_days_in_month(CAL_GREGORIAN,$month_val,$year_val); $lastdate = $year_val.'-'.$month_val.'-'.$date_val; - $sql="select T_Monthly_Pay_Inputs.*,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Loan_Master.Loan_ID,T_Payroll.Key + $sql="select T_Monthly_Pay_Inputs.*,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Loan_Master.Loan_ID,T_Loan_Master.Monthly_Due,T_Payroll.Key from T_Monthly_Pay_Inputs left join T_Employee_Details on T_Monthly_Pay_Inputs.EmpID=T_Employee_Details.EmpID and T_Employee_Details.DateofJoining <= ? left join T_Payroll on T_Monthly_Pay_Inputs.EmpID=T_Payroll.EmpID @@ -63,7 +68,11 @@ class monthlypay_model extends CI_Model */ function getEmpPayDetailsforMonthInputs($current="") { - + $month = $current; + if(strlen($month) == 6) + { + $month = '0'.$month; + } $current = '01-'.$current; $current = date_create($current); $current = date_format($current,'Y-m-d'); @@ -73,16 +82,20 @@ class monthlypay_model extends CI_Model $date_val =cal_days_in_month(CAL_GREGORIAN,$month_val,$year_val); $lastdate = $year_val.'-'.$month_val.'-'.$date_val; - $sql = "select T_Emp_Pay_Data.EmpID,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Employee_Details.DateofJoining,T_Attendance.Days_Worked as Days_worked,T_Attendance.Absent as LOP_Days,T_Attendance.Paid_Leave as Paid_leave,T_Attendance.Total_OTHrs as OT_Hrs_Worked,T_Attendance.NoofDays,T_Loan_Master.Loan_ID,T_Payroll.Key from T_Emp_Pay_Data + $sql ="select T_Emp_Pay_Data.EmpID, T_Emp_Pay_Data.Incentives as MasterIncentives,T_Emp_Pay_Data.*,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Employee_Details.DateofJoining,T_Attendance.Days_Worked as Days_worked,T_Attendance.Absent as LOP_Days,T_Attendance.Paid_Leave as Paid_leave,T_Attendance.Total_OTHrs as OT_Hrs_Worked,T_Attendance.NoofDays,T_Loan_Master.Loan_ID,T_Loan_Master.Monthly_Due,T_Loan_Master.Due_Start_Date as DueDate,T_Loan_Master.Loan_Amount,T_Loan_Master.Paid_Amount,T_Payroll.Key,T_Monthly_Pay_Inputs.Incentives as MonthlyIncentives,T_Monthly_Pay_Inputs.Loan_Recovered,T_Monthly_Pay_Inputs.Estimate,T_Monthly_Pay_Inputs.Festival_Bonus,T_Monthly_Pay_Inputs.Other_Deductions,T_Loan_History .Balance_Amount + from T_Emp_Pay_Data left join T_Employee_Details on T_Employee_Details.EmpID = T_Emp_Pay_Data.EmpID - left join T_Payroll on T_Employee_Details.EmpID = T_Payroll.EmpID and month(T_Payroll.PayOn) = month(?) and year(T_Payroll.PayOn) = year(?) + left join T_Payroll on T_Employee_Details.EmpID = T_Payroll.EmpID and T_Payroll.PayOn = ? left join T_Attendance on T_Emp_Pay_Data.EmpID = T_Attendance.EmpID + left join T_Monthly_Pay_Inputs on T_Monthly_Pay_Inputs.EmpID = T_Emp_Pay_Data.EmpID and T_Monthly_Pay_Inputs.Month_Year = ? left join T_Loan_Master on T_Emp_Pay_Data.EmpID = T_Loan_Master.EmpID and T_Loan_Master.is_Active = 1 + left join T_Loan_History on T_Loan_History .Loan_ID = T_Loan_Master.Loan_ID + where T_Employee_Details.DateofJoining <= ? and month(T_Attendance.Month_Year) = month(?) and year(T_Attendance.Month_Year) = year(?) order by T_Employee_Details.EmpID"; - $query = $this->db->query($sql,array($current,$current,$lastdate,$current,$current)); + $query = $this->db->query($sql,array($month,$month,$lastdate,$current,$current)); return $query->result(); } @@ -180,7 +193,7 @@ class monthlypay_model extends CI_Model $this->db->join('T_Employee_Details','T_Attendance.EmpID=T_Employee_Details.EmpID'); $this->db->where('T_Employee_Details.DateofJoining <= ',$lastdate); $this->db->where('Month_Year',$current); - $this->db->where('T_Employee_Details.IsActive',1); + // $this->db->where('T_Employee_Details.IsActive',1); $this->db->order_by('T_Attendance.EmpID', 'asc'); $query = $this->db->get(); diff --git a/application/views/monthlypayinputs.php b/application/views/monthlypayinputs.php index dbf03ec7..67dafd9c 100755 --- a/application/views/monthlypayinputs.php +++ b/application/views/monthlypayinputs.php @@ -1,5 +1,19 @@ Key)) + { + $show_hide_column_value = false; + } + else + { + $show_hide_column_value = true; + } + break; + } $ex = explode('-',$dropdownvalue); if(strlen($ex[0])== '2') { @@ -24,7 +38,7 @@ - + \ No newline at end of file