diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ed6c650..6b01eb0 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -117,5 +117,6 @@ $routes->post('create_manufacturer', 'Manufacturer::create_manufacturer'); $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->get('get_vendor/(:any)', 'Purchase::get_vendor/$1'); $routes->post("add_purchase", "Purchase::add_purchase"); +$routes->get("delete_purchase/(:any)", "Purchase::delete_purchase/$1"); diff --git a/app/Controllers/Purchase.php b/app/Controllers/Purchase.php index 780f6a3..7ef907c 100644 --- a/app/Controllers/Purchase.php +++ b/app/Controllers/Purchase.php @@ -21,187 +21,123 @@ class Purchase extends BaseController { $PurchaseOrderModel = new PurchaseOrderModel(); - $purchase = $PurchaseOrderModel->findAll(); + $purchase = $PurchaseOrderModel->select('purchase_order.*, vendor.vendor_name') + ->join('vendor', 'vendor.vendor_id = purchase_order.vendor_id') + ->findAll(); // echo "
";
// print_r($product);die;
$data['purchase']=$purchase;
- echo "";
- print_r($data);die;
+ // echo "";
+ // print_r($data);die;
return view('purchase_list',$data);
}
- public function new_purchase($purchase_id)
+ public function new_purchase($purchase_order_id)
{
- if ($purchase_id === '0') {
+ if ($purchase_order_id === '0') {
$data['purchase'] = [];
$PurchaseOrderModel = new PurchaseOrderModel();
- $ProductModel = new ProductModel();
- $product = $ProductModel->select('product_id,product_name')->findAll();
+
+ $VendorModel = new VendorModel();
+ $vendor = $VendorModel->select('vendor_id,vendor_name')->findAll();
+
+
+ $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();
+
+ $data['branch'] = $branch;
+ $data['business'] = $business;
$data['page_name']="Add Purchase Order";
- $data['product']=$product;
+ $data['vendor']=$vendor;
- } else if ($purchase_id !== '0') {
- $data['page_name']="Edit Product";
- $ProductModel = new ProductModel();
- $products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
+ } else if ($purchase_order_id !== '0') {
+ $data['page_name']="Edit Purchase Order";
+
+ $PurchaseOrderModel = new PurchaseOrderModel();
+ $purchase=$PurchaseOrderModel->where('purchase_order_id', $purchase_order_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();
+ $vendor = $VendorModel->select('vendor_id,vendor_name')->findAll();
+ $data['vendor']=$vendor;
+ $data['purchase'] = $purchase;
+ $data['vendor_id'] = $purchase['vendor_id'];
+
}
- $data['purchase_id'] = $purchase_id;
-
+ // echo "";
+ // print_r($data);die;
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_address' => $this->request->getPost('billing_address'),
'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_address' => $this->request->getPost('shipping_address'),
+ 'shipping_state' => $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');
+ // echo "";
+ // print_r($this->request->getPost());die;
+ $purchase_order_id = $this->request->getPost('purchase_order_id');
-
- // if (!empty($product_id)) {
+ if (!empty($purchase_order_id)) {
- // $PurchaseOrderModel->update($product_id, $data);
- // } else {
+ $PurchaseOrderModel->update($purchase_order_id, $data);
+ } else {
$PurchaseOrderModel->insert($data);
- // }
+ }
- return redirect()->to('product_index');
+ return redirect()->to('purchase_index');
}
- public function delete_product($product_id)
+ public function delete_purchase($purchase_order_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();
+ $PurchaseOrderModel = new PurchaseOrderModel();
+ $where = ['purchase_order_id' => $purchase_order_id, 'isactive' => 1 ]; // Assuming 'isactive' is a column in your database
+ $existingPurchase = $PurchaseOrderModel->where($where)->first();
- if ($existingProduct) {
+ if ($existingPurchase) {
$data['isactive'] = 0;
- if ($model->update($product_id, $data)) {
+ if ($PurchaseOrderModel->update($purchase_order_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.');
- $this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$product_id);
+ $this->logger->info("Purchase Order: has been Inactivated successfully. Inactivated ID = ".$purchase_order_id);
}
}
- return redirect()->to('product_index');
+ return redirect()->to('purchase_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)
+ public function get_vendor($vendor_id)
{
- $ProductModel = new ProductModel();
- $BranchModel = new BranchModel();
- $BusinessModel = new BusinessModel();
+ $VendorModel = new VendorModel();
- $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 =$VendorModel->where('vendor_id',$vendor_id)->select('vendor_name,contact_person_name1,contact_person_mobile1')->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);
}
diff --git a/app/Models/PurchaseOrderModel.php b/app/Models/PurchaseOrderModel.php
index cbbfede..429dff8 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','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'];
+ 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','order_date','contact_person_name','contact_person_mobile','description'];
}
\ No newline at end of file
diff --git a/app/Views/purchase_form.php b/app/Views/purchase_form.php
index cd4c575..e7b05d0 100644
--- a/app/Views/purchase_form.php
+++ b/app/Views/purchase_form.php
@@ -5,7 +5,7 @@