1031 lines
41 KiB
PHP
Executable File
1031 lines
41 KiB
PHP
Executable File
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class dahsboard_Model extends CI_Model
|
|
{
|
|
|
|
|
|
|
|
function totalpurchaseorder(){
|
|
|
|
|
|
$sql="select count(PONO) as totalpurchaseorder from T_PurchaseOrder_Master";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
}
|
|
function totalordervalue(){
|
|
|
|
|
|
$sql="select sum(totalordervalue) as totalordervalue from T_PurchaseOrder_Master";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
}
|
|
function pendingpo(){
|
|
|
|
|
|
$sql="select count(PONO) as pending from T_PurchaseOrder_Master where status='ST020'";
|
|
$query = $this->db->query($sql);
|
|
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;
|
|
|
|
while($i<=12){
|
|
|
|
$sql="SELECT count(cmast.PONO) as totalService 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
|
|
where ReqType='SERVICE' and month(PODate) = $i ";
|
|
|
|
$query = $this->db->query($sql);
|
|
$array_result[]=$query->result();
|
|
$i++;
|
|
|
|
}
|
|
|
|
return $array_result;
|
|
|
|
}
|
|
|
|
function getTotalimportPoCount(){
|
|
$i=1;
|
|
|
|
while($i<=12){
|
|
|
|
$sql="SELECT count(cmast.PONO) as totalImport 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
|
|
where ReqType='IMPORT' and month(PODate) = $i ";
|
|
|
|
$query = $this->db->query($sql);
|
|
$array_result[]=$query->result();
|
|
$i++;
|
|
|
|
}
|
|
|
|
return $array_result;
|
|
|
|
}
|
|
function getTotalcapitalPoCount(){
|
|
$i=1;
|
|
|
|
while($i<=12){
|
|
|
|
$sql="SELECT count(cmast.PONO) as totalcapital 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
|
|
where ReqType='CAPITAL' and month(PODate) = $i ";
|
|
|
|
$query = $this->db->query($sql);
|
|
$array_result[]=$query->result();
|
|
$i++;
|
|
|
|
}
|
|
|
|
return $array_result;
|
|
|
|
}
|
|
function getTotalrevenuePoCount(){
|
|
$i=1;
|
|
|
|
while($i<=12){
|
|
|
|
$sql="SELECT count(cmast.PONO) as totalrevenue 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
|
|
where ReqType='REVENUE' and month(PODate) = $i ";
|
|
|
|
$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 ()
|
|
{
|
|
$sql="SELECT ROUND(sum(BudgetAmount),2) as totalimportbudget FROM T_CostCenter_Budget where BudgetType ='IMPORT' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function importbal ()
|
|
{
|
|
$sql="SELECT ROUND(sum(BudgetAmount)-(SELECT
|
|
ifnull((sum(distinct(PO_Line_Item.Quantity * PO_Line_Item.Rate) * po.ExchangeRate)),0)
|
|
as Util_Amount
|
|
from T_CostCenter_Budget Cost_Center_Budget
|
|
join T_PurchaseOrder_LineItem PO_Line_Item on Cost_Center_Budget.CostCenterCode=PO_Line_Item.CostCenterCode
|
|
JOIN T_PurchaseOrder_Master po on po.PONO=PO_Line_Item.PONO and po.POType=Cost_Center_Budget.BudgetType
|
|
WHERE Cost_Center_Budget.BudgetType='IMPORT' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())),2) as balimportbudget FROM T_CostCenter_Budget where BudgetType ='IMPORT' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW()) ";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function capitalbud ()
|
|
{
|
|
$sql="SELECT sum(BudgetAmount) as totalcapitalbudget FROM T_CostCenter_Budget where BudgetType ='CAPITAL' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW()) ";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function capitalbal ()
|
|
{
|
|
$sql="SELECT ROUND(sum(BudgetAmount)-(SELECT
|
|
case po.CapitalRange
|
|
when '0'
|
|
then ifnull((sum(distinct(PO_Line_Item.Quantity * PO_Line_Item.Rate) * po.ExchangeRate)),0)
|
|
when '1'
|
|
then ifnull((sum(distinct PO_Line_Item.Quantity * PO_Line_Item.Rate)),0)
|
|
end
|
|
as Util_Amount
|
|
from T_CostCenter_Budget Cost_Center_Budget
|
|
join T_PurchaseOrder_LineItem PO_Line_Item on Cost_Center_Budget.CostCenterCode=PO_Line_Item.CostCenterCode
|
|
JOIN T_PurchaseOrder_Master po on po.PONO=PO_Line_Item.PONO and po.POType=Cost_Center_Budget.BudgetType
|
|
WHERE Cost_Center_Budget.BudgetType='CAPITAL' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())),2) as balcapitalbudget FROM T_CostCenter_Budget where BudgetType ='CAPITAL' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function servicebudgt ()
|
|
{
|
|
$sql="SELECT ROUND(sum(BudgetAmount),2) as totalservicebudget FROM T_CostCenter_Budget where BudgetType ='SERVICE' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function servicebal ()
|
|
{
|
|
$sql="SELECT ROUND(sum(BudgetAmount)-(SELECT
|
|
ifnull((sum(distinct PO_Line_Item.Quantity * PO_Line_Item.Rate)),0)
|
|
as Util_Amount
|
|
from T_CostCenter_Budget Cost_Center_Budget
|
|
join T_PurchaseOrder_LineItem PO_Line_Item on Cost_Center_Budget.CostCenterCode=PO_Line_Item.CostCenterCode
|
|
WHERE Cost_Center_Budget.BudgetType='SERVICE' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())),2) as balservicebudget FROM T_CostCenter_Budget where BudgetType ='SERVICE' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function revenuebudgt ()
|
|
{
|
|
$sql="SELECT ROUND(sum(BudgetAmount),2) as totalrevenuebudget FROM T_CostCenter_Budget where BudgetType ='REVENUE' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function revenuebal ()
|
|
{
|
|
$sql="SELECT ROUND(sum(BudgetAmount)-(SELECT
|
|
ifnull((sum(distinct PO_Line_Item.Quantity * PO_Line_Item.Rate) - sum(distinct T_Rev_Tax.AfterDiscount)),0)
|
|
as Util_Amount
|
|
from T_CostCenter_Budget Cost_Center_Budget
|
|
join T_PurchaseOrder_LineItem PO_Line_Item on Cost_Center_Budget.CostCenterCode=PO_Line_Item.CostCenterCode
|
|
JOIN T_Revenue_Tax T_Rev_Tax on PO_Line_Item.LineItemNo=T_Rev_Tax.LineItemNo
|
|
WHERE Cost_Center_Budget.BudgetType='REVENUE' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())),2) as balrevenuebudget FROM T_CostCenter_Budget where BudgetType ='REVENUE' and YEAR(STR_TO_DATE(`BudgetYear`,'%Y')) = YEAR(NOW())";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
function reqdetail(){
|
|
|
|
|
|
$sql="SELECT count(Status) as TODAY_REQUESTS FROM T_Requestion_Master where date(ReqDate) = date(now());";
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
// echo "from Model";
|
|
// print_r($query->result());
|
|
|
|
return $query->result();
|
|
|
|
|
|
|
|
}
|
|
|
|
function req_pending(){
|
|
|
|
|
|
$sql="SELECT count(Status) as TOTAL_PENDING_REQUESTS FROM T_Requestion_Master where Status = 'ST002';";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
|
|
|
|
}
|
|
|
|
function req_list(){
|
|
|
|
|
|
$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'
|
|
";
|
|
$query = $this->db->query($sql);
|
|
//print_r($this->db->last_query());
|
|
return $query->result();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
function report_relpo(){
|
|
|
|
|
|
$sql="select Mast.PONO,Mast.POType,date_format(Mast.CreatedDate,'%d-%m-%Y') as CreatedDate,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
|
|
JOIN T_Requestion_Master as Req on Req.ReqNo=Det.ReqNo
|
|
JOIN T_Employee_Details as Emp_Det on Emp_Det.EmpID=Req.RequestedBy
|
|
JOIN T_DepartmentDetails Dept_Details on Dept_Details.DEPCode=Emp_Det.Departmentcode
|
|
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'
|
|
group by Mast.PONO";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
|
|
|
|
}
|
|
|
|
function report_openpending(){
|
|
|
|
|
|
$sql="select Mast.PONO as PONO,Mast.POType as POType,date_format(Mast.CreatedDate,'%d-%m-%Y') as CreatedDate,date_format(Mast.ApprovedOn,'%d-%m-%Y') as ApprovedDate,Dept_Details.DepartmentName As Dept_Name,Mast.TotalOrderValue
|
|
from T_PurchaseOrder_Master Mast
|
|
JOIN T_PurchaseOrder_LineItem Det on Det.PONO=Mast.PONO
|
|
JOIN T_Requestion_Master as Req on Req.ReqNo=Det.ReqNo
|
|
JOIN T_Employee_Details as Emp_Det on Emp_Det.EmpID=Req.RequestedBy
|
|
JOIN T_DepartmentDetails Dept_Details on Dept_Details.DEPCode=Emp_Det.Departmentcode
|
|
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'
|
|
group by PONO,POType,Dept_Name";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
|
|
|
|
}
|
|
|
|
function report_total($fa,$aa){
|
|
|
|
|
|
$sql="select Dept_Details.DepartmentName As Dept_Name,
|
|
SUM(CASE WHEN Mast.Status = 'ST015' 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
|
|
JOIN T_Requestion_Master as Req on Req.ReqNo=Mast.ReqNo
|
|
JOIN T_Employee_Details as Emp_Det on Emp_Det.EmpID=Req.RequestedBy
|
|
JOIN T_DepartmentDetails Dept_Details on Dept_Details.DEPCode=Emp_Det.Departmentcode
|
|
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_Budget.CostCenterCode as Cost_Center_Code, CostCenterName as Cost_Center_Name,group_concat(distinct Dept_Details.DepartmentName) as Dept_Name,Cost_Center_Budget.BudgetType as BudgetType,Cost_Center_Budget.BudgetYear as BudgetYear,
|
|
case Cost_Center_Budget.BudgetType
|
|
when 'IMPORT'
|
|
then ifnull((sum(distinct(PO_Line_Item.Quantity * PO_Line_Item.Rate) * po.ExchangeRate)),0)
|
|
when 'CAPITAL'
|
|
then ifnull(sum(distinct if(CapitalRange=0,(( PO_Line_Item.Quantity * PO_Line_Item.Rate) * po.ExchangeRate),( PO_Line_Item.Quantity * PO_Line_Item.Rate) - st.Afterdiscountval)),0)
|
|
when 'SERVICE'
|
|
then ifnull((sum(distinct PO_Line_Item.Quantity * PO_Line_Item.Rate)),0)
|
|
when 'REVENUE'
|
|
then ifnull((sum(distinct PO_Line_Item.Quantity * PO_Line_Item.Rate) - sum(distinct T_Rev_Tax.AfterDiscount)),0)
|
|
end
|
|
as Util_Amount,
|
|
case Cost_Center_Budget.BudgetType
|
|
when 'IMPORT'
|
|
then (Cost_Center_Budget.BudgetAmount - ifnull((sum(distinct(PO_Line_Item.Quantity * PO_Line_Item.Rate) * po.ExchangeRate)),0))
|
|
when 'CAPITAL'
|
|
then (Cost_Center_Budget.BudgetAmount - ifnull(sum(distinct if(CapitalRange=0,(( PO_Line_Item.Quantity * PO_Line_Item.Rate) * po.ExchangeRate),( PO_Line_Item.Quantity * PO_Line_Item.Rate) - st.Afterdiscountval)),0))
|
|
when 'SERVICE'
|
|
then (Cost_Center_Budget.BudgetAmount - ifnull((sum(distinct PO_Line_Item.Quantity * PO_Line_Item.Rate)),0))
|
|
when 'REVENUE'
|
|
then (Cost_Center_Budget.BudgetAmount - ifnull((sum(distinct PO_Line_Item.Quantity * PO_Line_Item.Rate) - sum(distinct T_Rev_Tax.AfterDiscount)),0))
|
|
end
|
|
as Avlbl_Amt
|
|
from T_CostCenter_Budget Cost_Center_Budget
|
|
left join T_PurchaseOrder_LineItem PO_Line_Item on Cost_Center_Budget.CostCenterCode=PO_Line_Item.CostCenterCode
|
|
left JOIN T_PurchaseOrder_Master po on po.PONO=PO_Line_Item.PONO and po.Status !='ST030'
|
|
left JOIN T_Revenue_Tax T_Rev_Tax on PO_Line_Item.LineItemNo=T_Rev_Tax.LineItemNo
|
|
JOIN T_CostCenter_Master Cost_Mast on Cost_Center_Budget.CostCenterCode=Cost_Mast.CostCenterCode
|
|
JOIN T_CostCenter_Departments CostCentDept on CostCentDept.CostCenterCode=Cost_Mast.CostCenterCode
|
|
JOIN T_DepartmentDetails Dept_Details on Dept_Details.DEPCode= CostCentDept.DEPCode
|
|
left JOIN T_Service_Tax st on st.LineItemNo = PO_Line_Item.LineItemNo
|
|
WHERE Cost_Center_Budget.BudgetType = po.POType and date(po.CreatedDate) >= '".$fa."-04-01' and date(po.CreatedDate) <= '".$aa."-03-31'
|
|
group by
|
|
Cost_Center_Budget.CostCenterCode,Cost_Center_Budget.BudgetYear,Cost_Center_Budget.BudgetType
|
|
order by Cost_Center_Budget.CostCenterCode";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
function report_MMSupplier(){
|
|
|
|
|
|
$sql="select po.CreatedDate 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(){
|
|
|
|
|
|
$sql="select
|
|
DATE_FORMAT(IF(matv.CreatedDate = '0000-00-00', NOW(), matv.CreatedDate), '%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_MaterialMaster mat on matv.MaterialCode=mat.MaterialCode
|
|
group by matv.MaterialCode
|
|
order by monthname(matv.CreatedDate)";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
|
|
|
|
}
|
|
function report_purchase($cname,$prod,$fa,$aa,$m,$frm,$t){
|
|
|
|
|
|
$sql="SELECT pm.PONO as pono,date_format(pm.CreatedDate,'%d-%m-%Y') as created_date,
|
|
TIME_FORMAT(pm.CreatedDate,'%l:%i %p') as created_time,
|
|
mm.MaterialName as material_name,sd.SupplierName as supplier_name,
|
|
ifnull(sum(pl.Quantity),0) as quantity,mm.UOM as UOM,ifnull(sum(pl.Rate),0) as rate,
|
|
round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as value,
|
|
if(POType = 'IMPORT' or POType = 'CAPITAL',sum(pm.ExchangeRate),0) as exchange_rate,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterSGST),sum(st.After_SGST)),0) as sgst,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterCGST),sum(st.After_CGST)),0) as cgst,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterIGST),sum(st.After_IGST)),0) as igst,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterDiscount),sum(st.Afterdiscountval)),0) as discount,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterFreightValue),sum(st.AfterFreightValue)),0) as freight,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterPackagingValue),0),0) as Package,
|
|
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(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' ";
|
|
|
|
if ($cname!= ''){
|
|
|
|
$sql.="and sd.SupplierName = '".$cname."'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (pm.CreatedDate >= '".$fa."-04-01' and pm.CreatedDate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
if ($m!= ''){
|
|
|
|
$sql.="and monthname(pm.CreatedDate) = '".$m."'";
|
|
|
|
}
|
|
|
|
if ($frm and $t != ''){
|
|
$fromd= date("Y-m-d",strtotime($frm));
|
|
$tod=date("Y-m-d",strtotime($t));
|
|
|
|
$sql.="and date(pm.CreatedDate) >= '".$fromd."'
|
|
and date(pm.CreatedDate) <= '".$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,date_format(pm.CreatedDate,'%d-%m-%Y') as created_date,
|
|
TIME_FORMAT(pm.CreatedDate,'%l:%i %p') as created_time,
|
|
mm.MaterialName as material_name,sd.SupplierName as supplier_name,
|
|
ifnull(sum(pl.Quantity),0) as quantity,mm.UOM as UOM,ifnull(sum(pl.Rate),0) as rate,
|
|
round(ifnull(sum(pl.Quantity * pl.Rate),0),2) as value,
|
|
if(POType = 'IMPORT' or POType = 'CAPITAL',sum(pm.ExchangeRate),0) as exchange_rate,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterSGST),sum(st.After_SGST)),0) as sgst,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterCGST),sum(st.After_CGST)),0) as cgst,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterIGST),sum(st.After_IGST)),0) as igst,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterDiscount),sum(st.Afterdiscountval)),0) as discount,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterFreightValue),sum(st.AfterFreightValue)),0) as freight,
|
|
ifnull(if(POType = 'REVENUE',sum(rt.AfterPackagingValue),0),0) as Package,
|
|
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(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' ";
|
|
|
|
if ($cname!= ''){
|
|
|
|
$sql.="and sd.SupplierName = '".$cname."'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (pm.CreatedDate >= '".$fa."-04-01' and pm.CreatedDate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
if ($m!= ''){
|
|
|
|
$sql.="and monthname(pm.CreatedDate) = '".$m."'";
|
|
|
|
}
|
|
|
|
if ($frm and $t != ''){
|
|
$fromd= date("Y-m-d",strtotime($frm));
|
|
$tod=date("Y-m-d",strtotime($t));
|
|
|
|
$sql.="and date(pm.CreatedDate) >= '".$fromd."'
|
|
and date(pm.CreatedDate) <= '".$tod."'";
|
|
|
|
}
|
|
if ($prod!= ''){
|
|
|
|
$sql.=" and mm.MaterialName = '".$prod."' ";
|
|
|
|
}
|
|
if ($sid!= ''){
|
|
|
|
$sql.=" and sd.SupplierID = '".$sid."' ";
|
|
|
|
}
|
|
if ($mid!= ''){
|
|
|
|
$sql.=" and mm.MaterialCode = '".$mid."' ";
|
|
|
|
}
|
|
if ($d!= ''){
|
|
|
|
$sql.=" and date(pm.CreatedDate) = '".$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(CreatedDate)>=4 THEN
|
|
concat(YEAR(CreatedDate), '-',YEAR(CreatedDate)+1)
|
|
ELSE concat(YEAR(CreatedDate)-1,'-', YEAR(CreatedDate)) END AS financial_year
|
|
FROM T_PurchaseOrder_Master
|
|
GROUP BY financial_year";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
|
|
|
|
}
|
|
function report_year_wise(){
|
|
|
|
|
|
$sql="SELECT sd.SupplierID as sid,mm.MaterialCode as mid,pm.CreatedDate 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
|
|
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'
|
|
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 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 sd.SupplierName is not null and month(pm.CreatedDate)= ? and year(pm.CreatedDate) = ?
|
|
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 sd.SupplierName is not null and date(pm.CreatedDate) >= '$a-04-01' and date(pm.CreatedDate) <= '$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)
|
|
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)
|
|
|
|
|
|
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(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)
|
|
|
|
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' ";
|
|
|
|
if ($cname!= ''){
|
|
|
|
$sql.="and sd.SupplierName = '".$cname."'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (pm.CreatedDate >= '".$fa."-04-01' and pm.CreatedDate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
if ($m!= ''){
|
|
|
|
$sql.="and monthname(pm.CreatedDate) = '".$m."'";
|
|
|
|
}
|
|
|
|
if ($frm and $t != ''){
|
|
$fromd= date("Y-m-d",strtotime($frm));
|
|
$tod=date("Y-m-d",strtotime($t));
|
|
|
|
$sql.="and date(pm.CreatedDate) >= '".$fromd."'
|
|
and date(pm.CreatedDate) <= '".$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.CreatedDate) = 4, pl.Quantity, 0)) AS April,
|
|
SUM(IF(month(pm.CreatedDate) = 5, pl.Quantity, 0)) AS May,
|
|
SUM(IF(month(pm.CreatedDate) = 6, pl.Quantity, 0)) AS June,
|
|
SUM(IF(month(pm.CreatedDate) = 7, pl.Quantity, 0)) AS July,
|
|
SUM(IF(month(pm.CreatedDate) = 8, pl.Quantity, 0)) AS August,
|
|
SUM(IF(month(pm.CreatedDate) = 9, pl.Quantity, 0)) AS September,
|
|
SUM(IF(month(pm.CreatedDate) = 10, pl.Quantity, 0)) AS October,
|
|
SUM(IF(month(pm.CreatedDate) = 11, pl.Quantity, 0)) AS November,
|
|
SUM(IF(month(pm.CreatedDate) = 12, pl.Quantity, 0)) AS December,
|
|
SUM(IF(month(pm.CreatedDate) = 1, pl.Quantity, 0)) AS January,
|
|
SUM(IF(month(pm.CreatedDate) = 2, pl.Quantity, 0)) AS February,
|
|
SUM(IF(month(pm.CreatedDate) = 3, pl.Quantity, 0)) AS March,
|
|
sum(pl.Quantity) as qtotal,
|
|
SUM(IF(month(pm.CreatedDate) = 4, pl.Quantity * pl.Rate, 0)) AS vApril,
|
|
SUM(IF(month(pm.CreatedDate) = 5, pl.Quantity * pl.Rate, 0)) AS vMay,
|
|
SUM(IF(month(pm.CreatedDate) = 6, pl.Quantity * pl.Rate, 0)) AS vJune,
|
|
SUM(IF(month(pm.CreatedDate) = 7, pl.Quantity * pl.Rate, 0)) AS vJuly,
|
|
SUM(IF(month(pm.CreatedDate) = 8, pl.Quantity * pl.Rate, 0)) AS vAugust,
|
|
SUM(IF(month(pm.CreatedDate) = 9, pl.Quantity * pl.Rate, 0)) AS vSeptember,
|
|
SUM(IF(month(pm.CreatedDate) = 10, pl.Quantity * pl.Rate, 0)) AS vOctober,
|
|
SUM(IF(month(pm.CreatedDate) = 11, pl.Quantity * pl.Rate, 0)) AS vNovember,
|
|
SUM(IF(month(pm.CreatedDate) = 12, pl.Quantity * pl.Rate, 0)) AS vDecember,
|
|
SUM(IF(month(pm.CreatedDate) = 1, pl.Quantity * pl.Rate, 0)) AS vJanuary,
|
|
SUM(IF(month(pm.CreatedDate) = 2, pl.Quantity * pl.Rate, 0)) AS vFebruary,
|
|
SUM(IF(month(pm.CreatedDate) = 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' ";
|
|
|
|
if ($cname!= ''){
|
|
|
|
$sql.="and sd.SupplierName = '".$cname."'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($fa and $aa != ''){
|
|
|
|
$sql.=" and (pm.CreatedDate >= '".$fa."-04-01' and pm.CreatedDate <= '".$aa."-03-31')";
|
|
|
|
}
|
|
|
|
$sql.= "group by supplier_name,material_name";
|
|
//echo $sql;
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
}
|
|
function report_cumulative(){
|
|
|
|
$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 sd.SupplierName is not null and
|
|
case
|
|
when (month(pm.CreatedDate) >=4) then
|
|
(YEAR(pm.CreatedDate) = YEAR(CURRENT_DATE) and MONTH(pm.CreatedDate) >= 4 ) or ( YEAR(pm.CreatedDate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.CreatedDate) <= 3 )
|
|
else
|
|
(YEAR(pm.CreatedDate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.CreatedDate) >= 4 ) or ( YEAR(pm.CreatedDate) = YEAR(CURRENT_DATE) and MONTH(pm.CreatedDate) <= 3 )
|
|
end
|
|
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 sd.SupplierName is not null and
|
|
month(pm.CreatedDate) = 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 sd.SupplierName is not null and
|
|
date(pm.CreatedDate) = 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 sd.SupplierName is not null and month(pm.CreatedDate) = 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){
|
|
|
|
$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 sd.SupplierName is not null and
|
|
case
|
|
when (month(pm.CreatedDate) >=4) then
|
|
(YEAR(pm.CreatedDate) = YEAR(CURRENT_DATE) and MONTH(pm.CreatedDate) >= 4 ) or ( YEAR(pm.CreatedDate) = YEAR(CURRENT_DATE)+1 and MONTH(pm.CreatedDate) <= 3 )
|
|
else
|
|
(YEAR(pm.CreatedDate) = YEAR(CURRENT_DATE)-1 and MONTH(pm.CreatedDate) >= 4 ) or ( YEAR(pm.CreatedDate) = YEAR(CURRENT_DATE) and MONTH(pm.CreatedDate) <= 3 )
|
|
end
|
|
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 sd.SupplierName is not null and
|
|
date(pm.CreatedDate) = 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 cashbook()
|
|
{
|
|
$sql="SELECT date,type,total,towhom,description,account_code FROM kasiram9_SIADEV.t_income_expense";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
}
|
|
// function monthincomereport()
|
|
// {
|
|
// $sql="SELECT date,type,sum(total)as total,towhom,description,account_code FROM kasiram9_SIADEV.t_income_expense where type='INCOME' and month(date)= month(current_date()) group by account_code order by total desc limit 10 ";
|
|
// $query = $this->db->query($sql);
|
|
// //echo $query;
|
|
// return $query->result();
|
|
|
|
// }
|
|
function monthexpensereport()
|
|
{
|
|
$sql="SELECT date,type,sum(total)as total,towhom,description,account_code FROM kasiram9_SIADEV.t_income_expense where type='EXPENSE' and month(date)= month(current_date()) group by account_code order by total desc limit 10 ";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
}
|
|
// function yearincomereport()
|
|
// {
|
|
// $sql="SELECT date,type,sum(total)as total,towhom,description,account_code FROM kasiram9_SIADEV.t_income_expense where type='INCOME' and year(date)= year(current_date()) group by account_code order by total desc limit 10 ";
|
|
// $query = $this->db->query($sql);
|
|
// return $query->result();
|
|
|
|
// }
|
|
function yearexpensereport()
|
|
{
|
|
$sql="SELECT date,type,sum(total)as total,towhom,description,account_code,monthname(date)as month FROM kasiram9_SIADEV.t_income_expense where type='EXPENSE' and year(date)= year(current_date()) group by month order by total desc limit 10 ";
|
|
$query = $this->db->query($sql);
|
|
return $query->result();
|
|
|
|
}
|
|
function today_data($value='')
|
|
{
|
|
$sql="SELECT type,Sum(total) as todaydata FROM kasiram9_SIADEV.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 kasiram9_SIADEV.t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())";
|
|
$query = $this->db->query($sql,array($value));
|
|
return $query->result();
|
|
|
|
}
|
|
function yearwise_data($value='')
|
|
{
|
|
|
|
$sql="SELECT type,sum(total) as yearlydata from t_income_expense
|
|
where
|
|
type = ? and ((YEAR(date) = YEAR(CURRENT_DATE) and MONTH(date) >= 4) or (YEAR(date) = YEAR(CURRENT_DATE)+1 and MONTH(date) <= 3))";
|
|
$query = $this->db->query($sql,array($value));
|
|
return $query->result();
|
|
|
|
}
|
|
function departmentwise($sid='')
|
|
{
|
|
$sql="SELECT date,type,total,towhom,description,account_code FROM t_income_expense WHERE account_code = ?";
|
|
$query = $this->db->query($sql,array($sid));
|
|
//print_r($this->db->last_query());
|
|
return $query->result();
|
|
|
|
}
|
|
function yearmonthwise($sid='')
|
|
{
|
|
$sql="SELECT date,type,total,description,towhom,account_code FROM t_income_expense WHERE monthname(date) = ? group by account_code";
|
|
$query = $this->db->query($sql,array($sid));
|
|
//print_r($this->db->last_query());
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
?>zz
|