Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic
This commit is contained in:
commit
61605a3d14
@ -62,6 +62,7 @@ $routes->get('vendor_index/', 'Vendor::vendor_index');
|
||||
$routes->post("add_vendor", "Vendor::add_vendor");
|
||||
$routes->get("new_vendor/(:any)", "Vendor::new_vendor/$1");
|
||||
$routes->get("delete_vendor/(:any)", "Vendor::delete_vendor/$1");
|
||||
$routes->post("fetch_models", "Vendor::fetch_models");
|
||||
//end Vendor
|
||||
|
||||
//Vehicle//
|
||||
|
||||
@ -65,7 +65,8 @@ class Client extends BaseController
|
||||
'city' => $this->request->getPost('city'),
|
||||
'state' => $this->request->getPost('state'),
|
||||
'postal_code' => $this->request->getPost('postalcode'),
|
||||
|
||||
'gstnumber' => $this->request->getPost('gstnumber'),
|
||||
'client_type' => $this->request->getPost('clienttype'),
|
||||
'isactive' => 1 ,
|
||||
'branch_id' => $this->session->get('logged_user_branch_id')
|
||||
];
|
||||
|
||||
@ -5,6 +5,8 @@ namespace App\Controllers;
|
||||
use App\Models\VendorModel;
|
||||
|
||||
use App\Models\UsersModel;
|
||||
use App\Models\BikemakeModel;
|
||||
use App\Models\BikemodelsModel;
|
||||
|
||||
|
||||
class Vendor extends BaseController
|
||||
@ -31,36 +33,54 @@ class Vendor extends BaseController
|
||||
|
||||
public function new_vendor($vendor_id)
|
||||
{
|
||||
|
||||
|
||||
if ($vendor_id === '0') {
|
||||
|
||||
$data['vendor'] = [];
|
||||
$data['page_name']="Add Vendor";
|
||||
} else if ($vendor_id !== '0') {
|
||||
$data['page_name']="Edit Vendor";
|
||||
$data['vendor'] = [];
|
||||
$data['page_name'] = "Add Vendor";
|
||||
$BikemakeModel = new BikemakeModel();
|
||||
$data['make'] = $BikemakeModel->findAll();
|
||||
$data['models'] = []; // Initialize models array for the view
|
||||
} else {
|
||||
$VendorModel = new VendorModel();
|
||||
|
||||
$vendor=$VendorModel->where('vendor_id', $vendor_id)->get()->getRowArray();
|
||||
|
||||
$data['vendor']=$vendor;
|
||||
$vendor = $VendorModel->where('vendor_id', $vendor_id)->get()->getRowArray();
|
||||
$vendor['model_ids'] = json_decode($vendor['model'], true);
|
||||
$vendor['make_ids'] = json_decode($vendor['make'], true);
|
||||
|
||||
$data['vendor'] = $vendor;
|
||||
$data['page_name'] = "Edit Vendor";
|
||||
|
||||
// Load models based on the selected make IDs
|
||||
$BikemodelModel = new BikemodelsModel();
|
||||
$models = [];
|
||||
foreach ($vendor['make_ids'] as $make_id) {
|
||||
$models[] = $BikemodelModel->where('make_id', $make_id)->findAll();
|
||||
}
|
||||
$data['models'] = $models; // Pass models array to the view
|
||||
|
||||
// Load make data
|
||||
$BikemakeModel = new BikemakeModel();
|
||||
$data['make'] = $BikemakeModel->findAll();
|
||||
}
|
||||
|
||||
$data['vendor_id'] = $vendor_id;
|
||||
|
||||
return view('vendor_form',$data);
|
||||
|
||||
return view('vendor_form', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function add_vendor()
|
||||
{
|
||||
|
||||
$VendorModel = new VendorModel();
|
||||
|
||||
|
||||
// Retrieve the selected make IDs and model IDs from the form
|
||||
$make_ids = $this->request->getPost('make');
|
||||
$model_ids = $this->request->getPost('model');
|
||||
|
||||
// Convert model IDs to JSON format
|
||||
$model_json = json_encode($model_ids);
|
||||
$make_json=json_encode($make_ids);
|
||||
$data = [
|
||||
'vendor_name' => $this->request->getPost('vendor_name'),
|
||||
'contact_name' => $this->request->getPost('contact_name'),
|
||||
|
||||
'gstnumber' => $this->request->getPost('gstnumber'),
|
||||
'vendor_email' => $this->request->getPost('email'),
|
||||
'address' => $this->request->getPost('address'),
|
||||
@ -72,28 +92,22 @@ class Vendor extends BaseController
|
||||
'category' => $this->request->getPost('category'),
|
||||
'website' => $this->request->getPost('website'),
|
||||
'isactive' => 1 ,
|
||||
'branch_id' => $this->session->get('logged_user_branch_id')
|
||||
'branch_id' => $this->session->get('logged_user_branch_id'),
|
||||
'make' => $make_json, // Store the selected make IDs
|
||||
'model' => $model_json, // Store the selected model IDs in JSON format
|
||||
];
|
||||
|
||||
$make_array = $this->request->getPost('vendortype'); // Assuming 'make' is an array
|
||||
$make_json = json_encode($make_array);
|
||||
$data['vendortype'] = $make_json;
|
||||
|
||||
|
||||
|
||||
$vendor_id = $this->request->getPost('vendor_id');
|
||||
print_r($data);die;
|
||||
|
||||
|
||||
if (!empty($vendor_id)) {
|
||||
|
||||
$VendorModel->update($vendor_id, $data);
|
||||
} else {
|
||||
|
||||
$VendorModel->insert($data);
|
||||
}
|
||||
|
||||
|
||||
return redirect()->to('vendor_index');
|
||||
}
|
||||
|
||||
public function delete_vendor($vendor_id)
|
||||
{
|
||||
$model = new VendorModel();
|
||||
@ -112,5 +126,40 @@ class Vendor extends BaseController
|
||||
|
||||
return redirect()->to('vendor_index');
|
||||
}
|
||||
public function fetch_models()
|
||||
{
|
||||
// Retrieve the selected make IDs from the AJAX request
|
||||
$selected_makes = $this->request->getPost('selected_makes');
|
||||
|
||||
// Load the BikemakeModel to fetch models
|
||||
$BikemodelModel = new BikemodelsModel();
|
||||
|
||||
// Initialize an empty array to store formatted model data
|
||||
$formatted_models = [];
|
||||
|
||||
// Iterate over each selected make ID
|
||||
foreach ($selected_makes as $make_id) {
|
||||
// Fetch models based on the selected make ID
|
||||
$models = $BikemodelModel->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 = [
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
||||
// Send the formatted models as JSON response back to the client
|
||||
return $this->response->setJSON($formatted_models);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -5,7 +5,7 @@ class ClientModel extends Model
|
||||
{
|
||||
protected $table = 'client';
|
||||
protected $primaryKey = 'client_id';
|
||||
protected $allowedFields = ['client_id','client_name','email','mobile_no','address','city','state','postal_code','country','description','isactive','branch_id'];
|
||||
protected $allowedFields = ['client_id','client_type','gstnumber','client_name','email','mobile_no','address','city','state','postal_code','country','description','isactive','branch_id'];
|
||||
|
||||
|
||||
}
|
||||
@ -34,6 +34,21 @@
|
||||
<label for="inputEmail4" class="col-form-label">Email</label>
|
||||
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($client['email']) ? $client['email'] : '' ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputAddress" class="col-form-label">GST Number<span class="text-danger"></span></label>
|
||||
<input type="text" class="form-control" name="gstnumber" placeholder="GST Number" value="<?= isset($client['gstnumber']) ? $client['gstnumber'] : '' ?>"pattern="[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[0-9]{1}[Z]{1}[0-9A-Z]{1}" title="Enter a valid GST Number" />
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="inputPassword4" class="col-form-label">Client Type<span class="text-danger">*</span></label>
|
||||
<select class="form-control status-select" name="clienttype" required data-toggle="select2" >
|
||||
<!-- <option value="">Select a Status</option> -->
|
||||
<option value="Direct" <?= isset($client['client_type']) && $client['client_type'] === 'Direct' ? 'selected' : '' ?>>Direct</option>
|
||||
<option value="Mechanic" <?= isset($client['client_type']) && $client['client_type'] === 'Mechanic' ? 'selected' : '' ?>>Mechanic</option>
|
||||
<option value="Exp" <?= isset($client['client_type']) && $client['client_type'] === 'Exp' ? 'selected' : '' ?>>Exp</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -56,26 +56,28 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="inputPassword4" class="col-form-label">Make<span class="text-danger">*</span></label>
|
||||
<select class="form-control SelExample" name="make" required >
|
||||
<!-- <option value="">Select a Status</option> -->
|
||||
<option value="Retailer" <?= isset($vendor['vendortype']) && $vendor['vendortype'] === 'Retailer' ? 'selected' : '' ?>>Retailer</option>
|
||||
<option value="Authorised Dealer" <?= isset($vendor['vendortype']) && $vendor['vendortype'] === 'Authorised Dealer' ? 'selected' : '' ?>>Authorised Dealer</option>
|
||||
<option value="Wholesale Dealer" <?= isset($vendor['vendortype']) && $vendor['vendortype'] === 'Wholesale Dealer' ? 'selected' : '' ?>>Wholesale Dealer</option>
|
||||
<option value="Wholesale OEM Dealer" <?= isset($vendor['vendortype']) && $vendor['vendortype'] === 'Wholesale OEM Dealer' ? 'selected' : '' ?>>Wholesale OEM Dealer</option>
|
||||
<select class="form-control SelExample" id="make" name="make[]" required multiple>
|
||||
<!-- 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">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="inputPassword4" class="col-form-label">Model<span class="text-danger">*</span></label>
|
||||
<select class="form-control status-select" name="vendortype[]" required data-toggle="select2" multiple>
|
||||
<!-- <option value="">Select a Status</option> -->
|
||||
<option value="Retailer" <?= isset($vendor['vendortype']) && $vendor['vendortype'] === 'Created' ? 'selected' : '' ?>>Retailer</option>
|
||||
<option value="Authorised Dealer" <?= isset($vendor['vendortype']) && $vendor['vendortype'] === 'Paid' ? 'selected' : '' ?>>Authorised Dealer</option>
|
||||
<option value="Wholesale Dealer" <?= isset($vendor['vendortype']) && $vendor['vendortype'] === 'Created' ? 'selected' : '' ?>>Wholesale Dealer</option>
|
||||
<option value="Wholesale OEM Dealer" <?= isset($vendor['vendortype']) && $vendor['vendortype'] === 'Paid' ? 'selected' : '' ?>>Wholesale OEM Dealer</option>
|
||||
<select class="form-control status-select" id="model" name="model[]" required data-toggle="select2" multiple>
|
||||
<!-- Options for models -->
|
||||
<?php foreach ($models as $make_models): ?>
|
||||
<?php foreach ($make_models as $model): ?>
|
||||
<option value="<?= $model['model_id'] ?>" <?= isset($vendor['model_ids']) && in_array($model['model_id'], $vendor['model_ids']) ? 'selected' : '' ?>><?= $model['model_name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<br>
|
||||
@ -140,6 +142,7 @@ $(document).ready(function(){
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.status-select').select2({
|
||||
placeholder: "Select vendor types",
|
||||
@ -147,3 +150,57 @@ $(document).ready(function(){
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Initialize select2 for the make select dropdown
|
||||
$(".SelExample").select2();
|
||||
|
||||
// Event listener for change in make select dropdown
|
||||
$("#make").on('change', function() {
|
||||
var selected_makes = $(this).val(); // Get an array of selected make IDs
|
||||
|
||||
// AJAX request to fetch models based on selected make IDs
|
||||
$.ajax({
|
||||
url: '<?= base_url("fetch_models") ?>', // URL to your controller method for fetching models
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { selected_makes: selected_makes },
|
||||
success: function(response) {
|
||||
// Clear existing options in model select dropdown
|
||||
$("#model").empty();
|
||||
|
||||
// Populate model select dropdown with fetched models
|
||||
$.each(response, function(index, model) {
|
||||
$("#model").append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
|
||||
});
|
||||
|
||||
// Refresh select2 to reflect changes
|
||||
$("#model").trigger('change');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error(error); // Log any errors to the console
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</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