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.Id 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; } $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.*,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.Id,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)); // Get the last executed query // $last_query = $this->db->getLastQuery(); // echo $last_query; 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']; } 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(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(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(); } }