3154 lines
122 KiB
PHP
3154 lines
122 KiB
PHP
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
class dahsboard_Model extends CI_Model
|
|
{
|
|
|
|
|
|
/* HR DASHBOART Model START*/
|
|
function totemp()
|
|
{
|
|
$yes_date = date('Y-m-d',strtotime("-1 days"));
|
|
// $sql="select count(*) as emp_count from T_Employee_Details where date(T_Employee_Details.Created_date) <= ? and isActive = 1";
|
|
// $query =$this->db->query($sql,array($yes_date));
|
|
$this->db->select('count(*) as totemp');
|
|
$this->db->where('date(T_Employee_Details.Created_date)<=',$yes_date);
|
|
$this->db->where('isActive',1);
|
|
$query = $this->db->get('T_Employee_Details');
|
|
// print_r($query->row());die;
|
|
return $query->row();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getfile($PONO)
|
|
{
|
|
//$this->db->distinct();
|
|
$this->db->select('*');
|
|
$this->db->from('T_PurchaseOrder_BillUpload');
|
|
$this->db->where('PONO',$PONO);
|
|
|
|
|
|
$query = $this->db->get();
|
|
// print_r( $this->db->last_query());
|
|
$result = $query->result_array();
|
|
return $result;
|
|
}
|
|
function getfiles($igr,$PONO)
|
|
{
|
|
//$this->db->distinct();
|
|
$this->db->select('*');
|
|
$this->db->from('T_Inwardgateregister_fileupload');
|
|
$this->db->where('IGRNO',$igr);
|
|
$this->db->where('PONO',$PONO);
|
|
|
|
|
|
$query = $this->db->get();
|
|
// print_r( $this->db->last_query());
|
|
$result = $query->result_array();
|
|
return $result;
|
|
}
|
|
|
|
|
|
function viewIGRFile1($igr,$PONO)
|
|
{
|
|
$this->db->distinct();
|
|
$this->db->select('igrm.file,igrm.PONO as pono'); //BillNo,IGRNO,FilePath,PONO
|
|
$this->db->from('T_IGR_Master igrm');
|
|
$this->db->where('igrm.IGRNO',$igr);
|
|
$this->db->where('igrm.PONO',$PONO);
|
|
|
|
$query = $this->db->get();
|
|
|
|
$result = $query->result();
|
|
// print_r($result);die;
|
|
//print_r($this->db->last_query());
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectigrfiles()
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('T_Inwardgateregister_fileupload');
|
|
//$this->db->where('PONO',$PONO);
|
|
|
|
|
|
$query = $this->db->get();
|
|
// print_r( $this->db->last_query());
|
|
$result = $query->result_array();
|
|
return $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)" ;
|
|
|
|
$yes_date = date('Y-m-d',strtotime("-1 days"));
|
|
$sql="select att.EmpID,ifnull(".$WH.",0)".$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) and date(a.Created_date) <= '".$yes_date."' and isActive=1";
|
|
$query = $this->db->query($sql,array($date));
|
|
// print_r($query->result_array());die;
|
|
//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 get_employee(){
|
|
|
|
$yes_date = date('Y-m-d',strtotime("-1 days"));
|
|
$sql = "select * from T_Employee_Details where date(created_date) <='".$yes_date."' and isActive =1";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function per($fa,$aa,$m)
|
|
{
|
|
//echo $m;
|
|
$cur_month = date('M');
|
|
//echo $cur_month;
|
|
if($cur_month == $m ){
|
|
|
|
$cur_date = date('d');
|
|
}else{
|
|
|
|
$cur_date = date('t',strtotime($m));
|
|
}
|
|
//echo $cur_date;die;
|
|
$sql= "SELECT month.Eid as Eid,month.ename as ename,month.active as active,month.days as monthdays,month.Days_Worked as monthworked,month.percentage as monthpercentage
|
|
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/".$cur_date."*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";
|
|
|
|
$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);
|
|
// echo $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){
|
|
// echo "i am here 00";die;
|
|
|
|
$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 != '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 != '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 ireport_finyear(){
|
|
|
|
$sql="SELECT
|
|
CASE WHEN MONTH(MaterialRcvdDate)>=4
|
|
THEN concat(YEAR(MaterialRcvdDate), '-',YEAR(MaterialRcvdDate)+1)
|
|
ELSE concat(YEAR(MaterialRcvdDate)-1,'-', YEAR(MaterialRcvdDate))
|
|
END AS financial_year
|
|
FROM T_IGR_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 != '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 != '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 != '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 != '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 != '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 != '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 != '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 != '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 != '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 != '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 != '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 != '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 != '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, id.QuantityAsPerInvoice as quantity,pl.Rate as rate,round(id.QuantityAsPerInvoice * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',pm.ExchangeRate,0) as exchange_rate,date_format(im.MaterialRcvdDate,'%d-%m-%Y') as materialrcvddate,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2) as discount,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) as freight,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) as Package,
|
|
|
|
round((
|
|
if(POType = 'IMPORT',(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
|
|
if(POType = 'CAPITAL' && CapitalRange = 0,(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
|
|
ifnull((id.QuantityAsPerInvoice * pl.Rate),0)))
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2)
|
|
- round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total,
|
|
im.file as ifile,pb.FilePath as file,infiles.FilePath as Infiles
|
|
from T_IGR_Master im
|
|
left 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
|
|
left join T_Inwardgateregister_fileupload infiles on infiles.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')";
|
|
$sql.=" and (im.MaterialRcvdDate >= '".$fa."-04-01' and im.MaterialRcvdDate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
if ($m!= ''){
|
|
|
|
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
|
|
$sql.="and monthname(im.MaterialRcvdDate) = '".$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.="and date(im.MaterialRcvdDate) >= '".$fromd."'
|
|
and date(im.MaterialRcvdDate) <= '".$tod."'";
|
|
|
|
}
|
|
if ($prod!= ''){
|
|
|
|
$sql.=" and mm.MaterialName = '".$prod."' ";
|
|
|
|
}
|
|
if ($cat!= ''){
|
|
|
|
$sql.=" and mm.Category = '".$cat."' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql.="group by pono,material_name,category,supplier_name,id.IGRItemNo";
|
|
//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, id.QuantityAsPerInvoice as quantity,pl.Rate as rate,round(id.QuantityAsPerInvoice * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',pm.ExchangeRate,0) as exchange_rate,date_format(im.MaterialRcvdDate,'%d-%m-%Y') as materialrcvddate,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2) as discount,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) as freight,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) as Package,
|
|
|
|
round((
|
|
if(POType = 'IMPORT',(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
|
|
if(POType = 'CAPITAL' && CapitalRange = 0,(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
|
|
ifnull((id.QuantityAsPerInvoice * pl.Rate),0)))
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2)
|
|
- round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total,
|
|
im.file as ifile,pb.FilePath as file,infiles.FilePath as Infiles
|
|
from T_IGR_Master im
|
|
left 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
|
|
left join T_Inwardgateregister_fileupload infiles on infiles.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')";
|
|
$sql.=" and (im.MaterialRcvdDate >= '".$fa."-04-01' and im.MaterialRcvdDate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
if ($m!= ''){
|
|
|
|
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
|
|
$sql.="and monthname(im.MaterialRcvdDate) = '".$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.="and date(im.MaterialRcvdDate) >= '".$fromd."'
|
|
and date(im.MaterialRcvdDate) <= '".$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."' ";
|
|
$sql.=" and date(im.MaterialRcvdDate) = '".$d."' ";
|
|
|
|
}
|
|
if ($cat!= ''){
|
|
|
|
$sql.=" and mm.Category = '".$cat."' ";
|
|
|
|
}
|
|
if ($da!= ''){
|
|
$ddd= date("Y-m-d",strtotime($da));
|
|
|
|
//$sql.=" and date(im.CreatedDate) = '".$ddd."' ";
|
|
$sql.=" and date(im.MaterialRcvdDate) = '".$ddd."' ";
|
|
|
|
}
|
|
if ($po!= ''){
|
|
|
|
$sql.=" and im.PONO = '".$po."' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql.="group by pono,material_name,category,supplier_name,id.IGRItemNo";
|
|
// 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,date_format(materialrcvddate,'%d-%m-%Y') as materialrcvddate,supplier_name,
|
|
// sum(total) as total,file,ifile
|
|
// from igr
|
|
|
|
$sql="select pono,igrn,potype,date_format(created_date,'%d-%m-%Y') as created_date,date_format(materialrcvddate,'%d-%m-%Y') as materialrcvddate,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')";
|
|
$sql.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
if ($m!= ''){
|
|
|
|
//$sql.="and monthname(created_date) = '".$m."'";
|
|
$sql.="and monthname(materialrcvddate) = '".$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.="and date(materialrcvddate) >= '".$fromd."'
|
|
and date(materialrcvddate) <= '".$tod."'";
|
|
|
|
}
|
|
|
|
$sql.="group by pono,igrn";
|
|
// echo $m;
|
|
// echo $sid;
|
|
//echo $sql;
|
|
$query = $this->db->query($sql);
|
|
|
|
$filequery = $query->result();
|
|
|
|
$resultArray = array();
|
|
|
|
foreach ($filequery as $value) {
|
|
|
|
$tempArray['pono'] = $value->pono;
|
|
$tempArray['potype'] =$value->potype;
|
|
$tempArray['supplier_name'] = $value->supplier_name;
|
|
$tempArray['materialrcvddate'] = $value->materialrcvddate;
|
|
$tempArray['total'] = $value->total;
|
|
$tempArray['created_date'] = $value->created_date;
|
|
$tempArray['file'] = $value->file;
|
|
$tempArray['ifile'] = $value->ifile;
|
|
$tempArray['igrn'] =$value->igrn;
|
|
|
|
$sqli ="select FilePath as Infiles from T_Inwardgateregister_fileupload where PONO =? and IGRNO =? ";
|
|
$querys = $this->db->query($sqli,array( $tempArray['pono'],$tempArray['igrn']));
|
|
|
|
$filepath = $querys->result();
|
|
$tempArray['Infiles'] = $filepath;
|
|
|
|
$resultArray[] = $tempArray;
|
|
|
|
}
|
|
|
|
|
|
return $resultArray;
|
|
|
|
}
|
|
|
|
function ireport_year_wise($a,$b){
|
|
|
|
|
|
// $sql="select dat as CreatedDate,sum(quantity)as quantity,sum(value) as value, materialrcvddate
|
|
// from year_inward
|
|
// where status != 'ST030' and date(dat) >= '$a-04-01' and date(dat) <= '$b-03-31'
|
|
// group by month(CreatedDate)
|
|
// ";
|
|
//echo $sql;
|
|
$sql="select materialrcvddate,sum(quantity)as quantity,sum(value) as value
|
|
from igr
|
|
where status != 'ST030' and date(materialrcvddate) >= '$a-04-01' and date(materialrcvddate) <= '$b-03-31'
|
|
group by month(materialrcvddate)";
|
|
$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";
|
|
$sql="select sid,mid,supplier_name,material_name,sum(quantity)as quantity,sum(value) as total,materialrcvddate
|
|
from igr
|
|
where status != 'ST030' and month(materialrcvddate)= ? and year(materialrcvddate) = ?
|
|
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";
|
|
$sql="select sid,mid,supplier_name,material_name,sum(quantity)as quantity,sum(value) as total,materialrcvddate
|
|
from igr
|
|
where status != 'ST030' and date(materialrcvddate) >= '$a-04-01' and date(materialrcvddate) <= '$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,im.MaterialRcvdDate
|
|
from T_IGR_Master im
|
|
left 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
|
|
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')";
|
|
$sql.=" and (im.MaterialRcvdDate >= '".$fa."-04-01' and im.MaterialRcvdDate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
if ($m!= ''){
|
|
|
|
//$sql.="and monthname(im.CreatedDate) = '".$m."'";
|
|
$sql.="and monthname(im.MaterialRcvdDate) = '".$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.="and date(im.MaterialRcvdDate) >= '".$fromd."'
|
|
and date(im.MaterialRcvdDate) <= '".$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(materialrcvddate) = 4, quantity, 0)) AS April,
|
|
SUM(IF(month(materialrcvddate) = 5, quantity, 0)) AS May,
|
|
SUM(IF(month(materialrcvddate) = 6, quantity, 0)) AS June,
|
|
SUM(IF(month(materialrcvddate) = 7, quantity, 0)) AS July,
|
|
SUM(IF(month(materialrcvddate) = 8, quantity, 0)) AS August,
|
|
SUM(IF(month(materialrcvddate) = 9, quantity, 0)) AS September,
|
|
SUM(IF(month(materialrcvddate) = 10, quantity, 0)) AS October,
|
|
SUM(IF(month(materialrcvddate) = 11, quantity, 0)) AS November,
|
|
SUM(IF(month(materialrcvddate) = 12, quantity, 0)) AS December,
|
|
SUM(IF(month(materialrcvddate) = 1, quantity, 0)) AS January,
|
|
SUM(IF(month(materialrcvddate) = 2, quantity, 0)) AS February,
|
|
SUM(IF(month(materialrcvddate) = 3, quantity, 0)) AS March,
|
|
sum(quantity) as qtotal,
|
|
SUM(IF(month(materialrcvddate) = 4, value, 0)) AS vApril,
|
|
SUM(IF(month(materialrcvddate) = 5, value, 0)) AS vMay,
|
|
SUM(IF(month(materialrcvddate) = 6, value, 0)) AS vJune,
|
|
SUM(IF(month(materialrcvddate) = 7, value, 0)) AS vJuly,
|
|
SUM(IF(month(materialrcvddate) = 8, value, 0)) AS vAugust,
|
|
SUM(IF(month(materialrcvddate) = 9, value, 0)) AS vSeptember,
|
|
SUM(IF(month(materialrcvddate) = 10, value, 0)) AS vOctober,
|
|
SUM(IF(month(materialrcvddate) = 11, value, 0)) AS vNovember,
|
|
SUM(IF(month(materialrcvddate) = 12, value, 0)) AS vDecember,
|
|
SUM(IF(month(materialrcvddate) = 1, value, 0)) AS vJanuary,
|
|
SUM(IF(month(materialrcvddate) = 2, value, 0)) AS vFebruary,
|
|
SUM(IF(month(materialrcvddate) = 3, value, 0)) AS vMarch,
|
|
sum(value) as vtotal
|
|
FROM igr
|
|
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.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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 igr
|
|
where status != 'ST030' and
|
|
monthname(materialrcvddate) = '".$m."' and sid = '".$sid."' and mid = '".$mid."' ";
|
|
if ($fa and $aa != ''){
|
|
|
|
//$sql.=" and (dat >= '".$fa."-04-01' and dat <= '".$aa."-03-31')";
|
|
$sql.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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 igr
|
|
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.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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,materialrcvddate
|
|
FROM igr
|
|
where status != 'ST030' and
|
|
(materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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 igr
|
|
where status != 'ST030' and
|
|
month(materialrcvddate) = 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 igr
|
|
where status != 'ST030' and
|
|
date(materialrcvddate) = 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 igr
|
|
where status != 'ST030' and
|
|
month(materialrcvddate) = 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 igr
|
|
where status != 'ST030' and
|
|
(materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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 igr
|
|
where status != 'ST030' and
|
|
date(materialrcvddate) = 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 igr
|
|
where status != 'ST030' and
|
|
(materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$aa."-03-31')
|
|
group by category
|
|
) as year left join
|
|
(SELECT category,sum(Quantity) as mquantity,sum(value) as mtotal
|
|
FROM igr
|
|
where status != 'ST030' and
|
|
month(materialrcvddate) = 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 igr
|
|
where status != 'ST030' and
|
|
date(materialrcvddate) = 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 igr
|
|
where status != 'ST030' and
|
|
(materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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 igr
|
|
where status != 'ST030' and
|
|
month(materialrcvddate) = 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 igr
|
|
where status != 'ST030' and
|
|
date(materialrcvddate) = 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(materialrcvddate) = 4, quantity, 0)) AS April,
|
|
SUM(IF(month(materialrcvddate) = 5, quantity, 0)) AS May,
|
|
SUM(IF(month(materialrcvddate) = 6, quantity, 0)) AS June,
|
|
SUM(IF(month(materialrcvddate) = 7, quantity, 0)) AS July,
|
|
SUM(IF(month(materialrcvddate) = 8, quantity, 0)) AS August,
|
|
SUM(IF(month(materialrcvddate) = 9, quantity, 0)) AS September,
|
|
SUM(IF(month(materialrcvddate) = 10, quantity, 0)) AS October,
|
|
SUM(IF(month(materialrcvddate) = 11, quantity, 0)) AS November,
|
|
SUM(IF(month(materialrcvddate) = 12, quantity, 0)) AS December,
|
|
SUM(IF(month(materialrcvddate) = 1, quantity, 0)) AS January,
|
|
SUM(IF(month(materialrcvddate) = 2, quantity, 0)) AS February,
|
|
SUM(IF(month(materialrcvddate) = 3, quantity, 0)) AS March,
|
|
sum(quantity) as qtotal,
|
|
SUM(IF(month(materialrcvddate) = 4, value, 0)) AS vApril,
|
|
SUM(IF(month(materialrcvddate) = 5, value, 0)) AS vMay,
|
|
SUM(IF(month(materialrcvddate) = 6, value, 0)) AS vJune,
|
|
SUM(IF(month(materialrcvddate) = 7, value, 0)) AS vJuly,
|
|
SUM(IF(month(materialrcvddate) = 8, value, 0)) AS vAugust,
|
|
SUM(IF(month(materialrcvddate) = 9, value, 0)) AS vSeptember,
|
|
SUM(IF(month(materialrcvddate) = 10, value, 0)) AS vOctober,
|
|
SUM(IF(month(materialrcvddate) = 11, value, 0)) AS vNovember,
|
|
SUM(IF(month(materialrcvddate) = 12, value, 0)) AS vDecember,
|
|
SUM(IF(month(materialrcvddate) = 1, value, 0)) AS vJanuary,
|
|
SUM(IF(month(materialrcvddate) = 2, value, 0)) AS vFebruary,
|
|
SUM(IF(month(materialrcvddate) = 3, value, 0)) AS vMarch,
|
|
sum(value) as vtotal
|
|
FROM igr
|
|
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.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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 igr
|
|
where status != 'ST030' and
|
|
monthname(materialrcvddate) = '".$m."' and category = '".$cat."' ";
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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 igr
|
|
where status != 'ST030' and
|
|
category = '".$cat."' ";
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$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 monthly_gst_purchase($m,$frm,$t,$fa,$aa){
|
|
|
|
$sql="select sum(sgst) as sgst,sum(cgst) as cgst,sum(igst) as igst,sum(sgst + cgst + igst) as total from igr
|
|
where pono != 'null' ";
|
|
|
|
if ($m!= ''){
|
|
|
|
$sql.="and monthname(materialrcvddate) = '".$m."'";
|
|
|
|
}
|
|
|
|
if ($frm and $t != ''){
|
|
$fromd= date("Y-m-d",strtotime($frm));
|
|
$tod=date("Y-m-d",strtotime($t));
|
|
|
|
$sql.="and materialrcvddate >= '".$fromd."'
|
|
and materialrcvddate <= '".$tod."'";
|
|
|
|
}
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
|
|
|
|
//echo $sql;
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
public function monthly_gst_sales($m=null,$frm=null,$t=null,$fa=null,$aa=null)
|
|
{
|
|
|
|
$sql = "select ii.invoice_id as invoice_id,ifnull(iii.invnum,'-') as parent_invoice_id,ii.client_id as client_id,ii.invoice_number as invoice_number,date_format(ii.invoice_date_created,'%d-%m-%Y') as dates,TIME_FORMAT(ii.invoice_time_created,'%l:%i %p') as invoice_time_created,icf.invoice_custom_fieldvalue as vehicle_no,ip.product_description as product_description,concat(ic.client_name,'-',ic.client_surname)as client_name,sum(iit.item_quantity) as item_quantity,sum(iit.item_price) as item_price,sum(iia.item_subtotal) as item_subtotal,
|
|
sum(ifnull(((sgst.tax_rate_percent * (iia.item_subtotal))/100),0))
|
|
as sgst,
|
|
sum(ifnull(((iia.item_subtotal) * cgst.tax_rate_percent)/100,0))
|
|
as cgst,
|
|
sum(ifnull((igst.tax_rate_percent * (iia.item_subtotal))/100,0))
|
|
as igst,
|
|
sum((ifnull(((sgst.tax_rate_percent * iia.item_subtotal)/100),0)
|
|
+
|
|
ifnull(((iia.item_subtotal * cgst.tax_rate_percent)/100),0)
|
|
+
|
|
ifnull(((igst.tax_rate_percent * iia.item_subtotal)/100),0)))
|
|
as total
|
|
from ip_invoices ii
|
|
join ip_invoice_custom icf on icf.invoice_id = ii.invoice_id
|
|
join ip_invoice_items iit on iit.invoice_id = ii.invoice_id
|
|
join ip_invoice_item_amounts iia on iia.item_id = iit.item_id
|
|
join ip_clients ic on ic.client_id = ii.client_id
|
|
join ip_products ip on ip.product_id = iit.item_product_id
|
|
left join ip_tax_rates sgst on sgst.tax_rate_id = iit.sgst_item_tax_rate_id
|
|
left join ip_tax_rates cgst on cgst.tax_rate_id = iit.cgst_item_tax_rate_id
|
|
left join ip_tax_rates igst on igst.tax_rate_id = iit.igst_item_tax_rate_id
|
|
left join (select inv.invoice_id as inv_id,inv.invoice_number,iii.invnum from ip_invoices inv
|
|
left join
|
|
(select ii.invoice_id as ii,ii.invoice_number as invnum,ic.invoice_number as icnum,ic.creditinvoice_parent_id as cp from ip_invoices as ii
|
|
left join ip_invoices as ic on ii.invoice_id = ic.creditinvoice_parent_id) as iii
|
|
on iii.icnum = inv.invoice_number) as iii on iii.inv_id = ii.invoice_id
|
|
where icf.invoice_custom_fieldid = '8' and ii.invoice_status_id != 1 ";
|
|
|
|
|
|
|
|
|
|
if ($m!= ''){
|
|
|
|
$sql.="and monthname(ii.invoice_date_created) = '".$m."'";
|
|
|
|
}
|
|
|
|
if ($frm and $t != ''){
|
|
$fromdate= date("Y-m-d",strtotime($frm));
|
|
$todate=date("Y-m-d",strtotime($t));
|
|
|
|
$sql.="and ii.invoice_date_created >= '".$fromdate."'
|
|
and ii.invoice_date_created <= '".$todate."'";
|
|
|
|
}
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (ii.invoice_date_created >= '".$fa."-04-01' and ii.invoice_date_created <= '".$aa."-03-31')";
|
|
|
|
}
|
|
//echo $sql;
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
|
|
}
|
|
function sales_gst($m=null,$frm=null,$t=null,$fa=null,$aa=null)
|
|
{
|
|
|
|
$sql = "select ii.invoice_id as invoice_id,'Sales' as doc_type,ip.product_sku as hsn_code,ifnull(iii.invnum,'-') as parent_invoice_id,ii.client_id as client_id,ii.invoice_number as doc_no,date_format(ii.invoice_date_created,'%d-%m-%Y') as date,TIME_FORMAT(ii.invoice_time_created,'%l:%i %p') as invoice_time_created,icf.invoice_custom_fieldvalue as vehicle_no,ip.product_description as product_description,concat(ic.client_name,'-',ic.client_surname)as client_name,sum(iit.item_quantity) as item_quantity,sum(iit.item_price) as item_price,sum(iia.item_subtotal) as value,
|
|
sum(ifnull(((sgst.tax_rate_percent * (iia.item_subtotal))/100),0))
|
|
as sgst,
|
|
sum(ifnull(((iia.item_subtotal) * cgst.tax_rate_percent)/100,0))
|
|
as cgst,
|
|
sum(ifnull((igst.tax_rate_percent * (iia.item_subtotal))/100,0))
|
|
as igst,
|
|
sum((iia.item_subtotal + ifnull(((sgst.tax_rate_percent * iia.item_subtotal)/100),0)
|
|
+
|
|
ifnull(((iia.item_subtotal * cgst.tax_rate_percent)/100),0)
|
|
+
|
|
ifnull(((igst.tax_rate_percent * iia.item_subtotal)/100),0)))
|
|
as total
|
|
from ip_invoices ii
|
|
join ip_invoice_custom icf on icf.invoice_id = ii.invoice_id
|
|
join ip_invoice_items iit on iit.invoice_id = ii.invoice_id
|
|
join ip_invoice_item_amounts iia on iia.item_id = iit.item_id
|
|
join ip_clients ic on ic.client_id = ii.client_id
|
|
join ip_products ip on ip.product_id = iit.item_product_id
|
|
left join ip_tax_rates sgst on sgst.tax_rate_id = iit.sgst_item_tax_rate_id
|
|
left join ip_tax_rates cgst on cgst.tax_rate_id = iit.cgst_item_tax_rate_id
|
|
left join ip_tax_rates igst on igst.tax_rate_id = iit.igst_item_tax_rate_id
|
|
left join (select inv.invoice_id as inv_id,inv.invoice_number,iii.invnum from ip_invoices inv
|
|
left join
|
|
(select ii.invoice_id as ii,ii.invoice_number as invnum,ic.invoice_number as icnum,ic.creditinvoice_parent_id as cp from ip_invoices as ii
|
|
left join ip_invoices as ic on ii.invoice_id = ic.creditinvoice_parent_id) as iii
|
|
on iii.icnum = inv.invoice_number) as iii on iii.inv_id = ii.invoice_id
|
|
where icf.invoice_custom_fieldid = '8' and ii.invoice_status_id != 1 and ii.invoice_status_id != 1 ";
|
|
|
|
|
|
|
|
if ($m!= ''){
|
|
|
|
$sql.="and monthname(ii.invoice_date_created) = '".$m."'";
|
|
|
|
}
|
|
|
|
if ($frm and $t != ''){
|
|
$fromdate= date("Y-m-d",strtotime($frm));
|
|
$todate=date("Y-m-d",strtotime($t));
|
|
|
|
$sql.="and ii.invoice_date_created >= '".$fromdate."'
|
|
and ii.invoice_date_created <= '".$todate."'";
|
|
|
|
}
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (ii.invoice_date_created >= '".$fa."-04-01' and ii.invoice_date_created <= '".$aa."-03-31')";
|
|
|
|
}
|
|
|
|
|
|
// echo $fromdate;
|
|
//echo $sql;
|
|
$sql.="group by doc_no,product_description";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
|
|
}
|
|
function purchase_gst($m,$frm,$t,$fa,$aa){
|
|
|
|
|
|
$sql="select im.IGRNO as igrn,pm.POType as potype,im.PONO as doc_no,'Purchase' as doc_type,mm.HSNCODE as hsn_code,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, id.QuantityAsPerInvoice as quantity,pl.Rate as rate,round(id.QuantityAsPerInvoice * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',pm.ExchangeRate,0) as exchange_rate,date_format(im.MaterialRcvdDate,'%d-%m-%Y') as date,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst,
|
|
round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst,
|
|
(round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2)
|
|
- round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)) as others,
|
|
round((
|
|
if(POType = 'IMPORT',(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
|
|
if(POType = 'CAPITAL' && CapitalRange = 0,(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)),
|
|
ifnull((id.QuantityAsPerInvoice * pl.Rate),0)))
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2)
|
|
+ round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2)
|
|
- round(ifnull(if(POType = 'REVENUE',
|
|
(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity),
|
|
(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total,
|
|
im.file as ifile,pb.FilePath as file
|
|
from T_IGR_Master im
|
|
left 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 ($m!= ''){
|
|
|
|
$sql.="and monthname(materialrcvddate) = '".$m."'";
|
|
|
|
}
|
|
|
|
if ($frm and $t != ''){
|
|
$fromd= date("Y-m-d",strtotime($frm));
|
|
$tod=date("Y-m-d",strtotime($t));
|
|
|
|
$sql.="and date(materialrcvddate) >= '".$fromd."'
|
|
and date(materialrcvddate) <= '".$tod."'";
|
|
|
|
}
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (materialrcvddate >= '".$fa."-04-01' and materialrcvddate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
|
|
|
|
$sql.="group by doc_no,material_name,category,supplier_name,id.IGRItemNo";
|
|
//echo $sql;
|
|
$query = $this->db->query($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,date_format(tinex.created_on,'%d-%m-%Y') as CreatedDate,
|
|
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.date >= '".$fa."-04-01' and tinex.date <= '".$aa."-03-31')";
|
|
}
|
|
if ($m!= ''){
|
|
$sql.="and monthname(tinex.date) = '".$m."'";
|
|
}
|
|
if ($frm and $t != ''){
|
|
$fromd= date("Y-m-d",strtotime($frm));
|
|
$tod=date("Y-m-d",strtotime($t));
|
|
|
|
$sql.="and date(tinex.date) >= '".$fromd."'
|
|
and date(tinex.date) <= '".$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();
|
|
|
|
}**/
|
|
//home--report--Day Wise Report //
|
|
function today_data()
|
|
{
|
|
$sql="SELECT sum(if(type = 'RECEIPT',total,0)) as daily_income_amt,
|
|
sum(if(type = 'PAYMENT',total,0)) as daily_expenses_amt
|
|
FROM t_income_expense
|
|
WHERE DATE(date) = CURRENT_DATE";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
function monthwise_data()
|
|
{
|
|
//$sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())";
|
|
$sql="SELECT sum(if(type = 'RECEIPT',total,0)) as monthly_income_amt,
|
|
sum(if(type = 'PAYMENT',total,0)) as monthly_expenses_amt
|
|
FROM t_income_expense
|
|
WHERE YEAR(date) = YEAR(curdate()) AND MONTH(date) = MONTH(curdate())";
|
|
$query = $this->db->query($sql);
|
|
//,array($value));
|
|
return $query->result();
|
|
|
|
}
|
|
function yearwise_data()
|
|
{
|
|
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(if(type = 'RECEIPT',total,0)) as yearly_income_amt,
|
|
sum(if(type = 'PAYMENT',total,0)) as yearly_expenses_amt
|
|
FROM t_income_expense
|
|
WHERE (date >= '".$fa."-04-01' and date <= '".$aa."-03-31')";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
}
|
|
function departmentwise($sid,$d,$c='',$fy,$ty)
|
|
{
|
|
$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 tinc.type='$c'";
|
|
if ($sid != ''){
|
|
$sql.="and account_code = '".$sid."'";
|
|
}
|
|
if ($d != ''){
|
|
$sql.="and monthname(date)='".$d."'";
|
|
}
|
|
if ($fy and $ty != ''){
|
|
|
|
$sql.=" and (tinc.date >= '".$fy."-04-01' and tinc.date <= '".$ty."-03-31')";
|
|
|
|
}
|
|
// -- WHERE account_code = '$sid' and monthname(date)='$d' and tinc.type='$c'";
|
|
$query = $this->db->query($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 getYearlyOpeningAmt($prev_year){
|
|
$sql="SELECT min(date),(sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0)) ) as opening_amt
|
|
FROM t_income_expense
|
|
WHERE date >= (select min(date) from t_income_expense) and date <= '".$prev_year."-03-31' ";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
//print_r($query->result());
|
|
|
|
}
|
|
|
|
//function monthbeforetotal($month,$year){
|
|
function getMonthlyOpeningAmt($dateformat){
|
|
|
|
$sql="SELECT month('".$dateformat."') as monthnum ,year('".$dateformat."') as yearnum,
|
|
(sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0))) as opening_amt
|
|
FROM t_income_expense
|
|
WHERE date >= (select min(date) from t_income_expense) and date <= '".$dateformat."'";
|
|
//WHERE month(date) between (select month(min(date)) from t_income_expense) and '".$month."' and year(date) = '".$year."'";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
|
//function daybeforetotal($yesterday){
|
|
function getDailyOpeningAmt($yesterday){
|
|
$sql="select date,(sum(if(type = 'RECEIPT',total,0)) - sum(if(type = 'PAYMENT',total,0))) as opening_amt
|
|
from t_income_expense
|
|
where date between (select min(date) from t_income_expense) and '".$yesterday."'";
|
|
$query = $this->db->query($sql);
|
|
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,tinc.type,
|
|
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();
|
|
|
|
}
|
|
|
|
function update_FiscalYear(){
|
|
if(date('m') >= 4) {
|
|
$d = date('Y-m-d', strtotime('+1 years'));
|
|
$arr = array('FiscalYearStartOn' => date('Y')."-04-01",
|
|
'FiscalYearEndsOn' => date('Y', strtotime($d))."-03-31");
|
|
} else {
|
|
$d = date('Y-m-d', strtotime('-1 years'));
|
|
$arr = array('FiscalYearStartOn' => date('Y', strtotime($d))."-04-01",
|
|
'FiscalYearEndsOn' => date('Y')."-03-31");
|
|
|
|
}
|
|
$this->db->where('CompID', "SI001");
|
|
$this->db->update('T_Company_Details',$arr);
|
|
}
|
|
}
|
|
?>
|