From cfacb860a022476efdbc73f89eb9778f9c68c2eb Mon Sep 17 00:00:00 2001 From: heama Date: Wed, 10 Apr 2024 10:26:13 +0530 Subject: [PATCH 1/4] product --- app/Controllers/Products.php | 23 ++++-- app/Models/ManufacturerModel.php | 2 +- app/Models/ProductModel.php | 2 +- app/Views/product_form.php | 136 ++++++++++++++++++++++++++----- app/Views/product_list.php | 6 +- 5 files changed, 138 insertions(+), 31 deletions(-) diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index 0ac0388..940a4f5 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -6,6 +6,7 @@ use App\Models\ProductModel; use App\Models\BikemakeModel; use App\Models\VendorModel; use App\Models\BikemodelsModel; + use App\Models\ManufacturerModel; class Products extends BaseController @@ -60,6 +61,8 @@ class Products extends BaseController $data['make'] = $BikemakeModel->findAll(); $VendorModel = new VendorModel(); $data['vendors']=$VendorModel->findAll(); + $ManufacturerModel = new ManufacturerModel(); + $data['manufacturers']=$ManufacturerModel->findAll(); $data['page_name']="Add Product"; } else if ($product_id !== '0') { $data['page_name']="Edit Product"; @@ -78,9 +81,12 @@ class Products extends BaseController $data['tax']=$tax; $VendorModel = new VendorModel(); $data['vendors']=$VendorModel->findAll(); - - // print_r($data);die; - + $ManufacturerModel = new ManufacturerModel(); + $data['manufacturers']=$ManufacturerModel->findAll(); + $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; @@ -99,7 +105,7 @@ class Products extends BaseController 'product_name' => $this->request->getPost('productname'), 'product_category' => $this->request->getPost('productcategory'), 'mfr_part_no' => $this->request->getPost('mfr_part_no'), - 'serial_no' => $this->request->getPost('serial_no'), + 'unit_price' => $this->request->getPost('unit_price'), 'commision_rate' => $this->request->getPost('commision_rate'), 'sgst' => $tax, @@ -114,11 +120,14 @@ class Products extends BaseController 'quality' => $this->request->getPost('quality'), 'make_id' => $this->request->getPost('make'), 'models_id' => json_encode($this->request->getPost('model')), + 'rack_number' => $this->request->getPost('rack_number'), + 'manufacturer_id' => $this->request->getPost('manufacturer'), + 'prefered_vendor' => $this->request->getPost('prefered_vendor'), 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id') ]; -// print_r($data);die; - + + // print_r($data);die; $product_id = $this->request->getPost('product_id'); @@ -131,7 +140,7 @@ class Products extends BaseController $product_id = $ProductModel->getInsertID(); } - $orderNumber = 'SKU-' . date('md') . '-' . str_pad($product_id, 5, '0', STR_PAD_LEFT); + $orderNumber = 'TM' . str_pad($product_id, 8, '0', STR_PAD_LEFT); // print_r($orderNumber);die; // Update sales order with generated order number $ProductModel->update($product_id, ['sku_id' => $orderNumber]); diff --git a/app/Models/ManufacturerModel.php b/app/Models/ManufacturerModel.php index 4ce777f..174e858 100644 --- a/app/Models/ManufacturerModel.php +++ b/app/Models/ManufacturerModel.php @@ -5,7 +5,7 @@ class ManufacturerModel extends Model { protected $table = 'manufacturer'; protected $primaryKey = 'manufacturer_id'; - protected $allowedFields = ['manufacturer_id','manufacturer_name','isactive','quantity']; + protected $allowedFields = ['manufacturer_id','manufacturer_name','isactive','quality']; } \ No newline at end of file diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php index d7f0ae2..2c7de1f 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 = ['sku_id','product_id','manufacturer_id','make_id','models_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']; + protected $allowedFields = ['sku_id','product_id','rack_number','manufacturer_id','make_id','models_id','quality','product_name','branch_id','prefered_vendor','product_category','mfr_part_no','purchase_order_level','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/Views/product_form.php b/app/Views/product_form.php index c42505b..62f3159 100644 --- a/app/Views/product_form.php +++ b/app/Views/product_form.php @@ -56,6 +56,28 @@
+ + +
+
+ + +
+ +
+ + +
+
- - -
- + + + + +
- - + +
- - -
-
- - + +
@@ -282,4 +302,82 @@ document.addEventListener('DOMContentLoaded', function() { font-weight: 500; border-bottom: 1px solid #747474; } - \ No newline at end of file + + + + + + diff --git a/app/Views/product_list.php b/app/Views/product_list.php index f69d39b..9741f8f 100644 --- a/app/Views/product_list.php +++ b/app/Views/product_list.php @@ -30,9 +30,9 @@ + SKU Id Product Name Category - Serial Number Unit Price Qty in Stock Sgst @@ -46,10 +46,10 @@ + - - + % % From cfd1e9ec4cb039e333b0045acfee9484b7d42f7f Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Wed, 10 Apr 2024 13:24:33 +0530 Subject: [PATCH 2/4] FEATURE_PURCHASE:AADHAVAN --- app/Models/ManufacturerModel.php | 2 +- app/Models/PurchaseOrderModel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/ManufacturerModel.php b/app/Models/ManufacturerModel.php index 4ce777f..174e858 100644 --- a/app/Models/ManufacturerModel.php +++ b/app/Models/ManufacturerModel.php @@ -5,7 +5,7 @@ class ManufacturerModel extends Model { protected $table = 'manufacturer'; protected $primaryKey = 'manufacturer_id'; - protected $allowedFields = ['manufacturer_id','manufacturer_name','isactive','quantity']; + protected $allowedFields = ['manufacturer_id','manufacturer_name','isactive','quality']; } \ No newline at end of file diff --git a/app/Models/PurchaseOrderModel.php b/app/Models/PurchaseOrderModel.php index 3f9feba..cbbfede 100644 --- a/app/Models/PurchaseOrderModel.php +++ b/app/Models/PurchaseOrderModel.php @@ -5,7 +5,7 @@ class PurchaseOrderModel extends Model { protected $table = 'purchase_order'; protected $primaryKey = 'purchase_order_id'; - protected $allowedFields = ['purchase_order_id','subject','vendor','requesition_number','tracking_number','contact_name','due_date','carrier','sales_commision','excise_duty','status','billing_address','billing_city','billing_state','billing_country','billing_postal_code','shipping_address','shipping_city','shipping_state','shipping_country','shipping_postal_code','terms_condition','isactive']; + protected $allowedFields = ['purchase_order_id','vendor_id','status','billing_address','billing_city','billing_state','billing_country','billing_postal_code','shipping_address','shipping_city','shipping_state','shipping_country','shipping_postal_code','terms_condition','isactive','product_id','product_quantity','unit_price','total_price','order_date','contact_person_name','contact_person_mobile']; } \ No newline at end of file From 9197a5f76b69b3de61fa14cd56cfd5cda4f137b0 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Wed, 10 Apr 2024 13:25:24 +0530 Subject: [PATCH 3/4] FEATURE_PURCHASE:AADHAVAN --- app/Config/Routes.php | 9 +- app/Controllers/Manufacturer.php | 4 +- app/Controllers/Products.php | 4 + app/Controllers/Purchase.php | 209 ++++++++++++++++++++++++++ app/Views/layout/header.php | 3 + app/Views/manufacturer_list.php | 20 +-- app/Views/product_list.php | 6 +- app/Views/purchase_form.php | 242 +++++++++++++++++++++++++++++++ app/Views/purchase_list.php | 70 +++++++++ 9 files changed, 551 insertions(+), 16 deletions(-) create mode 100644 app/Controllers/Purchase.php create mode 100644 app/Views/purchase_form.php create mode 100644 app/Views/purchase_list.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3cdd261..ed6c650 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -86,7 +86,7 @@ $routes->get('dashboard', 'Users::dashboard'); -//---------------------- Make And Model | Service | Manufacturer +//---------------------- Make And Model | Service | Manufacturer | Inventory->Purchase // Make $routes->get('make_index', 'Make::index'); $routes->post('create_make', 'Make::create_make'); @@ -112,3 +112,10 @@ $routes->get("delete_service/(:any)", "Service::delete_service/$1"); $routes->get('spare_manufacturer_index', 'Manufacturer::index'); $routes->post('create_manufacturer', 'Manufacturer::create_manufacturer'); + +// Purchase + +$routes->get('purchase_index', 'Purchase::purchase_index'); +$routes->get("new_purchase/(:any)", "Purchase::new_purchase/$1"); +$routes->get('get_product/(:any)', 'Purchase::get_product/$1'); +$routes->post("add_purchase", "Purchase::add_purchase"); diff --git a/app/Controllers/Manufacturer.php b/app/Controllers/Manufacturer.php index 419be86..dd97d32 100644 --- a/app/Controllers/Manufacturer.php +++ b/app/Controllers/Manufacturer.php @@ -35,11 +35,11 @@ class Manufacturer extends BaseController { try { $manufacturer_name = $this->request->getPost('manufacturername'); - $quantity = $this->request->getPost('quantity'); + $quality = $this->request->getPost('quality'); $ManufacturerModel = new ManufacturerModel(); $data = [ 'manufacturer_name' => $manufacturer_name, - 'quantity' => $quantity, + 'quality' => $quality, ]; $inserted = $ManufacturerModel->insert($data); if ($inserted) { diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index bc8f5f5..ae45b8f 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -6,6 +6,7 @@ use App\Models\ProductModel; use App\Models\BikemakeModel; use App\Models\VendorModel; use App\Models\BikemodelsModel; + use App\Models\ManufacturerModel; class Products extends BaseController @@ -23,9 +24,12 @@ class Products extends BaseController if ($manufacturer_id) { $ProductModel = new ProductModel(); + $ManufacturerModel = new ManufacturerModel(); $products = $ProductModel->where('manufacturer_id',$manufacturer_id)->findAll(); + $manufacturer = $ManufacturerModel->where('manufacturer_id',$manufacturer_id)->select('manufacturer_name')->first(); $data['products']=$products; $data['manufacturer_id'] = $manufacturer_id; + $data['manufacturer_name'] = $manufacturer['manufacturer_name']; return view('product_list',$data); } else { diff --git a/app/Controllers/Purchase.php b/app/Controllers/Purchase.php new file mode 100644 index 0000000..780f6a3 --- /dev/null +++ b/app/Controllers/Purchase.php @@ -0,0 +1,209 @@ +session = session(); + } + + public function purchase_index() + { + $PurchaseOrderModel = new PurchaseOrderModel(); + + $purchase = $PurchaseOrderModel->findAll(); + // echo "
";
+        // print_r($product);die;
+        $data['purchase']=$purchase;
+    
+        echo "
";
+        print_r($data);die;
+        return view('purchase_list',$data);
+    }
+          
+    public function new_purchase($purchase_id)
+    {
+        if ($purchase_id === '0') {
+           
+            $data['purchase'] = [];  
+            $PurchaseOrderModel = new PurchaseOrderModel();
+            $ProductModel = new ProductModel();
+            $product = $ProductModel->select('product_id,product_name')->findAll();
+
+            $data['page_name']="Add Purchase Order";
+            $data['product']=$product;
+
+        } else if ($purchase_id !== '0') {
+            $data['page_name']="Edit Product";
+            $ProductModel = new ProductModel();
+            $products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
+           
+            $data['products']=$products;  
+
+            $BikemakeModel = new BikemakeModel();
+            $data['make'] = $BikemakeModel->findAll();
+            $BikemodelsModel = new BikemodelsModel();
+            $make_id = $products['make_id'];
+            $data['models'] = $BikemodelsModel->where('make_id', $make_id)->findAll();
+          
+            $tax=$ProductModel->getTax();
+            $data['tax']=$tax;
+            $VendorModel = new VendorModel();
+            $data['vendors']=$VendorModel->findAll();         
+        }
+        $data['purchase_id'] = $purchase_id;
+   
+        echo view('purchase_form',$data);
+    }
+
+    public function add_purchase()
+    {
+
+        $PurchaseOrderModel = new PurchaseOrderModel();
+    
+
+        $data = [
+            'product_id' => $this->request->getPost('product_id'),
+            'vendor_id' => $this->request->getPost('vendor_id'),
+            'product_quantity' => $this->request->getPost('product_quantity'),
+            'unit_price' => $this->request->getPost('unit_price'),
+            'total_price' => $this->request->getPost('total_price'),
+            'order_date' => $this->request->getPost('order_date'),
+            'contact_person_name' => $this->request->getPost('contact_person_name'),
+            'contact_person_mobile'=> $this->request->getPost('contact_person_mobile'),
+            'status'=> $this->request->getPost('purchase_status'),
+            'billing_addresss' => $this->request->getPost('billing_addresss'),
+            'billing_state' => $this->request->getPost('billing_state'),
+            'billing_city' => $this->request->getPost('billing_city'),
+            'billing_postal_code' => $this->request->getPost('billing_postal_code'), 
+            'shipping_addresss' => $this->request->getPost('shipping_addresss'), 
+            'shipping_state' => json_encode($this->request->getPost('shipping_state')), 
+            'shipping_city' =>$this->request->getPost('shipping_city'),
+            'shipping_postal_code' => $this->request->getPost('shipping_postal_code'),
+            'description' => $this->request->getPost('description'),
+        ];
+      
+        // $product_id = $this->request->getPost('product_id');
+    
+       
+        // if (!empty($product_id)) {
+        
+        //     $PurchaseOrderModel->update($product_id, $data);
+        // } else {
+            
+            $PurchaseOrderModel->insert($data);
+        // }
+    
+        
+        return redirect()->to('product_index');
+    }
+
+    public function delete_product($product_id)
+    {
+        $model = new ProductModel();
+        $where = ['product_id' => $product_id, 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id')]; // Assuming 'isactive' is a column in your database
+        $existingProduct = $model->where($where)->first();
+    
+        if ($existingProduct) {
+            $data['isactive'] = 0;
+            
+            if ($model->update($product_id, $data)) {
+                session()->setFlashdata('success', 'Deleted successfully.');
+                $this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$product_id); 
+            }
+        }
+    
+       
+        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 = [];
+
+                foreach ($model_ids as $modelKey => $modelValue) 
+                {
+                    foreach ($Vendors as $vendorsKey => $vendorsValue) 
+                    {
+                        $modelsArray = json_decode($vendorsValue['model'], true);
+                        if (is_array($modelsArray)) 
+                        {
+                            $findIfModelExist = array_search($modelValue, $modelsArray);
+                            if ($findIfModelExist !== false) 
+                            {
+                                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 {
+                
+            return $this->response->setJSON([]);
+        }
+    }
+
+
+    public function get_product($product_id)
+    {
+
+        $ProductModel = new ProductModel();
+        $BranchModel = new BranchModel();
+        $BusinessModel = new BusinessModel();
+
+        $branch = $BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray();
+        $business = $BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
+
+
+        $products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
+        if ($products['prefered_vendor']) {
+            $VendorModel = new VendorModel();
+            $products +=$VendorModel->where('vendor_id',$products['prefered_vendor'])->select('vendor_name,contact_person_name1,contact_person_mobile1')->get()->getRowArray(); 
+        }
+
+        $products['branch']=$branch;
+        $products['business']=$business;
+
+        return json_encode($products);
+
+    }
+
+}
\ No newline at end of file
diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php
index 269d64b..75b82cc 100644
--- a/app/Views/layout/header.php
+++ b/app/Views/layout/header.php
@@ -143,6 +143,9 @@
                                         
  • Vendor
  • +
  • + Purchase +
  • diff --git a/app/Views/manufacturer_list.php b/app/Views/manufacturer_list.php index b755642..c4a5894 100644 --- a/app/Views/manufacturer_list.php +++ b/app/Views/manufacturer_list.php @@ -26,7 +26,7 @@ Manufacturer - Quantity + Quality Action @@ -34,7 +34,7 @@ - + " class="view-list-button" title="Model List" style="margin-left: 16px;"> @@ -66,13 +66,13 @@
    - - + + + + +
    @@ -98,7 +98,7 @@ function submitMake(params) { var formData = { manufacturername: $('#manufacturer_name').val(), - quantity: $('#quantity').val() + quality: $('#quality').val() }; $.ajax({ diff --git a/app/Views/product_list.php b/app/Views/product_list.php index f69d39b..a693571 100644 --- a/app/Views/product_list.php +++ b/app/Views/product_list.php @@ -3,7 +3,7 @@
    -

    Product List

    +

    Product List