diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index b350f0f5..e0f437cd 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -470,9 +470,30 @@ class StockController extends BaseController $data['groupedBagStockDetails'] = array_values($groupedByDate); + /** + * need to change the below condition to allow active bag materials for new entries + * not for older entries + **/ - $bagMaterials = $this->rawmaterialdetails_model->getAllBagMaterialCode(); + if(!empty($data['groupedBagStockDetails'])){ + $result = $this->bagStockDetails_model + ->select('materialCode') // Specify the column you want to select + ->distinct() // Use distinct without arguments + ->orderBy('materialCode', 'asc') + ->findAll(); + $distinctMaterialCodes=[]; + foreach($result as $index => $eachResult){ + $distinctMaterialCodes[] = $result[$index]['materialCode']; + } + $bagMaterials = $this->rawmaterialdetails_model->getSelectedBagMaterialCode($distinctMaterialCodes); + + }else{ + $bagMaterials = $this->rawmaterialdetails_model->getAllBagMaterialCode(); + + } + + foreach ($bagMaterials as $key => $bagMaterial) { diff --git a/app/Models/Rawmaterialdetails_model.php b/app/Models/Rawmaterialdetails_model.php index 321d1a24..df8e28a6 100755 --- a/app/Models/Rawmaterialdetails_model.php +++ b/app/Models/Rawmaterialdetails_model.php @@ -164,6 +164,22 @@ class Rawmaterialdetails_model extends Model return $materialResults; } + + + function getSelectedBagMaterialCode($distinctMaterialCodes) + { + $builder = $this->db->table('t_materialmaster') + ->select('MaterialCode, MaterialName') + ->whereIn('MaterialCode', $distinctMaterialCodes) // Matches MaterialCode with the array + ->orderBy('MaterialCode', 'asc'); + + $query = $builder->get(); + $materialResults = $query->getResultArray(); + + return $materialResults; + } + + function getAllResinMaterialCode(){