diff --git a/app/Controllers/Emergencypurchaseorder.php b/app/Controllers/Emergencypurchaseorder.php index 8e6dab1e..4cecdeb2 100644 --- a/app/Controllers/Emergencypurchaseorder.php +++ b/app/Controllers/Emergencypurchaseorder.php @@ -386,7 +386,7 @@ class Emergencypurchaseorder extends BaseController function addNewRevenuePurchaseOrder() { - print_r($this->request->getPost());die; + // print_r($this->request->getPost());die; $txtspl = $this->request->getPost('txtSpecial'); diff --git a/app/Controllers/Payslip.php b/app/Controllers/Payslip.php index 1090edb5..b0b94253 100644 --- a/app/Controllers/Payslip.php +++ b/app/Controllers/Payslip.php @@ -61,12 +61,84 @@ class Payslip extends BaseController public function callsp() { - $payon = $this->request->getPost('payon'); - $employee = $this->request->getPost('employee'); - $result = $this->payroll_model->model_sp($payon, $employee); - // $result = $this->db->last_query(); - return $result; - //$this->db->call_function('model_sp'); + // $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; + 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, + ]; + + + + } + } + // 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' => 0, + 'LessAdvance' => 0, + 'BankAccountNumber' => $result->BankAccountNo, + 'PFNumber' => $result->PFNO, + 'ESINumber' => $result->ESINO, + 'UANNO' => $result->PFNO, + ]; + + + $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; + } @@ -615,9 +687,9 @@ class Payslip extends BaseController // die; $employeeSalary[] = round($salaryInCurrentday); - $esi[] = number_format($esiAmount,2); - $pf[] = number_format($pfAmount,2); - $ot[] = number_format($totSalayOT,2); + $esi[] = number_format($esiAmount,2, '.', ''); + $pf[] = number_format($pfAmount,2, '.', ''); + $ot[] = number_format($totSalayOT,2, '.', ''); } $data['empSalary'] = $employeeSalary; $data['esi'] = $esi; @@ -638,7 +710,7 @@ class Payslip extends BaseController $data['month'] = $this->monthlypay_model->monthlyListing($current); $data['dropdownvalue'] = $current; $data['fresh'] = $this->monthlypay_model->getEmpPayDetailsforMonthInputs($current); - //dd($data['fresh']); + // dd($data['fresh']); $employeeSalary = []; @@ -750,9 +822,9 @@ class Payslip extends BaseController // die; $employeeSalary[] = round($salaryInCurrentday); - $esi[] = number_format($esiAmount,2); - $pf[] = number_format($pfAmount,2); - $ot[] = number_format($totSalayOT,2); + $esi[] = number_format($esiAmount,2, '.', ''); + $pf[] = number_format($pfAmount,2, '.', ''); + $ot[] = number_format($totSalayOT,2, '.', ''); } $data['empSalary'] = $employeeSalary; $data['esi'] = $esi; @@ -863,11 +935,7 @@ class Payslip extends BaseController } } - // $Incentives_first = explode(".", $Incentives); - // if (!is_numeric($Incentives) || (strlen((string)$Incentives)) > 8 || (strlen((string)$Incentives_first[0])) > 5) { - // //echo $EmpID . "-Loan Recoverd Invalid Data!"; - // $ErrorFlag++; - // } + $Festivalbonus_first = explode(".", $Festival_Bonus); if (!is_numeric($Festival_Bonus) || (strlen((string)$Festival_Bonus)) > 8 || (strlen((string)$Festivalbonus_first[0])) > 5) { @@ -905,26 +973,53 @@ class Payslip extends BaseController $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; - // if (is_string($Loan_Recovered)) { - // $Loan_Recovered = strtoupper($Loan_Recovered); - // } - // $Incentives = isset($j['Incentives in ₹']) ? $j['Incentives in ₹'] : 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); + $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; } } - $total = $total - 1; + //echo ""; if (!empty($ErrorEmpId)) { echo $ErrorEmpId . "- are have Invalid Data!"; @@ -1018,63 +1113,55 @@ class Payslip extends BaseController 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'); - // if ($All == '') { - // $this->validator->setRules([ - // 'Employee' => [ - // 'label' => 'Employee', - // 'rules' => 'trim|callback_Employee_validate', - // ] - // ]); - // } - // $this->validator->setRules([ - // 'PayOn' => [ - // 'label' => 'PayOn', - // 'rules' => 'trim|callback_PayOn_validate', - // ] - // ]); - - // if ($this->validator->run() == FALSE) { - // $this->viewGenerator(); - // } else { $Payon = $this->request->getPost('PayOn'); $m = date("M", mktime(0, 0, 0, (int)$Payon, 10)); - //$y =date("Y",mktime(0, 0, 0, $Payon, 10)); - //$m=date("M-Y",mktime(0,0,0,$month,1,$year)); + $y = substr((string)$Payon, 3); - //echo "Payon" . $Payon; + if ($All != '') { $filename = 'PayslipFor-' . $m . '-' . $y; $result = $this->payroll_model->getEmpAll($Payon); - // print_r($result); - // die(); - + if ($result > 0) { for ($i = 0; $i < count($result); $i++) { $EmpID = $result[$i]['EmpId']; - //print_r( - //$EmpID ); - // die(); + $Data['PayDetails'] = $this->payroll_model->GetPayslipdata($Payon, $EmpID); - // + $totalsalary = $Data['PayDetails'][0]->LessAdvance; $totalsalaryinwords = $this->convertNumber(round($totalsalary)); $Data['amtinwords'] = $totalsalaryinwords; - // print_r ($Data); - // exit(); - //$Data['Count'] = $i; + $html .= view("payslipgenerateprint", $Data); - // print_r ($Data); - // exit(); + } } } else { @@ -1088,45 +1175,12 @@ class Payslip extends BaseController $totalsalary = $Data['PayDetails'][0]->LessAdvance; $totalsalaryinwords = $this->convertNumber(round($totalsalary)); $Data['amtinwords'] = $totalsalaryinwords; - //print_r ($Data); - //exit(); + // print_r ($Data); + // exit(); $html = view("payslipgenerateprint", $Data); } - // $php = $this->output->get_output(); - - // // Load library - // $this->load->library('dompdf_gen'); - - // if($All != '') - // { - // $filename = 'Payslip-'.$Payon.'.pdf' ; - // } - // else - // { - // $filename = 'Payslip-'.$EmpID . '-' .$Payon.'.pdf' ; - // } - - // require_once(APPPATH .'third_party/dompdf/dompdf_config.inc.php'); - // $dompdf = new DOMPDF(); - // $dompdf->set_paper('A4', 'portrait'); - // $dompdf->load_html($php); - - // $dompdf->render(); - - // // add the header - // $canvas = $dompdf->get_canvas(); - // $font = Font_Metrics::get_font("helvetica", "bold"); - - // // the same call as in my previous example - // $canvas->page_text(72, 18, "Page: {PAGE_NUM} of {PAGE_COUNT}", - // $font, 6, array(0,0,0)); - - // $dompdf->stream($filename); - // } - - // $mpdf = new mPDF('utf-8', 'A4-P', 10, 10, 10, 10, 10, 24, 4, 6); $mpdf = new Mpdf([ 'mode' => 'utf-8', 'format' => 'A4-P', @@ -1147,7 +1201,7 @@ class Payslip extends BaseController $mpdf->SetTitle('Resico:Payslip'); $mpdf->Output("Payslip-" . $filename . ".pdf", 'D'); - // } + } function updatePayslip() diff --git a/app/Models/Monthlypay_model.php b/app/Models/Monthlypay_model.php index 98c3665a..82fa5014 100644 --- a/app/Models/Monthlypay_model.php +++ b/app/Models/Monthlypay_model.php @@ -84,7 +84,7 @@ class Monthlypay_model extends Model $month = '0' . $month; } - //echo $month; + $current = '01-' . $current; //echo $current; @@ -100,7 +100,7 @@ class Monthlypay_model extends Model //echo $lastdate; //left join t_payroll on t_employee_details.EmpID = t_payroll.EmpID and month(t_payroll.PayOn) = month(?) and year(t_payroll.PayOn) = year(?) - $sql = "select t_emp_pay_data.EmpID,t_emp_pay_data.*,t_employee_details.FirstName,t_employee_details.DateofJoining,t_employee_details.Designation,t_employee_details.esi_applicable,t_employee_details.pf_applicable,t_employee_details.is_management_team,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_attendance.sunday_count,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 + $sql = "select t_emp_pay_data.EmpID,t_emp_pay_data.*,t_employee_details.FirstName,t_employee_details.DateofJoining,t_employee_details.Designation,t_employee_details.esi_applicable,t_employee_details.pf_applicable,t_employee_details.is_management_team,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_attendance.sunday_count,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.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 t_payroll.PayOn = ? @@ -113,6 +113,9 @@ class Monthlypay_model extends Model order by t_employee_details.EmpID"; $query = $this->db->query($sql, array($month, $month, $lastdate, $current, $current)); + // Get the last executed query + // $last_query = $this->db->getLastQuery(); + // echo $last_query; return $query->getResult(); } @@ -371,7 +374,7 @@ join t_departmentdetails as Dep on Dep.DEPCode=Emp.Departmentcode where Emp.IsA $pre_year = $curr_split[0]; $curr_year = $curr_split[1]; - $sql = "select t_monthly_pay_inputs.EmpID,t_employee_details.FirstName,t_employee_details.LastName,sum(Incentives) as Incentives,sum(Festival_Bonus) as Bonus + $sql = "select t_monthly_pay_inputs.EmpID,t_employee_details.FirstName,t_employee_details.LastName,sum(Festival_Bonus) as Bonus from t_monthly_pay_inputs join t_employee_details on t_monthly_pay_inputs.EmpID = t_employee_details.EmpID where @@ -393,7 +396,7 @@ join t_departmentdetails as Dep on Dep.DEPCode=Emp.Departmentcode where Emp.IsA $pre_year = $curr_split[0]; $curr_year = $curr_split[1]; - $sql = "select t_monthly_pay_inputs.EmpID,t_monthly_pay_inputs.Month_Year,t_employee_details.FirstName,t_employee_details.LastName,sum(Incentives) as Incentives,sum(Festival_Bonus) as Bonus + $sql = "select t_monthly_pay_inputs.EmpID,t_monthly_pay_inputs.Month_Year,t_employee_details.FirstName,t_employee_details.LastName,sum(Festival_Bonus) as Bonus from t_monthly_pay_inputs join t_employee_details on t_monthly_pay_inputs.EmpID = t_employee_details.EmpID and t_monthly_pay_inputs.EmpID = ? diff --git a/app/Models/Payroll_model.php b/app/Models/Payroll_model.php index 84001a78..aebe4db9 100644 --- a/app/Models/Payroll_model.php +++ b/app/Models/Payroll_model.php @@ -376,8 +376,10 @@ class Payroll_model extends Model function getEmpID() { - $builder = $this->db->table('t_employee_details') - ->select('EmpID,FirstName,LastName'); + $builder = $this->db->table('t_employee_details E') + ->select('E.EmpID, E.FirstName, E.LastName') + ->join('t_loan_master LM', 'LM.EmpID = E.EmpID', 'left') + ->where('LM.Loan_ID IS NULL'); $query = $builder->get(); return $query->getResult(); @@ -487,4 +489,42 @@ class Payroll_model extends Model //return $query_count; return $query->getResult(); } + + + function getMonthlyPayDetails($EmpId, $PayOn) + { + $builder = $this->db->table('t_monthly_pay_inputs MonthlyPay ') + ->select('MonthlyPay.*, E.BankAccountNo , E.PFNO , E.ESI as ESINO , L.*') + ->join('t_employee_details as E', 'MonthlyPay.EmpID = E.EmpID', 'left') + ->join('t_loan_master as L', 'MonthlyPay.EmpID = L.EmpID and L.is_Active = 1', 'left') + ->where('MonthlyPay.EmpID', $EmpId) + ->where('MonthlyPay.Month_Year', $PayOn); + + $query = $builder->get(); + return $query->getResult(); + } + + function insertPayroll($data) + { + $builder = $this->db->table('t_payroll'); + $builder->insert($data); + $count = $this->db->affectedRows(); + return $count; + } + function insertLoanHistory($data) + { + $builder = $this->db->table('t_loan_history'); + $builder->insert($data); + $count = $this->db->affectedRows(); + return $count; + } + function updateLoan($LoanID,$EmpID,$data) + { + $builder = $this->db->table('t_loan_master') + ->where('Loan_ID', $LoanID) + ->where('EmpID', $EmpID) + ->update($data); + $count = $this->db->affectedRows(); + return $count; + } } \ No newline at end of file diff --git a/app/Views/addemppaydate.php b/app/Views/addemppaydate.php index a7b11127..3b78043a 100644 --- a/app/Views/addemppaydate.php +++ b/app/Views/addemppaydate.php @@ -36,7 +36,7 @@