db->query($sql); return $query->result(); } function totloan() { $sql="select sum(Loan_Amount)as totloan FROM T_Loan_Master"; $query =$this->db->query($sql); return $query->result(); } function totpay() { $sql="select sum(Paid_Amount)as totpay FROM T_Loan_Master"; $query =$this->db->query($sql); return $query->result(); } function totrec() { $sql="select sum(Loan_Amount), sum(Paid_Amount),sum(Loan_Amount)-sum(Paid_Amount) as totrec FROM T_Loan_Master"; $query =$this->db->query($sql); return $query->result(); } function emplist() { $sql="select EmpID,CONCAT(FirstName,' ',LastName) as name FROM T_Employee_Details where IsActive ='1'"; $query =$this->db->query($sql); return $query->result(); } function attyesterday($WH,$date) { //echo 'model' . $WH.'-'.$date; // $sql="select EmpID,".$WH." from T_Attendance where Month_Year = ? and EmpID in (select EmpID from T_Attendance)" ; $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($date)); // print_r($query->result()); //echo count($query->result()); return $query->result_array(); } function dayAllPersentEmpSalary($WH,$OT,$date) { // echo $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 return $query->result_array(); } function yesterdayAllPersentEmpSalary($WH,$OT,$date) { // echo $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 return $query->result_array(); } function attendance($EmpID,$dates) { //echo $EmpID.'-'.$dates; $sql="select * from T_Attendance where EmpID =? and Month_Year=?"; $query = $this->db->query($sql,array($EmpID,$dates)); return $query->result(); } function getAllAttendance($EmpID,$CURMONTH) { $sql="select * from T_Attendance where EmpID =? and month(Month_Year)=?"; // $sql=" select T_Attendance.*,emp.FirstName from T_Attendance // join T_Employee_Details emp on T_Attendance.EmpID = emp.EmpID // where T_Attendance.EmpID = ? and month(Month_Year)= ? "; $query = $this->db->query($sql,array($EmpID,$CURMONTH)); return $query->result(); } function getAllAttendances($EmpID,$JoinedMonth) { //$sql="select * from T_Attendance where EmpID =? and month(Month_Year)=?"; $sql=" select T_Attendance.*,emp.FirstName from T_Attendance join T_Employee_Details emp on T_Attendance.EmpID = emp.EmpID where T_Attendance.EmpID = ? and month(Month_Year)= ? "; $query = $this->db->query($sql,array($EmpID,$JoinedMonth)); return $query->result(); } function joindate($EmpID) { $sql="select DateofJoining from T_Employee_Details where EmpID =? "; $query = $this->db->query($sql,array($EmpID)); return $query->result(); } function daysalary($EmpID,$dates) { //print_r($dates);die; $sql= "select * FROM T_Emp_Pay_Data as pay join T_Attendance att on att.EmpID = pay.EmpID where att.Month_Year = ? and att.EmpID = ?;"; $query = $this->db->query($sql,array($dates,$EmpID)); return $query->result(); } function persentEmployeeDetails($EmpID){ //join T_Attendance att on att.EmpID = pay.EmpID $sql= "select * FROM T_Emp_Pay_Data where EmpID = ?;"; $query = $this->db->query($sql,array($EmpID)); return $query->result(); } function attendanceyear($EmpID,$MONTH) { // //print_r($MONTH); // $sql="select Att.EmpID,Att.Month_Year,Att.*,NoofDays,Days_Worked,emp.DateofJoining from T_Attendance Att // join T_Employee_Details as emp on emp.EmpID = Att.EmpID // where Att.Month_Year between ? and Att.EmpID = ?"; // else // (YEAR(Month_Year) = YEAR(CURRENT_DATE)-1 and MONTH(Month_Year) >= ? ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) <= 3 ) // $sql = 'select sum(NoofDays) as TotalWorkingDays,sum(Days_worked) as DaysWorked from T_Attendance where // case // when (month(Month_Year) >=4) then // (YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) >= ? ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE)+1 and MONTH(Month_Year) <= 3 )end and EmpID = ? and month(Month_Year) != month(current_date()) // else // (YEAR(Month_Year) = YEAR(CURRENT_DATE)-1 and MONTH(Month_Year) >= ? ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) <= 3 )'; $sql = ' select sum(NoofDays) as TotalWorkingDays,sum(Days_worked) as DaysWorked from T_Attendance where case when (MONTH(CURRENT_DATE) >=4) then ((YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) >= ? )) and EmpID = ? and month(Month_Year) != MONTH(CURRENT_DATE) else ((YEAR(Month_Year) = YEAR(CURRENT_DATE)-1 and MONTH(Month_Year) >=4 and ? >= 4) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) <= 3 and ? <=3 )) and Month(Month_Year) >= ? and EmpID = ? and month(Month_Year) != MONTH(CURRENT_DATE) end'; /*$sql='select sum(NoofDays) as TotalWorkingDays,sum(Days_worked) as DaysWorked from T_Attendance where EmpID= ? and (MONTH(Month_Year) >=4) or (MONTH(Month_Year) <3) and (YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) >= ? )or ( YEAR(Month_Year) = YEAR(CURRENT_DATE)+1 and MONTH(Month_Year) <= 3 ) and MONTH(Month_Year) != MONTH(current_date())';*/ $query= $this->db->query($sql,array($MONTH,$EmpID,$MONTH,$MONTH,$MONTH,$EmpID)); return $query->result(); } function getEmployee(){ $sql="select EmpID,FirstName,LastName,IsActive FROM T_Employee_Details "; $query =$this->db->query($sql); return $query->result(); } function get_all_employee($Month) { $sql = "select T_Attendance.*,emp.EmpID,emp.FirstName,emp.LastName,emp.IsActive from T_Attendance join T_Employee_Details emp on T_Attendance.EmpID = emp.EmpID where Month_Year=?;"; $query = $this->db->query($sql,array($Month)); return $query->result(); } function get_all_employee1($finStart,$finEnd) { $sql = "select att.EmpID,att.*,att.Month_Year,emp.FirstName,emp.DateofJoining from T_Attendance att join T_Employee_Details emp on emp.EmpID = att.EmpID where att.Month_Year between ? and ?"; $query = $this->db->query($sql,array($finStart,$finEnd)); return $query->result(); } function holiDaySalaryMonth($month,$year) { $sql="SELECT H_Date FROM T_Public_Holidays where MONTH(H_Date)= ? and YEAR(H_Date) = ? "; $query = $this->db->query($sql,array($month,$year)); return $query->result(); } function fy() { $sql= "SELECT CASE WHEN MONTH(Month_year)>=4 THEN concat(YEAR(Month_year), '-',YEAR(Month_year)+1) ELSE concat(YEAR(Month_year)-1,'-', YEAR(Month_year)) END AS financial_year FROM T_Attendance GROUP BY financial_year"; $query = $this->db->query($sql); return $query->result(); } function per($fa,$aa,$m) { $sql= "SELECT year.Eid as Eid,year.ename as ename,year.active as active,month.days as days,month.Days_Worked as worked,month.percentage as percentage,year.days as yday,year.workd as yworkd,year.percentage as ypercentage from (select em.EmpID as Eid,concat(em.FirstName,'.',em.LastName) as ename,em.IsActive as active,at.NoofDays as days, Days_Worked,round((Days_Worked/NoofDays*100)) as percentage from T_Employee_Details em join T_Attendance at on at.EmpID = em.EmpID where (Month_Year >= '".$fa."-04-01' and Month_Year <= '".$aa."-04-01') and monthname(Month_Year) = '".$m."' ) as month left join (select em.EmpID as Eid,concat(em.FirstName,'.',em.LastName) as ename,em.IsActive as active,sum(at.NoofDays) as days, sum(Days_Worked) workd,round((sum(Days_Worked)/sum(NoofDays)*100)) as percentage from T_Employee_Details em join T_Attendance at on at.EmpID = em.EmpID where (Month_Year >= '".$fa."-04-01' and Month_Year <= '".$aa."-04-01') group by Eid ) as year on year.Eid = month.Eid and year.ename = month.ename group by Eid "; $query = $this->db->query($sql); return $query->result(); } /* HR DASHBOARD Model END*/ function totalpurchaseorder(){ $sql="select count(PONO) as totalpurchaseorder from T_PurchaseOrder_Master pm where Status != 'ST030' and case when (month(pm.PODate) >=4) then (YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.PODate) <= 3 ) else (YEAR(pm.PODate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) <= 3 ) end"; $query = $this->db->query($sql); return $query->result(); } function totalordervalue(){ $sql="select sum(totalordervalue) as totalordervalue from T_PurchaseOrder_Master pm where Status != 'ST030' and case when (month(pm.PODate) >=4) then (YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.PODate) <= 3 ) else (YEAR(pm.PODate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) <= 3 ) end"; $query = $this->db->query($sql); return $query->result(); } function pendingpo(){ $sql="select count(PONO) as pending from T_PurchaseOrder_Master pm where status='ST020' and Status != 'ST030' and case when (month(pm.PODate) >=4) then (YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.PODate) <= 3 ) else (YEAR(pm.PODate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.PODate) >= 4 ) or ( YEAR(pm.PODate) = YEAR(CURRENT_DATE) and MONTH(pm.PODate) <= 3 ) end"; $query = $this->db->query($sql); return $query->result(); } function req_pending(){ $sql="SELECT count(Status) as TOTAL_PENDING_REQUESTS FROM T_Requestion_Master pm where Status = 'ST002' and case when (month(pm.ReqDate) >=4) then (YEAR(pm.ReqDate) = YEAR(CURRENT_DATE) and MONTH(pm.ReqDate) >= 4 ) or ( YEAR(pm.ReqDate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.ReqDate) <= 3 ) else (YEAR(pm.ReqDate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.ReqDate) >= 4 ) or ( YEAR(pm.ReqDate) = YEAR(CURRENT_DATE) and MONTH(pm.ReqDate) <= 3 ) end"; $query = $this->db->query($sql); return $query->result(); } function reqdetail(){ $now= date('Y-m-d'); $sql="SELECT count(Status) as TODAY_REQUESTS FROM T_Requestion_Master where date(ReqDate) = '".$now."' "; $query = $this->db->query($sql); // echo "from Model"; // print_r($query->result()); return $query->result(); } function january(){ $sql="select count(PONO) as pending from T_PurchaseOrder_Master where status='ST020'"; $query = $this->db->query($sql); return $query->result(); } // function totalserviceamount() // { // $sql="select sum(BudgetAmount) as totalserviceamount from T_CostCenter_Budget where BudgetType='SERVICE'"; // $query = $this->db->query($sql); // return $query->result(); // } // function totalcapitalamount() // { // $sql="select sum(BudgetAmount) as totalcapitalamount from T_CostCenter_Budget where BudgetType='CAPITAL'"; // $query = $this->db->query($sql); // return $query->result(); // } // function totalimportamount() // { // $sql="select sum(BudgetAmount) as totalimportamount from T_CostCenter_Budget where BudgetType='IMPORT'"; // $query = $this->db->query($sql); // return $query->result(); // } // function totalrevenueamount() // { // $sql="select sum(BudgetAmount) as totalrevenueamount from T_CostCenter_Budget where BudgetType='REVENUE'"; // $query = $this->db->query($sql); // return $query->result(); // } //totalservice function getTotalServicePoCount(){ $i=1; if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); while($i<=12){ $sql="SELECT count(cmast.PONO) as totalService FROM T_PurchaseOrder_Master cmast where POType='SERVICE' and Status != 'ST030' and month(PODate) = $i and date(cmast.PODate) >= '".$fa."-04-01' and date(cmast.PODate) <= '".$aa."-03-31'"; $query = $this->db->query($sql); $array_result[]=$query->result(); $i++; } return $array_result; } function getTotalimportPoCount(){ $i=1; if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); while($i<=12){ $sql="SELECT count(cmast.PONO) as totalImport FROM T_PurchaseOrder_Master cmast where POType='IMPORT' and Status != 'ST030' and month(PODate) = $i and date(cmast.PODate) >= '".$fa."-04-01' and date(cmast.PODate) <= '".$aa."-03-31'"; $query = $this->db->query($sql); $array_result[]=$query->result(); $i++; } return $array_result; } function getTotalcapitalPoCount(){ $i=1; if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); while($i<=12){ $sql="SELECT count(cmast.PONO) as totalcapital FROM T_PurchaseOrder_Master cmast where POType='CAPITAL' and Status != 'ST030' and month(PODate) = $i and date(cmast.PODate) >= '".$fa."-04-01' and date(cmast.PODate) <= '".$aa."-03-31'"; $query = $this->db->query($sql); $array_result[]=$query->result(); $i++; } return $array_result; } function getTotalrevenuePoCount(){ $i=1; if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); while($i<=12){ $sql="SELECT count(cmast.PONO) as totalrevenue FROM T_PurchaseOrder_Master cmast where POType='REVENUE' and Status != 'ST030' and month(PODate) = $i and date(cmast.PODate) >= '".$fa."-04-01' and date(cmast.PODate) <= '".$aa."-03-31'"; $query = $this->db->query($sql); $array_result[]=$query->result(); $i++; } return $array_result; } function serviceprogress() { $sql="SELECT count(cmast.PONO) as serviceprogress FROM T_PurchaseOrder_Master cmast join T_PurchaseOrder_LineItem line on line.PONO=cmast.PONO join T_Requestion_Master req on req.ReqNo=line.ReqNo join T_Status sta on sta.statusCode=req.status where ReqType='SERVICE' and statusCode='ST018'"; $query = $this->db->query($sql); return $query->result(); } function revenueprogress() { $sql="SELECT count(cmast.PONO) as revenueprogress FROM T_PurchaseOrder_Master cmast join T_PurchaseOrder_LineItem line on line.PONO=cmast.PONO join T_Requestion_Master req on req.ReqNo=line.ReqNo join T_Status sta on sta.statusCode=req.status where ReqType='REVENUE' and statusCode='ST018'"; $query = $this->db->query($sql); return $query->result(); } function importprogress() { $sql="SELECT count(cmast.PONO) as importprogress FROM T_PurchaseOrder_Master cmast join T_PurchaseOrder_LineItem line on line.PONO=cmast.PONO join T_Requestion_Master req on req.ReqNo=line.ReqNo join T_Status sta on sta.statusCode=req.status where ReqType='IMPORT' and statusCode='ST018'"; $query = $this->db->query($sql); return $query->result(); } function capitalprogress() { $sql="SELECT count(cmast.PONO) as capitalprogress FROM T_PurchaseOrder_Master cmast join T_PurchaseOrder_LineItem line on line.PONO=cmast.PONO join T_Requestion_Master req on req.ReqNo=line.ReqNo join T_Status sta on sta.statusCode=req.status where ReqType='CAPITAL' and statusCode='ST018'"; $query = $this->db->query($sql); return $query->result(); } function totalservicepo () { $sql="SELECT count(cmast.PONO) as totalservicepo FROM T_PurchaseOrder_Master cmast join T_PurchaseOrder_LineItem line on line.PONO=cmast.PONO join T_Requestion_Master req on req.ReqNo=line.ReqNo join T_Status sta on sta.statusCode=req.status where ReqType='SERVICE'"; $query = $this->db->query($sql); return $query->result(); } function totalrevenuepo () { $sql="SELECT count(cmast.PONO) as totalrevenuepo FROM T_PurchaseOrder_Master cmast join T_PurchaseOrder_LineItem line on line.PONO=cmast.PONO join T_Requestion_Master req on req.ReqNo=line.ReqNo join T_Status sta on sta.statusCode=req.status where ReqType='REVENUE'"; $query = $this->db->query($sql); return $query->result(); } function totalimportpo () { $sql="SELECT count(cmast.PONO) as totalimportpo FROM T_PurchaseOrder_Master cmast join T_PurchaseOrder_LineItem line on line.PONO=cmast.PONO join T_Requestion_Master req on req.ReqNo=line.ReqNo join T_Status sta on sta.statusCode=req.status where ReqType='IMPORT'"; $query = $this->db->query($sql); return $query->result(); } function importbudgt () { if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT ROUND(sum(BudgetAmount),2) as totalimportbudget FROM T_CostCenter_Budget where BudgetType ='IMPORT' and date(CreatedDate) >= '".$fa."-04-01' and date(CreatedDate) <= '".$aa."-03-31'"; $query = $this->db->query($sql); return $query->result(); } function capitalbud () { if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT sum(BudgetAmount) as totalcapitalbudget FROM T_CostCenter_Budget where BudgetType ='CAPITAL' and date(CreatedDate) >= '".$fa."-04-01' and date(CreatedDate) <= '".$aa."-03-31' "; $query = $this->db->query($sql); return $query->result(); } function servicebudgt () { if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT ROUND(sum(BudgetAmount),2) as totalservicebudget FROM T_CostCenter_Budget where BudgetType ='SERVICE' and date(CreatedDate) >= '".$fa."-04-01' and date(CreatedDate) <= '".$aa."-03-31'"; $query = $this->db->query($sql); return $query->result(); } function revenuebudgt () { if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT ROUND(sum(BudgetAmount),2) as totalrevenuebudget FROM T_CostCenter_Budget where BudgetType ='REVENUE' and date(CreatedDate) >= '".$fa."-04-01' and date(CreatedDate) <= '".$aa."-03-31'"; $query = $this->db->query($sql); return $query->result(); } function typebal () { if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT BudgetYear, sum(if(BudgetType = 'SERVICE', Util_Amount,0)) as sr, sum(if(BudgetType = 'REVENUE', Util_Amount,0)) as rv, sum(if(BudgetType = 'IMPORT', Util_Amount,0)) as im, sum(if(BudgetType = 'CAPITAL', Util_Amount,0)) as ca FROM cost_center where Status !='ST030' and date(PODate) >= '".$fa."-04-01' and date(PODate) <= '".$aa."-03-31'; "; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function req_list($fa,$aa,$m,$frm,$t,$agf,$agt){ $sql="select date_format(mas.ReqDate,'%d-%m-%Y') as ReqDate,mas.ReqNo,emp.FirstName as Requestedby,dep.DepartmentName,mas.ReqType,DATEDIFF(CURDATE(),mas.ReqDate) AS Aging from T_Requestion_Master as mas join T_CostCenter_Master cos on cos.CostCenterCode = mas.CostCenterCode join T_Employee_Details emp on emp.EmpID = mas.Requestedby join T_DepartmentDetails dep on dep.DEPCode=emp.Departmentcode where mas.Status = 'ST002' "; if ($fa and $aa != ''){ $sql.=" and (mas.ReqDate >= '".$fa."-04-01' and mas.ReqDate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(mas.ReqDate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(mas.ReqDate) >= '".$fromd."' and date(mas.ReqDate) <= '".$tod."'"; } if ($agf and $agt != ''){ $sql.="and DATEDIFF(CURDATE(),mas.ReqDate) >= '".$agf."' and DATEDIFF(CURDATE(),mas.ReqDate) <= '".$agt."'"; } $query = $this->db->query($sql); //print_r($this->db->last_query()); return $query->result(); } function report_relpo($fa,$aa,$m,$frm,$t,$agf,$agt){ $sql="select Mast.PONO,Mast.POType,date_format(Mast.PODate,'%d-%m-%Y') as PODate,date_format(Mast.ReleasedOn,'%d-%m-%Y') as ReleasedDate,Dept_Details.DepartmentName As Dept_Name,Mast.TotalOrderValue from T_PurchaseOrder_Master Mast JOIN T_PurchaseOrder_LineItem Det on Det.PONO=Mast.PONO left JOIN T_Requestion_Master as Req on Req.ReqNo=Det.ReqNo left JOIN T_DepartmentDetails Dept_Details on Dept_Details.DEPCode=Req.RequestedDept left JOIN T_CostCenter_Master as Cost on Cost.CostCenterCode=Req.CostCenterCode JOIN T_CostCenter_Budget as Cost_Center_Bdgt on Cost.CostCenterCode=Cost_Center_Bdgt.CostCenterCode where Mast.Status='ST026' "; if ($fa and $aa != ''){ $sql.=" and (Mast.PODate >= '".$fa."-04-01' and Mast.PODate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(Mast.PODate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(Mast.PODate) >= '".$fromd."' and date(Mast.PODate) <= '".$tod."'"; } if ($agf and $agt != ''){ $sql.="and Mast.TotalOrderValue >= '".$agf."' and Mast.TotalOrderValue <= '".$agt."'"; } $sql.=" group by Mast.PONO"; $query = $this->db->query($sql); return $query->result(); } function report_openpending($fa,$aa,$m,$frm,$t,$agf,$agt){ $sql="select Mast.PONO as PONO,Mast.POType as POType,date_format(Mast.PODate,'%d-%m-%Y') as PODate,date_format(Mast.ApprovedOn,'%d-%m-%Y') as ApprovedDate,Dept_Details.DepartmentName As Dept_Name,Mast.TotalOrderValue from T_PurchaseOrder_Master Mast left JOIN T_PurchaseOrder_LineItem Det on Det.PONO=Mast.PONO left JOIN T_Requestion_Master as Req on Req.ReqNo=Det.ReqNo left JOIN T_DepartmentDetails Dept_Details on Dept_Details.DEPCode=Req.RequestedDept left JOIN T_CostCenter_Master as Cost on Cost.CostCenterCode=Req.CostCenterCode JOIN T_CostCenter_Budget as Cost_Center_Bdgt on Cost.CostCenterCode=Cost_Center_Bdgt.CostCenterCode where (Mast.Status='ST025' or Mast.Status='ST005') "; if ($fa and $aa != ''){ $sql.=" and (Mast.PODate >= '".$fa."-04-01' and Mast.PODate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(Mast.PODate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(Mast.PODate) >= '".$fromd."' and date(Mast.PODate) <= '".$tod."'"; } if ($agf and $agt != ''){ $sql.="and Mast.TotalOrderValue >= '".$agf."' and Mast.TotalOrderValue <= '".$agt."'"; } $sql.=" group by PONO,POType,Dept_Name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function report_total($fa,$aa){ $sql="select ifnull(Dept_Details.DepartmentName,'-') As Dept_Name, SUM(CASE WHEN Mast.Status = 'ST015' or Mast.Status = 'ST024' THEN 1 ELSE 0 END) AS PO_Created, SUM(CASE WHEN Mast.Status = 'ST025' THEN 1 ELSE 0 END) AS Approved, SUM(CASE WHEN Mast.Status = 'ST051' THEN 1 ELSE 0 END) AS Approver_Onhold, SUM(CASE WHEN Mast.Status = 'ST052' THEN 1 ELSE 0 END) AS Releaser_Onhold, SUM(CASE WHEN Mast.Status = 'ST053' THEN 1 ELSE 0 END) AS Service_completed, SUM(CASE WHEN Mast.Status = 'ST026' THEN 1 ELSE 0 END) AS Released, SUM(CASE WHEN Mast.Status = 'ST027' THEN 1 ELSE 0 END) AS IGR_Created, SUM(CASE WHEN Mast.Status = 'ST044' THEN 1 ELSE 0 END) AS MRIR_Approved, SUM(CASE WHEN Mast.Status = 'ST045' THEN 1 ELSE 0 END) AS MRIR_Rejected, SUM(CASE WHEN Mast.Status = 'ST056' THEN 1 ELSE 0 END) AS Special_po from T_PO_Detail Mast left JOIN T_Requestion_Master as Req on Req.ReqNo=Mast.ReqNo left JOIN T_DepartmentDetails Dept_Details on Dept_Details.DEPCode=Req.RequestedDept where Mast.PODate >= '".$fa."-04-01' and Mast.PODate <= '".$aa."-03-31' group by Dept_Name"; $query = $this->db->query($sql); return $query->result(); } function report_ccr($fa,$aa){ $sql="SELECT Cost_Center_Code,Cost_Center_Name,Dept_Name,BudgetType,BudgetYear,sum(Util_Amount) as Util_Amount, budget - sum(Util_Amount) as Avlbl_Amt FROM cost_center where Status !='ST030' and date(PODate) >= '".$fa."-04-01' and date(PODate) <= '".$aa."-03-31' group by Cost_Center_Code,BudgetYear,BudgetType"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function report_MMSupplier(){ $sql="select po.PODate as Material_Date,po.SupplierID,sup.SupplierName,pl.MaterialCode,mm.MaterialName,mm.MaterialType,mm.UOM,mm.HSNCODE from T_PurchaseOrder_Master po join T_PurchaseOrder_LineItem pl on pl.PONO=po.PONO join T_MaterialMaster mm on mm.MaterialCode=pl.MaterialCode join T_SupplierDetailsN sup on sup.SupplierID=po.SupplierID group by po.SupplierID,pl.MaterialCode"; $query = $this->db->query($sql); return $query->result(); } function report_MMItem(){ $sql="SELECT MaterialCode,MaterialName,UOM,Category,HSNCODE FROM T_MaterialMaster group by MaterialCode"; $query = $this->db->query($sql); return $query->result(); } function report_MMReceiptValue($fa,$aa,$m){ $sql="select DATE_FORMAT(IF(pm.PODate = '0000-00-00', NOW(), pm.PODate), '%b-%Y') AS Month, matv.MaterialCode,mat.MaterialName,mat.UOM,ROUND(AVG(matv.Rate),2) as Average_Rate from T_MaterialItem_PO matv join T_PurchaseOrder_Master pm on pm.CreatedDate = matv.CreatedDate join T_MaterialMaster mat on matv.MaterialCode=mat.MaterialCode where pm.PODate != 0 "; if ($fa and $aa != ''){ $sql.=" and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(pm.PODate) = '".$m."'"; } $sql.=" group by matv.MaterialCode"; $sql.=" order by monthname(pm.PODate)"; $query = $this->db->query($sql); return $query->result(); } function report_purchase($cname,$prod,$fa,$aa,$m,$frm,$t){ $sql="SELECT pm.PONO as pono,pm.POType as potype,date_format(pm.PODate,'%d-%m-%Y') as created_date, TIME_FORMAT(pm.PODate,'%l:%i %p') as created_time, mm.MaterialName as material_name,sd.SupplierName as supplier_name, ifnull(sum(distinct pl.Quantity),0) as quantity,mm.UOM as UOM,ifnull(sum(distinct pl.Rate),0) as rate, round(ifnull(sum(distinct pl.Quantity * pl.Rate),0),2) as value, if(POType = 'IMPORT' or POType = 'CAPITAL',sum(distinct pm.ExchangeRate),0) as exchange_rate, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterSGST),sum(distinct st.After_SGST)),0) as sgst, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterCGST),sum(distinct st.After_CGST)),0) as cgst, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IGST)),0) as igst, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterDiscount),sum(distinct st.Afterdiscountval)),0) as discount, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterFreightValue),sum(distinct st.AfterFreightValue)),0) as freight, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterPackagingValue),0),0) as Package, ifnull(rt.Insurance,0) as insurance, round(( if(POType = 'IMPORT',sum(distinct pm.ExchangeRate * (pl.Quantity * pl.Rate)), if(POType = 'CAPITAL' && CapitalRange = 0,sum(distinct pm.ExchangeRate * (pl.Quantity * pl.Rate)), ifnull(sum(pl.Quantity * pl.Rate),0))) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterSGST),sum(distinct st.After_SGST)),0) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterCGST),sum(distinct st.After_CGST)),0) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IGST)),0) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterFreightValue),sum(distinct st.AfterFreightValue)),0) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterPackagingValue),0),0) + ifnull(rt.Insurance,0) - ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterDiscount),sum(distinct st.Afterdiscountval)),0)),2) as total FROM T_PurchaseOrder_Master pm join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo left join T_Revenue_Tax rt on rt.LineItemNo = pl.LineItemNo where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027'"; if ($cname!= ''){ $sql.="and sd.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(pm.PODate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(pm.PODate) >= '".$fromd."' and date(pm.PODate) <= '".$tod."'"; } if ($prod!= ''){ $sql.=" and mm.MaterialName = '".$prod."' "; } $sql.="group by pono,material_name,supplier_name"; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function report_purchase_link($cname,$prod,$fa,$aa,$m,$frm,$t,$sid,$mid,$d){ $sql="SELECT pm.PONO as pono,pm.POType as potype,date_format(pm.PODate,'%d-%m-%Y') as created_date, TIME_FORMAT(pm.PODate,'%l:%i %p') as created_time, mm.MaterialName as material_name,sd.SupplierName as supplier_name, ifnull(sum(distinct pl.Quantity),0) as quantity,mm.UOM as UOM,ifnull(sum(distinct pl.Rate),0) as rate, round(ifnull(sum(distinct pl.Quantity * pl.Rate),0),2) as value, if(POType = 'IMPORT' or POType = 'CAPITAL',sum(distinct pm.ExchangeRate),0) as exchange_rate, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterSGST),sum(distinct st.After_SGST)),0) as sgst, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterCGST),sum(distinct st.After_CGST)),0) as cgst, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IGST)),0) as igst, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterDiscount),sum(distinct st.Afterdiscountval)),0) as discount, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterFreightValue),sum(distinct st.AfterFreightValue)),0) as freight, ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterPackagingValue),0),0) as Package, ifnull(rt.Insurance,0) as insurance, round(( if(POType = 'IMPORT',sum(distinct pm.ExchangeRate * (pl.Quantity * pl.Rate)), if(POType = 'CAPITAL' && CapitalRange = 0,sum(distinct pm.ExchangeRate * (pl.Quantity * pl.Rate)), ifnull(sum(pl.Quantity * pl.Rate),0))) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterSGST),sum(distinct st.After_SGST)),0) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterCGST),sum(distinct st.After_CGST)),0) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IGST)),0) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterFreightValue),sum(distinct st.AfterFreightValue)),0) + ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterPackagingValue),0),0) + ifnull(rt.Insurance,0) - ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterDiscount),sum(distinct st.Afterdiscountval)),0)),2) as total FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo left join T_Revenue_Tax rt on rt.LineItemNo = pl.LineItemNo where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' "; if ($cname!= ''){ $sql.="and sd.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(pm.PODate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(pm.PODate) >= '".$fromd."' and date(pm.PODate) <= '".$tod."'"; } if ($prod!= ''){ $sql.=" and mm.MaterialName = '".$prod."' "; } if ($sid!= ''){ $sql.=" and sd.SupplierID = '".$sid."' "; } if ($mid!= ''){ $sql.=" and mm.MaterialCode = '".$mid."' "; } if ($d!= ''){ $sql.=" and date(pm.PODate) = '".$d."' "; } $sql.="group by pono,material_name,supplier_name"; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function report_finyear(){ $sql="SELECT CASE WHEN MONTH(PODate)>=4 THEN concat(YEAR(PODate), '-',YEAR(PODate)+1) ELSE concat(YEAR(PODate)-1,'-', YEAR(PODate)) END AS financial_year FROM T_PurchaseOrder_Master GROUP BY financial_year"; $query = $this->db->query($sql); return $query->result(); } function report_year_wise($a=null, $b=null){ $sql="SELECT sd.SupplierID as sid,mm.MaterialCode as mid,pm.POdate as created_date,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as total FROM T_PurchaseOrder_Master pm join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and date(pm.POdate) >= '$a-04-01' and date(pm.PODate) <= '$b-03-31' group by month(created_date)"; $query = $this->db->query($sql); return $query->result(); } function customer_name(){ $sql="SELECT distinct SupplierName FROM T_SupplierDetailsN;"; $query = $this->db->query($sql); return $query->result(); } function material_name(){ $sql="SELECT distinct MaterialName FROM T_MaterialMaster;"; $query = $this->db->query($sql); return $query->result(); } function category(){ $sql="SELECT distinct Category FROM T_MaterialMaster;"; $query = $this->db->query($sql); return $query->result(); } function report_month_wise($mont){ $month= date("m",strtotime($mont)); $year = date("Y",strtotime($mont)); $sql="SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as total FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and month(pm.PODate)= ? and year(pm.PODate) = ? group by supplier_name,material_name"; $query = $this->db->query($sql,array($month,$year)); return $query->result(); } function report_year_wise_total($a,$b){ $sql="SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as total FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and date(pm.POdate) >= '$a-04-01' and date(pm.PODate) <= '$b-03-31' group by supplier_name,material_name"; $query = $this->db->query($sql,array()); return $query->result(); } function report_supplier($cname,$fa,$aa,$m,$frm,$t){ $sql="SELECT sd.SupplierID as sid,sd.SupplierName as supplier_name,count(pm.PONO) as counts,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as value, case pm.POType when 'IMPORT' then ifnull((sum(distinct(pl.Quantity * pl.Rate) * pm.ExchangeRate) ),0) + ifnull(rt.Insurance,0) when 'CAPITAL' then sum(distinct if(pm.CapitalRange=0,(( pl.Quantity * pl.Rate) * pm.ExchangeRate),( pl.Quantity * pl.Rate) - st.Afterdiscountval)) + ifnull(sum(distinct st.After_SGST),0) + ifnull(sum(distinct st.After_CGST),0) + ifnull(sum(distinct st.After_IGST),0) + ifnull(sum(distinct st.AfterFreightValue),0) + ifnull(rt.Insurance,0) when 'SERVICE' then ifnull(sum(distinct pl.Quantity * pl.Rate),0) + ifnull(sum(distinct st.After_SGST),0) + ifnull(sum(distinct st.After_CGST),0) + ifnull(sum(distinct st.After_IGST),0) + ifnull(sum(distinct st.AfterFreightValue),0) + ifnull(rt.Insurance,0) - ifnull(sum(distinct st.Afterdiscountval),0) when 'REVENUE' then ifnull(sum(distinct pl.Quantity * pl.Rate),0) - ifnull(sum(distinct rt.AfterDiscount),0) + ifnull(sum(distinct rt.AfterSGST),0) + ifnull(sum(distinct rt.AfterCGST),0) + ifnull(sum(distinct rt.AfterIGST),0) + ifnull(sum(distinct rt.AfterFreightValue),0) + ifnull(sum(distinct rt.AfterPackagingValue),0) + ifnull(rt.Insurance,0) end as total FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo left join T_Revenue_Tax rt on rt.LineItemNo = pl.LineItemNo where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' "; if ($cname!= ''){ $sql.="and sd.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(pm.PODate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(pm.PODate) >= '".$fromd."' and date(pm.PODate) <= '".$tod."'"; } $sql.= "group by supplier_name"; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function report_consolidate($cname,$fa,$aa){ $sql="select sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,mm.MaterialName as material_name, SUM(IF(month(pm.PODate) = 4, pl.Quantity, 0)) AS April, SUM(IF(month(pm.PODate) = 5, pl.Quantity, 0)) AS May, SUM(IF(month(pm.PODate) = 6, pl.Quantity, 0)) AS June, SUM(IF(month(pm.PODate) = 7, pl.Quantity, 0)) AS July, SUM(IF(month(pm.PODate) = 8, pl.Quantity, 0)) AS August, SUM(IF(month(pm.PODate) = 9, pl.Quantity, 0)) AS September, SUM(IF(month(pm.PODate) = 10, pl.Quantity, 0)) AS October, SUM(IF(month(pm.PODate) = 11, pl.Quantity, 0)) AS November, SUM(IF(month(pm.PODate) = 12, pl.Quantity, 0)) AS December, SUM(IF(month(pm.PODate) = 1, pl.Quantity, 0)) AS January, SUM(IF(month(pm.PODate) = 2, pl.Quantity, 0)) AS February, SUM(IF(month(pm.PODate) = 3, pl.Quantity, 0)) AS March, sum(pl.Quantity) as qtotal, SUM(IF(month(pm.PODate) = 4, pl.Quantity * pl.Rate, 0)) AS vApril, SUM(IF(month(pm.PODate) = 5, pl.Quantity * pl.Rate, 0)) AS vMay, SUM(IF(month(pm.PODate) = 6, pl.Quantity * pl.Rate, 0)) AS vJune, SUM(IF(month(pm.PODate) = 7, pl.Quantity * pl.Rate, 0)) AS vJuly, SUM(IF(month(pm.PODate) = 8, pl.Quantity * pl.Rate, 0)) AS vAugust, SUM(IF(month(pm.PODate) = 9, pl.Quantity * pl.Rate, 0)) AS vSeptember, SUM(IF(month(pm.PODate) = 10, pl.Quantity * pl.Rate, 0)) AS vOctober, SUM(IF(month(pm.PODate) = 11, pl.Quantity * pl.Rate, 0)) AS vNovember, SUM(IF(month(pm.PODate) = 12, pl.Quantity * pl.Rate, 0)) AS vDecember, SUM(IF(month(pm.PODate) = 1, pl.Quantity * pl.Rate, 0)) AS vJanuary, SUM(IF(month(pm.PODate) = 2, pl.Quantity * pl.Rate, 0)) AS vFebruary, SUM(IF(month(pm.PODate) = 3, pl.Quantity * pl.Rate, 0)) AS vMarch, sum(pl.Quantity * pl.Rate) as vtotal FROM T_PurchaseOrder_Master pm join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' "; if ($cname!= ''){ $sql.="and sd.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31')"; } $sql.= "group by supplier_name,material_name"; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function consolidate_month($m=null,$sid=null,$mid=null,$fa=null,$aa=null){ $sql="select mm.Category as category,sd.SupplierID as sid,sd.SupplierName as supplier_name,mm.MaterialCode as mid,mm.MaterialName as material_name, sum(pl.Quantity) as quantity, sum(pl.Quantity * pl.Rate) as total FROM T_PurchaseOrder_Master pm join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo left join T_Revenue_Tax rt on rt.LineItemNo = pl.LineItemNo where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and monthname(pm.PODate) = '".$m."' and sd.SupplierID = '".$sid."' and mm.MaterialCode = '".$mid."' "; if ($fa and $aa != ''){ $sql.=" and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31')"; } $sql.= "group by supplier_name,material_name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function consolidate_year($sid=null,$mid=null,$fa=null,$aa=null){ $sql="select mm.Category as category,sd.SupplierID as sid,sd.SupplierName as supplier_name,mm.MaterialCode as mid,mm.MaterialName as material_name, sum(pl.Quantity) as quantity, sum(pl.Quantity * pl.Rate) as total FROM T_PurchaseOrder_Master pm join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo left join T_Revenue_Tax rt on rt.LineItemNo = pl.LineItemNo where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierID = '".$sid."' and mm.MaterialCode = '".$mid."' "; if ($fa and $aa != ''){ $sql.=" and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31')"; } $sql.= "group by supplier_name,material_name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function report_cumulative(){ if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT year.sid as sid,year.mid as mid,year.supplier_name as supplier_name,year.material_name as material_name,year.quantity as quantity,year.total as total,month.mquantity as mquantity,month.mtotal as mtotal,today.tquantity as tquantity,today.ttotal as ttotal FROM (SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,ifnull(sum(pl.Quantity),0) as quantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as total FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31') group by supplier_name,material_name ) as year left join (SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,ifnull(sum(pl.Quantity),0) as mquantity,round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as mtotal FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and month(pm.PODate) = month(current_date()) group by supplier_name,material_name ) as month on month.supplier_name=year.supplier_name and month.material_name=year.material_name left join (SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,IF(pl.Quantity IS NULL or pl.Quantity = '', 0, sum(pl.Quantity)) as tquantity,ifnull(sum(pl.Quantity * pl.Rate),0) as ttotal FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and date(pm.PODate) = current_date() group by supplier_name,material_name ) as today on today.supplier_name=month.supplier_name and today.material_name=month.material_name group by supplier_name,material_name "; $query = $this->db->query($sql); return $query->result(); } function report_cum_month($sup=null,$mat=null){ $sql="SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,IF(pl.Quantity IS NULL or pl.Quantity = '', 0, sum(pl.Quantity)) as tquantity,ifnull(sum(pl.Quantity * pl.Rate),0) as ttotal FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and month(pm.PODate) = month(current_date()) and sd.SupplierID = '".$sup."' and mm.MaterialCode = '".$mat."' group by supplier_name,material_name"; $query = $this->db->query($sql); return $query->result(); } function report_cum_year($sup=null,$mat=null){ if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,IF(pl.Quantity IS NULL or pl.Quantity = '', 0, sum(pl.Quantity)) as tquantity,ifnull(sum(pl.Quantity * pl.Rate),0) as ttotal FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and (pm.PODate >= '".$fa."-04-01' and pm.PODate <= '".$aa."-03-31') and sd.SupplierID = '".$sup."' and mm.MaterialCode = '".$mat."' group by supplier_name,material_name"; $query = $this->db->query($sql); return $query->result(); } function report_cum_day($sup=null,$mat=null){ $sql="SELECT sd.SupplierID as sid,mm.MaterialCode as mid,sd.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,IF(pl.Quantity IS NULL or pl.Quantity = '', 0, sum(pl.Quantity)) as tquantity,ifnull(sum(pl.Quantity * pl.Rate),0) as ttotal FROM T_PurchaseOrder_Master pm left join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID where pm.Status != 'ST030' and pm.Status != 'ST056' and pm.Status != 'ST027' and sd.SupplierName is not null and date(pm.PODate) = current_date() and sd.SupplierID = '".$sup."' and mm.MaterialCode = '".$mat."' group by supplier_name,material_name"; $query = $this->db->query($sql); return $query->result(); } function ireport_purchase($cname,$prod,$fa,$aa,$m,$frm,$t,$cat){ $sql="select im.IGRNO as igrn,pm.POType as potype,im.PONO as pono,date_format(im.CreatedDate,'%d-%m-%Y') as created_date,TIME_FORMAT(im.CreatedDate,'%l:%i %p') as created_time,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, sum(id.QuantityAsPerInvoice) as quantity,pl.Rate as rate,round(sum(id.QuantityAsPerInvoice) * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',sum(pm.ExchangeRate),0) as exchange_rate, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity), sum(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2) as discount, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity), sum(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) as freight, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) as Package, round(( if(POType = 'IMPORT',sum(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), if(POType = 'CAPITAL' && CapitalRange = 0,sum(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0))) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity), sum(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) - round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity), sum(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total, im.file as ifile,pb.FilePath as file from T_IGR_Master im join T_PurchaseOrder_LineItem pl on pl.PONO = im.PONO join T_IGR_Details id on id.IGRNO = im.IGRNO and id.MaterialCode = pl.MaterialCode join T_PurchaseOrder_Master pm on pm.PONO = pl.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo left join T_Revenue_Tax rt on rt.LineItemNo = pl.LineItemNo left join T_PurchaseOrder_BillUpload pb on pb.IGRNO=im.IGRNO where pm.Status != 'ST030' "; if ($cname!= ''){ $sql.="and sd.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(im.CreatedDate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(im.CreatedDate) >= '".$fromd."' and date(im.CreatedDate) <= '".$tod."'"; } if ($prod!= ''){ $sql.=" and mm.MaterialName = '".$prod."' "; } if ($cat!= ''){ $sql.=" and mm.Category = '".$cat."' "; } $sql.="group by pono,material_name,category,supplier_name"; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function ireport_purchase_link($cname,$prod,$fa,$aa,$m,$frm,$t,$sid,$mid,$d,$cat,$da,$po){ $sql="select im.IGRNO as igrn,pm.POType as potype,im.PONO as pono,date_format(im.CreatedDate,'%d-%m-%Y') as created_date,TIME_FORMAT(im.CreatedDate,'%l:%i %p') as created_time,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, sum(id.QuantityAsPerInvoice) as quantity,pl.Rate as rate,round(sum(id.QuantityAsPerInvoice) * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',sum(pm.ExchangeRate),0) as exchange_rate, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity), sum(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2) as discount, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity), sum(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) as freight, round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) as Package, round(( if(POType = 'IMPORT',sum(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), if(POType = 'CAPITAL' && CapitalRange = 0,sum(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0))) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity), sum(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity), sum(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) + round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) - round(ifnull(if(POType = 'REVENUE', sum(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity), sum(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total, im.file as ifile,pb.FilePath as file from T_IGR_Master im join T_PurchaseOrder_LineItem pl on pl.PONO = im.PONO join T_IGR_Details id on id.IGRNO = im.IGRNO and id.MaterialCode = pl.MaterialCode join T_PurchaseOrder_Master pm on pm.PONO = pl.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo left join T_Revenue_Tax rt on rt.LineItemNo = pl.LineItemNo left join T_PurchaseOrder_BillUpload pb on pb.IGRNO=im.IGRNO where pm.Status != 'ST030' "; if ($cname!= ''){ $sql.="and sd.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(im.CreatedDate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(im.CreatedDate) >= '".$fromd."' and date(im.CreatedDate) <= '".$tod."'"; } if ($prod!= ''){ $sql.=" and mm.MaterialName = '".$prod."' "; } if ($sid!= ''){ $sql.=" and sd.SupplierID = '".$sid."' "; } if ($mid!= ''){ $sql.=" and mm.MaterialCode = '".$mid."' "; } if ($d!= ''){ $sql.=" and date(im.CreatedDate) = '".$d."' "; } if ($cat!= ''){ $sql.=" and mm.Category = '".$cat."' "; } if ($da!= ''){ $ddd= date("Y-m-d",strtotime($da)); $sql.=" and date(im.CreatedDate) = '".$ddd."' "; } if ($po!= ''){ $sql.=" and im.PONO = '".$po."' "; } $sql.="group by pono,material_name,category,supplier_name"; // echo $m; // echo $sid; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function ireport_attachment($cname,$fa,$aa,$m,$frm,$t){ $sql="select pono,potype,date_format(created_date,'%d-%m-%Y') as created_date,supplier_name, sum(total) as total,file,ifile from igr where status != 'ST030' "; if ($cname!= ''){ $sql.="and supplier_name = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (created_date >= '".$fa."-04-01' and created_date <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(created_date) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(created_date) >= '".$fromd."' and date(created_date) <= '".$tod."'"; } $sql.="group by pono,igrn"; // echo $m; // echo $sid; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function ireport_year_wise($a,$b){ $sql="select dat as CreatedDate,sum(quantity)as quantity,sum(value) as value from year_inward where status != 'ST030' and date(dat) >= '$a-04-01' and date(dat) <= '$b-03-31' group by month(CreatedDate) "; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function ireport_month_wise($mont){ $month= date("m",strtotime($mont)); $year = date("Y",strtotime($mont)); $sql="select sid,mid,supplier_name,material_name,sum(quantity)as quantity,sum(value) as total from year_inward where status != 'ST030' and month(dat)= ? and year(dat) = ? group by material_name,supplier_name"; $query = $this->db->query($sql,array($month,$year)); return $query->result(); } function ireport_year_wise_total($a,$b){ $sql="select sid,mid,supplier_name,material_name,sum(quantity)as quantity,sum(value) as total from year_inward where status != 'ST030' and date(dat) >= '$a-04-01' and date(dat) <= '$b-03-31' group by material_name,supplier_name"; $query = $this->db->query($sql,array()); return $query->result(); } function ireport_supplier($cname,$fa,$aa,$m,$frm,$t){ $sql="SELECT sd.SupplierID as sid,sd.SupplierName as supplier_name,count(im.PONO) as counts,ifnull(sum(id.QuantityAsPerInvoice),0) as quantity,round(ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0),2) as value, case pm.POType when 'IMPORT' then ifnull((sum((id.QuantityAsPerInvoice * pl.Rate) * pm.ExchangeRate) + ifnull(rt.Insurance,0) ),0) when 'CAPITAL' then sum( if(pm.CapitalRange=0,(( id.QuantityAsPerInvoice * pl.Rate) * pm.ExchangeRate),( id.QuantityAsPerInvoice * pl.Rate) - st.Afterdiscountval)) + ifnull(sum(st.After_SGST),0) + ifnull(sum(st.After_CGST),0) + ifnull(sum(st.After_IGST),0) + ifnull(sum(st.AfterFreightValue),0) + ifnull(rt.Insurance,0) when 'SERVICE' then ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0) + ifnull(sum(st.After_SGST),0) + ifnull(sum(st.After_CGST),0) + ifnull(sum(st.After_IGST),0) + ifnull(sum(st.AfterFreightValue),0) + ifnull(rt.Insurance,0) - ifnull(sum(st.Afterdiscountval),0) when 'REVENUE' then ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0) - ifnull(sum(rt.AfterDiscount),0) + ifnull(sum(rt.AfterSGST),0) + ifnull(sum(rt.AfterCGST),0) + ifnull(sum(rt.AfterIGST),0) + ifnull(sum(rt.AfterFreightValue),0) + ifnull(sum(rt.AfterPackagingValue),0) + ifnull(rt.Insurance,0) end as total from T_IGR_Master im join T_PurchaseOrder_LineItem pl on pl.PONO = im.PONO join T_IGR_Details id on id.IGRNO = im.IGRNO and id.MaterialCode = pl.MaterialCode join T_PurchaseOrder_Master pm on pm.PONO = pl.PONO left join T_MaterialMaster mm on mm.MaterialCode = pl.MaterialCode left join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo left join T_Revenue_Tax rt on rt.LineItemNo = pl.LineItemNo left join T_PurchaseOrder_BillUpload pb on pb.IGRNO=im.IGRNO where pm.Status != 'ST030'"; if ($cname!= ''){ $sql.="and sd.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (im.CreatedDate >= '".$fa."-04-01' and im.CreatedDate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(im.CreatedDate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(im.CreatedDate) >= '".$fromd."' and date(im.CreatedDate) <= '".$tod."'"; } $sql.= "group by supplier_name"; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function ireport_consolidate($cname,$fa,$aa){ $sql="select sid,mid,supplier_name,material_name, SUM(IF(month(dat) = 4, quantity, 0)) AS April, SUM(IF(month(dat) = 5, quantity, 0)) AS May, SUM(IF(month(dat) = 6, quantity, 0)) AS June, SUM(IF(month(dat) = 7, quantity, 0)) AS July, SUM(IF(month(dat) = 8, quantity, 0)) AS August, SUM(IF(month(dat) = 9, quantity, 0)) AS September, SUM(IF(month(dat) = 10, quantity, 0)) AS October, SUM(IF(month(dat) = 11, quantity, 0)) AS November, SUM(IF(month(dat) = 12, quantity, 0)) AS December, SUM(IF(month(dat) = 1, quantity, 0)) AS January, SUM(IF(month(dat) = 2, quantity, 0)) AS February, SUM(IF(month(dat) = 3, quantity, 0)) AS March, sum(quantity) as qtotal, SUM(IF(month(dat) = 4, value, 0)) AS vApril, SUM(IF(month(dat) = 5, value, 0)) AS vMay, SUM(IF(month(dat) = 6, value, 0)) AS vJune, SUM(IF(month(dat) = 7, value, 0)) AS vJuly, SUM(IF(month(dat) = 8, value, 0)) AS vAugust, SUM(IF(month(dat) = 9, value, 0)) AS vSeptember, SUM(IF(month(dat) = 10, value, 0)) AS vOctober, SUM(IF(month(dat) = 11, value, 0)) AS vNovember, SUM(IF(month(dat) = 12, value, 0)) AS vDecember, SUM(IF(month(dat) = 1, value, 0)) AS vJanuary, SUM(IF(month(dat) = 2, value, 0)) AS vFebruary, SUM(IF(month(dat) = 3, value, 0)) AS vMarch, sum(value) as vtotal FROM year_inward where status != 'ST030' "; if ($cname!= ''){ $sql.="and supplier_name = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')"; } $sql.= "group by supplier_name,material_name"; // echo $sql; $query = $this->db->query($sql); return $query->result(); } function i_consolidate_month($m=null,$sid=null,$mid=null,$fa=null,$aa=null){ $sql="select sid,mid,supplier_name,material_name,sum(quantity) as quantity,sum(value) as total from year_inward where status != 'ST030' and monthname(dat) = '".$m."' and sid = '".$sid."' and mid = '".$mid."' "; if ($fa and $aa != ''){ $sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')"; } $sql.= "group by supplier_name,material_name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function i_consolidate_year($sid=null,$mid=null,$fa=null,$aa=null){ $sql="select sid,mid,supplier_name,material_name,sum(quantity) as quantity,sum(value) as total from year_inward where status != 'ST030' and sid = '".$sid."' and mid = '".$mid."' "; if ($fa and $aa != ''){ $sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')"; } $sql.= "group by supplier_name,material_name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function ireport_cumulative(){ if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT year.sid as sid,year.mid as mid,year.supplier_name as supplier_name,year.material_name as material_name,year.quantity as quantity,year.total as total,month.mquantity as mquantity,month.mtotal as mtotal,today.tquantity as tquantity,today.ttotal as ttotal FROM (SELECT sid,mid,supplier_name,material_name,sum(Quantity) as quantity,sum(value) as total FROM year_inward where status != 'ST030' and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31') group by supplier_name,material_name ) as year left join (SELECT sid,mid,supplier_name,material_name,sum(Quantity) as mquantity,sum(value) as mtotal FROM year_inward where status != 'ST030' and month(dat) = month(current_date()) group by supplier_name,material_name ) as month on month.supplier_name=year.supplier_name and month.material_name=year.material_name left join (SELECT sid,mid,supplier_name,material_name,sum(Quantity) as tquantity,sum(value) as ttotal FROM year_inward where status != 'ST030' and date(dat) = current_date() group by supplier_name,material_name ) as today on today.supplier_name=month.supplier_name and today.material_name=month.material_name group by supplier_name,material_name "; $query = $this->db->query($sql); return $query->result(); } function ireport_cum_month($sup=null,$mat=null){ $sql="SELECT sid,mid,supplier_name,material_name,sum(Quantity) as tquantity,sum(value) as ttotal FROM year_inward where status != 'ST030' and month(dat) = month(current_date()) and sid = '".$sup."' and mid = '".$mat."' group by supplier_name,material_name"; $query = $this->db->query($sql); return $query->result(); } function ireport_cum_year($sup=null,$mat=null){ if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal FROM year_inward where status != 'ST030' and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31') and sid = '".$sup."' and mid= '".$mat."' group by supplier_name,material_name "; $query = $this->db->query($sql); return $query->result(); } function ireport_cum_day($sup=null,$mat=null){ $sql="SELECT sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal FROM year_inward where status != 'ST030' and date(dat) = current_date() and sid = '".$sup."' and mid = '".$mat."' group by supplier_name,material_name"; $query = $this->db->query($sql); return $query->result(); } function rawi_report_cumulative(){ if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT year.category as category,year.quantity as quantity,year.total as total,month.mquantity as mquantity,month.mtotal as mtotal,today.tquantity as tquantity,today.ttotal as ttotal FROM (SELECT category,sum(Quantity) as quantity,sum(value) as total FROM year_inward where status != 'ST030' and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31') group by category ) as year left join (SELECT category,sum(Quantity) as mquantity,sum(value) as mtotal FROM year_inward where status != 'ST030' and month(dat) = month(current_date()) group by category ) as month on month.category=year.category left join (SELECT category,sum(Quantity) as tquantity,sum(value) as ttotal FROM year_inward where status != 'ST030' and date(dat) = current_date() group by category ) as today on today.category=month.category group by category "; $query = $this->db->query($sql); return $query->result(); } function rawi_report_cum_year($cat=null){ if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT category,sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal FROM year_inward where status != 'ST030' and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31') and category = '".$cat."' group by supplier_name,material_name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function rawi_report_cum_month($cat=null){ $sql="SELECT category,sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal FROM year_inward where status != 'ST030' and month(dat) = month(current_date()) and category = '".$cat."' group by supplier_name,material_name"; $query = $this->db->query($sql); return $query->result(); } function rawi_report_cum_day($cat=null){ $sql="SELECT category,sid,mid,supplier_name,material_name,IF(Quantity IS NULL or Quantity = '', 0, sum(Quantity)) as tquantity,sum(value) as ttotal FROM year_inward where status != 'ST030' and date(dat) = current_date() and category = '".$cat."' group by supplier_name,material_name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function rawi_report_consolidate($cname,$fa,$aa){ $sql="select sid,mid,category,supplier_name,material_name, SUM(IF(month(dat) = 4, quantity, 0)) AS April, SUM(IF(month(dat) = 5, quantity, 0)) AS May, SUM(IF(month(dat) = 6, quantity, 0)) AS June, SUM(IF(month(dat) = 7, quantity, 0)) AS July, SUM(IF(month(dat) = 8, quantity, 0)) AS August, SUM(IF(month(dat) = 9, quantity, 0)) AS September, SUM(IF(month(dat) = 10, quantity, 0)) AS October, SUM(IF(month(dat) = 11, quantity, 0)) AS November, SUM(IF(month(dat) = 12, quantity, 0)) AS December, SUM(IF(month(dat) = 1, quantity, 0)) AS January, SUM(IF(month(dat) = 2, quantity, 0)) AS February, SUM(IF(month(dat) = 3, quantity, 0)) AS March, sum(quantity) as qtotal, SUM(IF(month(dat) = 4, value, 0)) AS vApril, SUM(IF(month(dat) = 5, value, 0)) AS vMay, SUM(IF(month(dat) = 6, value, 0)) AS vJune, SUM(IF(month(dat) = 7, value, 0)) AS vJuly, SUM(IF(month(dat) = 8, value, 0)) AS vAugust, SUM(IF(month(dat) = 9, value, 0)) AS vSeptember, SUM(IF(month(dat) = 10, value, 0)) AS vOctober, SUM(IF(month(dat) = 11, value, 0)) AS vNovember, SUM(IF(month(dat) = 12, value, 0)) AS vDecember, SUM(IF(month(dat) = 1, value, 0)) AS vJanuary, SUM(IF(month(dat) = 2, value, 0)) AS vFebruary, SUM(IF(month(dat) = 3, value, 0)) AS vMarch, sum(value) as vtotal FROM year_inward where status != 'ST030' "; if ($cname!= ''){ $sql.="and Category = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')"; } $sql.= "group by category"; //echo $sql; $query = $this->db->query($sql); return $query->result(); } function rawi_consolidate_month($m=null,$cat=null,$sup=null,$fa=null,$aa=null){ $sql="select category,sid,supplier_name,mid,material_name, sum(Quantity) as quantity, sum(value) as total FROM year_inward where status != 'ST030' and monthname(dat) = '".$m."' and category = '".$cat."' "; if ($fa and $aa != ''){ $sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')"; } $sql.= "group by category,supplier_name,material_name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function rawi_consolidate_year($cat=null,$sup=null,$fa=null,$aa=null){ $sql="select category,sid,supplier_name,mid,material_name, sum(Quantity) as quantity, sum(value) as total FROM year_inward where status != 'ST030' and category = '".$cat."' "; if ($fa and $aa != ''){ $sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')"; } $sql.= "group by category,supplier_name,material_name"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function pending_purchase($cname,$prod,$fa,$aa,$m,$frm,$t){ $sql="select po.PONO as po,date_format(po.PODate,'%d-%m-%Y') as pdate,sup.SupplierName as supplier,mm.MaterialName as material,mm.Category as category,pl.Quantity as quantity,pl.ReceivedQuantity as received, (pl.Quantity - pl.ReceivedQuantity) as pending from T_PurchaseOrder_LineItem pl join T_PurchaseOrder_Master po on po.PONO = pl.PONO join T_SupplierDetailsN sup on sup.SupplierID=po.SupplierID join T_MaterialMaster mm on mm.MaterialCode=pl.MaterialCode where po.Status != 'ST030' and po.Status = 'ST026' "; if ($cname!= ''){ $sql.="and sup.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (po.PODate >= '".$fa."-04-01' and po.PODate <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(po.PODate) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(po.PODate) >= '".$fromd."' and date(po.PODate) <= '".$tod."'"; } if ($prod!= ''){ $sql.=" and mm.MaterialName = '".$prod."' "; } // if ($cat!= ''){ // $sql.=" and mm.Category = '".$cat."' "; // } $sql.="order by po.PONO"; $query = $this->db->query($sql); //echo $sql; return $query->result(); } function report_inwardcashbook($cname,$fa,$aa,$m,$frm,$t,$cat){ $sql="select tinex.account_code as AccountCode,date_format(tinex.date,'%d-%m-%Y') as Date,ac.name as AccountName, tinex.type as type,tinex.cashtype as category ,tinex.merchant as merchantname,tinex.Supplier_id as Supplierid,sup.SupplierName as Suppliername, tinex.sgst as sgst, tinex.value_before_gst as Value,tinex.cgst as cgst,tinex.igst as igst,tinex.document as cashbookfile, tinex.total as Total FROM t_income_expense tinex join t_accountcode ac on ac.code = tinex.account_code join T_SupplierDetailsN sup on sup.SupplierID = tinex.Supplier_id where tinex.gststatus = '1' "; if ($cname!= ''){ // $sql.="and tinex.merchant = '".$cname."'"; $sql.="and sup.SupplierName = '".$cname."'"; } if ($fa and $aa != ''){ $sql.=" and (tinex.created_on >= '".$fa."-04-01' and tinex.created_on <= '".$aa."-03-31')"; } if ($m!= ''){ $sql.="and monthname(tinex.created_on) = '".$m."'"; } if ($frm and $t != ''){ $fromd= date("Y-m-d",strtotime($frm)); $tod=date("Y-m-d",strtotime($t)); $sql.="and date(tinex.created_on) >= '".$fromd."' and date(tinex.created_on) <= '".$tod."'"; } if ($cat!= ''){ $sql.=" and tinex.type = '".$cat."' "; } $query = $this->db->query($sql); return $query->result(); } function cashbook() { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date, ifnull(case when tinc.type = 'PAYMENT' then tinc.total end,'0') as expense, ifnull(case when tinc.type = 'RECEIPT' then tinc.total end, '0') as income, ifnull(case when tinc.type = 'PAYMENT' then tinc.towhom end,'-') as paymentname, ifnull(case when tinc.type = 'RECEIPT' then tinc.towhom end, '-') as receiptname, tinc.total,tinc.towhom,tinc.description,tinc.type,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code "; $query = $this->db->query($sql); return $query->result(); } //home --this month// function monthexpensereport($month,$year) { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date, ifnull(case when tinc.type = 'PAYMENT' then sum(tinc.total) end,'0') as expense, ifnull(case when tinc.type = 'RECEIPT' then sum(tinc.total) end, '0') as income, ifnull(case when tinc.type = 'PAYMENT' then tinc.towhom end,'-') as paymentname, ifnull(case when tinc.type = 'RECEIPT' then tinc.towhom end, '-') as receiptname, tinc.total,tinc.towhom,tinc.description,monthname(tinc.date)as month,tinc.type,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code where month(tinc.date)= ".$month." and year(tinc.date)=".$year." group by tinc.account_code"; //tinc.total,tinc.towhom,tinc.description,monthname(tinc.date)as month,tinc.type,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code where month(tinc.date)= month(current_date())group by tinc.account_code"; $query = $this->db->query($sql); return $query->result(); } //home--this year// function yearexpensereport($fa,$aa) { $sql="select monthname(date) as month, sum(if(type='PAYMENT',total,0)) as exp, sum(if(type='RECEIPT',total,0)) as inc, sum(total) as total from t_income_expense where date >= '".$fa."-04-01' and date <= '".$aa."-03-31' group by month ORDER BY FIELD(month,'April','May','June','July','August','September','October','November','December','January', 'February', 'March') "; $query = $this->db->query($sql); return $query->result(); } //home--report--Day Wise Report // function today_data($value='') { $sql="SELECT type,Sum(total) as todaydata FROM t_income_expense WHERE type = ? AND DATE(date) = CURRENT_DATE"; $query = $this->db->query($sql,array($value)); return $query->result(); } function monthwise_data($value='') { $sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())"; $query = $this->db->query($sql,array($value)); return $query->result(); } function yearwise_data($value='') { if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql="SELECT type,sum(total) as yearlydata from t_income_expense where type = ? and (date >= '".$fa."-04-01' and date <= '".$aa."-03-31')"; $query = $this->db->query($sql,array($value)); return $query->result(); } function departmentwise($sid='',$d='',$c='') { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date, ifnull(case when tinc.type = 'PAYMENT' then tinc.total end,'0') as expense, ifnull(case when tinc.type = 'RECEIPT' then tinc.total end, '0') as income, ifnull(case when tinc.type = 'PAYMENT' then tinc.towhom end,'-') as paymentname, ifnull(case when tinc.type = 'RECEIPT' then tinc.towhom end, '-') as receiptname, date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.total,tinc.document,tinc.towhom,.tinc.description, ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code WHERE account_code = '$sid' and monthname(date)='$d' and tinc.type='$c'"; $query = $this->db->query($sql); //print_r($this->db->last_query()); //echo $sql; return $query->result(); } //yearwise/month// function yearmonthwise($sid='') { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date, ifnull(case when tinc.type = 'PAYMENT' then sum(tinc.total) end,'0') as expense, ifnull(case when tinc.type = 'RECEIPT' then sum(tinc.total) end, '0') as income, ifnull(case when tinc.type = 'PAYMENT' then tinc.towhom end,'-') as paymentname, ifnull(case when tinc.type = 'RECEIPT' then tinc.towhom end, '-') as receiptname, date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.account_code,sum(tinc.total)as total,monthname(tinc.date)as month,tinc.description,tinc.towhom,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code WHERE monthname(date) = ? group by tinc.account_code"; $query = $this->db->query($sql,array($sid)); //print_r($this->db->last_query()); return $query->result(); } //for dashboard graph in cashbook// function gettoptotal(){ $i=1; while($i<=12){ $sql="SELECT sum(total) as tot FROM t_income_expense where month(date)= $i"; // $sql="SELECT sum(total)as ttl,concat(sum(total),'-',account_code)as atotal FROM t_income_expense where month(date)= $i // group by account_code order by ttl desc limit 4"; $query = $this->db->query($sql); //print_r($this->db->last_query()); //return $query->result(); $array_result[]=$query->result(); $i++; } return $array_result; } function INRSymbol() { $sql='select FontCode2000 from T_Currency_Details where Currency_Code="INR"'; $query=$this->db->query($sql); return $query->result(); } function cashbookfinyear(){ $sql="SELECT CASE WHEN MONTH(date)>=4 THEN concat(YEAR(date), '-',YEAR(date)+1) ELSE concat(YEAR(date)-1,'-', YEAR(date)) END AS financial_year FROM t_income_expense GROUP BY financial_year"; $query = $this->db->query($sql); return $query->result(); } function today() { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date, ifnull(case when tinc.type = 'PAYMENT' then tinc.total end,'0') as expense, ifnull(case when tinc.type = 'RECEIPT' then tinc.total end, '0') as income, ifnull(case when tinc.type = 'PAYMENT' then tinc.towhom end,'-') as paymentname, ifnull(case when tinc.type = 'RECEIPT' then tinc.towhom end, '-') as receiptname, tinc.total,tinc.towhom,tinc.description,tinc.document,tinc.type,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code WHERE DATE(date) = CURRENT_DATE"; $query = $this->db->query($sql); return $query->result(); } // $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.total,tinc.towhom,tinc.description,tinc.account_code,tac.name FROM t_income_expense tinc // LEFT JOIN t_accountcode tac ON tac.code = tinc.account_code // WHERE DATE(date) = CURRENT_DATE"; // $query = $this->db->query($sql); // return $query->result(); //} function monthlypayments() { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.total,tinc.towhom,.tinc.description, ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code WHERE MONTH(date) = MONTH(curdate()) group by account_code"; $query = $this->db->query($sql); //print_r($this->db->last_query()); return $query->result(); } //home page --Reports// function departmentmenu($fdate,$tdate,$fa,$aa) { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date, ifnull(case when tinc.type = 'PAYMENT' then tinc.total end,'0') as expense, ifnull(case when tinc.type = 'RECEIPT' then tinc.total end, '0') as income, ifnull(case when tinc.type = 'PAYMENT' then tinc.towhom end,'-') as paymentname, ifnull(case when tinc.type = 'RECEIPT' then tinc.towhom end, '-') as receiptname, tinc.total,tinc.towhom,tinc.description,tinc.type,tinc.document,tinc.account_code,ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code where tinc.date !=0 "; if ($fdate and $tdate != ''){ $fdate= date("Y-m-d",strtotime($fdate)); $tdate=date("Y-m-d",strtotime($tdate)); $sql.="and date(tinc.date) >= '".$fdate."' and date(tinc.date) <= '".$tdate."'"; } if ($fa and $aa != ''){ $sql.=" and (tinc.date >= '".$fa."-04-01' and tinc.date <= '".$aa."-03-31')"; } $query = $this->db->query($sql); //echo $fdate; //print_r($this->db->last_query()); //echo $sql; return $query->result(); } function menudepartmentwise($sid='') { $sql="SELECT date_format(tinc.date,'%d-%m-%Y')as date,tinc.type,tinc.total,tinc.document,tinc.towhom,tinc.description, ac.name FROM t_income_expense tinc join t_accountcode ac on ac.code=tinc.account_code WHERE account_code = '$sid'"; $query = $this->db->query($sql); //print_r($this->db->last_query()); //echo $sql; return $query->result(); } function report_cumulative_cashbook(){ if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); $sql = "SELECT year.name as name,year.yearexpense as yexp,year.yearincome as yinc,month.monthexpense as mexp,month.monthincome as minc,today.todayexpense as texp,today.todayincome as tinc FROM (select ac1.name, ifnull(case when tinc1.type = 'PAYMENT' then sum(tinc1.total) end,'0') as yearexpense, ifnull(case when tinc1.type = 'RECEIPT' then sum(tinc1.total) end, '0') as yearincome FROM t_income_expense tinc1 join t_accountcode ac1 on ac1.code = tinc1.account_code WHERE (tinc1.date >= '".$fa."-04-01' and tinc1.date <= '".$aa."-03-31') group by ac1.name ) as year left join (select ac2.name ,ifnull(case when tinc2.type = 'PAYMENT' then sum(tinc2.total) end,'0') as monthexpense, ifnull(case when tinc2.type = 'RECEIPT' then sum(tinc2.total) end, '0') as monthincome FROM t_income_expense tinc2 join t_accountcode ac2 on ac2.code = tinc2.account_code where month(tinc2.date) = month(current_date()) group by ac2.name) as month on month.name = year.name left join (select ac3.name ,ifnull(case when tinc3.type = 'PAYMENT' then sum(tinc3.total) end,'0') as todayexpense, ifnull(case when tinc3.type = 'RECEIPT' then sum(tinc3.total) end, '0') as todayincome FROM t_income_expense tinc3 join t_accountcode ac3 on ac3.code = tinc3.account_code where date(tinc3.date) = current_date() group by ac3.name ) as today on today.name=month.name group by name "; $query = $this->db->query($sql); return $query->result(); } function monthbeforetotal($month,$year){ $sql="SELECT month(date) as monthnum ,year(date) as yearnum, sum(if(type = 'PAYMENT',total,0)) as payment_amt, sum(if(type = 'RECEIPT',total,0)) as receipt_amt FROM t_income_expense WHERE month(date) = '".$month."'and year(date) = '".$year."'"; $query = $this->db->query($sql); return $query->result(); } function yearbeforetotal($pre,$curr){ $sql="SELECT sum(if(type = 'PAYMENT',total,0)) as payment_amt, sum(if(type = 'RECEIPT',total,0)) as receipt_amt FROM t_income_expense where date >= '".$pre."-04-01' and date <= '".$curr."-03-31'"; $query = $this->db->query($sql); return $query->result(); //print_r($query->result()); } function daybeforetotal($yesterday){ $sql="select date, sum(if(type = 'PAYMENT',total,0)) as payment_amt, sum(if(type = 'RECEIPT',total,0)) as receipt_amt from t_income_expense where date = ? "; $query = $this->db->query($sql,array($yesterday)); return $query->result(); } function accountname() { $sql = "SELECT name from t_accountcode "; $query = $this->db->query($sql); return $query->result(); } function cashbook_finyear(){ $sql="SELECT CASE WHEN MONTH(date)>=4 THEN concat(YEAR(date), '-',YEAR(date)+1) ELSE concat(YEAR(date)-1,'-', YEAR(date)) END AS financial_year FROM t_income_expense GROUP BY financial_year"; $query = $this->db->query($sql); return $query->result(); } //function report_cumulative_month_cashbook(){ function report_cumulative_month_cashbook($cname,$yr1,$yr2){ if ($yr1 == '' && $yr2 == ''){ if (date('m') >= 4) { $yearl = date('Y').'-'.(date('Y')+1); } else { $yearl = (date('Y')-1).'-'.date('Y'); } $ab=$yearl; $fa=substr($ab,0,-5); $aa=substr($ab,5,5); } else{ $fa=$yr1; $aa=$yr2; } $sql = "select tinc.account_code,ac.name, SUM(IF(month(tinc.date) = 4, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS AprilExpense, SUM(IF(month(tinc.date) = 4, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS AprilIncome, SUM(IF(month(tinc.date) = 5, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS MayExpense, SUM(IF(month(tinc.date) = 5, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS MayIncome, SUM(IF(month(tinc.date) = 6, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS JuneExpense, SUM(IF(month(tinc.date) = 6, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS JuneIncome, SUM(IF(month(tinc.date) = 7, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS JulyExpense, SUM(IF(month(tinc.date) = 7, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS JulyIncome, SUM(IF(month(tinc.date) = 8, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS AugustExpense, SUM(IF(month(tinc.date) = 8, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS AugustIncome, SUM(IF(month(tinc.date) = 9, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS SepExpense, SUM(IF(month(tinc.date) = 9, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS SepIncome, SUM(IF(month(tinc.date) = 10, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS OctExpense, SUM(IF(month(tinc.date) = 10, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS OctIncome, SUM(IF(month(tinc.date) = 11, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS NovExpense, SUM(IF(month(tinc.date) = 11, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS NovIncome, SUM(IF(month(tinc.date) = 12, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS DecExpense, SUM(IF(month(tinc.date) = 12, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS DecIncome, SUM(IF(month(tinc.date) = 1, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS JanExpense, SUM(IF(month(tinc.date) = 1, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS JanIncome, SUM(IF(month(tinc.date) = 2, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS FebExpense, SUM(IF(month(tinc.date) = 2, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS FebIncome, SUM(IF(month(tinc.date) = 3, IF(tinc.type = 'PAYMENT', tinc.total, 0), 0)) AS MarExpense, SUM(IF(month(tinc.date) = 3, IF(tinc.type = 'RECEIPT', tinc.total, 0), 0)) AS MarIncome, SUM(IF(tinc.type = 'RECEIPT', tinc.total, 0)) AS receiptoverall, SUM(IF(tinc.type = 'PAYMENT', tinc.total, 0)) AS paymentoverall, SUM(tinc.total) as overalltotal from t_income_expense tinc join t_accountcode ac on ac.code = tinc.account_code where (tinc.date >='".$fa."-04-01' and tinc.date <= '".$aa."-03-31')"; if ($cname!= ''){ $sql.="and ac.name = '".$cname."'"; } $sql.= " group by tinc.account_code"; $query = $this->db->query($sql); return $query->result(); } } ?>