diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index bf26151b..cbb9f924 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -1189,7 +1189,7 @@ class StockController extends BaseController //diesel stock details - + public function dieselMachineStockDetails(){ @@ -2064,9 +2064,17 @@ class StockController extends BaseController ->where('stock_category','resin') ->findAll(); + $filterUpdateNeeded = true ; + + if( empty($customisedMaterialCodes) && !empty($existingCustomMaterialCodes)){ + $customisedMaterialCodes = array_column($existingCustomMaterialCodes, 'materialCode') ; + $filterUpdateNeeded = false ; + + } + //check user applies for filter currently - if(!empty($customisedMaterialCodes)){ + if(!empty($customisedMaterialCodes) && $filterUpdateNeeded){ //user applied filter, @@ -2201,7 +2209,35 @@ class StockController extends BaseController $groupedByDate[$date][] = $detail; } + // Sort each date's materials based on the custom order to set table body td + if (!empty($customisedMaterialCodes)) { + + foreach ($groupedByDate as $date => &$materials) { + + usort($materials, function ($a, $b) use ($customisedMaterialCodes) { + + $indexA = array_search($a['materialCode'], $customisedMaterialCodes); + $indexB = array_search($b['materialCode'], $customisedMaterialCodes); + + if ($indexA === false && $indexB === false) { + return 0; + } + if ($indexA === false) { + return 1; + } + if ($indexB === false) { + return -1; + } + + return $indexA - $indexB; + }); + } + unset($materials); + } + // Reset the structure to have indexed arrays without the date keys + + //this is for tbody table data td $data['groupedResinStockDetails'] = array_values($groupedByDate); @@ -2219,6 +2255,30 @@ class StockController extends BaseController ->first()['customer'] ?? ''; } + // Sort each date's materials based on the custom order to set table header th + if (!empty($customisedMaterialCodes)) { + + usort($resinMaterials, function ($a, $b) use ($customisedMaterialCodes) { + + $indexA = array_search($a['MaterialCode'], $customisedMaterialCodes); + $indexB = array_search($b['MaterialCode'], $customisedMaterialCodes); + + if ($indexA === false && $indexB === false) { + return 0; + } + if ($indexA === false) { + return 1; + } + if ($indexB === false) { + return -1; + } + + return $indexA - $indexB; + }); + + } + + $resinMaterialCount = count($resinMaterials); $data['resinMaterialCount'] = $resinMaterialCount; diff --git a/app/Models/Dashboard_model.php b/app/Models/Dashboard_model.php index b9580445..82e2cd67 100755 --- a/app/Models/Dashboard_model.php +++ b/app/Models/Dashboard_model.php @@ -2188,12 +2188,20 @@ category = '" . $cat . "' "; function pending_purchase($cname, $prod, $fa, $aa, $m, $frm, $t, $purchaseorder_number) { - $sql = "select po.PONO as po,date_format(po.PODate,'%d-%m-%Y') as pdate,sup.SupplierName as supplier,mm.MaterialName as material,mm.Category as category,pl.Quantity as quantity,pl.ReceivedQuantity as received, (pl.Quantity - pl.ReceivedQuantity) as pending + $sql = "select po.PONO as po, + date_format(po.PODate,'%d-%m-%Y') as pdate, + sup.SupplierName as supplier, + mm.MaterialName as material, + cd.ConfigValue as category, + pl.Quantity as quantity, + pl.ReceivedQuantity as received, + (pl.Quantity - pl.ReceivedQuantity) as pending from t_purchaseorder_lineitem pl join t_purchaseorder_master po on po.PONO = pl.PONO join t_supplierdetailsn sup on sup.SupplierID=po.SupplierID join t_materialmaster mm on mm.MaterialCode=pl.MaterialCode -where po.Status != 'ST030' and po.Status = 'ST026' +join t_configdetails cd on cd.key = mm.Category +where po.Status != 'ST030' and po.Status = 'ST026' "; if ($cname != '') { @@ -2231,7 +2239,7 @@ where po.Status != 'ST030' and po.Status = 'ST026' if($purchaseorder_number != ''){ $sql .= " and po.PONO = '" . $purchaseorder_number . "' "; } - $sql .= "order by po.PONO"; + $sql .= "order by date(po.PODate) desc"; $query = $this->db->query($sql); //echo $sql; return $query->getResult(); diff --git a/app/Views/Report_pending_purchase.php b/app/Views/Report_pending_purchase.php index 901e3a75..bc2f926f 100755 --- a/app/Views/Report_pending_purchase.php +++ b/app/Views/Report_pending_purchase.php @@ -220,11 +220,12 @@ $yqt = 0.00; $yvt = 0.00; - + foreach ($ppurchse as $rel) { $cat = $rel->category; + //dd($rel); ?>