diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7c8a199..88f06db 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -39,6 +39,8 @@ $routes->get('product_index/', 'Products::product_index'); $routes->post("add_product", "Products::add_product"); $routes->get("new_product/(:any)", "Products::new_product/$1"); $routes->get("delete_product/(:any)", "Products::delete_product/$1"); +$routes->post("get_vendors_by_model", "Products::get_vendors_by_model"); +$routes->post("get_models", "Products::get_models"); //end products// //Sales order // diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index 3b7954c..9ade4f0 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -3,7 +3,9 @@ namespace App\Controllers; use App\Models\ProductModel; -// use App\Models\RoleModel; + use App\Models\BikemakeModel; + use App\Models\VendorModel; + use App\Models\BikemodelsModel; class Products extends BaseController @@ -37,10 +39,13 @@ class Products extends BaseController $ProductModel = new ProductModel(); $tax=$ProductModel->getTax(); $data['tax']=$tax; - + $BikemakeModel = new BikemakeModel(); + $data['make'] = $BikemakeModel->findAll(); $data['page_name']="Add Product"; } else if ($product_id !== '0') { $data['page_name']="Edit Product"; + $BikemakeModel = new BikemakeModel(); + $data['make'] = $BikemakeModel->findAll(); $ProductModel = new ProductModel(); $tax=$ProductModel->getTax(); $data['tax']=$tax; @@ -75,6 +80,8 @@ class Products extends BaseController 'qty_in_demand'=> $this->request->getPost('qty_in_demand'), 'description' => $this->request->getPost('description'), 'vendor' => $this->request->getPost('vendor'), + 'purchase_order_level' => $this->request->getPost('purchase_order_level'), + 'quality' => $this->request->getPost('quality'), 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id') ]; @@ -113,5 +120,47 @@ class Products extends BaseController return redirect()->to('product_index'); } + + // 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.']); + 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([]); + } + } + + + + + +public function get_models() +{ + $make_id = $this->request->getPost('make_id'); // Assuming you are sending make_id via POST + + // Fetch models based on the selected make ID + $BikemodelsModel = new BikemodelsModel(); // Adjust this according to your actual model name + $models = $BikemodelsModel->where('make_id', $make_id)->findAll(); // Implement this method in your model + // Return the model data as JSON + return $this->response->setJSON($models); +} + } \ No newline at end of file diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php index d971eea..a0f7a1f 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','product_name','branch_id','search_tag','product_category','mfr_part_no','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','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/Models/VendorModel.php b/app/Models/VendorModel.php index d6b35d9..547b2e1 100644 --- a/app/Models/VendorModel.php +++ b/app/Models/VendorModel.php @@ -6,6 +6,24 @@ class VendorModel extends Model protected $table = 'vendor'; protected $primaryKey = 'vendor_id'; protected $allowedFields = ['vendor_id','branch_id','vendor_name','vendor_email','vendor_mobile','contact_name','website','gstnumber','conatct_person','vendortype','make','model','category','address','state','postal_code','city','country','description','isactive']; - + + public function get_vendors_by_model($model_ids) + { + // Encode the model IDs array as JSON + $json_model_ids = json_encode($model_ids); + + // Query the database to retrieve vendors based on the model IDs + $query = $this->query("SELECT * FROM vendor WHERE JSON_CONTAINS(model, '{$json_model_ids}')")->getResult(); + + // Check if any vendors are found + if (!empty($query)) { + return $query; // Return the result as an array of vendors + } else { + return array(); // Return an empty array if no vendors are found + } + } + + + +} -} \ No newline at end of file diff --git a/app/Views/product_form.php b/app/Views/product_form.php index 89a25e2..e79bb74 100644 --- a/app/Views/product_form.php +++ b/app/Views/product_form.php @@ -23,15 +23,43 @@
" method="post">

Product Details :


- +
+ + +
+
+ + +
- - -
+ + +
+
+ + +
+
@@ -41,9 +69,10 @@
- - + +
+

Pricing Information :


@@ -87,6 +116,10 @@ +
+ + +