diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3cdd261..a1ffcee 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -42,6 +42,7 @@ $routes->get("new_product/(:any)", "Products::new_product/$1"); $routes->get("delete_product/(:any)", "Products::delete_product/$1"); $routes->post("get_vendors_by_model", "Products::get_vendors_by_model"); $routes->post("get_models", "Products::get_models"); +$routes->post("save_make", "Products::save_make"); //end products// //Sales order // @@ -86,7 +87,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 +113,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 0ac0388..76e14cf 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -6,6 +6,8 @@ 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 +25,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 { @@ -60,7 +65,10 @@ 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"; + $data['vendorsProduct'] =[]; } else if ($product_id !== '0') { $data['page_name']="Edit Product"; $ProductModel = new ProductModel(); @@ -78,9 +86,24 @@ 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(); + $vendorIds = json_decode($products['vendor'], true); + $vendors = []; + $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['product_id'] = $product_id; @@ -99,7 +122,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 +137,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 +157,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]); @@ -226,4 +252,47 @@ public function get_models() return $this->response->setJSON($models); } + + + +public function save_make() { + $response = []; // Initialize an empty array to hold the response data + + // Assuming BikemakeModel and BikemodelsModel are properly defined + + $BikemakeModel = new BikemakeModel(); + $BikemodelsModel = new BikemodelsModel(); + + $make = $this->request->getPost('make'); + $model = $this->request->getPost('model'); + + // Check if both make and model are provided + if (!empty($make) && !empty($model)) { + $data = [ + 'make' => $make + ]; + + // Insert the make into the database + $BikemakeModel->insert($data); + $make_id = $BikemakeModel->getInsertID(); + + $modelData = [ + 'model_name' => $model, + 'make_id' => $make_id, + ]; + + // Insert the model into the database + $BikemodelsModel->insert($modelData); + + // Set success status in the response + $response['success'] = true; + } else { + // If make or model is empty, set success status to false + $response['success'] = false; + } + + // Send JSON response back to the client + return $this->response->setJSON($response); +} + } \ No newline at end of file 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/Controllers/Vendor.php b/app/Controllers/Vendor.php
index a59f33e..16a7961 100644
--- a/app/Controllers/Vendor.php
+++ b/app/Controllers/Vendor.php
@@ -7,6 +7,7 @@ use App\Models\VendorModel;
use App\Models\UsersModel;
use App\Models\BikemakeModel;
use App\Models\BikemodelsModel;
+use App\Models\ManufacturerModel;
class Vendor extends BaseController
@@ -36,10 +37,13 @@ class Vendor extends BaseController
if ($vendor_id === '0') {
$data['vendor'] = [];
$data['page_name'] = "Add Vendor";
+ $ManufacturerModel = new ManufacturerModel();
+ $data['manufacturers']=$ManufacturerModel->findAll();
} else {
$VendorModel = new VendorModel();
$vendor = $VendorModel->where('vendor_id', $vendor_id)->get()->getRowArray();
-
+ $ManufacturerModel = new ManufacturerModel();
+ $data['manufacturers']=$ManufacturerModel->findAll();
$data['vendor'] = $vendor;
$data['page_name'] = "Edit Vendor";
@@ -66,6 +70,7 @@ class Vendor extends BaseController
'state' => $this->request->getPost('state'),
'postal_code' => $this->request->getPost('postalcode'),
'country' => $this->request->getPost('country'),
+ 'vendortype' => $this->request->getPost('vendortype'),
'category' => $this->request->getPost('category'),
'contact_person_name1' => $this->request->getPost('contact_person_name1'),
'contact_person_name2' => $this->request->getPost('contact_person_name2'),
@@ -73,9 +78,10 @@ class Vendor extends BaseController
'contact_person_mobile1' => $this->request->getPost('contact_person_mobile1'),
'contact_person_mobile2' => $this->request->getPost('contact_person_mobile2'),
'contact_person_mobile3' => $this->request->getPost('contact_person_mobile3'),
- 'contact_person_resignation1' => $this->request->getPost('contact_person_resignation1'),
- 'contact_person_resignation2' => $this->request->getPost('contact_person_resignation2'),
- 'contact_person_resignation3' => $this->request->getPost('contact_person_resignation3'),
+ 'contact_person_designation1' => $this->request->getPost('contact_person_designation1'),
+ 'contact_person_designation2' => $this->request->getPost('contact_person_designation2'),
+ 'contact_person_designation3' => $this->request->getPost('contact_person_designation3'),
+ 'manufacturer_id' => json_encode($this->request->getPost('manufacturer')),
'isactive' => 1 ,
'branch_id' => $this->session->get('logged_user_branch_id'),
];
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/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
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 @@