560 lines
16 KiB
PHP
Executable File
560 lines
16 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class Payroll_model extends Model
|
|
{
|
|
|
|
/**
|
|
* This function is used to insert the File details in database
|
|
* @FileDetails array : This will have the set of value which we need to insert into database
|
|
* @return number $Payon : Insert row count will be the return value
|
|
*/
|
|
function UploadFileName($FileDetails)
|
|
{
|
|
$builder = $this->db->table('t_payroll_file');
|
|
$builder->insert($FileDetails);
|
|
|
|
$Payon = $this->db->affectedRows();
|
|
|
|
return $Payon;
|
|
}
|
|
|
|
function model_sp($payon, $employee)
|
|
{
|
|
|
|
//echo "<script>alert('mod');</script>";
|
|
//echo "highlight_file(filename)";
|
|
//die();
|
|
$result = $this->db->query("call P_FINAL_PAYROLL_DATA('" . $payon . "','" . $employee . "')"); // or die(mysql_error());
|
|
//$result->next_result();
|
|
|
|
return $result;
|
|
}
|
|
/**
|
|
* This function is used to update the File details in which is already exists in the database
|
|
* @FileDetails array : This will have the set of value which we need to insert into database
|
|
* @return number boolean: success of the updation
|
|
*/
|
|
function UpdateFileName($FileDetails, $PayOn)
|
|
{
|
|
$builder = $this->db->table('t_payroll_file')
|
|
->where('PayOn', $PayOn)
|
|
->update($FileDetails);
|
|
return TRUE;
|
|
}
|
|
/**
|
|
* This function is used to check the File details is already exists in the database or not
|
|
* @FileDetails array : This will have the set of value which we need to insert into database
|
|
* @return number boolean: success of the updation
|
|
*/
|
|
function checkFileDetailsExists($PayOn)
|
|
{
|
|
$builder = $this->db->table('t_payroll_file')
|
|
->select('PayOn')
|
|
->where('PayOn', $PayOn);
|
|
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
return $query->getResult();
|
|
}
|
|
}
|
|
|
|
function checkExistPayData($empid, $payon)
|
|
{
|
|
|
|
$builder = $this->db->table('t_payroll')
|
|
->select('PayOn,EmpID')
|
|
->where('PayOn', $payon)
|
|
->where('EmpID', $empid);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function checkFileDetailsExists2($PayOn, $EmpId)
|
|
{
|
|
//echo $EmpId;
|
|
//die();
|
|
$builder = $this->db->table('t_monthly_pay_inputs')
|
|
->select('Month_Year', 'EmpID')
|
|
->where('EmpID', $EmpId)
|
|
->where('Month_Year', $PayOn);
|
|
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
//echo "success";
|
|
//return $query->getResult();
|
|
return TRUE;
|
|
} else {
|
|
//echo "fail";
|
|
return FALSE;
|
|
}
|
|
}
|
|
/**
|
|
* This function is used to insert the File data in database
|
|
* @FileDetails array : This will have the set of value which we need to insert into database
|
|
* @return number $Payon : Insert row count will be the return value
|
|
*/
|
|
function UploadFileData($FileData)
|
|
{
|
|
$builder = $this->db->table('t_payroll');
|
|
$builder->insert($FileData);
|
|
|
|
$Payon = $this->db->affectedRows();
|
|
|
|
return $Payon;
|
|
}
|
|
|
|
function UploadFileData2($FileData)
|
|
{
|
|
$builder = $this->db->table('t_monthly_pay_inputs');
|
|
$builder->insert($FileData);
|
|
|
|
$Payon = $this->db->affectedRows();
|
|
|
|
return $Payon;
|
|
}
|
|
|
|
/**
|
|
* This function is used to update the File details in which is already exists in the database
|
|
* @FileDetails array : This will have the set of value which we need to insert into database
|
|
* @return number boolean: success of the updation
|
|
*/
|
|
function UpdateFiledata($FileData, $PayOn, $EmpId)
|
|
{
|
|
$builder = $this->db->table('t_payroll')
|
|
->where('PayOn', $PayOn)
|
|
->where('EmpID', $EmpId)
|
|
->update($FileData);
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the data details in which is already exists in the database
|
|
* @FileDetails array : This will have the set of value which we need to insert into database
|
|
* @return number boolean: success of the updation
|
|
*/
|
|
function GetPayslipdata($PayOn = '', $EmpId = '')
|
|
{
|
|
//echo "FROM MODEL" . $PayOn . $EmpId;
|
|
$builder = $this->db->table('t_payroll Pay')->select('Pay.*,Emp.FirstName as FName ,Emp.LastName as Lname,Emp.DateofBirth as Dob,Emp.PANNo as Pan,Emp.BankBranchName as BankName,Emp.BankAccountNo as BankAccountNumber,Emp.IFSCCode as IFSCCode,Emp.DateofJoining as DOJ,Emp.AadharNo,Emp.Designation as Designation,Dep.DepartmentName as DeptName')
|
|
//->join('t_payroll_file payfile', 'Pay.PayOn = payfile.PayOn')
|
|
->join('t_employee_details Emp', 'Pay.EmpID = Emp.EmpID')
|
|
->join('t_departmentdetails Dep', 'Emp.Departmentcode = Dep.DEPCode');
|
|
if ($PayOn != '') {
|
|
$builder->where('Pay.PayOn', $PayOn);
|
|
}
|
|
|
|
if ($EmpId != '') {
|
|
$builder->where('Pay.EmpID', $EmpId);
|
|
}
|
|
if ($PayOn != '') {
|
|
$builder->orderBy("Pay.EmpID", "asc");
|
|
}
|
|
if ($PayOn == '' && $EmpId == '') {
|
|
$builder->orderBy("Pay.PayOn", "desc");
|
|
}
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
//print_r($query-getResult());die();
|
|
}
|
|
|
|
/* */
|
|
/**
|
|
* This function is used to get the PayOn details from t_payroll_file
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getPayOn()
|
|
{
|
|
|
|
// For Employee - old
|
|
$builder = $this->db->table('t_monthly_pay_inputs')
|
|
->select('DISTINCT(Month_Year)')
|
|
->orderBy("Month_Year", "desc");
|
|
$query = $builder->get();
|
|
$result1 = $query->getResult();
|
|
|
|
// For Driver - new
|
|
$builder = $this->db->table('t_driver_monthly_pay_inputs')
|
|
->select('DISTINCT(month_year) as Month_Year')
|
|
->orderBy("month_year", "desc");
|
|
$query = $builder->get();
|
|
$result2 = $query->getResult();
|
|
|
|
$result = array_merge($result1, $result2);
|
|
// removed duplicates - refer gpt - gpt solved
|
|
$unique = array_map("unserialize", array_unique(array_map("serialize", $result)));
|
|
return $unique;
|
|
|
|
|
|
|
|
}
|
|
|
|
function getBankInfo($bank = "")
|
|
{
|
|
|
|
$builder = $this->db->table('t_bank_details')
|
|
->select('*')
|
|
->where("Is_Active", 1);
|
|
if (!empty($bank)) {
|
|
$builder->where('Bank_name', $bank);
|
|
}
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function getReportforBank($bank, $payon)
|
|
{
|
|
$builder = $this->db->table('t_payroll Pay')
|
|
->select('Pay.*,Emp.FirstName as FName ,Emp.LastName as Lname,Emp.PANNo as Pan,Emp.BankBranchName as BankName,Emp.IFSCCode as IFSC,Bank.Address as BAddress')
|
|
->distinct()
|
|
->join('t_employee_details Emp', 'Pay.EmpID = Emp.EmpID')
|
|
->join('t_bank_details Bank', 'Emp.BankBranchName = Bank.Bank_name')
|
|
->orderBy("Pay.EmpID", "asc")
|
|
->where('Emp.BankBranchName', $bank)
|
|
->where('Pay.PayOn', $payon)
|
|
->where('Pay.TotalSalary > 0');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getReportforPFESI($payon)
|
|
{
|
|
$builder = $this->db->table('t_payroll Pay')->distinct()
|
|
->select('Pay.EmployeeESI,Pay.PF,Pay.CompanyESI,Pay.CompanyPF,Pay.NoofDaysWorked,Pay.OTperHours,Emp.FirstName as FName ,Emp.LastName as Lname,Emp.PFNO,Emp.ESI')
|
|
->join('t_employee_details Emp', 'Pay.EmpID = Emp.EmpID')
|
|
->where('Pay.PayOn', $payon)
|
|
// ->where('Pay.EmployeeESI > 0 ')
|
|
// ->where('Pay.CompanyESI > 0')
|
|
->orderBy("Pay.EmpID", "asc");
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function getLoanReport($source = '', $year1 = "", $year2 = "")
|
|
{
|
|
// echo "<br>---------------------------";
|
|
// echo "<br>From Model-";
|
|
// echo $source.'-'.$year1.'-'.$year2;
|
|
$builder = $this->db->table('t_emp_pay_data Pay')
|
|
->distinct()
|
|
->select('Pay.EmpID,Emp.FirstName as FName ,Emp.LastName as Lname,sum(loan.Loan_Amount) as Loan_Amount,sum(loan.Paid_Amount) as Paid_Amount')
|
|
->join('t_employee_details Emp', 'Pay.EmpID = Emp.EmpID')
|
|
->join('t_loan_master loan', 'Pay.EmpID = loan.EmpID');
|
|
|
|
if ($source != 'company') {
|
|
$builder->where('Pay.EmpID', $source);
|
|
}
|
|
|
|
if ($year1 != "" and $year2 != "") {
|
|
$builder->where('month(loan.Loan_Issued_Date)>=', 4);
|
|
$builder->where('year(loan.Loan_Issued_Date)=', $year1);
|
|
$builder->orWhere('month(loan.Loan_Issued_Date)<=', 3);
|
|
$builder->where('year(loan.Loan_Issued_Date)=', $year2);
|
|
}
|
|
$builder->groupBy('Pay.EmpID');
|
|
$builder->orderBy('Pay.EmpID', 'asc');
|
|
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
//print_r($query-getResult());die();
|
|
|
|
}
|
|
|
|
function getEmpDetailsforLoan()
|
|
{
|
|
|
|
$builder = $this->db->table('t_employee_details Pay')
|
|
->select('Pay.EmpID,Pay.FirstName as FName ,Pay.LastName as Lname')
|
|
->join('t_loan_master loan', 'Pay.EmpID = loan.EmpID')
|
|
->orderBy('Pay.EmpID', 'asc');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function getLoanReportforEmp($eid = '', $year1 = "", $year2 = "", $string = "")
|
|
{
|
|
|
|
|
|
//$this->db->distinct();
|
|
if ($string == 'emp') {
|
|
|
|
$builder = $this->db->table('t_emp_pay_data Pay')
|
|
->select('Pay.EmpID,Emp.FirstName as FName ,Emp.LastName as Lname,loan.*')
|
|
->join('t_employee_details Emp', 'Pay.EmpID = Emp.EmpID')
|
|
->join('t_loan_master loan', 'Pay.EmpID = loan.EmpID', 'left')
|
|
// if($source != 'company'){
|
|
->where('Pay.EmpID', $eid);
|
|
//}
|
|
if ($year1 != "" and $year2 != "") {
|
|
$builder->where('month(loan.Loan_Issued_Date)>=', 4);
|
|
$builder->where('year(loan.Loan_Issued_Date)=', $year1);
|
|
$builder->orWhere('month(loan.Loan_Issued_Date)<=', 3);
|
|
$builder->where('year(loan.Loan_Issued_Date)=', $year2);
|
|
//$this->db->group_by('Pay.EmpID');
|
|
}
|
|
$builder->orderBy('loan.Loan_Issued_Date', 'asc');
|
|
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
} elseif ($string == 'history') {
|
|
|
|
$builder = $this->db->table('t_loan_history')
|
|
->select('t_loan_master.EmpID,Emp.FirstName,Emp.LastName,t_loan_master.Loan_Amount,t_loan_master.Loan_Issued_Date,t_loan_history.*')
|
|
->join('t_loan_master', 't_loan_master.Loan_ID=t_loan_history.Loan_ID')
|
|
->join('t_employee_details Emp', 't_loan_master.EmpID = Emp.EmpID')
|
|
->where('t_loan_history.Loan_ID', $eid);
|
|
$q = $builder->get();
|
|
// ->orderBy('Entry_Date','asc');
|
|
//->where('Loan_ID',$eid);
|
|
// $q = $tdb->get('t_loan_history');
|
|
//print_r($q-getResult());
|
|
return $q->getResult();
|
|
// print_r($q-getResult());
|
|
// die();
|
|
|
|
|
|
}
|
|
//print_r($query-getResult());die();
|
|
|
|
}
|
|
/* */
|
|
/**
|
|
* This function is used to get the PayOn details from t_payroll_fileOTperHours
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getEmployeelist($Payon = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_payroll Pay')
|
|
->select('Pay.EmpID as EmpId,Emp.FirstName as Fname,Emp.LastName as Lname')
|
|
->join('t_employee_details Emp', 'Pay.EmpID = Emp.EmpID');
|
|
if ($Payon != '') {
|
|
$builder->where('Pay.PayOn', $Payon);
|
|
}
|
|
$builder->orderBy("Pay.EmpID", "asc");
|
|
|
|
$query = $builder->get();
|
|
return $query;
|
|
}
|
|
|
|
|
|
function getEmployeelist2($Payon = '')
|
|
{
|
|
// CONCAT_WS(' ', Emp.FirstName, Emp.LastName)
|
|
$builder = $this->db->table('t_monthly_pay_inputs Pay')
|
|
->select('Pay.EmpID as EmpId,CONCAT_WS(" ",Emp.FirstName,Emp.LastName) AS FullName')
|
|
->join('t_employee_details Emp', 'Pay.EmpID = Emp.EmpID and Emp.is_driver = 0');
|
|
if ($Payon != '') {
|
|
$builder->where('Pay.Month_Year', $Payon);
|
|
}
|
|
$builder->orderBy("Pay.EmpID", "asc");
|
|
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
/* */
|
|
/**
|
|
* This function is used to get the PayOn details from t_payroll_file
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getEmpAll($Payon = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_payroll Pay')
|
|
->select('Pay.EmpID as EmpId,Emp.FirstName as Fname,Emp.LastName as Lname')
|
|
->join('t_employee_details Emp', 'Pay.EmpID = Emp.EmpID');
|
|
if ($Payon != '') {
|
|
$builder->where('Pay.PayOn', $Payon);
|
|
}
|
|
$builder->orderBy("Pay.EmpID", "asc");
|
|
|
|
$query = $builder->get();
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
/* */
|
|
/**
|
|
* This function is used to delete the PayOn details from t_payroll
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function deleteFileData($PayOn = '')
|
|
{
|
|
$this->db->table('t_payroll')->delete(['PayOn' => $PayOn]);
|
|
}
|
|
|
|
function getEmpID()
|
|
{
|
|
|
|
$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();
|
|
}
|
|
|
|
|
|
function getEmpIDfromPayData()
|
|
{
|
|
|
|
$builder = $this->db->table('t_emp_pay_data')
|
|
->select('EmpID');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function updateEmpPayslip($data)
|
|
{
|
|
|
|
$key = $data['Key'];
|
|
$PayOn = $data['PayOn'];
|
|
$EmpID = $data['EmpID'];
|
|
|
|
$builder = $this->db->table('t_payroll')
|
|
->where('Key', $key)
|
|
->where('PayOn', $PayOn)
|
|
->where('EmpID', $EmpID)
|
|
->update($data);
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
|
|
|
|
function getCompanyInformation()
|
|
{
|
|
|
|
$subQuery = "select CompanyName,Address,GSTNO,PAN,ContactNumber,EmailAddress,AlternateContactNumber,companyWebsite,StateCode
|
|
from t_company_details ";
|
|
$query = $this->db->query($subQuery);
|
|
//print_r($query-getResult());die();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function ChequeDetails($cheque)
|
|
{
|
|
$builder = $this->db->table('t_chequedetails');
|
|
$builder->insert($cheque);
|
|
}
|
|
|
|
public function getFiscalYear()
|
|
{
|
|
$sql = "SELECT FiscalYearStartOn, FiscalYearEndsOn FROM t_company_details";
|
|
$query = $this->db->query($sql);
|
|
$result = $query->getRow();
|
|
return $result;
|
|
}
|
|
public function getEmpDetailsforLeave($financial_year){
|
|
$years = explode('-', $financial_year);
|
|
|
|
$builder = $this->db->table('t_attendance as A');
|
|
|
|
$builder->select('A.EmpID, GROUP_CONCAT(A.Month_Year) AS Month_Year, SUM(A.Days_Worked) AS NoofWorkedDays, SUM(A.Absent) AS NoofAbsentDays, SUM(A.Paid_Leave) AS NoofPaidLeaveDays, CONCAT_WS(" ", E.FirstName, E.LastName) AS FullName');
|
|
$builder->join('t_employee_details as E', 'A.EmpID = E.EmpID', 'left');
|
|
$builder->where('A.Month_Year >=', $years[0].'-04-01');
|
|
$builder->where('A.Month_Year <=', $years[1].'-03-31');
|
|
$builder->groupBy('A.EmpID');
|
|
$builder->orderBy('A.EmpID', 'asc');
|
|
|
|
$query = $builder->get();
|
|
$results = $query->getResult();
|
|
|
|
return $results;
|
|
}
|
|
public function getMonthwiseEmpDetailsforLeave($financial_year, $employee_id){
|
|
|
|
$years = explode('-', $financial_year);
|
|
|
|
$builder = $this->db->table('t_attendance as A');
|
|
|
|
$builder->select('A.EmpID, A.Days_Worked AS NoofWorkedDays, A.Absent AS NoofAbsentDays, A.Paid_Leave AS NoofPaidLeaveDays');
|
|
$builder->select('CONCAT_WS(" ", E.FirstName, E.LastName) AS FullName');
|
|
$builder->select('DATE_FORMAT(A.Month_Year, "%Y-%m") AS Month_Year'); // Format as YYYY-MM
|
|
$builder->join('t_employee_details as E', 'A.EmpID = E.EmpID', 'left');
|
|
$builder->where('A.Month_Year >=', $years[0].'-04-01');
|
|
$builder->where('A.Month_Year <=', $years[1].'-03-31');
|
|
$builder->where('A.EmpID', $employee_id);
|
|
$builder->where('A.Absent !=', 0);
|
|
$builder->groupBy('A.EmpID, Month_Year');
|
|
$builder->orderBy('A.Month_Year');
|
|
|
|
$query = $builder->get();
|
|
$results = $query->getResult();
|
|
|
|
return $results;
|
|
}
|
|
|
|
function getChequeInfo($bank, $payon)
|
|
{
|
|
|
|
$sql = "SELECT Cheque.*
|
|
FROM t_chequedetails Cheque
|
|
WHERE Cheque.BankName = ?
|
|
AND Cheque.MonthYear = ? ";
|
|
|
|
$query = $this->db->query($sql, array($bank, $payon));
|
|
//$query_count = $query->getNumRows()();
|
|
|
|
//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.Loan_ID, L.Loan_Amount, L.Loan_Issued_Date, L.Monthly_Due, L.Due_Start_Date, L.No_of_Dues, L.Paid_Due, L.Remaining_Due, L.Paid_Amount')
|
|
->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 and L.Remaining_Due != 0', 'left')
|
|
->where('MonthlyPay.EmpID', $EmpId)
|
|
->where('MonthlyPay.Month_Year', $PayOn);
|
|
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function updatePaySlipGeneration($EmpId, $PayOn)
|
|
{
|
|
$builder = $this->db->table('t_monthly_pay_inputs'); // Define the table
|
|
$builder->where('EmpID', $EmpId)
|
|
->where('Month_Year', $PayOn)
|
|
->set(['is_payslip_generated' => 1])
|
|
->update();
|
|
|
|
return $this->db->affectedRows(); // Return number of affected rows
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
} |