diff --git a/app/Models/TrpProductionModel.php b/app/Models/TrpProductionModel.php index 3b854187..e9d85b5d 100644 --- a/app/Models/TrpProductionModel.php +++ b/app/Models/TrpProductionModel.php @@ -54,18 +54,19 @@ class TrpProductionModel extends Model public function trpProductionDetails($startDate,$endDate){ + $data =[]; - - - + // Subquery definition $subquery = $this->db->table('t_materialmaster') ->select('materialCode') - ->where('Category', 'waste core') + ->where('Category = 328') ->get() ->getResultArray(); $materialCodes = array_column($subquery, 'materialCode'); // Extracts 'materialCode' values + + // dd($this->db->getLastQuery()); // Convert the array of material codes to a comma-separated string // $materialCodesString = "'" . implode("','", $materialCodes) . "'"; @@ -185,7 +186,7 @@ class TrpProductionModel extends Model $subquery3 = $this->db->table('ip_invoice_items invItems') ->select([ - 'invItems.*', + 'invItems.item_date_added', $caseSQL ]) ->join('ip_invoices inv', 'inv.invoice_id = invItems.invoice_id', 'left') @@ -205,6 +206,7 @@ class TrpProductionModel extends Model + $materialCodes = ! empty($materialCodes) ? $materialCodes : [''] ; // Subquery: Waste Core Sand Suppliers $subquery4 = $this->db->table('t_igr_details tigrd') @@ -221,7 +223,7 @@ class TrpProductionModel extends Model ->join('t_igr_master tigm', 'tigm.IGRNo = tigrd.IGRNo', 'left') ->join('t_purchaseorder_master tpom', 'tpom.PONO = tigm.PONO', 'left') ->join('t_supplierdetailsn ts', 'tpom.SupplierID = ts.SupplierID', 'left') - ->whereIn('tigrd.MaterialCode', $materialCodes) // FIXED: Now correctly formatted + ->whereIn('tigrd.MaterialCode', $materialCodes) ->where('tigrd.CreatedDate >=', $startDate) ->where('tigrd.CreatedDate <=', $endDate) ->groupBy('DATE(tigrd.CreatedDate)') @@ -237,9 +239,13 @@ class TrpProductionModel extends Model $builder->where('tpmd.date >=', $startDate); $builder->where('tpmd.date <=', $endDate); + + // Order by date $builder->orderBy('tpmd.date', 'ASC'); + + // Execute the query $query = $builder->get(); $result = $query->getResultArray(); diff --git a/app/Views/stock/trpProductionStockDetails.php b/app/Views/stock/trpProductionStockDetails.php index 73604cba..31f5cc6f 100644 --- a/app/Views/stock/trpProductionStockDetails.php +++ b/app/Views/stock/trpProductionStockDetails.php @@ -485,8 +485,8 @@ $timeOtions[] = "12:00 AM";