diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index ece7133..873e0b1 100755 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -3,25 +3,27 @@ namespace App\Controllers; use App\Models\ProductModel; - use App\Models\BikemakeModel; - use App\Models\VendorModel; - use App\Models\BikemodelsModel; - use App\Models\ManufacturerModel; - use App\Models\ProductCategoryModel; +use App\Models\BikemakeModel; +use App\Models\VendorModel; +use App\Models\BikemodelsModel; +use App\Models\ManufacturerModel; +use App\Models\ProductCategoryModel; +use App\Models\AdditionalProductNameModal; use CodeIgniter\API\ResponseTrait; class Products extends BaseController -{ +{ + protected $additionalProductNameModal; public $session; use ResponseTrait; public function __construct() { - $this->session = session(); + $this->additionalProductNameModal = new AdditionalProductNameModal(); } public function product_index($manufacturer_id = null) @@ -53,11 +55,6 @@ class Products extends BaseController } - - - - - public function new_product($product_id) { @@ -80,7 +77,9 @@ class Products extends BaseController $productcategory = $ProductCategoryModel->orderBy('product_category_id')->findAll(); $data['productcategory']=$productcategory; $data['vendorsProduct'] =[]; + } else if ($product_id !== '0') { + $data['page_name']="Edit Product"; $ProductModel = new ProductModel(); $products=$ProductModel->where('product_id', $product_id)->get()->getRowArray(); @@ -118,35 +117,43 @@ class Products extends BaseController $vendors = []; - $VendorModel = new VendorModel(); - foreach ($vendorIds as $vendorId) { - $vendor = $VendorModel->find($vendorId); - if ($vendor) { - $vendors[] = ['id' => $vendor['vendor_id'], 'name' => $vendor['vendor_name']]; + + + $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; + // print_r($data);die; } - $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; - // print_r($data);die; - } + $data['product_id'] = $product_id; $ProductCategoryModel = new ProductCategoryModel(); $productcategory = $ProductCategoryModel->orderBy('product_category_id')->findAll(); + $additionalProdutName = $this->additionalProductNameModal->where('product_id', $product_id)->orderBy('product_names_id')->findAll(); $data['productcategory']=$productcategory; -// print_r($data);die; + $data['additionalProdutName']=$additionalProdutName; + + // dd($data); + // print_r($data);die; // echo "
";
         // print_r($data['manufacturers']);die;
 
         echo view('product_form',$data);
     }
 
-   
     public function add_product()
-    {
+    {   
+        // dd($this->request->getPost());
+
         if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
         $ProductModel = new ProductModel();
     
@@ -198,16 +205,19 @@ 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');
     
         // print_r($data);die;
         if (!empty($product_id)) {
-        
             $ProductModel->update($product_id, $data);
         } else {
-            
             $ProductModel->insert($data);
             $product_id = $ProductModel->getInsertID();
         }
+
+        //for insert or update Additional Product Names
+        $this->insertOrUpdateAdditionalProductName($additional_product_name,  $product_names_id, $product_id, $data['product_name']);
     
         $orderNumber = 'TM' .  str_pad($product_id, 8, '0', STR_PAD_LEFT);
 
@@ -236,65 +246,61 @@ class Products extends BaseController
         return redirect()->to('product_index');
     }
   
-        // Retrieve the make_id from the AJAX request
-        public function get_vendors_by_model()
-        {
-            
-            $model_ids = $this->request->getPost('model_ids');
-            $make_id = $this->request->getPost('make_id');
-            $vendorModel = new VendorModel();
-            $Vendors = $vendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
-            if($Vendors){
-            
-                    $data = [];
+    // Retrieve the make_id from the AJAX request
+    public function get_vendors_by_model()
+    {
+        
+        $model_ids = $this->request->getPost('model_ids');
+        $make_id = $this->request->getPost('make_id');
+        $vendorModel = new VendorModel();
+        $Vendors = $vendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+        if($Vendors){
+        
+                $data = [];
 
-                    foreach ($model_ids as $modelKey => $modelValue) 
+                foreach ($model_ids as $modelKey => $modelValue) 
+                {
+                    foreach ($Vendors as $vendorsKey => $vendorsValue) 
                     {
-                        foreach ($Vendors as $vendorsKey => $vendorsValue) 
+                        print_r($vendorsValue);die;
+                        $modelsArray = json_decode($vendorsValue['model'], true);
+                        if (is_array($modelsArray)) 
                         {
-                            print_r($vendorsValue);die;
-                            $modelsArray = json_decode($vendorsValue['model'], true);
-                            if (is_array($modelsArray)) 
+                            $findIfModelExist = array_search($modelValue, $modelsArray);
+                            if ($findIfModelExist !== false) 
                             {
-                                $findIfModelExist = array_search($modelValue, $modelsArray);
-                                if ($findIfModelExist !== false) 
-                                {
-                                    array_push($data,$vendorsValue);
-                                }
+                                array_push($data,$vendorsValue);
                             }
                         }
                     }
-        
-                if (count($data)) {
-
-                    $arrayOfArrays = array_map(function($obj) {
-                        return (array) $obj;
-                    }, $data);
-                    
-                    // Remove duplicates based on string representation of each object
-                    $uniqueArray = array_map('unserialize', array_unique(array_map('serialize', $arrayOfArrays)));
-                    
-                    // Convert the unique array of associative arrays back to an array of objects
-                    $uniqueObjectsArray = array_map(function($arr) {
-                        return (object) $arr;
-                    }, $uniqueArray);
-
-                    return $this->response->setJSON($uniqueArray);
-
-                } else {
-                
-                    return $this->response->setJSON([]);
                 }
-            }else {
-                    
+    
+            if (count($data)) {
+
+                $arrayOfArrays = array_map(function($obj) {
+                    return (array) $obj;
+                }, $data);
+                
+                // Remove duplicates based on string representation of each object
+                $uniqueArray = array_map('unserialize', array_unique(array_map('serialize', $arrayOfArrays)));
+                
+                // Convert the unique array of associative arrays back to an array of objects
+                $uniqueObjectsArray = array_map(function($arr) {
+                    return (object) $arr;
+                }, $uniqueArray);
+
+                return $this->response->setJSON($uniqueArray);
+
+            } else {
+            
                 return $this->response->setJSON([]);
             }
+        }else {
+                
+            return $this->response->setJSON([]);
         }
+    }
         
-    
-    
-    
-
     public function get_models()
     {
         $make_ids = $this->request->getPost('make_id'); // Assuming you are sending make_id via POST
@@ -328,10 +334,8 @@ class Products extends BaseController
         return $this->response->setJSON($formatted_models);
     }
 
-
-
-
-    public function save_make() {
+    public function save_make() 
+    {
         $response = []; // Initialize an empty array to hold the response data
 
         // Assuming BikemakeModel and BikemodelsModel are properly defined
@@ -372,13 +376,16 @@ class Products extends BaseController
         // Send JSON response back to the client
         return $this->response->setJSON($response);
     }
+
     public function get_makes()
     {
         $BikeMakeModel = new BikeMakeModel(); // Adjust this according to your actual model name
         $makes = $BikeMakeModel->findAll();   
         return $this->response->setJSON($makes);
     }
-    public function save_model() {
+
+    public function save_model() 
+    {
         $response = []; 
         $BikemodelsModel = new BikemodelsModel();
         
@@ -409,9 +416,8 @@ class Products extends BaseController
         return $this->response->setJSON($response);
     }
 
-
-
-    public function save_manufacturer(){
+    public function save_manufacturer()
+    {
         $response = []; 
         $ManufacturerModel = new ManufacturerModel();
         
@@ -443,7 +449,8 @@ class Products extends BaseController
         return $this->response->setJSON($response);
     }
 
-    public function product_list_for_service(){
+    public function product_list_for_service()
+    {
         $ProductModel = new ProductModel();
         // Assuming you have a model for products and one for manufacturers
         $products = $ProductModel
@@ -455,7 +462,6 @@ class Products extends BaseController
         return $this->response->setJSON($products);
     }
 
-
     public function status_product()
     {
 
@@ -481,4 +487,44 @@ class Products extends BaseController
        }
     }
 
+    //----VENKAT------------------------------------------------------------------------------------------------
+
+    public function insertOrUpdateAdditionalProductName($product_names, $product_name_id, $product_id, $first_product_name)
+    {   
+        $firstProductNameData = [
+            'product_id' => $product_id,
+            'additional_product_name' => $first_product_name,
+        ];
+
+        // Delete existing records for the given product ID
+        $this->additionalProductNameModal->where('product_id', $product_id)->delete();
+
+        // Insert the first product name (if any)
+        $this->additionalProductNameModal->insert($firstProductNameData);
+
+        $productNameData = [];
+
+        // If there are additional product names, loop through and prepare them
+        if (!empty($product_names) && count($product_names) > 0) {
+
+            foreach ($product_names as $name) {
+                if (!empty($name)) {
+                    $productNameData[] = [
+                        'product_id' => $product_id,
+                        'additional_product_name' => $name,
+                    ];
+                }
+            }
+
+            // Insert additional product names in batch if there are valid entries
+            if (!empty($productNameData) && count($product_names) > 0) {
+                $this->additionalProductNameModal->insertBatch($productNameData);
+            }
+        }
+
+        return true;
+    }
+
+
+    
 }
\ No newline at end of file
diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php
index 8795558..e5a0242 100755
--- a/app/Controllers/Sales.php
+++ b/app/Controllers/Sales.php
@@ -11,22 +11,27 @@ use App\Models\BikemakeModel;
 use App\Models\VehicleModel;
 use App\Models\BusinessModel;
 use App\Models\BranchModel;
+use App\Models\AdditionalProductNameModal;
+
+
 use Mpdf\Mpdf;
 use CodeIgniter\API\ResponseTrait;
 use App\Helpers\InvNoHelper; 
+
 class Sales extends BaseController
 {
     public $session;
     use ResponseTrait;
     protected $BikemodelsModel;
     protected $BikemakeModel;
+    protected $additionalProductNameModal;
+
     public function __construct()
 	{
-
 		$this->session = session();
         $this->BikemodelsModel = new BikemodelsModel();
         $this->BikemakeModel = new BikemakeModel();
-		
+        $this->additionalProductNameModal =   new AdditionalProductNameModal();		
     }
  
     public function sales_order_index()
@@ -41,7 +46,6 @@ class Sales extends BaseController
         return view('sales_list',$data);
     }
 
-           
     public function new_sale($sales_order_id)
     {
        
@@ -71,8 +75,7 @@ class Sales extends BaseController
 
 
 
-        } else if ($sales_order_id !== '0') 
-        {
+        } else if ($sales_order_id !== '0') {
 
 
             $data['page_name']="Edit Sale Order";
@@ -98,27 +101,33 @@ class Sales extends BaseController
             // Load the ProductModel
             $productModel = new ProductModel();
 
-                // Query the database to find the product based on make_id and model_id
-                $makemodelproduct = $productModel->select('products.*, manufacturer.manufacturer_name')
+                    // Query the database to find the product based on make_id and model_id
+                    $makeproduct = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.additional_product_name')
+                    ->join('products', 'products.product_id = product_names.product_id')
+                    ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
+                    ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
+                    ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
+                    ->where('qty_stock >',0)
+                    ->where('products.isactive', 1)
+                    ->findAll();
+
+                    $encodedMakeId = json_encode(['0']);
+                    $encodedModelId = json_encode(['0']);
+
+                    $common_product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.additional_product_name')
+                                    ->join('products', 'products.product_id = product_names.product_id')
                                     ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
                                     ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
                                     ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
+                                    ->where('qty_stock >',0)
+                                    ->where('products.isactive', 1)
                                     ->findAll();
-
-                $encodedMakeId1 = json_encode(['0']);
-                $encodedModelId1 = json_encode(['0']);
-            
-                $common_product = $productModel->select('products.*, manufacturer.manufacturer_name')
-                                        ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
-                                        ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId1 . '\')', null, false)
-                                        ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId1 . '\')', null, false)
-                                        ->where('qty_stock >',0)
-                                        ->where('products.isactive',1)
-                                        ->findAll();
-                $product = array_merge($common_product, $makemodelproduct);
+                                    
+                    $product = array_merge($common_product, $makeproduct);
 
 
-                        $data['product']=$product;
+                    $data['product']=$product;
+
                     $SalesProductOrderModel = new SalesOrderProductModel();
                     $sales_product=$SalesProductOrderModel->where('sales_order_id', $sales_order_id)->findAll();
                     $data['sales_product']=$sales_product;
@@ -139,7 +148,6 @@ class Sales extends BaseController
         return view('sales_order_form',$data);
     }
 
-   
     public function add_sales()
     {
         if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
@@ -518,7 +526,8 @@ class Sales extends BaseController
 
 
         // Query the database to find the product based on make_id and model_id
-        $makeproduct = $productModel->select('products.*, manufacturer.manufacturer_name')
+        $makeproduct = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.additional_product_name')
+                                ->join('products', 'products.product_id = product_names.product_id')
                                 ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
                                 ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
                                 ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
@@ -529,15 +538,18 @@ class Sales extends BaseController
         $encodedMakeId = json_encode(['0']);
         $encodedModelId = json_encode(['0']);
 
-        $common_product = $productModel->select('products.*, manufacturer.manufacturer_name')
+        $common_product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.additional_product_name')
+                                ->join('products', 'products.product_id = product_names.product_id')
                                 ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
                                 ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
                                 ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
                                 ->where('qty_stock >',0)
                                 ->where('products.isactive', 1)
                                 ->findAll();
+                                
         $product = array_merge($common_product, $makeproduct);
 
+
         $modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name;
         $makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make;
         if($product){
diff --git a/app/Models/AdditionalProductNameModal.php b/app/Models/AdditionalProductNameModal.php
new file mode 100644
index 0000000..b43a222
--- /dev/null
+++ b/app/Models/AdditionalProductNameModal.php
@@ -0,0 +1,25 @@
+Description
                             
                         
-                    
+                    
+

Additional Product Names :


+
@@ -364,7 +366,33 @@ $(document).ready(function() { $("input[name='hiddenproductcategory']").val($(this).val()); }); - + //---------VENKAT----------------------------------------------------------------------------------- + + // for Additional Product Name Edit Purpose + var additionalProductName = ; + + // console.log(additionalProductName); + // console.log(additionalProductName.length); + + if (Array.isArray(additionalProductName) && additionalProductName.length > 0) { + + var firstProductName = ''; + console.log('firstProductName', firstProductName); + additionalProductName.forEach(function(item) { + if (firstProductName !== item.additional_product_name) { + addHTMLInput(item); // for if edit + } + }); + if(additionalProductName.length == 1){ + addHTMLInput() + } + } else { + addHTMLInput(); // for else add + } + // end of Additional Product Name Edit Purpose + + //------------------------------------------------------------------------------------------------ + }); /** CALCULATE TOTAL AMOUNT ( UNIT PRICE + TAX ) */ @@ -863,4 +891,40 @@ $('#saveMakeBtn').click(function() { .select2-container--default .select2-selection--single .select2-selection__arrow{ top:4px; } - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index ab20252..5789482 100755 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -196,7 +196,7 @@ @@ -721,7 +721,7 @@ $(document).ready(function() { var product = productarray[i]; if(!selected_pr.includes(product.product_id)) { - newRow += ''; } }