siddharth_application/application/models/dahsboard_model.php
2017-11-24 18:29:09 +05:30

603 lines
21 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 totalcapitalpo ()
{
$sql="SELECT count(cmast.PONO) as totalcapitalpo 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'";
$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,Mast.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 Dept_Name";
$query = $this->db->query($sql);
return $query->result();
}
function report_total(){
$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
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
group by Dept_Name";
$query = $this->db->query($sql);
return $query->result();
}
function report_ccr(){
$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( PO_Line_Item.Quantity * PO_Line_Item.Rate) * if (po.ExchangeRate is null or po.ExchangeRate = '',1,po.ExchangeRate) ),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( PO_Line_Item.Quantity * PO_Line_Item.Rate) * if (po.ExchangeRate is null or po.ExchangeRate = '',1,po.ExchangeRate) ),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
WHERE Cost_Center_Budget.BudgetType = po.POType and DATE(Cost_Center_Budget.CreatedDate) BETWEEN '2017-04-01' AND '2018-03-31'
group by
Cost_Center_Budget.BudgetYear,Cost_Center_Budget.CostCenterCode,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 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(pl.Quantity,0) as quantity,ifnull(pl.Rate,0) as rate,round(ifnull((pl.Quantity * pl.Rate),0),2) as value,ifnull(st.After_SGST,0) as sgst,ifnull(st.After_CGST,0) as cgst,ifnull(st.After_IGST,0) as igst,round((ifnull((pl.Quantity * pl.Rate),0) + ifnull(st.After_SGST,0) + ifnull(st.After_CGST,0) + ifnull(st.After_IGST,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.PONO>'0' ";
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.="order by pono";
//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 pm.CreatedDate as created_date,ifnull(sum(pl.Quantity),0) as quantity,round((ifnull(sum(pl.Quantity * pl.Rate),0) + ifnull(sum(st.After_SGST),0) + ifnull(sum(st.After_CGST),0) + ifnull(sum(st.After_IGST),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
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.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,pl.Quantity as quantity,round((ifnull((pl.Quantity * pl.Rate),0) + ifnull(st.After_SGST,0) + ifnull(st.After_CGST,0) + ifnull(st.After_IGST,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 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.SupplierName as supplier_name,ifnull(mm.MaterialName,'-') as material_name,pl.Quantity as quantity,round((ifnull((pl.Quantity * pl.Rate),0) + ifnull(st.After_SGST,0) + ifnull(st.After_CGST,0) + ifnull(st.After_IGST,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 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.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,round(sum(ifnull((pl.Quantity * pl.Rate),0) + ifnull(st.After_SGST,0) + ifnull(st.After_CGST,0) + ifnull(st.After_IGST,0)),2) as total
FROM T_PurchaseOrder_Master pm
join T_PurchaseOrder_LineItem pl on pl.PONO = pm.PONO
join T_SupplierDetailsN sd on sd.SupplierID = pm.SupplierID
left join T_Service_Tax st on st.LineItemNo = pl.LineItemNo
where
pm.PONO>'0' ";
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();
}
}
?>