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 @@