diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index 9ade4f0..4918b0d 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -65,7 +65,7 @@ class Products extends BaseController $ProductModel = new ProductModel(); $tax= $this->request->getPost('tax')/2; - + // print_r($this->request->getPost());die; $data = [ 'product_name' => $this->request->getPost('productname'), 'product_category' => $this->request->getPost('productcategory'), @@ -82,6 +82,8 @@ class Products extends BaseController 'vendor' => $this->request->getPost('vendor'), 'purchase_order_level' => $this->request->getPost('purchase_order_level'), 'quality' => $this->request->getPost('quality'), + 'make_id' => $this->request->getPost('make'), + 'models_id' => json_encode($this->request->getPost('model')), 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id') ]; @@ -124,26 +126,17 @@ class Products extends BaseController // Retrieve the make_id from the AJAX request public function get_vendors_by_model() { - $make_id = $this->request->getPost('make_id'); + $model_ids = $this->request->getPost('model_ids'); - // print_r( $model_ids);die; - - // If make_id or model_ids is not provided, return an empty response - - // Create an instance of VendorModel $vendorModel = new VendorModel(); - - // Call the get_vendors_by_model method from the model - $vendors = $vendorModel->get_vendors_by_model($make_id, $model_ids); - // print_r($vendors); - // Return the response as JSON - // return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']); + $vendors = $vendorModel->get_vendors_by_model( $model_ids); + if ($vendors) { - // Return the retrieved vendors as JSON response + return $this->response->setJSON($vendors); } else { - // If no vendors were found, return an empty response or handle the error accordingly + return $this->response->setJSON([]); } } diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php index a0f7a1f..63c54ff 100644 --- a/app/Models/ProductModel.php +++ b/app/Models/ProductModel.php @@ -5,7 +5,7 @@ class ProductModel extends Model { protected $table = 'products'; protected $primaryKey = 'product_id'; - protected $allowedFields = ['product_id','quality','product_name','branch_id','search_tag','product_category','mfr_part_no','purchase_order_level','serial_no','unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level','handler','qty_in_demand','product_image','description','isactive']; + protected $allowedFields = ['product_id','make_id','models_id','quality','product_name','branch_id','search_tag','product_category','mfr_part_no','purchase_order_level','serial_no','unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level','handler','qty_in_demand','product_image','description','isactive']; public function getTax() diff --git a/app/Views/client_form.php b/app/Views/client_form.php index a8c072a..e962a9a 100644 --- a/app/Views/client_form.php +++ b/app/Views/client_form.php @@ -21,6 +21,7 @@