igr tax value : GWM
This commit is contained in:
parent
c58c62ae19
commit
e09955acdb
@ -372,18 +372,42 @@ class Inwardgateregister_model extends Model
|
||||
|
||||
function ViewigrListing($fromDate,$toDate)
|
||||
{
|
||||
$subQuery = $this->db->table('t_igr_remarkes')
|
||||
->select('COUNT(id)')
|
||||
->where('igr_no = igr.IGRNo')
|
||||
->getCompiledSelect();
|
||||
$subQuery1 = $this->db->table('t_igr_remarkes')
|
||||
->select('COUNT(id)')
|
||||
->where('igr_no = igr.IGRNo')
|
||||
->getCompiledSelect();
|
||||
|
||||
// Build subQuery2 dynamically for rate and tax based on POType
|
||||
$subQuery2 = "(CASE
|
||||
WHEN PO.POType = 'revenue' THEN (
|
||||
SELECT JSON_OBJECT('total_rate', SUM(POL.Rate), 'total_tax', AVG(tax.CGST + tax.SGST + tax.IGST))
|
||||
FROM t_igr_details IGRD
|
||||
LEFT JOIN t_purchaseorder_lineitem POL ON PONO = POL.PONO AND IGRD.MaterialCode = POL.MaterialCode
|
||||
LEFT JOIN t_revenue_tax tax ON tax.LineItemNo = POL.LineItemNo
|
||||
WHERE IGRD.IGRNO = igr.IGRNO
|
||||
)
|
||||
WHEN PO.POType = 'service' THEN (
|
||||
SELECT JSON_OBJECT('total_rate', SUM(POL.Rate), 'total_tax', AVG(tax.CGST + tax.SGST + tax.IGST))
|
||||
FROM t_igr_details IGRD
|
||||
LEFT JOIN t_purchaseorder_lineitem POL ON PONO = POL.PONO AND IGRD.MaterialCode = POL.MaterialCode
|
||||
LEFT JOIN t_service_tax tax ON tax.LineItemNo = POL.LineItemNo
|
||||
WHERE IGRD.IGRNO = igr.IGRNO
|
||||
)
|
||||
|
||||
ELSE NULL
|
||||
END)";
|
||||
|
||||
|
||||
// Main query
|
||||
$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
|
||||
COALESCE(($subQuery1), 0) as remark_count,
|
||||
JSON_EXTRACT(($subQuery2), '$.total_rate') as total_rate,
|
||||
JSON_EXTRACT(($subQuery2), '$.total_tax') as total_tax")
|
||||
->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')
|
||||
@ -391,13 +415,15 @@ class Inwardgateregister_model extends Model
|
||||
->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();
|
||||
|
||||
|
||||
$query = $builder->get();
|
||||
$result = $query->getResult();
|
||||
|
||||
|
||||
// echo $this->db->getLastQuery()->getQuery();die;
|
||||
// dd($result);
|
||||
|
||||
|
||||
// old - issue in t_igr_remarkes join
|
||||
|
||||
Loading…
Reference in New Issue
Block a user