From a95d17b15d8b48e603bdd8ac5bfdbf025bf5515c Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Mon, 27 Jan 2025 17:39:30 +0530 Subject: [PATCH] GWM --- app/Models/Inwardgateregister_model.php | 82 +++++++++++++++++-------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/app/Models/Inwardgateregister_model.php b/app/Models/Inwardgateregister_model.php index a6af106c..ef94a74d 100755 --- a/app/Models/Inwardgateregister_model.php +++ b/app/Models/Inwardgateregister_model.php @@ -372,35 +372,67 @@ class Inwardgateregister_model extends Model function ViewigrListing($fromDate,$toDate) { - - $builder = $this->db->table('t_igr_master igr') - ->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName , SUM(IGRD.QuantityAsPerInvoice) as ReceivedQuantity, SUM(IGRD.NetWeight) as NetWeight , count(IGRD.IGRNo) as itemCount , count(remark.id) as remark_count') - ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO') - ->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID') - ->join('t_transporter trans', 'igr.TransporterId = trans.id' , 'left') + $subQuery = $this->db->table('t_igr_remarkes') + ->select('COUNT(id)') + ->where('igr_no = igr.IGRNo') + ->getCompiledSelect(); + + $builder = $this->db->table('t_igr_master igr') + ->select("igr.*, PO.IsOpenOrder, PO.DeliveryDate, sup.SupplierName, PO.POType, + trans.name as TransporterName, + SUM(IGRD.QuantityAsPerInvoice) as ReceivedQuantity, + SUM(IGRD.NetWeight) as NetWeight, + COUNT(IGRD.IGRNo) as itemCount, + COALESCE(($subQuery), 0) as remark_count") // COALESCE to handle no matches + ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO') + ->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID') + ->join('t_transporter trans', 'igr.TransporterId = trans.id', 'left') ->join('t_igr_details IGRD', 'igr.IGRNo = IGRD.IGRNo') - ->join('t_igr_remarkes remark', 'igr.IGRNo = remark.igr_no', 'left') - ->where('igr.IGRStatus !=', MRIR_CREATED) - ->where('Date(igr.CreatedDate) >=',"$fromDate") + ->where('igr.IGRStatus !=', MRIR_CREATED) + ->where('Date(igr.CreatedDate) >=', "$fromDate") ->where('Date(igr.CreatedDate) <=', "$toDate") - ->groupBy('igr.IGRNo') - ->orderBy('igr.CreatedDate', 'desc'); - $query = $builder->get(); - $result = $query->getResult(); - - $builder2 = $this->db->table('t_igr_details igr_details') - ->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName,item.MaterialName, igr_details.QuantityAsPerInvoice as ReceivedQuantity , igr_details.NetWeight as NetWeight') - ->join('t_igr_master igr', 'igr_details.IGRNo = igr.IGRNo') - ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO') - ->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID') - ->join('t_transporter trans', 'igr.TransporterId = trans.id' , 'left') - ->join('t_materialmaster` item', 'igr_details.MaterialCode = item.MaterialCode' , 'left') - ->where('igr.IGRStatus !=', MRIR_CREATED) + // ->where('igr.IGRNo', "IGRNO-1627") + ->groupBy('IGRD.IGRNo') ->orderBy('igr.CreatedDate', 'desc'); - $query2 = $builder2->get(); - $result2 = $query2->getResult(); + + $query = $builder->get(); + $result = $query->getResult(); + + + + // old - issue in t_igr_remarkes join + // $builder = $this->db->table('t_igr_master igr') + // ->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName , SUM(IGRD.QuantityAsPerInvoice) as ReceivedQuantity, SUM(IGRD.NetWeight) as NetWeight , count(IGRD.IGRNo) as itemCount , count(remark.id) as remark_count') + // ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO') + // ->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID') + // ->join('t_transporter trans', 'igr.TransporterId = trans.id' , 'left') + // ->join('t_igr_details IGRD', 'igr.IGRNo = IGRD.IGRNo') + // ->join('t_igr_remarkes remark', 'igr.IGRNo = remark.igr_no', 'left') + // ->where('igr.IGRStatus !=', MRIR_CREATED) + // ->where('Date(igr.CreatedDate) >=',"$fromDate") + // ->where('Date(igr.CreatedDate) <=', "$toDate") + // ->where('igr.IGRNo', "IGRNO-1627") + // ->groupBy('IGRD.IGRNo') + // ->orderBy('igr.CreatedDate', 'desc'); + // $query = $builder->get(); + // $result = $query->getResult(); + + + + + // $builder2 = $this->db->table('t_igr_details igr_details') + // ->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName,item.MaterialName, igr_details.QuantityAsPerInvoice as ReceivedQuantity , igr_details.NetWeight as NetWeight') + // ->join('t_igr_master igr', 'igr_details.IGRNo = igr.IGRNo') + // ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO') + // ->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID') + // ->join('t_transporter trans', 'igr.TransporterId = trans.id' , 'left') + // ->join('t_materialmaster` item', 'igr_details.MaterialCode = item.MaterialCode' , 'left') + // ->where('igr.IGRStatus !=', MRIR_CREATED) + // ->orderBy('igr.CreatedDate', 'desc'); + // $query2 = $builder2->get(); + // $result2 = $query2->getResult(); // echo $this->db->getLastQuery()->getQuery();die; - return [$result,$result2]; + return [$result,[]]; }