diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0287e95..7e7fa97 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -129,6 +129,7 @@ $routes->get('dashboard', 'Users::dashboard'); // Make // $routes->get('make_index', 'Make::index'); $routes->post('create_make/(:any)', 'Make::create_make/$1'); + $routes->post('status_make', 'Make::status_make'); // Make End's // diff --git a/app/Controllers/Make.php b/app/Controllers/Make.php index f232920..b5382aa 100644 --- a/app/Controllers/Make.php +++ b/app/Controllers/Make.php @@ -2,6 +2,7 @@ namespace App\Controllers; +use App\Models\BikemodelsModel; use App\Models\BikemakeModel; use CodeIgniter\API\ResponseTrait; @@ -40,10 +41,18 @@ class Make extends BaseController 'make' => $make_name ]; if (!$make_id) { - $inserted = $BikemakeModel->insert($data); + try { + $inserted = $BikemakeModel->insert($data); + } catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) { + + return $this->respond(['status' => 'failed','code' => 404,'data' => $e->getMessage()],200); + } + if ($inserted) { $result = $data; - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + $make_list = $BikemakeModel->orderBy('make','asc')->findAll(); + + return $this->respond(['status' => 'success','code' => 200,'data' => $result,'make_list'=>$make_list],200); } else { $result = "No Match's"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); @@ -63,4 +72,39 @@ class Make extends BaseController } } + + public function status_make() + { + + try { + $make_id = $this->request->getPost('make_id'); + $isactive = $this->request->getPost('isactive'); + + $BikemakeModel = new BikemakeModel(); + $BikemodelsModel = new BikemodelsModel(); + $data = [ + 'isactive' => $isactive + ]; + $updated = $BikemakeModel->update($make_id, $data); + $make_list = $BikemakeModel->orderBy('make','asc')->findAll(); + $model_list = $BikemodelsModel->where('make_id',$make_id)->findAll(); + + foreach ($model_list as $model) { + $model_id= $model['model_id']; + $model_updated = $BikemodelsModel->update($model_id, $data); + } + + if ($updated) { + $result = $data; + return $this->respond(['status' => 'success','code' => 200,'data' => $make_list],200); + } else { + $result = "No Match's"; + return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); + } + } catch (\Exception $exception) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500); + } + } + + } \ No newline at end of file diff --git a/app/Controllers/Model.php b/app/Controllers/Model.php index fff9b49..61b0bf2 100644 --- a/app/Controllers/Model.php +++ b/app/Controllers/Model.php @@ -54,10 +54,18 @@ class Model extends BaseController ]; if (!$model_id) { - $inserted = $BikemodelsModel->insert($data); + + try { + $inserted = $BikemodelsModel->insert($data); + } catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) { + + return $this->respond(['status' => 'failed','code' => 404,'data' => $e->getMessage()],200); + } if ($inserted) { $result = $data; - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + $model_list = $BikemodelsModel->where('make_id',$make_id)->orderBy('make','asc')->findAll(); + + return $this->respond(['status' => 'success','code' => 200,'data' => $result,'model_list'=>$model_list],200); } else { $result = "No Match's"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); @@ -93,10 +101,13 @@ class Model extends BaseController ]; $updated = $BikemodelsModel->update($model_id, $data); - $model_list = $BikemodelsModel->findAll(); + $model = $BikemodelsModel->where('model_id',$model_id)->first(); + + $models = $BikemodelsModel->where('make_id', $model['make_id'])->orderBy('model_name', 'asc')->findAll(); if ($updated) { - $result = $data; - return $this->respond(['status' => 'success','code' => 200,'data' => $model_list],200); + + // $result = $data; + return $this->respond(['status' => 'success','code' => 200,'data' => $models],200); } else { $result = "No Match's"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index f6df5a8..1a66db3 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -69,18 +69,30 @@ class Products extends BaseController $data['manufacturers']=$ManufacturerModel->findAll(); $data['page_name']="Add Product"; $data['vendorsProduct'] =[]; - } else if ($product_id !== '0') { + } else if ($product_id !== '0') { $data['page_name']="Edit Product"; $ProductModel = new ProductModel(); $products=$ProductModel->where('product_id', $product_id)->get()->getRowArray(); + $products['make_id'] = json_decode($products['make_id'], true); + $products['models_id'] = json_decode($products['models_id'], true); + + $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(); + $BikemodelsModel = new BikemodelsModel(); + + $models = []; + if( $products['make_id'] != null) { + foreach ($products['make_id'] as $make_id) { + $models[] = $BikemodelsModel->where('make_id', $make_id)->findAll(); + } + } + $data['models'] = $models; $tax=$ProductModel->getTax(); $data['tax']=$tax; @@ -89,6 +101,9 @@ class Products extends BaseController $ManufacturerModel = new ManufacturerModel(); $data['manufacturers']=$ManufacturerModel->findAll(); $vendorIds = json_decode($products['vendor'], true); + + + $vendors = []; $VendorModel = new VendorModel(); foreach ($vendorIds as $vendorId) { @@ -103,10 +118,13 @@ class Products extends BaseController $preferredVendorId = $products['prefered_vendor']; // Pass the preferred vendor ID to the view $data['preferredVendorId'] = $preferredVendorId; // print_r($data);die; - // print_r($data);die; + // print_r($data);die; } $data['product_id'] = $product_id; + // echo "
";
+ // print_r($data);die;
+
echo view('product_form',$data);
}
@@ -135,7 +153,7 @@ class Products extends BaseController
'purchase_order_level' => $this->request->getPost('purchase_order_level'),
'reorder_level' => $this->request->getPost('reorder_level'),
'quality' => $this->request->getPost('quality'),
- 'make_id' => $this->request->getPost('make'),
+ 'make_id' => json_encode($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'),
@@ -146,7 +164,6 @@ class Products extends BaseController
'branch_id' => $this->session->get('logged_user_branch_id')
];
-
$product_id = $this->request->getPost('product_id');
@@ -244,92 +261,114 @@ class Products extends BaseController
-public function get_models()
-{
- $make_id = $this->request->getPost('make_id'); // Assuming you are sending make_id via POST
-
- // Fetch models based on the selected make ID
- $BikemodelsModel = new BikemodelsModel(); // Adjust this according to your actual model name
- $models = $BikemodelsModel->where('make_id', $make_id)->findAll(); // Implement this method in your model
- // Return the model data as JSON
- return $this->response->setJSON($models);
-}
+ public function get_models()
+ {
+ $make_ids = $this->request->getPost('make_id'); // Assuming you are sending make_id via POST
+ $BikemodelsModel = new BikemodelsModel(); // Adjust this according to your actual model name
-
-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;
+ $formatted_models = [];
+
+ // Iterate over each selected make ID
+ if ($make_ids) {
+ foreach ($make_ids as $make_id) {
+ // Fetch models based on the selected make ID
+ $models = $BikemodelsModel->where('make_id', $make_id)->findAll();
+
+ // Iterate over each fetched model and format it as needed
+ foreach ($models as $model) {
+ // Create an associative array with 'model_id' and 'model_name' properties
+ $formatted_model = [
+ 'make_id' => $model['make_id'],
+ 'model_id' => $model['model_id'],
+ 'model_name' => $model['model_name']
+ // Add other properties if needed
+ ];
+
+ // Push the formatted model into the array
+ $formatted_models[] = $formatted_model;
+ }
+ }
+ }
+ return $this->response->setJSON($formatted_models);
}
- // 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() {
- $response = [];
- $BikemodelsModel = new BikemodelsModel();
-
- $make_id = $this->request->getPost('make_id');
- $model = $this->request->getPost('modelvalue');
- if (!empty($make_id) && !empty($model)) {
- $modelData = [
- 'model_name' => $model,
- 'make_id' => $make_id,
- ];
+
+
+
+ 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);
+ }
+ 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() {
+ $response = [];
+ $BikemodelsModel = new BikemodelsModel();
+
+ $make_id = $this->request->getPost('make_id');
+ $model = $this->request->getPost('modelvalue');
+ if (!empty($make_id) && !empty($model)) {
+ $modelData = [
+ 'model_name' => $model,
+ 'make_id' => $make_id,
+ ];
+
+
+ $model_id = $BikemodelsModel->insert($modelData);
+
+ $modelData = $BikemodelsModel->where('make_id',$make_id)->findAll();
- $model_id = $BikemodelsModel->insert($modelData);
+ $response['success'] = true;
+ $response['model_id'] = $model_id;
+ $response['model_value'] = $model;
+ } else {
+
+ $response['success'] = false;
+ }
- $modelData = $BikemodelsModel->where('make_id',$make_id)->findAll();
-
-
- $response['success'] = true;
- $response['model_id'] = $model_id;
- $response['model_value'] = $model;
- } else {
-
- $response['success'] = false;
+
+ return $this->response->setJSON($response);
}
-
-
- return $this->response->setJSON($response);
-}
}
\ No newline at end of file
diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php
index de1d87e..28459dc 100644
--- a/app/Controllers/Sales.php
+++ b/app/Controllers/Sales.php
@@ -31,6 +31,8 @@ class Sales extends BaseController
$sales=$SalesOrderModel->getSalesOrdersWithProducts($this->session->get('logged_user_branch_id'));
$data['sales']=$sales;
+ // echo"";
+ // print_r($data);die;
return view('sales_list',$data);
}
@@ -52,17 +54,17 @@ class Sales extends BaseController
// ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$ProductModel = new ProductModel();
- $product=$ProductModel
- ->where('isactive',1)
- ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
- $data['product']=$product;
- $data['client']=$client;
- $data['vehicle']=$vehicle;
+ $product=$ProductModel
+ ->where('isactive',1)
+ ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+ $data['product']=$product;
+ $data['client']=$client;
+ $data['vehicle']=$vehicle;
- } else if ($sales_order_id !== '0')
- {
+ } else if ($sales_order_id !== '0')
+ {
$data['page_name']="Edit Sale Order";
@@ -80,13 +82,14 @@ class Sales extends BaseController
$modelId = $vehicles['model'];
// Encode the modelId before searching
+ $encodedMakeId = json_encode([$makeId]);
$encodedModelId = json_encode([$modelId]);
// Load the ProductModel
$productModel = new ProductModel();
// Query the database to find the product based on make_id and model_id
- $product = $productModel->where('make_id', $makeId)
+ $product = $productModel->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->findAll();
$data['product']=$product;
@@ -426,16 +429,18 @@ public function getProducts()
$modelId = $this->request->getPost('model_id');
// Encode the modelId before searching
+ $encodedMakeId = json_encode([$makeId]);
$encodedModelId = json_encode([$modelId]);
// Load the ProductModel
$productModel = new ProductModel();
// Query the database to find the product based on make_id and model_id
- $product = $productModel->where('make_id', $makeId)
+ $product = $productModel->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->where('qty_stock >',0)
->findAll();
+ // print_r($product);die;
$modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name;
$makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make;
diff --git a/app/Models/SalesOrderModel.php b/app/Models/SalesOrderModel.php
index 8edbadc..2d58a55 100644
--- a/app/Models/SalesOrderModel.php
+++ b/app/Models/SalesOrderModel.php
@@ -22,7 +22,7 @@ class SalesOrderModel extends Model
public function getSalesOrdersWithProducts($logged_user_branch_id)
{
// Select required fields from both tables
- $this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,vehicle.reg_no');
+ $this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,vehicle.reg_no,SUM(sales_order_product.qty) AS product_qty ');
// Join the sales_order_product table based on sales_order_id
$this->join('sales_order_product', 'sales_order_product.sales_order_id = sales_order.sales_order_id');
diff --git a/app/Views/bike_model_list.php b/app/Views/bike_model_list.php
index cc62271..03abaaa 100644
--- a/app/Views/bike_model_list.php
+++ b/app/Views/bike_model_list.php
@@ -44,9 +44,9 @@
-
+
-
+
@@ -115,10 +115,43 @@
data: formData,
dataType: 'json',
success: function(response) {
- // Handle success response here
- console.log(response);
+ if (response.status == "failed") {
+ toastr.warning(response.data, 'Warning');
+ }else{
$('#bike_model_login-modal_1').modal('hide');
+ $('#makename').val('');
$('#modelname').val('');
+ toastr.success(response.data, 'Success');
+
+ $('tbody').html('');
+
+ $.each(response.model_list, function(index, item) {
+ var row = '' +
+ '' + item.model_name + ' ' +
+ '';
+
+ if (item.isactive == 1) {
+ row += 'Active';
+ } else if (item.isactive == 0) {
+ row += 'Inactive';
+ }
+
+ row += ' ';
+
+ row += '';
+ // Check the isactive status and set the icon color accordingly
+ if (item.isactive == 1) {
+ row += '';
+ } else if (item.isactive == 0) {
+ row += '';
+ }
+
+ row += ' ';
+
+ // Append the row to the tbody
+ $('tbody').append(row);
+ });
+ }
},
error: function(xhr, status, error) {
// Handle error response here
@@ -147,29 +180,29 @@
data: formData,
dataType: 'json',
success: function(response) {
- console.log(response);
if (response.status == "success") {
$('tbody').html('');
$.each(response.data, function(index, item) {
- var row = '' +
- '' + item.model_name + ' ' +
- '';
+ var row = ' ' +
+ '' + item.model_name + ' ' +
+ '';
- if (item.isactive == 1) {
- row += 'Active';
- } else if (item.isactive == 0) {
- row += 'Inactive';
- }
+ if (item.isactive == 1) {
+ row += 'Active';
+ } else if (item.isactive == 0) {
+ row += 'Inactive';
+ }
row += ' ';
+ row += '';
// Check the isactive status and set the icon color accordingly
if (item.isactive == 1) {
- row += '';
+ row += '';
} else if (item.isactive == 0) {
- row += '';
+ row += '';
}
row += ' ';
diff --git a/app/Views/make_list.php b/app/Views/make_list.php
index edda05b..76b3c9a 100644
--- a/app/Views/make_list.php
+++ b/app/Views/make_list.php
@@ -26,6 +26,7 @@
Bike Make
+ Status
Action
@@ -33,6 +34,13 @@
+
+
+ Active
+
+ Inactive
+
+
@@ -42,6 +50,11 @@
" class="view-list-button" title="Model List" style="margin-left: 12px;">
+
+
+
+
+
@@ -62,7 +75,7 @@
Add Bike Make
-
+
@@ -91,7 +104,7 @@