CHANGE_PRODUCT_MAKE_MULTIPLE : AADHAVAN

This commit is contained in:
aadhavan valli 2024-04-26 15:23:29 +05:30
parent 7e309f9594
commit 9935089af0
11 changed files with 407 additions and 143 deletions

View File

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

View File

@ -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);
}
}
}

View File

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

View File

@ -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 "<pre>";
// 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);
}
}

View File

@ -31,6 +31,8 @@ class Sales extends BaseController
$sales=$SalesOrderModel->getSalesOrdersWithProducts($this->session->get('logged_user_branch_id'));
$data['sales']=$sales;
// echo"<pre>";
// 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;

View File

@ -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');

View File

@ -44,9 +44,9 @@
<a data-toggle="modal" data-target="#bike_model_login-modal_1" data-value="<?php echo $item['model_id']; ?>" class="edit-button" onclick="editModel(this)"><i class="ri-pencil-line"></i></a>
<?php if($item['isactive'] == 1): ?>
<a style="color:red; margin-left:12px;" data-id="<?php echo $item['model_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Deactivate" onclick="statusChange(this)" class="fa fa-user-times"></a>
<a style="color:red; margin-left:12px;" data-id="<?php echo $item['model_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Deactivate" onclick="statusChange(this)"><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i></a>
<?php else: ?>
<a style="color:green; margin-left:12px;" data-id="<?php echo $item['model_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Activate" onclick="statusChange(this)" class="fa fa-user"></a>
<a style="color:green; margin-left:12px;" data-id="<?php echo $item['model_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Activate" onclick="statusChange(this)"><i class="fa fa-bicycle"></i></a>
<?php endif; ?>
</td>
</tr>
@ -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 = '<tr>' +
'<td class="model_name">' + item.model_name + '</td>' +
'<td>';
if (item.isactive == 1) {
row += '<span style="color:green">Active</span>';
} else if (item.isactive == 0) {
row += '<span style="color:red">Inactive</span>';
}
row += '</td><td>';
row += '<a data-toggle="modal" data-target="#bike_model_login-modal_1" data-value="' + item.model_id + '" class="edit-button" onclick="editModel(this)"><i class="ri-pencil-line"></i></a>';
// Check the isactive status and set the icon color accordingly
if (item.isactive == 1) {
row += '<a style="color:red; margin-left:12px;" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Deactivate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i></a>';
} else if (item.isactive == 0) {
row += '<a style="color:green; margin-left:12px;" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Activate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i></a>';
}
row += '</td><td></td></tr>';
// 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 = '<tr>' +
'<td>' + item.model_name + '</td>' +
'<td>';
var row = '<tr>' +
'<td class="model_name">' + item.model_name + '</td>' +
'<td>';
if (item.isactive == 1) {
row += '<span style="color:green">Active</span>';
} else if (item.isactive == 0) {
row += '<span style="color:red">Inactive</span>';
}
if (item.isactive == 1) {
row += '<span style="color:green">Active</span>';
} else if (item.isactive == 0) {
row += '<span style="color:red">Inactive</span>';
}
row += '</td><td>';
row += '<a data-toggle="modal" data-target="#bike_model_login-modal_1" data-value="' + item.model_id + '" class="edit-button" onclick="editModel(this)"><i class="ri-pencil-line"></i></a>';
// Check the isactive status and set the icon color accordingly
if (item.isactive == 1) {
row += '<a style="color:red" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Deactivate" onclick="statusChange(this)" class="fa fa-user-times"></a>';
row += '<a style="color:red; margin-left:12px;" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Deactivate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i></a>';
} else if (item.isactive == 0) {
row += '<a style="color:green" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Activate" onclick="statusChange(this)" class="fa fa-user"></a>';
row += '<a style="color:green; margin-left:12px;" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Activate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i></a>';
}
row += '</td><td></td></tr>';

View File

