product
This commit is contained in:
parent
aa528d3411
commit
edc9737402
@ -39,6 +39,8 @@ $routes->get('product_index/', 'Products::product_index');
|
||||
$routes->post("add_product", "Products::add_product");
|
||||
$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");
|
||||
//end products//
|
||||
|
||||
//Sales order //
|
||||
|
||||
@ -3,7 +3,9 @@
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ProductModel;
|
||||
// use App\Models\RoleModel;
|
||||
use App\Models\BikemakeModel;
|
||||
use App\Models\VendorModel;
|
||||
use App\Models\BikemodelsModel;
|
||||
|
||||
|
||||
class Products extends BaseController
|
||||
@ -37,10 +39,13 @@ class Products extends BaseController
|
||||
$ProductModel = new ProductModel();
|
||||
$tax=$ProductModel->getTax();
|
||||
$data['tax']=$tax;
|
||||
|
||||
$BikemakeModel = new BikemakeModel();
|
||||
$data['make'] = $BikemakeModel->findAll();
|
||||
$data['page_name']="Add Product";
|
||||
} else if ($product_id !== '0') {
|
||||
$data['page_name']="Edit Product";
|
||||
$BikemakeModel = new BikemakeModel();
|
||||
$data['make'] = $BikemakeModel->findAll();
|
||||
$ProductModel = new ProductModel();
|
||||
$tax=$ProductModel->getTax();
|
||||
$data['tax']=$tax;
|
||||
@ -75,6 +80,8 @@ class Products extends BaseController
|
||||
'qty_in_demand'=> $this->request->getPost('qty_in_demand'),
|
||||
'description' => $this->request->getPost('description'),
|
||||
'vendor' => $this->request->getPost('vendor'),
|
||||
'purchase_order_level' => $this->request->getPost('purchase_order_level'),
|
||||
'quality' => $this->request->getPost('quality'),
|
||||
'isactive' => 1 ,
|
||||
'branch_id' => $this->session->get('logged_user_branch_id')
|
||||
];
|
||||
@ -113,5 +120,47 @@ class Products extends BaseController
|
||||
|
||||
return redirect()->to('product_index');
|
||||
}
|
||||
|
||||
// Retrieve the make_id from the AJAX request
|
||||
public function get_vendors_by_model()
|
||||
{
|
||||
$make_id = $this->request->getPost('make_id');
|
||||
$model_ids = $this->request->getPost('model_ids');
|
||||
// print_r( $model_ids);die;
|
||||
|
||||
// If make_id or model_ids is not provided, return an empty response
|
||||
|
||||
|
||||
// Create an instance of VendorModel
|
||||
$vendorModel = new VendorModel();
|
||||
|
||||
// Call the get_vendors_by_model method from the model
|
||||
$vendors = $vendorModel->get_vendors_by_model($make_id, $model_ids);
|
||||
// print_r($vendors);
|
||||
// Return the response as JSON
|
||||
// return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']);
|
||||
if ($vendors) {
|
||||
// Return the retrieved vendors as JSON response
|
||||
return $this->response->setJSON($vendors);
|
||||
} else {
|
||||
// If no vendors were found, return an empty response or handle the error accordingly
|
||||
return $this->response->setJSON([]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,7 +5,7 @@ class ProductModel extends Model
|
||||
{
|
||||
protected $table = 'products';
|
||||
protected $primaryKey = 'product_id';
|
||||
protected $allowedFields = ['product_id','product_name','branch_id','search_tag','product_category','mfr_part_no','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 = ['product_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'];
|
||||
|
||||
|
||||
public function getTax()
|
||||
|
||||
@ -6,6 +6,24 @@ class VendorModel extends Model
|
||||
protected $table = 'vendor';
|
||||
protected $primaryKey = 'vendor_id';
|
||||
protected $allowedFields = ['vendor_id','branch_id','vendor_name','vendor_email','vendor_mobile','contact_name','website','gstnumber','conatct_person','vendortype','make','model','category','address','state','postal_code','city','country','description','isactive'];
|
||||
|
||||
|
||||
public function get_vendors_by_model($model_ids)
|
||||
{
|
||||
// Encode the model IDs array as JSON
|
||||
$json_model_ids = json_encode($model_ids);
|
||||
|
||||
// Query the database to retrieve vendors based on the model IDs
|
||||
$query = $this->query("SELECT * FROM vendor WHERE JSON_CONTAINS(model, '{$json_model_ids}')")->getResult();
|
||||
|
||||
// Check if any vendors are found
|
||||
if (!empty($query)) {
|
||||
return $query; // Return the result as an array of vendors
|
||||
} else {
|
||||
return array(); // Return an empty array if no vendors are found
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -23,15 +23,43 @@
|
||||
<form action="<?= base_url() . "add_product"; ?>" method="post">
|
||||
<h4 class="header-title">Product Details :</h4><br>
|
||||
<div class="form-row">
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="make" class="col-form-label">Make<span class="text-danger">*</span></label>
|
||||
<select class="form-control SelExample" id="make" name="make" required>
|
||||
<!-- Options for make -->
|
||||
<?php foreach ($make as $value): ?>
|
||||
<option value="<?= $value['make_id'] ?>" <?= isset($vendor['make_ids']) && in_array($value['make_id'], $vendor['make_ids']) ? 'selected' : '' ?>><?= $value['make'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="model" class="col-form-label">Model<span class="text-danger">*</span></label>
|
||||
<select class="form-control SelExample" id="model" name="model[]" required multiple>
|
||||
<!-- Options for model will be populated dynamically via AJAX -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputEmail4" class="col-form-label">Product Name<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="productname" placeholder="Product Name" value="<?= isset($products['product_name']) ? $products['product_name'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputEmail4" class="col-form-label">Product Category<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="productcategory" placeholder="Product Category" value="<?= isset($products['product_category']) ? $products['product_category'] : '' ?>" required>
|
||||
</div>
|
||||
<label for="vendor" class="col-form-label">Vendor<span class="text-danger">*</span></label>
|
||||
<select class="form-control" id="vendor" name="vendor" required>
|
||||
<!-- Placeholder option -->
|
||||
<option value="">Select Vendor</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="vendor" class="col-form-label">Quality<span class="text-danger">*</span></label>
|
||||
<select class="form-control " name="quality" required data-toggle="select2" >
|
||||
<!-- <option value="">Select a Status</option> -->
|
||||
<option value="Q1" <?= isset($products['quality']) && $products['quality'] === 'Q1' ? 'selected' : '' ?>>Q1</option>
|
||||
<option value="Q2" <?= isset($products['quality']) && $products['quality'] === 'Q2' ? 'selected' : '' ?>>Q2 </option>
|
||||
<option value="Q3" <?= isset($products['quality']) && $products['quality'] === 'Q3' ? 'selected' : '' ?>>Q3</option>
|
||||
<option value="Q4" <?= isset($products['quality']) && $products['quality'] === 'Q4' ? 'selected' : '' ?>>Q4</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputAddress" class="col-form-label">Manfacturer Part Number</label>
|
||||
<input type="text" class="form-control" name="mfr_part_no" placeholder="Manfacturer Part Number" value="<?= isset($products['mfr_part_no']) ? $products['mfr_part_no'] : '' ?>" >
|
||||
@ -41,9 +69,10 @@
|
||||
<input type="text" class="form-control" name="serial_no" placeholder="Serial Number"value="<?= isset($products['serial_no']) ? $products['serial_no'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Vendor<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="vendor" placeholder="Vendor"value="<?= isset($products['vendor']) ? $products['vendor'] : '' ?>" required>
|
||||
<label for="inputEmail4" class="col-form-label">Product Category<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="productcategory" placeholder="Product Category" value="<?= isset($products['product_category']) ? $products['product_category'] : '' ?>" required>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<input type="hidden" id="product_id" name="product_id" value="<?= isset($products['product_id']) ? $products['product_id'] : '' ?>"><br>
|
||||
<h4 class="header-title">Pricing Information :</h4><br>
|
||||
@ -87,6 +116,10 @@
|
||||
<label for="inputPassword4" class="col-form-label">Qty in Stock<span class="text-danger">*</span></label>
|
||||
<input type="number" class="form-control" name="qty_in_stock" placeholder="Qty in Stock" value="<?= isset($products['qty_stock']) ? $products['qty_stock'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Purchase Order Level<span class="text-danger"></span></label>
|
||||
<input type="number" class="form-control" name="purchase_order_level" placeholder="Purchase Order Level" value="<?= isset($products['purchase_order_level']) ? $products['purchase_order_level'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4" hidden>
|
||||
<label for="inputPassword4" class="col-form-label">Qty in Demand</label>
|
||||
<input type="number" class="form-control" name="qty_in_demand" placeholder="Qty in Demand" value="<?= isset($products['qty_in_demand']) ? $products['qty_in_demand'] : '' ?>" >
|
||||
@ -139,4 +172,104 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
// Initialize select2
|
||||
$(".SelExample").select2();
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#make').change(function() {
|
||||
var make_id = $(this).val(); // Get the selected make ID
|
||||
|
||||
// AJAX request to get models based on the selected make ID
|
||||
$.ajax({
|
||||
url: '<?php echo base_url('get_models') ?>', // URL to your CodeIgniter controller method
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { make_id: make_id }, // Send the selected make ID to the controller
|
||||
success: function(response) {
|
||||
// Update models dropdown based on the response
|
||||
if (response.length > 0) {
|
||||
// Clear existing options
|
||||
$('#model').empty();
|
||||
// Append new options
|
||||
$.each(response, function(index, model) {
|
||||
$('#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
|
||||
console.error(xhr.responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#model').change(function() {
|
||||
var make_id = $(this).val(); // Get the selected make ID
|
||||
var model_ids = $('#model').val(); // Get the selected model IDs
|
||||
console.log(model_ids);
|
||||
|
||||
// AJAX request to get vendors based on the selected model ID
|
||||
$.ajax({
|
||||
url: '<?php echo base_url('get_vendors_by_model') ?>', // URL to your CodeIgniter controller method
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { make_id: make_id, model_ids: model_ids }, // Send the selected make ID and model IDs to the controller
|
||||
success: function(response) {
|
||||
// Update vendor dropdown based on the response
|
||||
if (response) {
|
||||
// Clear existing options
|
||||
$('#vendor').empty();
|
||||
// Append new options
|
||||
$('#vendor').append('<option value>"hello"</option>');
|
||||
$.each(response, function(index, vendor) {
|
||||
$('#vendor').append('<option value="' + vendor.vendor_id + '">' + vendor.vendor_name + '</option>');
|
||||
});
|
||||
} else {
|
||||
// Handle case when no vendors are found for the selected model
|
||||
console.log('No vendors found for the selected model');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error(xhr.responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
<style>
|
||||
.select2-container .select2-selection--multiple .select2-selection__choice{
|
||||
padding: 5px 7px 5px 0 !important;
|
||||
color: #000000;
|
||||
|
||||
}
|
||||
.select2-container--default .select2-results__option--highlighted[aria-selected]{
|
||||
color:#ffffff;
|
||||
background-color: #526dee;
|
||||
}
|
||||
.select2-container--default .select2-results__option{
|
||||
border-bottom: 1px solid #dddddd;
|
||||
}
|
||||
.select2-container--default .select2-results__option[aria-selected=true]{
|
||||
color: #000000;
|
||||
background-color: #3efba4;
|
||||
font-weight: 500;
|
||||
border-bottom: 1px solid #747474;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user