diff --git a/app/Config/Routes.php b/app/Config/Routes.php index de4c7ba..969622d 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -51,6 +51,7 @@ $routes->get("delete_sale/(:any)", "Sales::delete_sale/$1"); $routes->post("delete_sales_product", "Sales::delete_sales_product"); $routes->get("download_invoice/(:any)", "Sales::download_invoice/$1"); $routes->post("save_vehicle", "Sales::save_vehicle"); +$routes->post("getProducts", "Sales::getProducts"); //end salle order// //Client// diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 376bcf3..a2b85f9 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -53,13 +53,37 @@ class Sales extends BaseController $data['product']=$product; $data['client']=$client; $data['vehicle']=$vehicle; - } else if ($sales_order_id !== '0') { + + + + } else if ($sales_order_id !== '0') + { + + $data['page_name']="Edit Sale Order"; $ClientModel = new ClientModel(); $client=$ClientModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $SalesOrderModel = new SalesOrderModel(); $sales=$SalesOrderModel->where('sales_order_id', $sales_order_id)->get()->getRowArray(); $data['sales']=$sales; +$VehicleModel = new VehicleModel(); +$vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$sales['vehicle_id']) + ->where('branch_id',$this->session->get('logged_user_branch_id')) + ->first(); +$makeId = $vehicles['make']; + $modelId = $vehicles['model']; + + // Encode the modelId before searching + $encodedModelId = json_encode([$modelId]); + + // Load the ProductModel + $productModel = new ProductModel(); + + // Query the database to find the product based on make_id and model_id + $product = $productModel->where('make_id', $makeId) + ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) + ->findAll(); + $data['product']=$product; $SalesProductOrderModel = new SalesOrderProductModel(); $sales_product=$SalesProductOrderModel->where('sales_order_id', $sales_order_id)->findAll(); $data['sales_product']=$sales_product; @@ -70,9 +94,8 @@ $VehicleModel = new VehicleModel(); ->where('isactive',1) ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $data['vehicle']=$vehicle; -$ProductModel = new ProductModel(); - $product=$ProductModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); -$data['product']=$product; + + } // print_r($data);die; $data['sales_order_id'] = $sales_order_id; @@ -328,5 +351,40 @@ public function delete_sales_product() return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']); } } + +public function get_vehicle_products(){ -} \ No newline at end of file +} + + + + + public function getProducts() +{ + // Retrieve make_id and model_id from the request + $makeId = $this->request->getPost('make_id'); + $modelId = $this->request->getPost('model_id'); + + // Encode the modelId before searching + $encodedModelId = json_encode([$modelId]); + + // Load the ProductModel + $productModel = new ProductModel(); + + // Query the database to find the product based on make_id and model_id + $product = $productModel->where('make_id', $makeId) + ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) + ->findAll(); + + +if($product){ + // Send JSON response + return $this->response->setJSON($product); + } else { + // If product is not found, return an empty response or appropriate message + return $this->response->setJSON([]); + } +} + // Check if product exists + +} diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index 408b5a5..2d132ed 100644 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -43,11 +43,11 @@