517 lines
15 KiB
PHP
517 lines
15 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class Monthlypay_model extends Model
|
|
{
|
|
|
|
/**
|
|
* This function is used to get the user listing count
|
|
* @param string $searchText : This is optional search text
|
|
* @param number $page : This is pagination offset
|
|
* @param number $segment : This is pagination limit
|
|
* @return array $result : This is result
|
|
*/
|
|
function monthlyListing($current = "")
|
|
{
|
|
|
|
$month = $current;
|
|
if (strlen($month) == 6) {
|
|
$month = '0' . $month;
|
|
}
|
|
//echo $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;
|
|
//echo $lastdate ;
|
|
|
|
// ->select('T_Monthly_Pay_Inputs.*,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Payroll.Key,T_Loan_Master.Loan_ID');
|
|
// $builder = $this->db->table('T_Monthly_Pay_Inputs');
|
|
// ->join('T_Employee_Details','T_Monthly_Pay_Inputs.EmpID=T_Employee_Details.EmpID');
|
|
// ->join('T_Payroll','T_Monthly_Pay_Inputs.EmpID=T_Payroll.EmpID','left');
|
|
// ->join('T_Loan_Master','T_Monthly_Pay_Inputs.EmpID=T_Loan_Master.EmpID','left');
|
|
// $this->db->orderBy('T_Employee_Details.EmpID','asc');
|
|
// $this->db->where('T_Employee_Details.DateofJoining <=',$lastdate);
|
|
// $this->db->where('Month_Year',$current);
|
|
|
|
$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
|
|
left join T_Loan_Master on T_Monthly_Pay_Inputs.EmpID=T_Loan_Master.EmpID and T_Loan_Master.is_Active = 1
|
|
where Month_Year = ?
|
|
order by T_Employee_Details.EmpID asc";
|
|
|
|
$query = $this->db->query($sql, array($lastdate, $current));
|
|
// print_r($query-getResult());
|
|
$result = $query->getResult();
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
function getEmpPayDetails($current = "", $s = "")
|
|
{
|
|
|
|
$month_val = date('m', strtotime($current));
|
|
$year_val = date('Y', strtotime($current));
|
|
$date_val = cal_days_in_month(CAL_GREGORIAN, $month_val, $year_val);
|
|
//$monthyear_val = date('Y-m',strtotime($current));
|
|
$lastdate = $year_val . '-' . $month_val . '-' . $date_val;
|
|
$builder = $this->db->table('T_Employee_Details')
|
|
->select('T_Employee_Details.EmpID,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Employee_Details.DateofJoining')
|
|
//->join('T_Emp_Pay_Data','T_Emp_Pay_Data.EmpID=T_Employee_Details.EmpID','Left')
|
|
->where('T_Employee_Details.IsActive', 1)
|
|
->where('T_Employee_Details.DateofJoining <=', $lastdate)
|
|
->orderBy('EmpID', 'asc');
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
function getEmpPayDetailsforMonthInputs($current = "")
|
|
{
|
|
|
|
//$month = '0'.$current;
|
|
|
|
$month = $current;
|
|
if (strlen($month) == 6) {
|
|
$month = '0' . $month;
|
|
}
|
|
|
|
//echo $month;
|
|
|
|
$current = '01-' . $current;
|
|
//echo $current;
|
|
|
|
$current = format_date($current);//3rd
|
|
|
|
//echo 'Final'.$current;
|
|
$month_val = date('m', strtotime($current));
|
|
$year_val = date('Y', strtotime($current));
|
|
$date_val = cal_days_in_month(CAL_GREGORIAN, $month_val, $year_val);
|
|
//$monthyear_val = date('Y-m',strtotime($current));
|
|
$lastdate = $year_val . '-' . $month_val . '-' . $date_val;
|
|
//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.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 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($month, $month, $lastdate, $current, $current));
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getPublicHoldays($current = "")
|
|
{
|
|
if (!empty($current)) {
|
|
$sql = "select * from T_Public_Holidays where month(H_Date) = month(?) and year(H_Date) = year(?)";
|
|
$query = $this->db->query($sql, array($current, $current));
|
|
return $query->getResult();
|
|
} else {
|
|
$sql = "select * from T_Public_Holidays where year(H_Date)=year(CURRENT_DATE) order by H_Date";
|
|
$query = $this->db->query($sql);
|
|
return $query->getResult();
|
|
}
|
|
}
|
|
|
|
function checkHoliday($Date)
|
|
{
|
|
$Date = format_date($Date);
|
|
//echo $Date;die();[
|
|
|
|
$sql = "select count(*) as count from T_Public_Holidays where H_Date = ?";
|
|
$query = $this->db->query($sql, array($Date));
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
function saveHolidays($data, $string)
|
|
{
|
|
//print_r($data);
|
|
if ($string == 'i') {
|
|
$builder = $this->db->table('T_Public_Holidays');
|
|
$builder->insert($data);
|
|
$i = $this->db->affectedRows();
|
|
return $i;
|
|
} else if ($string == 'u') {
|
|
$this->db->table('T_Public_Holidays')
|
|
->where('H_date', $data['H_Date'])
|
|
->update($data);
|
|
|
|
$i = $this->db->affectedRows();
|
|
return $i;
|
|
}
|
|
}
|
|
|
|
|
|
function deleteHoliday($d)
|
|
{
|
|
$d = format_date($d);//3rd
|
|
$this->db->table('T_Public_Holidays')->delete(['H_date' => $d]);
|
|
return $this->db->affectedRows();
|
|
}
|
|
function monthlyAttendance($current = "")
|
|
{
|
|
|
|
$month_val = date('m', strtotime($current));
|
|
$year_val = date('Y', strtotime($current));
|
|
$date_val = cal_days_in_month(CAL_GREGORIAN, $month_val, $year_val);
|
|
$lastdate = $year_val . '-' . $month_val . '-' . $date_val;
|
|
|
|
$builder = $this->db->table('T_Attendance')
|
|
->select('T_Attendance.*,T_Employee_Details.FirstName,T_Employee_Details.LastName')
|
|
->join('T_Employee_Details', 'T_Attendance.EmpID=T_Employee_Details.EmpID')
|
|
// ->where('year(T_Employee_Details.DateofJoining) <= ',$year_val)
|
|
// ->where('month(T_Employee_Details.DateofJoining) <= ',$month_val)
|
|
->where('T_Employee_Details.DateofJoining <= ', $lastdate)
|
|
->where('Month_Year', $current)
|
|
// ->where('T_Employee_Details.IsActive',1)
|
|
->orderBy('T_Attendance.EmpID', 'asc');
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
|
|
return $result;
|
|
}
|
|
function saveMonthlyData_model($data)
|
|
{
|
|
|
|
$month = $data['Month_Year'];
|
|
$empid = $data['EmpID'];
|
|
$count = 0;
|
|
|
|
|
|
$builder = $this->db->table('T_Monthly_Pay_Inputs')->select('count(*) as count')
|
|
->where('Month_Year', $month)
|
|
->where('EmpID', $empid);
|
|
$isExits = $builder->get();
|
|
$res = $isExits->getResultArray();
|
|
|
|
if (!empty($res)) {
|
|
|
|
$count = $res[0]['count'];
|
|
}
|
|
// print_r($data);die;
|
|
|
|
if ($count == 0) {
|
|
$builder = $this->db->table('T_Monthly_Pay_Inputs');
|
|
$builder->insert($data);
|
|
$i = $this->db->affectedRows();
|
|
return $i;
|
|
} elseif ($count == 1) {
|
|
|
|
$this->db->table('T_Monthly_Pay_Inputs')
|
|
// ->where('H_date', $data['H_Date']) // ask velmurugan H_Date public hoilday table la irukku
|
|
->where('EmpID', $data['EmpID']) // temp solution
|
|
->update($data);
|
|
|
|
$i = $this->db->affectedRows();
|
|
return $i;
|
|
}
|
|
}
|
|
|
|
function saveAttendance($monthattendance, $Month_Year, $EmpID)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Attendance')->select('count(*) as c')
|
|
->where('Month_Year', $Month_Year)
|
|
->where('EmpID', $EmpID);
|
|
$isExist = $builder->get();
|
|
$isExist = $isExist->getResultArray();
|
|
$ans = $isExist[0]['c'];
|
|
|
|
if ($ans == 0) {
|
|
|
|
//array_pop();
|
|
$builder = $this->db->table('T_Attendance');
|
|
$builder->insert($monthattendance);
|
|
|
|
return $this->db->affectedRows();
|
|
//echo "INS";
|
|
// if($this->db->affected_rows() > 0)
|
|
// {
|
|
|
|
// return true;
|
|
// }
|
|
// else
|
|
// {
|
|
// return false;
|
|
// }
|
|
} else {
|
|
$this->db->table('T_Attendance')
|
|
->where('Month_Year', $Month_Year)
|
|
->where('EmpID', $EmpID)
|
|
->update($monthattendance);
|
|
//echo "UPDATE";
|
|
$i = $this->db->affectedRows();
|
|
return $i;
|
|
}
|
|
}
|
|
|
|
|
|
function addNewmonthlisting($m_list)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('T_Monthly_Pay_Inputs');
|
|
$builder->insert($m_list);
|
|
$Asset_Code = $this->db->insertId();
|
|
|
|
$this->db->transComplete();
|
|
|
|
return $m_list;
|
|
}
|
|
function getUserInfo($EmpID, $month_year)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Monthly_Pay_Inputs')
|
|
->select('T_Monthly_Pay_Inputs.*,T_Employee_Details.FirstName,T_Employee_Details.LastName')
|
|
->join('T_Employee_Details', 'T_Monthly_Pay_Inputs.EmpID=T_Employee_Details.EmpID')
|
|
->where('T_Monthly_Pay_Inputs.EmpID', $EmpID)
|
|
->where('T_Monthly_Pay_Inputs.Month_Year', $month_year);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function editmonth($monthdata, $EmpID)
|
|
{
|
|
$monthyear = $monthdata['Month_Year'];
|
|
$this->db->table('T_Monthly_Pay_Inputs')
|
|
->where('EmpID', $EmpID)
|
|
->where('Month_Year', $monthyear)
|
|
->update($monthdata);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function viewmonth($monthdata, $employeeid)
|
|
{
|
|
|
|
$this->db->table('T_Monthly_Pay_Inputs')
|
|
->orderBy('Month_Year')
|
|
->where('EmpID', $employeeid)
|
|
->update($monthdata);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/*permission form model */
|
|
function emplist()
|
|
{
|
|
|
|
$sql = "select Emp.EmpID,CONCAT(FirstName,' ',LastName)as name ,Emp.Departmentcode, Dep.DepartmentName FROM T_Employee_Details as Emp
|
|
join T_DepartmentDetails as Dep on Dep.DEPCode=Emp.Departmentcode where Emp.IsActive = 1;";
|
|
$query = $this->db->query($sql);
|
|
return $query->getResult();
|
|
}
|
|
|
|
function addper($Permissiondata)
|
|
{
|
|
|
|
|
|
//if(!empty($Permissiondata){
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('T_Permission');
|
|
$builder->insert($Permissiondata);
|
|
|
|
//$Asset_Code = $this->db->insert_id();
|
|
$Permission = $this->db->affectedRows();
|
|
|
|
$this->db->transComplete();
|
|
|
|
return $Permission;
|
|
}
|
|
|
|
function perlist()
|
|
{
|
|
|
|
|
|
$builder = $this->db->table('T_Permission')->select('*');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function pdf($SNO)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Permission per')->select('per.*,emp.FirstName,LastName,dep.DepartmentName')
|
|
->join('T_Employee_Details emp', 'emp.EmpID = per.EmpID')
|
|
->join('T_DepartmentDetails dep', 'dep.DEPCode = emp.Departmentcode')
|
|
->where('per.SNO', $SNO);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function reportvalue($fin_year)
|
|
{
|
|
|
|
if (empty($fin_year)) {
|
|
return [];
|
|
} else {
|
|
|
|
$curr_split = explode('-', $fin_year);
|
|
$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
|
|
from T_Monthly_Pay_Inputs
|
|
join T_Employee_Details on T_Monthly_Pay_Inputs.EmpID = T_Employee_Details.EmpID
|
|
where
|
|
substr(T_Monthly_Pay_Inputs.Month_Year,4) = ?
|
|
and substr(T_Monthly_Pay_Inputs.Month_Year,1,2) >= 4
|
|
or substr(T_Monthly_Pay_Inputs.Month_Year,4) = ?
|
|
and substr(T_Monthly_Pay_Inputs.Month_Year,1,2) <= 3
|
|
group by T_Monthly_Pay_Inputs.EmpID";
|
|
|
|
$query = $this->db->query($sql, array($pre_year, $curr_year));
|
|
return $query->getResult();
|
|
}
|
|
}
|
|
function Monthwisereportvalue($Fin_year, $EmployeeID)
|
|
{
|
|
|
|
|
|
$curr_split = explode('-', $Fin_year);
|
|
$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
|
|
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 = ?
|
|
where substr(T_Monthly_Pay_Inputs.Month_Year,4) = ? and substr(T_Monthly_Pay_Inputs.Month_Year,1,2) >= 4
|
|
or substr(T_Monthly_Pay_Inputs.Month_Year,4) = ? and substr(T_Monthly_Pay_Inputs.Month_Year,1,2) <= 3
|
|
group by T_Monthly_Pay_Inputs.Month_Year";
|
|
|
|
$query = $this->db->query($sql, array($EmployeeID, $pre_year, $curr_year));
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//this function Production Salary cost details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function productionsalarycosts($productions)
|
|
{
|
|
$builder = $this->db->table('T_ProductionSalaryCost');
|
|
$builder->insert($productions);
|
|
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
|
|
function updateproduction($productions, $sno)
|
|
{
|
|
|
|
$builder = $this->db->table('T_ProductionSalaryCost')
|
|
->where('sno', $sno)
|
|
->update($productions);
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
|
|
function productionsalarycost()
|
|
{
|
|
$builder = $this->db->table('T_ProductionSalaryCost')->select('*');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function attyesterday($WH, $daydate)
|
|
{
|
|
|
|
|
|
|
|
$sql = "select att.EmpID," . $WH . ",a.FirstName from T_Attendance as att
|
|
join T_Employee_Details as a on a.EmpID= att.EmpID
|
|
where Month_Year = ? and att.EmpID in (select EmpID from T_Attendance)";
|
|
$query = $this->db->query($sql, array($daydate));
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
function dayAllPersentEmpSalary($WH, $OT, $date)
|
|
{
|
|
|
|
$sql = "select EmpID," . $WH . "," . $OT . " from T_Attendance where Month_Year = ? and EmpID in (select EmpID from T_Attendance)";
|
|
$query = $this->db->query($sql, array($date));
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
|
|
function persentEmployeeDetails($EmpID)
|
|
{
|
|
|
|
$sql = "select * FROM T_Emp_Pay_Data where EmpID = ?;";
|
|
$query = $this->db->query($sql, array($EmpID));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
// function cost($ab)
|
|
// {
|
|
|
|
|
|
|
|
// $sql = "select * from T_ProductionSalaryCost where month(date)=month('".$ab."')";
|
|
|
|
// //echo $sql;die;
|
|
|
|
// $query = $this->db->query($sql);
|
|
|
|
// return $query->getResult();
|
|
// }
|
|
|
|
|
|
|
|
function cost($ab, $from, $to)
|
|
{
|
|
// echo $ab;echo $from;echo $to;
|
|
// die;
|
|
$sql = "select * from T_ProductionSalaryCost where
|
|
month(date)= month('" . $ab . "')";
|
|
|
|
if ($from and $to != '') {
|
|
$sql .= "or date >= '" . $from . "'
|
|
and date <= '" . $to . "'";
|
|
}
|
|
|
|
// echo $sql;
|
|
|
|
$query = $this->db->query($sql);
|
|
return $query->getResult();
|
|
}
|
|
} |