diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index 9845943..46b92a4 100755 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -111,6 +111,7 @@ class Products extends BaseController $productcategory = $this->ProductCategoryModel->orderBy('product_category_id')->findAll(); $data['product_id'] = 0; + $data['products'] = []; $data['additionalProdutName'] = []; @@ -237,6 +238,7 @@ class Products extends BaseController $product_id = $this->request->getPost('product_id'); $additional_product_name = $this->request->getPost('additional_product_name'); $product_names_id = $this->request->getPost('product_names_id'); + $model_ids = $this->request->getPost('fk_model_id'); // print_r($data);die; if (!empty($product_id)) { @@ -247,7 +249,7 @@ class Products extends BaseController } //for insert or update Additional Product Names - $this->insertOrUpdateAdditionalProductName($additional_product_name, $product_names_id, $product_id, $data['product_name']); + $this->insertOrUpdateAdditionalProductName($additional_product_name, $product_names_id, $model_ids, $product_id, $data['product_name']); $orderNumber = 'TM' . str_pad($product_id, 8, '0', STR_PAD_LEFT); @@ -520,39 +522,39 @@ class Products extends BaseController //----VENKAT------------------------------------------------------------------------------------------------ - public function insertOrUpdateAdditionalProductName($product_names, $product_name_id, $product_id, $first_product_name) + public function insertOrUpdateAdditionalProductName($product_names, $product_name_id,$model_ids, $product_id, $first_product_name) { // Fetch existing product names for the given product ID $product_name_data = $this->additionalProductNameModal->where('product_id', $product_id) ->orderBy('product_names_id', 'asc') ->findAll(); $product_name_count = count($product_name_data); - // Check if there are no existing product names and insert the first product name - if ($product_name_count == 0 && !empty($first_product_name)) { + // if ($product_name_count == 0 && !empty($first_product_name)) { - $firstProductNameData = [ - 'product_id' => $product_id, - 'additional_product_name' => $first_product_name, - ]; + // $firstProductNameData = [ + // 'product_id' => $product_id, + // 'additional_product_name' => $first_product_name, + // 'model_id' => 0 + // ]; - // Insert the first product name - $this->additionalProductNameModal->insert($firstProductNameData); + // // Insert the first product name + // $this->additionalProductNameModal->insert($firstProductNameData); - } else { + // } else { - // Update the first product name if it has changed - if ($product_name_data[0]['additional_product_name'] != $first_product_name) { - $firstProductNameUpdateData = [ - 'additional_product_name' => $first_product_name, - ]; + // // Update the first product name if it has changed + // if ($product_name_data[0]['additional_product_name'] != $first_product_name) { + // $firstProductNameUpdateData = [ + // 'additional_product_name' => $first_product_name, + // ]; - $this->additionalProductNameModal - ->where('product_names_id', $product_name_data[0]['product_names_id']) - ->set($firstProductNameUpdateData) - ->update(); - } - } + // $this->additionalProductNameModal + // ->where('product_names_id', $product_name_data[0]['product_names_id']) + // ->set($firstProductNameUpdateData) + // ->update(); + // } + // } $productNameData = []; @@ -563,6 +565,7 @@ class Products extends BaseController 'product_id' => $product_id, 'additional_product_name' => $name, 'product_names_id' => $product_name_id[$index] ?? null, + 'model_id' => $model_ids[$index] ?? null ]; } } @@ -585,6 +588,30 @@ class Products extends BaseController if (!empty($updateData)) { $this->additionalProductNameModal->updateBatch($updateData, 'product_names_id'); } + + if (!empty($product_name_id)) { + + $filtering_ids = []; + + for ($y = 0; $y < count($product_name_data); $y++) { + $filtering_ids[$y] = $product_name_data[$y]['product_names_id']; + } + + + if (!empty($filtering_ids)) { + $A = $filtering_ids; + $B = $product_name_id; + $missing_ids = array_diff($A, $B); + + + if (!empty($missing_ids)) { + $this->additionalProductNameModal + ->whereIn('product_names_id', $missing_ids) + ->delete(); + } + } + } + } return true; diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 1529673..bb4d20f 100755 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -506,9 +506,6 @@ class Sales extends BaseController } - - - public function getProducts() { if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } @@ -516,6 +513,36 @@ class Sales extends BaseController $makeId = $this->request->getPost('make_id'); $modelId = $this->request->getPost('model_id'); + + $modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name; + $makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make; + + $product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name') + ->join('products', 'products.product_id = product_names.product_id') + ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') + ->whereIn('product_names.model_id',[$modelId, 0]) + ->where('qty_stock >',0) + ->where('product_names.isactive', 1) + ->findAll(); + + if($product){ + // Send JSON response + return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] ); + } else { + // If product is not found, return an empty response or appropriate message + return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]); + } + } + + + + public function getProducts_old() + { + if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } + // 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 $encodedMakeId = json_encode([$makeId]); $encodedModelId = json_encode([$modelId]); diff --git a/app/Controllers/Vehicle.php b/app/Controllers/Vehicle.php index f0e7942..89db4d3 100755 --- a/app/Controllers/Vehicle.php +++ b/app/Controllers/Vehicle.php @@ -68,7 +68,7 @@ class Vehicle extends BaseController } // dd($vehicle); $data['vehicle_id'] = $vehicle_id; - $data['makeData'] =$this->bikeMakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll(); + $data['makeData'] =$this->bikeMakeModel->where('make_id != ', 0)->where('business_id', $this->session->get('logged_user_business_id'))->findAll(); return view('vehicle_form',$data); } diff --git a/app/Models/AdditionalProductNameModal.php b/app/Models/AdditionalProductNameModal.php index 57bf17a..1ea8d25 100644 --- a/app/Models/AdditionalProductNameModal.php +++ b/app/Models/AdditionalProductNameModal.php @@ -15,7 +15,7 @@ class AdditionalProductNameModal extends Model protected $allowedFields = [ 'product_names_id', 'product_id', - 'make_id_for_additional_name', + 'model_id', 'additional_product_name', 'isactive', 'created_at', diff --git a/app/Views/product_form.php b/app/Views/product_form.php index 6abadf2..c081a32 100755 --- a/app/Views/product_form.php +++ b/app/Views/product_form.php @@ -457,8 +457,8 @@ $("#model").change(function () {