From 34e3f0a56a40ecf8e8871836c552cd521d27840a Mon Sep 17 00:00:00 2001 From: "venbatechnologies@gmail.com" Date: Tue, 24 Apr 2018 16:18:00 +0530 Subject: [PATCH] changes in dashboard model --- application/models/dahsboard_model.php | 361 +++++++++++++------------ 1 file changed, 192 insertions(+), 169 deletions(-) diff --git a/application/models/dahsboard_model.php b/application/models/dahsboard_model.php index 7a6c04b5..87a583e9 100755 --- a/application/models/dahsboard_model.php +++ b/application/models/dahsboard_model.php @@ -2,6 +2,14 @@ class dahsboard_Model extends CI_Model { + function getUserCount() + { + + $sql="select count(userId) as users FROM tbl_users where isDeleted ='0'"; + $query =$this->db->query($sql); + return $query->result(); + + } /* HR DASHBOART Model START*/ @@ -895,7 +903,6 @@ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IG 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)), @@ -905,7 +912,6 @@ ifnull(sum(pl.Quantity * pl.Rate),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 @@ -971,7 +977,6 @@ ifnull(if(POType = 'REVENUE',sum(distinct rt.AfterIGST),sum(distinct st.After_IG 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)), @@ -981,7 +986,6 @@ ifnull(sum(pl.Quantity * pl.Rate),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 @@ -1131,7 +1135,8 @@ group by supplier_name,material_name"; case pm.POType when 'IMPORT' then ifnull((sum(distinct(pl.Quantity * pl.Rate) * pm.ExchangeRate) -),0) + ifnull(rt.Insurance,0) + +),0) when 'CAPITAL' then sum(distinct if(pm.CapitalRange=0,(( pl.Quantity * pl.Rate) * pm.ExchangeRate),( pl.Quantity * pl.Rate) - st.Afterdiscountval)) @@ -1139,7 +1144,6 @@ then sum(distinct if(pm.CapitalRange=0,(( pl.Quantity * pl.Rate) * pm.ExchangeR + 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' @@ -1148,7 +1152,6 @@ then ifnull(sum(distinct pl.Quantity * pl.Rate),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' @@ -1159,7 +1162,6 @@ then ifnull(sum(distinct pl.Quantity * pl.Rate),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 @@ -1398,56 +1400,32 @@ group by supplier_name,material_name"; function ireport_purchase($cname,$prod,$fa,$aa,$m,$frm,$t,$cat){ - $sql="select im.IGRNO as igrn,pm.POType as potype,im.PONO as pono,date_format(im.CreatedDate,'%d-%m-%Y') as created_date,TIME_FORMAT(im.CreatedDate,'%l:%i %p') as created_time,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, sum(id.QuantityAsPerInvoice) as quantity,pl.Rate as rate,round(sum(id.QuantityAsPerInvoice) * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',sum(pm.ExchangeRate),0) as exchange_rate, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2) as discount, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) as freight, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) as Package, - + $sql="select im.IGRNO as igrn,im.PONO as pono,pm.POType as potype,date_format(im.CreatedDate,'%d-%m-%Y') as created_date,TIME_FORMAT(im.CreatedDate,'%l:%i %p') as created_time,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, sum(distinct id.QuantityAsPerInvoice) as quantity,pl.Rate as rate,sum(distinct id.QuantityAsPerInvoice) * pl.Rate 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, round(( - if(POType = 'IMPORT',sum(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), -if(POType = 'CAPITAL' && CapitalRange = 0,sum(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), -ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0))) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) -- round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total, -pb.FilePath as file + if(POType = 'IMPORT',sum(distinct pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), +if(POType = 'CAPITAL' && CapitalRange = 0,sum(distinct pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), +ifnull(sum(distinct id.QuantityAsPerInvoice * 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,pb.FilePath as file from T_IGR_Master im +join T_IGR_Details id on id.IGRNO = im.IGRNO 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_PurchaseOrder_BillUpload pb on pb.PONO=pm.PONO where pm.Status != 'ST030' "; if ($cname!= ''){ @@ -1495,59 +1473,35 @@ $sql.="group by pono,material_name,category,supplier_name"; $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){ + function ireport_purchase_link($cname,$prod,$fa,$aa,$m,$frm,$t,$sid,$mid,$d,$cat){ - $sql="select im.IGRNO as igrn,pm.POType as potype,im.PONO as pono,date_format(im.CreatedDate,'%d-%m-%Y') as created_date,TIME_FORMAT(im.CreatedDate,'%l:%i %p') as created_time,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, sum(id.QuantityAsPerInvoice) as quantity,pl.Rate as rate,round(sum(id.QuantityAsPerInvoice) * pl.Rate,2) as value,if(POType = 'IMPORT' or POType = 'CAPITAL',sum(pm.ExchangeRate),0) as exchange_rate, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) as sgst, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) as cgst, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) as igst, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2) as discount, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity), -sum(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) as freight, -round(ifnull(if(POType = 'REVENUE', -sum(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) as Package, - + $sql="select im.IGRNO as igrn,im.PONO as pono,pm.POType as potype,date_format(im.CreatedDate,'%d-%m-%Y') as created_date,TIME_FORMAT(im.CreatedDate,'%l:%i %p') as created_time,mm.MaterialName as material_name,mm.Category as category,sd.SupplierName as supplier_name,mm.UOM as UOM, sum(distinct id.QuantityAsPerInvoice) as quantity,pl.Rate as rate,sum(distinct id.QuantityAsPerInvoice) * pl.Rate 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, round(( - if(POType = 'IMPORT',sum(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), -if(POType = 'CAPITAL' && CapitalRange = 0,sum(pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), -ifnull(sum(id.QuantityAsPerInvoice * pl.Rate),0))) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterSGST / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.After_SGST / pl.Quantity)),0),2) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterCGST / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.After_CGST / pl.Quantity)),0),2) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterIGST / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.After_IGST / pl.Quantity)),0),2) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterFreightValue / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.AfterFreightValue / pl.Quantity)),0),2) -+ round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterPackagingValue / pl.Quantity),0),0),2) -- round(ifnull(if(POType = 'REVENUE', - sum(id.QuantityAsPerInvoice * rt.AfterDiscount / pl.Quantity), - sum(id.QuantityAsPerInvoice * st.Afterdiscountval / pl.Quantity)),0),2)),2) as total, -pb.FilePath as file + if(POType = 'IMPORT',sum(distinct pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), +if(POType = 'CAPITAL' && CapitalRange = 0,sum(distinct pm.ExchangeRate * (id.QuantityAsPerInvoice * pl.Rate)), +ifnull(sum(distinct id.QuantityAsPerInvoice * 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,pb.FilePath as file from T_IGR_Master im +join T_IGR_Details id on id.IGRNO = im.IGRNO 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_PurchaseOrder_BillUpload pb on pb.PONO=pm.PONO where pm.Status != 'ST030' "; if ($cname!= ''){ @@ -1601,16 +1555,6 @@ if ($cname!= ''){ $sql.=" and mm.Category = '".$cat."' "; - } - if ($da!= ''){ - $ddd= date("Y-m-d",strtotime($da)); - $sql.=" and date(im.CreatedDate) = '".$ddd."' "; - - } - if ($po!= ''){ - - $sql.=" and im.PONO = '".$po."' "; - } @@ -1622,51 +1566,53 @@ $sql.="group by pono,material_name,category,supplier_name"; $query = $this->db->query($sql); return $query->result(); } - function ireport_attachment($cname,$fa,$aa,$m,$frm,$t){ + + + function ireport_attachment($cname,$fa,$aa,$m,$frm,$t){ - $sql="select pono,potype,date_format(created_date,'%d-%m-%Y') as created_date,supplier_name, + $sql="select pono,potype,date_format(created_date,'%d-%m-%Y') as created_date,supplier_name, sum(total) as total,file from igr where status != 'ST030' "; if ($cname!= ''){ + + $sql.="and supplier_name = '".$cname."'"; - $sql.="and supplier_name = '".$cname."'"; - - } - - - - if ($fa and $aa != ''){ + } - $sql.=" and (created_date >= '".$fa."-04-01' and created_date <= '".$aa."-03-31')"; - - } - if ($m!= ''){ - $sql.="and monthname(created_date) = '".$m."'"; - - } - - if ($frm and $t != ''){ - $fromd= date("Y-m-d",strtotime($frm)); - $tod=date("Y-m-d",strtotime($t)); - $sql.="and date(created_date) >= '".$fromd."' - and date(created_date) <= '".$tod."'"; - - } + if ($fa and $aa != ''){ + + $sql.=" and (created_date >= '".$fa."-04-01' and created_date <= '".$aa."-03-31')"; - $sql.="group by pono"; + } + if ($m!= ''){ + + $sql.="and monthname(created_date) = '".$m."'"; + + } + + if ($frm and $t != ''){ + $fromd= date("Y-m-d",strtotime($frm)); + $tod=date("Y-m-d",strtotime($t)); + + $sql.="and date(created_date) >= '".$fromd."' + and date(created_date) <= '".$tod."'"; + + } + + $sql.="group by pono"; // echo $m; // echo $sid; //echo $sql; - $query = $this->db->query($sql); - return $query->result(); - } - + $query = $this->db->query($sql); + return $query->result(); + } + function ireport_year_wise($a,$b){ @@ -1707,55 +1653,51 @@ group by material_name,supplier_name"; 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, + $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) +then ifnull((sum(distinct(id.QuantityAsPerInvoice * pl.Rate) * pm.ExchangeRate) ),0) when 'CAPITAL' -then sum( if(pm.CapitalRange=0,(( id.QuantityAsPerInvoice * pl.Rate) * pm.ExchangeRate),( id.QuantityAsPerInvoice * pl.Rate) +then sum(distinct 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) ++ 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(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) +then ifnull(sum(distinct id.QuantityAsPerInvoice * 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(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) +then ifnull(sum(distinct id.QuantityAsPerInvoice * 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_IGR_Master im +from T_IGR_Master im +join T_IGR_Details id on id.IGRNO = im.IGRNO 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'"; +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.PONO=pm.PONO +where pm.Status != 'ST030' "; if ($cname!= ''){ @@ -2207,17 +2149,42 @@ if ($cname!= ''){ $query = $this->db->query($sql); return $query->result(); + } + function month_incexp_report($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"; + $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 "; + 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(); @@ -2234,7 +2201,8 @@ if ($cname!= ''){ function monthwise_data($value='') { - $sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate())"; + $sql="SELECT type,Sum(total) as monthlydata FROM t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate()) AND YEAR(date) = YEAR(curdate())"; + //$sql="SELECT type,Sum(total) as monthlydata FROM resicoin_RIADev.t_income_expense WHERE type = ? AND MONTH(date) = MONTH(curdate()) And YEAR(date) = YEAR(curdate())" $query = $this->db->query($sql,array($value)); return $query->result(); @@ -2446,6 +2414,61 @@ function INRSymbol() //echo $sql; return $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 minmaxdatevalue(){ + $sql="SELECT MAX(date) AS Max_Date, MIN(date) AS Min_Date + FROM t_income_expense"; + $query = $this->db->query($sql); + return $query->result(); + } + + // function monthbeforetotal($mindate,$maxdate){ + + // $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 BETWEEN ? AND ? "; + // $query = $this->db->query($sql,array($mindate,$maxdate)); + // 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($prefy,$fa){ + $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 >= '".$prefy."-04-01' and date <= '".$fa."-03-31'"; + $query = $this->db->query($sql); + return $query->result(); + //print_r($query->result()); + + } + } ?> \ No newline at end of file