This commit is contained in:
Gowtham M 2025-01-27 17:39:30 +05:30
parent 06fd8031d3
commit a95d17b15d

View File

@ -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,[]];
}