FIX_AssignedSupportWork
This commit is contained in:
parent
dd502de48b
commit
cf26a1d723
@ -111,6 +111,7 @@ class Products extends BaseController
|
|||||||
|
|
||||||
$productcategory = $this->ProductCategoryModel->orderBy('product_category_id')->findAll();
|
$productcategory = $this->ProductCategoryModel->orderBy('product_category_id')->findAll();
|
||||||
$data['product_id'] = 0;
|
$data['product_id'] = 0;
|
||||||
|
$data['products'] = [];
|
||||||
$data['additionalProdutName'] = [];
|
$data['additionalProdutName'] = [];
|
||||||
|
|
||||||
|
|
||||||
@ -237,6 +238,7 @@ class Products extends BaseController
|
|||||||
$product_id = $this->request->getPost('product_id');
|
$product_id = $this->request->getPost('product_id');
|
||||||
$additional_product_name = $this->request->getPost('additional_product_name');
|
$additional_product_name = $this->request->getPost('additional_product_name');
|
||||||
$product_names_id = $this->request->getPost('product_names_id');
|
$product_names_id = $this->request->getPost('product_names_id');
|
||||||
|
$model_ids = $this->request->getPost('fk_model_id');
|
||||||
|
|
||||||
// print_r($data);die;
|
// print_r($data);die;
|
||||||
if (!empty($product_id)) {
|
if (!empty($product_id)) {
|
||||||
@ -247,7 +249,7 @@ class Products extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
//for insert or update Additional Product Names
|
//for insert or update Additional Product Names
|
||||||
$this->insertOrUpdateAdditionalProductName($additional_product_name, $product_names_id, $product_id, $data['product_name']);
|
$this->insertOrUpdateAdditionalProductName($additional_product_name, $product_names_id, $model_ids, $product_id, $data['product_name']);
|
||||||
|
|
||||||
$orderNumber = 'TM' . str_pad($product_id, 8, '0', STR_PAD_LEFT);
|
$orderNumber = 'TM' . str_pad($product_id, 8, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
@ -520,39 +522,39 @@ class Products extends BaseController
|
|||||||
|
|
||||||
//----VENKAT------------------------------------------------------------------------------------------------
|
//----VENKAT------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
public function insertOrUpdateAdditionalProductName($product_names, $product_name_id, $product_id, $first_product_name)
|
public function insertOrUpdateAdditionalProductName($product_names, $product_name_id,$model_ids, $product_id, $first_product_name)
|
||||||
{
|
{
|
||||||
// Fetch existing product names for the given product ID
|
// Fetch existing product names for the given product ID
|
||||||
$product_name_data = $this->additionalProductNameModal->where('product_id', $product_id)
|
$product_name_data = $this->additionalProductNameModal->where('product_id', $product_id)
|
||||||
->orderBy('product_names_id', 'asc')
|
->orderBy('product_names_id', 'asc')
|
||||||
->findAll();
|
->findAll();
|
||||||
$product_name_count = count($product_name_data);
|
$product_name_count = count($product_name_data);
|
||||||
|
|
||||||
// Check if there are no existing product names and insert the first product name
|
// Check if there are no existing product names and insert the first product name
|
||||||
if ($product_name_count == 0 && !empty($first_product_name)) {
|
// if ($product_name_count == 0 && !empty($first_product_name)) {
|
||||||
|
|
||||||
$firstProductNameData = [
|
// $firstProductNameData = [
|
||||||
'product_id' => $product_id,
|
// 'product_id' => $product_id,
|
||||||
'additional_product_name' => $first_product_name,
|
// 'additional_product_name' => $first_product_name,
|
||||||
];
|
// 'model_id' => 0
|
||||||
|
// ];
|
||||||
|
|
||||||
// Insert the first product name
|
// // Insert the first product name
|
||||||
$this->additionalProductNameModal->insert($firstProductNameData);
|
// $this->additionalProductNameModal->insert($firstProductNameData);
|
||||||
|
|
||||||
} else {
|
// } else {
|
||||||
|
|
||||||
// Update the first product name if it has changed
|
// // Update the first product name if it has changed
|
||||||
if ($product_name_data[0]['additional_product_name'] != $first_product_name) {
|
// if ($product_name_data[0]['additional_product_name'] != $first_product_name) {
|
||||||
$firstProductNameUpdateData = [
|
// $firstProductNameUpdateData = [
|
||||||
'additional_product_name' => $first_product_name,
|
// 'additional_product_name' => $first_product_name,
|
||||||
];
|
// ];
|
||||||
|
|
||||||
$this->additionalProductNameModal
|
// $this->additionalProductNameModal
|
||||||
->where('product_names_id', $product_name_data[0]['product_names_id'])
|
// ->where('product_names_id', $product_name_data[0]['product_names_id'])
|
||||||
->set($firstProductNameUpdateData)
|
// ->set($firstProductNameUpdateData)
|
||||||
->update();
|
// ->update();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
$productNameData = [];
|
$productNameData = [];
|
||||||
|
|
||||||
@ -563,6 +565,7 @@ class Products extends BaseController
|
|||||||
'product_id' => $product_id,
|
'product_id' => $product_id,
|
||||||
'additional_product_name' => $name,
|
'additional_product_name' => $name,
|
||||||
'product_names_id' => $product_name_id[$index] ?? null,
|
'product_names_id' => $product_name_id[$index] ?? null,
|
||||||
|
'model_id' => $model_ids[$index] ?? null
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -585,6 +588,30 @@ class Products extends BaseController
|
|||||||
if (!empty($updateData)) {
|
if (!empty($updateData)) {
|
||||||
$this->additionalProductNameModal->updateBatch($updateData, 'product_names_id');
|
$this->additionalProductNameModal->updateBatch($updateData, 'product_names_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($product_name_id)) {
|
||||||
|
|
||||||
|
$filtering_ids = [];
|
||||||
|
|
||||||
|
for ($y = 0; $y < count($product_name_data); $y++) {
|
||||||
|
$filtering_ids[$y] = $product_name_data[$y]['product_names_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($filtering_ids)) {
|
||||||
|
$A = $filtering_ids;
|
||||||
|
$B = $product_name_id;
|
||||||
|
$missing_ids = array_diff($A, $B);
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($missing_ids)) {
|
||||||
|
$this->additionalProductNameModal
|
||||||
|
->whereIn('product_names_id', $missing_ids)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -506,9 +506,6 @@ class Sales extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getProducts()
|
public function getProducts()
|
||||||
{
|
{
|
||||||
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
||||||
@ -516,6 +513,36 @@ class Sales extends BaseController
|
|||||||
$makeId = $this->request->getPost('make_id');
|
$makeId = $this->request->getPost('make_id');
|
||||||
$modelId = $this->request->getPost('model_id');
|
$modelId = $this->request->getPost('model_id');
|
||||||
|
|
||||||
|
|
||||||
|
$modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name;
|
||||||
|
$makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make;
|
||||||
|
|
||||||
|
$product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
|
||||||
|
->join('products', 'products.product_id = product_names.product_id')
|
||||||
|
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
|
||||||
|
->whereIn('product_names.model_id',[$modelId, 0])
|
||||||
|
->where('qty_stock >',0)
|
||||||
|
->where('product_names.isactive', 1)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
if($product){
|
||||||
|
// Send JSON response
|
||||||
|
return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] );
|
||||||
|
} else {
|
||||||
|
// If product is not found, return an empty response or appropriate message
|
||||||
|
return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function getProducts_old()
|
||||||
|
{
|
||||||
|
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
||||||
|
// Retrieve make_id and model_id from the request
|
||||||
|
$makeId = $this->request->getPost('make_id');
|
||||||
|
$modelId = $this->request->getPost('model_id');
|
||||||
|
|
||||||
// Encode the modelId before searching
|
// Encode the modelId before searching
|
||||||
$encodedMakeId = json_encode([$makeId]);
|
$encodedMakeId = json_encode([$makeId]);
|
||||||
$encodedModelId = json_encode([$modelId]);
|
$encodedModelId = json_encode([$modelId]);
|
||||||
|
|||||||
@ -68,7 +68,7 @@ class Vehicle extends BaseController
|
|||||||
}
|
}
|
||||||
// dd($vehicle);
|
// dd($vehicle);
|
||||||
$data['vehicle_id'] = $vehicle_id;
|
$data['vehicle_id'] = $vehicle_id;
|
||||||
$data['makeData'] =$this->bikeMakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
|
$data['makeData'] =$this->bikeMakeModel->where('make_id != ', 0)->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
|
||||||
|
|
||||||
return view('vehicle_form',$data);
|
return view('vehicle_form',$data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class AdditionalProductNameModal extends Model
|
|||||||
protected $allowedFields = [
|
protected $allowedFields = [
|
||||||
'product_names_id',
|
'product_names_id',
|
||||||
'product_id',
|
'product_id',
|
||||||
'make_id_for_additional_name',
|
'model_id',
|
||||||
'additional_product_name',
|
'additional_product_name',
|
||||||
'isactive',
|
'isactive',
|
||||||
'created_at',
|
'created_at',
|
||||||
|
|||||||
@ -457,8 +457,8 @@ $("#model").change(function () {
|
|||||||
<div id="field_${modelId}" class="form-row">
|
<div id="field_${modelId}" class="form-row">
|
||||||
<input type="hidden" class="form-control" id="product_names_id_${modelId}" name="product_names_id[]" >
|
<input type="hidden" class="form-control" id="product_names_id_${modelId}" name="product_names_id[]" >
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="make_option_${modelId}">Make Options:</label>
|
<label for="fk_model_id_${modelId}">Model Options:</label>
|
||||||
<select class="form-control" id="make_option_${modelId}" name="make_id_for_additional_name[]">
|
<select class="form-control" id="fk_model_id_${modelId}" name="fk_model_id[]">
|
||||||
<option value="${modelId}">${modelName}</option>
|
<option value="${modelId}">${modelName}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -530,12 +530,50 @@ $(document).ready(function(){
|
|||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
var makeData = <?php echo json_encode($make); ?>;
|
||||||
$('#make').change(function() {
|
$('#make').change(function() {
|
||||||
var make_id = $(this).val(); // Get the selected make ID
|
var make_id = $(this).val(); // Get the selected make ID
|
||||||
make_value = $('option:selected', this).text();
|
make_value = $('option:selected', this).text();
|
||||||
var models_id = $('#model').val();
|
var models_id = $('#model').val();
|
||||||
$('#makeSelect').empty();
|
if (make_id.includes('0')) {
|
||||||
$('#makeSelect').append('<option value="' + make_id + '">' + make_value + '</option>');
|
|
||||||
|
$('#make').empty();
|
||||||
|
$('#make').append('<option value="" disabled > Select a Make </option>')
|
||||||
|
if (makeData.length > 0) {
|
||||||
|
makeData.forEach(function(make) {
|
||||||
|
if(make.make_id == 0){
|
||||||
|
$('#make').append('<option value="' + make.make_id + '" selected >' + make.make + '</option>')
|
||||||
|
}else{
|
||||||
|
$('#make').append('<option value="' + make.make_id + '" disabled >' + make.make + '</option>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#model').trigger('change');
|
||||||
|
}
|
||||||
|
make_id = ['0'];
|
||||||
|
} else {
|
||||||
|
// Enable all options if 'General' is not selected
|
||||||
|
$('#make option').each(function () {
|
||||||
|
$(this).prop('disabled', false); // Enable the option
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$('#makeSelect').empty(); // Clear existing options
|
||||||
|
console.log(make_id);
|
||||||
|
|
||||||
|
// Assuming make is an array of objects
|
||||||
|
var filteredMakes = makeData.filter(function(item) {
|
||||||
|
return make_id.includes(String(item.make_id)); // Check if make_id matches in the array
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check if filteredMakes has any results
|
||||||
|
if (filteredMakes.length > 0) {
|
||||||
|
filteredMakes.forEach(function(make) {
|
||||||
|
$('#makeSelect').append('<option value="' + make.make_id + '">' + make.make + '</option>');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('No matching makes found!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// $('#makeSelect').append('<option value="' + make_id + '">' + make_value + '</option>');
|
||||||
$('#makeSelectMessage').hide();
|
$('#makeSelectMessage').hide();
|
||||||
|
|
||||||
// AJAX request to get models based on the selected make ID
|
// AJAX request to get models based on the selected make ID
|
||||||
@ -640,6 +678,8 @@ $('#qty_in_stock').on('keyup change', function() {
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Check if products data is available (for editing)
|
// Check if products data is available (for editing)
|
||||||
var productsData = <?= isset($products) ? json_encode($products) : '' ?>;
|
var productsData = <?= isset($products) ? json_encode($products) : '' ?>;
|
||||||
|
var addtProductsData = <?= isset($additionalProdutName) ? json_encode($additionalProdutName) : '' ?>;
|
||||||
|
|
||||||
if (productsData) {
|
if (productsData) {
|
||||||
// Set selected manufacturer
|
// Set selected manufacturer
|
||||||
$('#manufacturer').val(productsData.manufacturer_id);
|
$('#manufacturer').val(productsData.manufacturer_id);
|
||||||
@ -648,6 +688,32 @@ $('#qty_in_stock').on('keyup change', function() {
|
|||||||
// Set selected quality
|
// Set selected quality
|
||||||
|
|
||||||
$('#quality').val(productsData.quality);
|
$('#quality').val(productsData.quality);
|
||||||
|
// ******************* //
|
||||||
|
if (productsData.make_id) {
|
||||||
|
if (productsData.make_id.includes('0')) {
|
||||||
|
// Set the value of the select element to '0'
|
||||||
|
$('#make').val('0');
|
||||||
|
|
||||||
|
// Disable all other options except the selected one
|
||||||
|
$('#make option').each(function () {
|
||||||
|
if ($(this).val() !== '0') {
|
||||||
|
$(this).prop('disabled', true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ******************* //
|
||||||
|
if(productsData.models_id){
|
||||||
|
$('#model').trigger('change');
|
||||||
|
if(addtProductsData){
|
||||||
|
addtProductsData.forEach(function(product) {
|
||||||
|
$('#additional_product_name_' + product.model_id).val(product.additional_product_name);
|
||||||
|
$('#product_names_id_' + product.model_id).val(product.product_names_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user