diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3cdd261..0830e2b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -42,6 +42,7 @@ $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"); +$routes->post("save_make", "Products::save_make"); //end products// //Sales order // diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index 940a4f5..70e799a 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -64,6 +64,7 @@ class Products extends BaseController $ManufacturerModel = new ManufacturerModel(); $data['manufacturers']=$ManufacturerModel->findAll(); $data['page_name']="Add Product"; + $data['vendorsProduct'] =[]; } else if ($product_id !== '0') { $data['page_name']="Edit Product"; $ProductModel = new ProductModel(); @@ -83,6 +84,18 @@ class Products extends BaseController $data['vendors']=$VendorModel->findAll(); $ManufacturerModel = new ManufacturerModel(); $data['manufacturers']=$ManufacturerModel->findAll(); + $vendorIds = json_decode($products['vendor'], true); + $vendors = []; + $VendorModel = new VendorModel(); + foreach ($vendorIds as $vendorId) { + $vendor = $VendorModel->find($vendorId); + if ($vendor) { + $vendors[] = ['id' => $vendor['vendor_id'], 'name' => $vendor['vendor_name']]; + } + } + $data['vendorsProduct'] = $vendors; + // print_r($data['vendors']);die; + $preferredVendorId = $products['prefered_vendor']; // Pass the preferred vendor ID to the view $data['preferredVendorId'] = $preferredVendorId; // print_r($data);die; @@ -235,4 +248,47 @@ public function get_models() return $this->response->setJSON($models); } + + + +public function save_make() { + $response = []; // Initialize an empty array to hold the response data + + // Assuming BikemakeModel and BikemodelsModel are properly defined + + $BikemakeModel = new BikemakeModel(); + $BikemodelsModel = new BikemodelsModel(); + + $make = $this->request->getPost('make'); + $model = $this->request->getPost('model'); + + // Check if both make and model are provided + if (!empty($make) && !empty($model)) { + $data = [ + 'make' => $make + ]; + + // Insert the make into the database + $BikemakeModel->insert($data); + $make_id = $BikemakeModel->getInsertID(); + + $modelData = [ + 'model_name' => $model, + 'make_id' => $make_id, + ]; + + // Insert the model into the database + $BikemodelsModel->insert($modelData); + + // Set success status in the response + $response['success'] = true; + } else { + // If make or model is empty, set success status to false + $response['success'] = false; + } + + // Send JSON response back to the client + return $this->response->setJSON($response); +} + } \ No newline at end of file diff --git a/app/Controllers/Vendor.php b/app/Controllers/Vendor.php index a59f33e..16a7961 100644 --- a/app/Controllers/Vendor.php +++ b/app/Controllers/Vendor.php @@ -7,6 +7,7 @@ use App\Models\VendorModel; use App\Models\UsersModel; use App\Models\BikemakeModel; use App\Models\BikemodelsModel; +use App\Models\ManufacturerModel; class Vendor extends BaseController @@ -36,10 +37,13 @@ class Vendor extends BaseController if ($vendor_id === '0') { $data['vendor'] = []; $data['page_name'] = "Add Vendor"; + $ManufacturerModel = new ManufacturerModel(); + $data['manufacturers']=$ManufacturerModel->findAll(); } else { $VendorModel = new VendorModel(); $vendor = $VendorModel->where('vendor_id', $vendor_id)->get()->getRowArray(); - + $ManufacturerModel = new ManufacturerModel(); + $data['manufacturers']=$ManufacturerModel->findAll(); $data['vendor'] = $vendor; $data['page_name'] = "Edit Vendor"; @@ -66,6 +70,7 @@ class Vendor extends BaseController 'state' => $this->request->getPost('state'), 'postal_code' => $this->request->getPost('postalcode'), 'country' => $this->request->getPost('country'), + 'vendortype' => $this->request->getPost('vendortype'), 'category' => $this->request->getPost('category'), 'contact_person_name1' => $this->request->getPost('contact_person_name1'), 'contact_person_name2' => $this->request->getPost('contact_person_name2'), @@ -73,9 +78,10 @@ class Vendor extends BaseController 'contact_person_mobile1' => $this->request->getPost('contact_person_mobile1'), 'contact_person_mobile2' => $this->request->getPost('contact_person_mobile2'), 'contact_person_mobile3' => $this->request->getPost('contact_person_mobile3'), - 'contact_person_resignation1' => $this->request->getPost('contact_person_resignation1'), - 'contact_person_resignation2' => $this->request->getPost('contact_person_resignation2'), - 'contact_person_resignation3' => $this->request->getPost('contact_person_resignation3'), + 'contact_person_designation1' => $this->request->getPost('contact_person_designation1'), + 'contact_person_designation2' => $this->request->getPost('contact_person_designation2'), + 'contact_person_designation3' => $this->request->getPost('contact_person_designation3'), + 'manufacturer_id' => json_encode($this->request->getPost('manufacturer')), 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id'), ]; diff --git a/app/Views/product_form.php b/app/Views/product_form.php index 62f3159..d1ecae4 100644 --- a/app/Views/product_form.php +++ b/app/Views/product_form.php @@ -1,5 +1,5 @@ - +
@@ -25,7 +25,8 @@

Product Details :


- + + - - @@ -187,7 +188,34 @@
- + + + \ No newline at end of file diff --git a/app/Views/vehicle_form.php b/app/Views/vehicle_form.php index 3491543..71e6855 100644 --- a/app/Views/vehicle_form.php +++ b/app/Views/vehicle_form.php @@ -23,7 +23,7 @@

Vehicle Details :

- + +
+
+ + +
+ +
+ +
+
+
+