GWM assigned in model , service : ps

This commit is contained in:
VE10-Sanjeev 2025-02-19 12:17:28 +00:00
parent 2b1526b886
commit a221412a5f
8 changed files with 224 additions and 159 deletions

View File

@ -173,9 +173,9 @@ $routes->get('dashboard', 'Users::dashboard');
$routes->get('service_index', 'Service::service_index');
$routes->get("new_service/(:any)", "Service::new_service/$1");
$routes->post("add_service", "Service::add_service");
$routes->post("get_models_service", "Service::get_models");
// $routes->post("get_models_service", "Service::get_models");
$routes->get("delete_service/(:any)", "Service::delete_service/$1");
$routes->post("get_product_by_models", "Service::get_product_by_models");
// $routes->post("get_product_by_models", "Service::get_product_by_models");
$routes->post('status_service', 'Service::status_service');

View File

@ -4,6 +4,7 @@ namespace App\Controllers;
use App\Models\BikemodelsModel;
use App\Models\BikemakeModel;
use App\Models\ComplaintModel;
use CodeIgniter\API\ResponseTrait;
@ -15,29 +16,36 @@ class Model extends BaseController
use ResponseTrait;
public $BikemodelsModel;
public $BikemakeModel;
public $ComplaintModel;
public function __construct()
{
$this->session = session();
$this->BikemodelsModel = new BikemodelsModel();
$this->BikemakeModel = new BikemakeModel();
$this->ComplaintModel = new ComplaintModel();
}
public function index($make_id)
{
$BikemodelsModel = new BikemodelsModel();
$BikemakeModel = new BikemakeModel();
$make_value = $BikemakeModel->where('make_id',$make_id)->select('make_id,make')->find();
$make_value = $this->BikemakeModel->where('make_id',$make_id)->select('make_id,make')->find();
$make_name= $make_value[0]['make'];
$make_id= $make_value[0]['make_id'];
$model = $BikemodelsModel->orderBy('model_name')->where('make_id',$make_id)->findAll();
$model = $this->BikemodelsModel->select('model.*, cubic_capacity.value')
->join('cubic_capacity', 'cubic_capacity.id = model.cubic_capacity_id', 'left')
->where('make_id',$make_id)->orderBy('model_name')
->findAll();
$data['model']=$model;
$data['make_name'] =$make_name;
$data['make_id'] =$make_id;
$cubiccapacity = $this->ComplaintModel->getCubicCapacityName();
$data['cubiccapacity']=$cubiccapacity;
// dd($model);
return view('bike_model_list',$data);
}
@ -64,6 +72,7 @@ class Model extends BaseController
try {
$make_id = $this->request->getPost('make_id');
$model_name = $this->request->getPost('modelname');
$cubic_capacity = $this->request->getPost('cubiccapacity');
$BikemodelsModel = new BikemodelsModel();
//they check model name already exist or not here.
@ -83,7 +92,8 @@ class Model extends BaseController
$data = [
'make_id' => $make_id,
'model_name' => $model_name
'model_name' => $model_name,
'cubic_capacity_id'=>$cubic_capacity
];
// print_r($model_id);die;

View File

@ -8,6 +8,7 @@ use App\Models\VendorModel;
use App\Models\BikemodelsModel;
use App\Models\ProductModel;
use App\Models\AdditionalProductNameModal;
use App\Models\ComplaintModel;
use CodeIgniter\API\ResponseTrait;
class Service extends BaseController
@ -20,6 +21,7 @@ class Service extends BaseController
protected $vendorModel;
protected $BikemodelsModel;
protected $ProductModel;
protected $ComplaintModel;
use ResponseTrait;
public function __construct()
@ -32,6 +34,7 @@ class Service extends BaseController
$this->vendorModel = new VendorModel();
$this->BikemodelsModel = new BikemodelsModel();
$this->ProductModel = new ProductModel();
$this->ComplaintModel = new ComplaintModel();
}
public function service_index()
@ -89,6 +92,7 @@ class Service extends BaseController
->findAll();
$data['tax'] = $this->ServiceModel->getTax();
$data['cubiccapacity']= $this->ComplaintModel->getCubicCapacityName();
if ($service_id === '0') {
@ -135,11 +139,11 @@ class Service extends BaseController
// print $final_price;
// print_r($this->request->getPost());
$make_ids = $this->request->getPost('make');
$model_ids = $this->request->getPost('model');
// $make_ids = $this->request->getPost('make');
// $model_ids = $this->request->getPost('model');
$model_json = json_encode($model_ids);
$make_json = json_encode($make_ids);
// $model_json = json_encode($model_ids);
// $make_json = json_encode($make_ids);
$data = [
'service_name' => $this->request->getPost('servicename'),
'category' => $this->request->getPost('category'),
@ -151,10 +155,11 @@ class Service extends BaseController
'labour_cost' => $this->request->getPost('labour_cost'),
'labour_cost_with_cost' => $this->request->getPost('labour_cost_with_cost'),
'price' => $final_price,
'makes_id' => $make_json,
'models_id' => $model_json,
// 'makes_id' => $make_json,
// 'models_id' => $model_json,
'description' => $this->request->getPost('description'),
'isactive' => 1 ,
'cubic_capacity_id' => $this->request->getPost('cubiccapacity'),
];
$service_id = $this->request->getPost('service_id');
@ -208,64 +213,64 @@ class Service extends BaseController
}
public function get_product_by_models(){
$make_id = $this->request->getPost('make_id');
$model_ids = $this->request->getPost('model_ids');
// public function get_product_by_models(){
// $make_id = $this->request->getPost('make_id');
// $model_ids = $this->request->getPost('model_ids');
$products = [];
array_push($model_ids,'0');
// $products = [];
// array_push($model_ids,'0');
foreach ($model_ids as $modelId) {
$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')
->where('JSON_CONTAINS(products.models_id, \'["' . $modelId . '"]\')', null, false)
->where('products.isactive', 1)
->findAll();
// foreach ($model_ids as $modelId) {
// $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')
// ->where('JSON_CONTAINS(products.models_id, \'["' . $modelId . '"]\')', null, false)
// ->where('products.isactive', 1)
// ->findAll();
$products = array_merge($products, $product);
}
// $products = array_merge($products, $product);
// }
$products = array_unique($products, SORT_REGULAR);
// $products = array_unique($products, SORT_REGULAR);
return $this->response->setJSON($products);
}
// return $this->response->setJSON($products);
// }
public function get_models()
{
$selected_makes = $this->request->getPost('selected_makes');
// public function get_models()
// {
// $selected_makes = $this->request->getPost('selected_makes');
// Initialize an empty array to store formatted model data
$formatted_models = [];
// // Initialize an empty array to store formatted model data
// $formatted_models = [];
// Iterate over each selected make ID
if ($selected_makes) {
foreach ($selected_makes as $make_id) {
// Fetch models based on the selected make ID
$models = $this->BikemodelsModel->where('make_id', $make_id)->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
// // Iterate over each selected make ID
// if ($selected_makes) {
// foreach ($selected_makes as $make_id) {
// // Fetch models based on the selected make ID
// $models = $this->BikemodelsModel->where('make_id', $make_id)->where('business_id', $this->session->get('logged_user_business_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
];
// // 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;
}
}
}
// print_r($formatted_models);die;
// Send the formatted models as JSON response back to the client
return $this->response->setJSON($formatted_models);
}
// // Push the formatted model into the array
// $formatted_models[] = $formatted_model;
// }
// }
// }
// // print_r($formatted_models);die;
// // Send the formatted models as JSON response back to the client
// return $this->response->setJSON($formatted_models);
// }
public function status_service()