@ -26,6 +26,7 @@
<thead>
<tr>
<th>Bike Make</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
@ -33,6 +34,13 @@
<?php foreach ($make as $item): ?>
<tr>
<td class="make"><?php echo $item['make']; ?></td>
<td>
<?php if($item['isactive'] == 1): ?>
<span style="color:green">Active</span>
<?php else: ?>
<span style="color:red">Inactive</span>
<?php endif; ?>
</td>
<td>
<a data-toggle="modal" data-target="#bike_make_login-modal" data-value="<?php echo $item['make_id']; ?>" class="edit-button" onclick="editMake(this)"><i class="ri-pencil-line"></i></a>
@ -42,6 +50,11 @@
<a href="<?= "bike_model_index/" . $item['make_id']; ?>" class="view-list-button" title="Model List" style="margin-left: 12px;">
<i class="ri-list-check-2 icon-large"></i>
</a>
<?php if($item['isactive'] == 1): ?>
<a style="color:red; margin-left:12px;" data-id="<?php echo $item['make_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Deactivate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i></a>
<?php else: ?>
<a style="color:green; margin-left:12px;" data-id="<?php echo $item['make_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Activate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i></a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
@ -62,7 +75,7 @@
<h4 id="form_add_edit">Add Bike Make</h4>
</div>
<form id="model_form_data" class="px-3">
<!-- <form id="model_form_data" class="px-3"> -->
<div class="form-group">
<label for="makename">Make Name </label>
@ -74,7 +87,7 @@
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitMake(this)">Submit</button>
</div>
</form>
<!-- </form> -->
</div>
</div><!-- /.modal-content -->
@ -91,7 +104,7 @@
<h4>Add Models</h4>
</div>
<form id="model_form_data" class="px-3">
<!-- <form id="model_form_data" class="px-3"> -->
<div class="form-group">
<input class="form-control" type="text" id="make_id" required="" placeholder="Make Name...." style="display:none;">
@ -105,7 +118,7 @@
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitModel(this)">Submit</button>
</div>
</form>
<!-- </form> -->
</div>
</div><!-- /.modal-content -->
@ -169,8 +182,48 @@
dataType: 'json',
success: function(response) {
console.log(response);
$('#bike_model_login-modal').modal('hide');
$('#bike_make_name').val('');
if (response.status == "failed") {
toastr.warning(response.data, 'Warning');
}else{
$('#bike_make_login-modal').modal('hide');
$('#bike_make_name').val('');
toastr.success(response.data, 'Success');
$('tbody').html('');
$.each(response.make_list, function(index, item) {
var row = '<tr>' +
'<td class="make">' + item.make + '</td>' +
'<td>';
if (item.isactive == 1) {
row += '<span style="color:green">Active</span>';
} else if (item.isactive == 0) {
row += '<span style="color:red">Inactive</span>';
}
row += '</td><td>';
// Check the isactive status and set the icon color accordingly
row += '<a data-toggle="modal" data-target="#bike_make_login-modal" data-value="'+ item.make_id +'" class="edit-button" onclick="editMake(this)"><i class="ri-pencil-line"></i></a>';
row +='<a href="#" data-toggle="modal" data-target="#bike_model_login-modal" style="margin-left: 12px;" class="add-button" title="Add" data-id="'+ item.make_id+'" data-value="' +item.make+'" onclick="setMakeName(this)"><i class="ri-add-line icon-large"></i></a>';
row +='<a href="bike_model_index/' +item.make_id+'" class="view-list-button" title="Model List" style="margin-left: 12px;"><i class="ri-list-check-2 icon-large"></i></a>';
if (item.isactive == 1) {
row += '<a style="color:red; margin-left:12px;" data-id="' + item.make_id + '" data-isactive="' + item.isactive + '" title="Deactivate" onclick="statusChange(this)"><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i></a>';
} else if (item.isactive == 0) {
row += '<a style="color:green; margin-left:12px;" data-id="' + item.make_id + '" data-isactive="' + item.isactive + '" title="Activate" onclick="statusChange(this)"><i class="fa fa-bicycle"></i></a>';
}
row += '</td><td></td></tr>';
// Append the row to the tbody
$('tbody').append(row);
});
}
},
error: function(xhr, status, error) {
// Handle error response here
@ -186,7 +239,7 @@
$('#form_add_edit').text('Edit Bike Make');
var full_div = $(params).parent().parent()[0];
console.log($(full_div));
$('#bike_make_name').val($(full_div).find('.make').text());
}
@ -197,4 +250,68 @@
}
function statusChange(params) {
var status = params.getAttribute('data-isactive');
var make_id = params.getAttribute('data-id');
if(status == 1){
var isactive= 0;
}else{
var isactive= 1;
}
var formData = {
make_id: make_id,
isactive: isactive
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."status_make"?>',
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
if (response.status == "success") {
$('tbody').html('');
$.each(response.data, function(index, item) {
var row = '<tr>' +
'<td class="make">' + item.make + '</td>' +
'<td>';
if (item.isactive == 1) {
row += '<span style="color:green">Active</span>';
} else if (item.isactive == 0) {
row += '<span style="color:red">Inactive</span>';
}
row += '</td><td>';
// Check the isactive status and set the icon color accordingly
row += '<a data-toggle="modal" data-target="#bike_make_login-modal" data-value="'+ item.make_id +'" class="edit-button" onclick="editMake(this)"><i class="ri-pencil-line"></i></a>';
row +='<a href="#" data-toggle="modal" data-target="#bike_model_login-modal" style="margin-left: 12px;" class="add-button" title="Add" data-id="'+ item.make_id+'" data-value="' +item.make+'" onclick="setMakeName(this)"><i class="ri-add-line icon-large"></i></a>';
row +='<a href="bike_model_index/' +item.make_id+'" class="view-list-button" title="Model List" style="margin-left: 12px;"><i class="ri-list-check-2 icon-large"></i></a>';
if (item.isactive == 1) {
row += '<a style="color:red; margin-left:12px;" data-id="' + item.make_id + '" data-isactive="' + item.isactive + '" title="Deactivate" onclick="statusChange(this)"><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i></a>';
} else if (item.isactive == 0) {
row += '<a style="color:green; margin-left:12px;" data-id="' + item.make_id + '" data-isactive="' + item.isactive + '" title="Activate" onclick="statusChange(this)"><i class="fa fa-bicycle"></i></a>';
}
row += '</td><td></td></tr>';
// Append the row to the tbody
$('tbody').append(row);
});
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
</script>

View File

@ -28,12 +28,12 @@
<label for="make" class="col-form-label">Make<span class="text-danger">*</span></label>
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addMakeModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addMakeModal" title="Add Client"></i>' ?>
<select class="form-control SelExample" id="make" name="make" required>
<select class="form-control SelExample" id="make" name="make[]" required multiple>
<option value="">Select a Make</option>
<!-- Options for make -->
<?php foreach ($make as $value): ?>
<option value="<?= $value['make_id'] ?>" <?= isset($products['make_id']) && $products['make_id'] == $value['make_id'] ? 'selected' : '' ?>>
<option value="<?= $value['make_id'] ?>" <?= isset($products['make_id']) && in_array($value['make_id'], $products['make_id']) ? 'selected' : '' ?>>
<?= $value['make'] ?>
</option>
<?php endforeach; ?>
@ -46,11 +46,11 @@
<select class="form-control SelExample" id="model" name="model[]" required multiple>
<!-- Options for model will be populated dynamically via AJAX -->
<?php if(isset($models) && !empty($models)): ?>
<?php foreach($models as $model): ?>
<option value="<?= $model['model_id'] ?>" <?= isset($products['models_id']) && in_array($model['model_id'], json_decode($products['models_id'], true)) ? 'selected' : '' ?>>
<?= $model['model_name'] ?>
</option>
<?php endforeach; ?>
<?php foreach ($models as $make_models): ?>
<?php foreach ($make_models as $model): ?>
<option value="<?= $model['model_id'] ?>" <?= isset($products['models_id']) && in_array($model['model_id'], $products['models_id']) ? 'selected' : '' ?>><?= $model['model_name'] ?></option>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
@ -359,6 +359,8 @@ $(document).ready(function() {
$('#make').change(function() {
var make_id = $(this).val(); // Get the selected make ID
make_value = $('option:selected', this).text();
var models_id = $('#model').val();
$('#makeSelect').empty();
$('#makeSelect').append('<option value="' + make_id + '">' + make_value + '</option>');
$('#makeSelectMessage').hide();
@ -372,17 +374,28 @@ $(document).ready(function() {
success: function(response) {
// Update models dropdown based on the response
if (response.length > 0) {
// Clear existing options
$('#model').empty();
// Append new options
$("#model").append('<option value=""> Select a Model </option>');
$.each(response, function(index, model) {
$('#model').append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
// Clear existing options
$('#model').empty();
// Iterate through response and models_id
$.each(response, function(index, model) {
var count =0;
$.each(models_id, function(index, model_id) {
if (model.model_id == model_id) {
// Append option for the model
$('#model').append('<option value="' + model.model_id + '" selected>' + model.model_name + '</option>');
count =1;
}
});
} else {
// Handle case when no models are found
$('#model').empty().append('<option value="">No models found</option>');
}
if (count == 0) {
$('#model').append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
}
});
} else {
// Handle case when no models are found
$('#model').empty().append('<option value="">No models found</option>');
}
},
error: function(xhr, status, error) {
// Handle error

View File

@ -56,7 +56,7 @@
<th>Client Name</th>
<th>Items</th>
<th>Qty</th>
<th>Total</th>
<th>Status</th>
<th>Actions</th>
@ -77,6 +77,7 @@
<td><?= $value['client_name']; ?></td>
<td><?= $value['product_count']; ?></td>
<td><?= $value['product_qty']; ?></td>
<td><?= $value['total']; ?></td>
<td class="<?php

View File

@ -152,7 +152,7 @@
<!-- Dynamically add rows for item details -->
<?php if (isset($sales_product) && !empty($sales_product)) : ?>
<?php foreach ($sales_product as $salechild) :
if ($salechild['isactive'] == 1) : ?>
if ($salechild['isactive'] == 1) : ?>
<tr>
<td>
<select class="form-control book-select SelExample" name="item_details[]"