View File

@ -5,5 +5,5 @@ class BikemodelsModel extends Model
{
protected $table = 'model';
protected $primaryKey = 'model_id';
protected $allowedFields = ['model_id','business_id','make_id','model_name','isactive'];
protected $allowedFields = ['model_id','business_id','make_id','model_name','isactive','cubic_capacity_id'];
}

View File

@ -5,7 +5,7 @@ class ServiceModel extends Model
{
protected $table = 'services';
protected $primaryKey = 'service_id';
protected $allowedFields = ['service_id','branch_id','category','service_name','labour_cost','cgst','sgst','price','tax','labour_cost_with_cost','description','makes_id','models_id','product_id','sub_service_id','isactive'];
protected $allowedFields = ['service_id','branch_id','category','service_name','labour_cost','cgst','sgst','price','tax','labour_cost_with_cost','description','makes_id','models_id','product_id','sub_service_id','isactive','cubic_capacity_id'];
public function getTax()

View File

@ -5,7 +5,7 @@ class ServicesModel extends Model
{
protected $table = 'services';
protected $primaryKey = 'service_id';
protected $allowedFields = ['service_id','service_name','price','commission_rate','cgst','sgst','purchase_cost','description','isactive'];
protected $allowedFields = ['service_id','service_name','price','commission_rate','cgst','sgst','purchase_cost','description','isactive','cubic_capacity_id'];
}

View File

@ -25,6 +25,7 @@
<thead>
<tr>
<th>Model Name</th>
<th>Cubic Capacity</th>
<th>Status</th>
<th>Action</th>
</tr>
@ -33,6 +34,7 @@
<?php foreach ($model as $index => $item): ?>
<tr class="model_tr_<?php echo $index+1;?>">
<td class="model_name"><?php echo $item['model_name']; ?></td>
<td class="cubic_capacity"><?php echo $item['value']; ?></td>
<td>
<?php if($item['isactive'] == 1): ?>
<span style="color:green">Active</span>
@ -77,11 +79,27 @@
<div class="form-group">
<input type="text" id="edit_model_id" hidden>
<input type="text" id="cubic_capacity_id" hidden>
<div class="form-group">
<input class="form-control" type="text" id="make_id" required="" value="<?php echo $make_id; ?>" placeholder="Make Name...." style="display:none;">
<label for="makename">Make Name </label>
<input class="form-control" type="text" id="makename" required="" value="<?php echo $make_name; ?>" placeholder="Make Name...." disabled>
</div>
<div class="form-group">
<label for="cubiccapacity">Cubic capacity</label>
<select class="form-control" id="cubiccapacity" required data-toggle="select2">
<option value="0">Select Cubic capacity</option>
<?php foreach ($cubiccapacity as $item): ?>
<option value="<?= $item['id'] ?>"><?= $item['value'] ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="modelname">Model Name </label>
<input class="form-control" type="text" id="modelname" required="" placeholder="Model Name....">
</div>
</div>
<div class="form-group text-center">
@ -98,8 +116,6 @@
<script>
function submitModels(params) {
// console.log( $('#modelname').val());
var edit_model_id = $('#edit_model_id').val();
if (!edit_model_id) {
edit_model_id =0;
@ -107,7 +123,8 @@
var formData = {
make_id: $('#make_id').val(),
modelname: $('#modelname').val()
modelname: $('#modelname').val(),
cubiccapacity: $('#cubiccapacity').val()
};
$.ajax({
type: 'POST',
@ -122,6 +139,8 @@
$('#bike_model_login-modal_1').modal('hide');
$('#makename').val('');
$('#modelname').val('');
$('#cubiccapacity').val('');
toastr.success(response.data, 'Success');
// $('tbody').html('');
@ -236,14 +255,31 @@
$('#form_add_edit').text('Edit Models');
var full_div = $(params).closest('tr')[0];
$('#modelname').val($(full_div).find('.model_name').text());
var cubicCapacity = $(full_div).find('.cubic_capacity').text();
console.log(cubicCapacity);
$('#cubiccapacity option').each(function() {
if ($(this).text().trim() === cubicCapacity.trim()) {
$(this).prop('selected', true).trigger('change');
}
});
// var cc_id = $(full_div).find('.cubic_capacity_id').text();
// var selectElementForCC = document.getElementById('cubiccapacity');
// var ccOptions = selectElementForCC.options;
// for (var j = 0; j < ccOptions.length; j++) {
// if (ccOptions[j].value === cc_id) {
// ccOptions[j].selected = true;
// break;
// }
// }
}
function clearDetials(params) {
$('#form_add_edit').text('Add Models');
$('#modelname').val('');
$('#cubiccapacity').val('');
}
function deleteModel(params) {

View File

@ -29,17 +29,26 @@
<option value="1" <?= (isset($services['category']) && $services['category'] == 1) ? 'selected' : '' ?> >Standalone Service</option>
</select>
</div>
<div class="form-group col-md-3" id="make_hide" <?= (!isset($services['category']) || $services['category'] == 0) ? 'style="display: none;"' : '' ?>>
<div class="form-group col-md-3" id="cc_hide" <?= (!isset($services['category']) || $services['category'] == 0) ? 'style="display: none;"' : '' ?>>
<label for="cubiccapacity" class="col-form-label">Cubic capacity<span class="text-danger">*</span></label>
<select class="form-control" id="cubiccapacity" name="cubiccapacity" style="height:32px" required>
<option value="">Select</option>
<?php foreach ($cubiccapacity as $item): ?>
<option value="<?= $item['id'] ?>" <?php if (isset($services['cubic_capacity_id']) && (($services['cubic_capacity_id'] === $item['id']))) echo "selected"; ?>><?= $item['value'] ?></option>
<?php endforeach; ?>
</select>
</div>
<!-- <div class="form-group col-md-3" id="make_hide" <?= (!isset($services['category']) || $services['category'] == 0) ? 'style="display: none;"' : '' ?>>
<label for="inputPassword4" class="col-form-label">Make<span class="text-danger">*</span></label>
<select class="form-control SelExample" id="make" name="make[]" multiple>
<!-- Options for make -->
<!-- <option value="0">Custom</option> -->
<!- Options for make ->
<!- <option value="0">Custom</option> ->
<?php foreach ($make as $value): ?>
<option value="<?= $value['make_id'] ?>" <?= isset($services['makes_id']) && in_array($value['make_id'], $services['makes_id']) ? 'selected' : '' ?>><?= $value['make'] ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-3" id="model_hide" <?= (!isset($services['category']) || $services['category'] == 0) ? 'style="display: none;"' : '' ?>>
</div> -->
<!-- <div class="form-group col-md-3" id="model_hide" <?= (!isset($services['category']) || $services['category'] == 0) ? 'style="display: none;"' : '' ?>>
<label for="model" class="col-form-label">Model<span class="text-danger">*</span></label>
<select class="form-control SelExample" id="model" name="model[]" multiple>
<option value="0">Custom</option>
@ -49,7 +58,7 @@
<?php endforeach; ?>
<?php endforeach; ?>
</select>
</div>
</div> -->
<div class="form-group col-md-3">
<label for="inputEmail4" class="col-form-label">Service Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="servicename" style="height:32px" placeholder="Service Name" value="<?= isset($services['service_name']) ? $services['service_name'] : '' ?>" required>
@ -192,90 +201,90 @@ $(document).ready(function(){
$(document).ready(function() {
$('#make').change(function() {
var selected_makes = $(this).val(); // Get the selected make ID
// $('#make').change(function() {
// var selected_makes = $(this).val(); // Get the selected make ID
console.log(selected_makes);
var models_id = $('#model').val();
// AJAX request to get models based on the selected make ID
$.ajax({
url: '<?php echo base_url('get_models_service') ?>', // URL to your CodeIgniter controller method
type: 'POST',
dataType: 'json',
data: { selected_makes: selected_makes }, // Send the selected make ID to the controller
success: function(response) {
// console.log(response);
// Update models dropdown based on the response
if (response.length > 0) {
// Clear existing options
$('#model').empty();
// Iterate through response and models_id
$.each(response, function(index, model) {
var count =0;
// $('#model').empty();
$.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;
}
// console.log(selected_makes);
// var models_id = $('#model').val();
// // AJAX request to get models based on the selected make ID
// $.ajax({
// url: '<?php // echo base_url('get_models_service') ?>', // URL to your CodeIgniter controller method
// type: 'POST',
// dataType: 'json',
// data: { selected_makes: selected_makes }, // Send the selected make ID to the controller
// success: function(response) {
// // console.log(response);
// // Update models dropdown based on the response
// if (response.length > 0) {
// // Clear existing options
// $('#model').empty();
// // Iterate through response and models_id
// $.each(response, function(index, model) {
// var count =0;
// // $('#model').empty();
// $.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;
// }
});
if (count == 0) {
$('#model').append('<option value="' + model.model_id + '">' + model.model_name + '</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
console.error(xhr.responseText);
}
});
});
// });
// } 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 = $('#make').val(); // Get the selected make ID
var model_ids = $('#model').val(); // Get the selected model IDs
// $('#model').change(function() {
// var make_id = $('#make').val(); // Get the selected make ID
// var model_ids = $('#model').val(); // Get the selected model IDs
// AJAX request to get vendors based on the selected model ID
console.log(model_ids);
if (model_ids.length > 0) {
$.ajax({
url: '<?php echo base_url('get_product_by_models') ?>', // 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) {
console.log(response);
// Update vendor dropdown based on the response
if (response) {
// Clear existing options
$('#productSelect').empty();
// Append new options
$('#productSelect').append('<option value>Select Product</option>');
$.each(response, function(index, product) {
$('#productSelect').append('<option value="' + product.product_id + '">' + product.product_name +' - '+ product.manufacturer_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);
}
});
}
});
// // AJAX request to get vendors based on the selected model ID
// console.log(model_ids);
// if (model_ids.length > 0) {
// $.ajax({
// url: '<?php // echo base_url('get_product_by_models') ?>', // 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) {
// console.log(response);
// // Update vendor dropdown based on the response
// if (response) {
// // Clear existing options
// $('#productSelect').empty();
// // Append new options
// $('#productSelect').append('<option value>Select Product</option>');
// $.each(response, function(index, product) {
// $('#productSelect').append('<option value="' + product.product_id + '">' + product.product_name +' - '+ product.manufacturer_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);
// }
// });
// }
// });
data = <?php echo json_encode($product) ?>;
servicedata = <?php echo json_encode($service) ?>;
@ -292,24 +301,29 @@ $(document).ready(function() {
<script>
document.getElementById('category').addEventListener('change', function() {
// var customFields = document.getElementById('customFields');
var makeSelect = document.getElementById('make');
var modelSelect = document.getElementById('model');
// var makeSelect = document.getElementById('make');
// var modelSelect = document.getElementById('model');
var ccSelect = document.getElementById('cubiccapacity');
var serviceSelected = document.getElementById('serviceSelected');
if (this.value == '1') {
// customFields.style.display = 'block';
$('#make_hide').css('display' , 'block');
$('#model_hide').css('display' ,'block');
// $('#make_hide').css('display' , 'block');
// $('#model_hide').css('display' ,'block');
$('#cc_hide').css('display' , 'block');
$('#service_hide').css('display' ,'block');
makeSelect.setAttribute('required', 'required');
modelSelect.setAttribute('required', 'required');
ccSelect.setAttribute('required', 'required');
// makeSelect.setAttribute('required', 'required');
// modelSelect.setAttribute('required', 'required');
// serviceSelected.setAttribute('required', 'required');
} else {
// customFields.style.display = 'none';
$('#make_hide').css('display' , 'none');
$('#model_hide').css('display' ,'none');
// $('#make_hide').css('display' , 'none');
// $('#model_hide').css('display' ,'none');
$('#cc_hide').css('display' , 'none');
$('#service_hide').css('display' ,'none');
makeSelect.removeAttribute('required');
modelSelect.removeAttribute('required');
ccSelect.removeAttribute('required');
// makeSelect.removeAttribute('required');
// modelSelect.removeAttribute('required');
serviceSelected.removeAttribute('required');
$.ajax({