quick Add
This commit is contained in:
parent
c3bc769fa9
commit
dd502de48b
@ -425,18 +425,32 @@ class Sales extends BaseController
|
||||
|
||||
|
||||
public function save_vehicle(){
|
||||
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
||||
|
||||
|
||||
|
||||
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
||||
|
||||
if($this->request->getPost('formType') == 'create')
|
||||
{
|
||||
|
||||
|
||||
$client['client_name'] = $this->request->getPost('createclientName');
|
||||
$client['mobile_no'] = $this->request->getPost('createclientMobile');
|
||||
$client['client_type'] = $this->request->getPost('createclientType');
|
||||
$client['branch_id'] = $this->session->get('logged_user_branch_id');
|
||||
$client['isactive'] = 1;
|
||||
$client['created_by'] = (int)$this->session->get('logged_user');
|
||||
$existingClient1 = $this->ClientModel->where('client_name', $client['client_name'])->first();
|
||||
if ($existingClient1) {
|
||||
return $this->response->setJSON([
|
||||
'success' => true, 'code' => 404,'field'=>'create-clientName',
|
||||
'message' => 'The client name is already registered. Please use a different Name.'
|
||||
]);
|
||||
}
|
||||
$existingClient2 = $this->ClientModel->where('mobile_no', $client['mobile_no'])->first();
|
||||
if ($existingClient2) {
|
||||
return $this->response->setJSON([
|
||||
'success' => true,'code' => 404,'field'=>'create-clientMobile',
|
||||
'message' => 'The mobile number is already registered. Please use a different number.'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$client_id = $this->ClientModel->insert($client);
|
||||
|
||||
@ -451,7 +465,8 @@ class Sales extends BaseController
|
||||
'branch_id'=> $this->session->get('logged_user_branch_id'),
|
||||
'city'=>'Chennai',
|
||||
'state'=>'Tamil Nadu',
|
||||
'isactive' => 1
|
||||
'isactive' => 1,
|
||||
'created_by' => (int)$this->session->get('logged_user')
|
||||
];
|
||||
|
||||
}
|
||||
@ -468,25 +483,22 @@ class Sales extends BaseController
|
||||
'branch_id'=> $this->session->get('logged_user_branch_id'),
|
||||
'city'=>'Chennai',
|
||||
'state'=>'Tamil Nadu',
|
||||
'isactive' => 1
|
||||
'isactive' => 1,
|
||||
'created_by' => (int)$this->session->get('logged_user')
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Attempt to insert the client data
|
||||
$id = $this->VehicleModel->insert($data);
|
||||
if ($id) {
|
||||
$vehicleData = $this->VehicleModel->where('vehicle_id',$id)->first();
|
||||
|
||||
// If insertion succeeds, return success response
|
||||
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData, 'vehicle_id' => $id]);
|
||||
return $this->response->setJSON(['success' => true,'code' => 200, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData, 'vehicle_id' => $id]);
|
||||
} else {
|
||||
// If insertion fails, return error response
|
||||
return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);
|
||||
return $this->response->setJSON(['success' => false, 'code' => 404,'message' => 'Failed to save client.']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ class Vendor extends BaseController
|
||||
'address' => $this->request->getPost('address'),
|
||||
'city' => $this->request->getPost('city'),
|
||||
'state' => $this->request->getPost('state'),
|
||||
'postal_code' => $this->request->getPost('postalcode'),
|
||||
'postal_code' => $this->request->getPost('postalcode') != '' ? $this->request->getPost('postalcode') : NULL,
|
||||
'country' => $this->request->getPost('country'),
|
||||
'vendortype' => $this->request->getPost('vendortype'),
|
||||
'category' => $this->request->getPost('category'),
|
||||
|
||||
@ -88,7 +88,7 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputEmail4" class="col-form-label">Vehicle<span class="text-danger">*</span></label>
|
||||
<?= isset($sales['vehicle_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addVehicleModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addVehicleModal" title="Add Client"></i>' ?>
|
||||
<?= isset($sales['vehicle_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addVehicleModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addVehicleModal" title="Add Vehicle"></i>' ?>
|
||||
|
||||
<select class="form-control vehicle-select SelExample job_card_basic_details" name="vehicle_id" id="vehicle_name" <?= isset($sales['vehicle_id']) ? 'readonly' : 'required="true"' ?>>
|
||||
|
||||
@ -166,7 +166,7 @@
|
||||
<input type="date" class="form-control job_card_basic_details" name="delivery_date" placeholder="Delivery Date" value="<?= isset($jobs['delivery_date']) ? $jobs['delivery_date'] : '' ?>">
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>(<?php echo isset($jobs['status']) ? $jobs['status'] : '' ?>)</label>
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span><?php echo isset($jobs['status']) ? '( '.$jobs['status'].' )' : '' ?></label>
|
||||
<select class="form-control status-select status_class_for_change" name="status" required data-toggle="select2">
|
||||
<?php if (isset($jobs['status'])): ?>
|
||||
<?php if ($jobs['status'] === 'Cancelled'): ?>
|
||||
@ -2174,6 +2174,9 @@ $(document).ready(function() {
|
||||
var ifStatementCondition = "createclientName !== '' && createclientMobile !== '' && createclientType !== '' && reg_no !== '' && model !== '' && make !== ''";
|
||||
}
|
||||
|
||||
const button = $('#saveVehcileBtn');
|
||||
button.prop('disabled', true).text('Processing...');
|
||||
|
||||
if(createclientMobile) {
|
||||
var clientArray = <?php echo json_encode($client) ?>;
|
||||
console.log(clientArray);
|
||||
@ -2183,11 +2186,11 @@ $(document).ready(function() {
|
||||
|
||||
if(mobileIdExists) {
|
||||
toastr.warning("Mobile Number Already Added!");
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (reg_no) {
|
||||
$('#saveVehcileBtn').prop('disabled', true);
|
||||
$.ajax({
|
||||
url: '<?= base_url("checkRegisterNo") ?>', // URL to your controller method for fetching models
|
||||
type: 'POST',
|
||||
@ -2198,7 +2201,7 @@ $(document).ready(function() {
|
||||
if (response) {
|
||||
$('#reg_no').val("");
|
||||
toastr.warning("Register Number Already Added!");
|
||||
$('#saveVehcileBtn').prop('disabled', false);
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}else{
|
||||
if( eval(ifStatementCondition) ){
|
||||
|
||||
@ -2218,25 +2221,29 @@ $(document).ready(function() {
|
||||
formType:formType,
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
if (response.success && response.code == 200 ) {
|
||||
toastr.success("Vehicle saved successfully!");
|
||||
localStorage.setItem('vehicle_id',response.vehicle_id);
|
||||
$('#addVehicleModal').modal('hide');
|
||||
toastr.success("Vehicle saved successfully!");
|
||||
localStorage.setItem('vehicle_id',response.vehicle_id)
|
||||
window.location.reload();
|
||||
} else {
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
$('#saveVehcileBtn').prop('disabled', false);
|
||||
window.location.reload();
|
||||
}else if (response.success && response.code == 404 ) {
|
||||
$('#'+response.field).val("");
|
||||
toastr.warning(response.message);
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}else {
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while saving vehicle:', error);
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
$('#saveVehcileBtn').prop('disabled', false);
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}
|
||||
});
|
||||
}else{
|
||||
toastr.warning("Please Fill All Data");
|
||||
$('#saveVehcileBtn').prop('disabled', false);
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -83,7 +83,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group text-center">
|
||||
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitproductcategory(this)">Submit</button>
|
||||
<button class="btn btn-rounded btn-primary" type="submit" id="pcBtn" onclick="submitproductcategory(this)">Submit</button>
|
||||
</div>
|
||||
|
||||
<!-- </form> -->
|
||||
@ -111,11 +111,13 @@
|
||||
function submitproductcategory(params) {
|
||||
// Get the value of the Product Category Name input field
|
||||
var productcategoryname = $('#product_category_name').val().trim();
|
||||
|
||||
const pcButton = $('#pcBtn');
|
||||
pcButton.prop('disabled', true).text('Processing...');
|
||||
// Check if Product Category Name is empty
|
||||
if (productcategoryname === '') {
|
||||
// Display error message
|
||||
toastr.error('Please enter a Product Category Name.', 'Error');
|
||||
pcButton.prop('disabled', false).text('Submit');
|
||||
return; // Stop further execution of the function
|
||||
}
|
||||
var formData = {
|
||||
@ -135,6 +137,7 @@
|
||||
console.log(response);
|
||||
if (response.status == "failed") {
|
||||
toastr.warning(response.data, 'Warning');
|
||||
pcButton.prop('disabled', false).text('Submit');
|
||||
}else{
|
||||
$('#product_category_modal').modal('hide');
|
||||
$('#product_category_name').val('');
|
||||
@ -147,6 +150,7 @@
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response here
|
||||
console.error(xhr.responseText);
|
||||
pcButton.prop('disabled', false).text('Submit');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<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>' ?>
|
||||
<?= 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 Make"></i>' ?>
|
||||
<select class="form-control SelExample" id="make" name="make[]" required multiple>
|
||||
<option value="">Select a Make</option>
|
||||
<!-- Options for make -->
|
||||
@ -68,7 +68,7 @@
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="model" class="col-form-label">Model<span class="text-danger">*</span></label>
|
||||
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addModelModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addModelModal" title="Add Client"></i>'; ?>
|
||||
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addModelModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addModelModal" title="Add Modal"></i>'; ?>
|
||||
<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)): ?>
|
||||
@ -99,7 +99,7 @@
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="manufacturer" class="col-form-label">Manufacturer<span class="text-danger">*</span></label>
|
||||
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addManufacturerButton" style="font-size: 18px;" data-toggle="modal" data-target="#manufacturer_login-modal" title="Add Client"></i>' ?>
|
||||
<?= isset($products['product_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addManufacturerButton" style="font-size: 18px;" data-toggle="modal" data-target="#manufacturer_login-modal" title="Add Manufacturer"></i>' ?>
|
||||
<select class="form-control SelExample" id="manufacturer" name="manufacturer" required>
|
||||
<option value="">Select a Manufacturer</option>
|
||||
<?php foreach ($manufacturers as $value): ?>
|
||||
@ -380,7 +380,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group text-center">
|
||||
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitManufacturers(this)">Submit</button>
|
||||
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitManufacturers(this)" id="saveManufacturersBtn">Save Manufacturers</button>
|
||||
</div>
|
||||
|
||||
|
||||
@ -680,7 +680,8 @@ $(document).ready(function() {
|
||||
$('#saveMakeBtn').click(function() {
|
||||
var make = $('#makes').val();
|
||||
var model = $('#models').val();
|
||||
|
||||
const button = $('#saveMakeBtn');
|
||||
button.prop('disabled', true).text('Processing...');
|
||||
if (make != '' && model != '') {
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'save_make'?>',
|
||||
@ -698,15 +699,18 @@ $('#saveMakeBtn').click(function() {
|
||||
} else {
|
||||
// Handle failure here, e.g., show an error message
|
||||
toastr.error("Failed to save make and model");
|
||||
button.prop('disabled', false).text('Save Make');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while saving make and model:', error);
|
||||
toastr.error("Failed to save make and model. Please try again");
|
||||
button.prop('disabled', false).text('Save Make');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toastr.warning("Please fill in both make and model fields");
|
||||
button.prop('disabled', false).text('Save Make');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@ -740,6 +744,8 @@ $('#saveMakeBtn').click(function() {
|
||||
$('#saveModelBtn').click(function() {
|
||||
var makeId = $('#makeSelect').val();
|
||||
var model = $('#modelInput').val();
|
||||
const button = $('#saveModelBtn');
|
||||
button.prop('disabled', true).text('Processing...');
|
||||
if (makeId != '' && model != '') {
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'save_model'?>',
|
||||
@ -759,15 +765,18 @@ $('#saveMakeBtn').click(function() {
|
||||
toastr.error("Failed to save model");
|
||||
}
|
||||
$('#model').val(response.model_id);
|
||||
button.prop('disabled', false).text('Save Model');
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while saving model:', error);
|
||||
toastr.error("Failed to save model. Please try again");
|
||||
button.prop('disabled', false).text('Save Model');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toastr.warning("Please fill in both make and model fields");
|
||||
button.prop('disabled', false).text('Save Model');
|
||||
}
|
||||
});
|
||||
|
||||
@ -895,6 +904,9 @@ $('#saveMakeBtn').click(function() {
|
||||
if (!$('#manufacturer_name').val() || !$('#manufacturer_quality').val()) {
|
||||
return false;
|
||||
}
|
||||
const button = $('#saveManufacturersBtn');
|
||||
button.prop('disabled', true).text('Processing...');
|
||||
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'save_manufacturer'?>',
|
||||
type: 'POST',
|
||||
@ -922,10 +934,12 @@ $('#saveMakeBtn').click(function() {
|
||||
}
|
||||
|
||||
}
|
||||
button.prop('disabled', false).text('Save Manufacturer');//doubted
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response here
|
||||
console.error(xhr.responseText);
|
||||
button.prop('disabled', false).text('Save Manufacturer');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -139,8 +139,8 @@
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<!-- <option value="PO Issued" selected>PO Issued</option> -->
|
||||
<option value="Received" <?= $purchase['status'] === 'Received' ? 'selected' : '' ?>>Received</option>
|
||||
<option value="PO Issued" <?= $purchase['status'] === 'PO Issued' ? 'selected' : '' ?>>PO Issued</option>
|
||||
<option value="PO Issued" <?= isset($purchase['status']) && !isset($reorder) && $purchase['status'] === 'PO Issued' ? 'selected' : '' ?>>PO Issued</option>
|
||||
<option value="Received" <?= isset($purchase['status']) && !isset($reorder) && $purchase['status'] === 'Received' ? 'selected' : '' ?>>Received</option>
|
||||
<!-- <option value="Paid">Paid</option> -->
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
<div class="form-group col-md-6">
|
||||
<label for="inputEmail4" class="col-form-label">Vehicle<span
|
||||
class="text-danger">*</span></label>
|
||||
<?= isset($sales['vehicle_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addVehicleModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addVehicleModal" title="Add Client"></i>' ?>
|
||||
<?= isset($sales['vehicle_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addVehicleModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addVehicleModal" title="Add Vehicle"></i>' ?>
|
||||
|
||||
<select class="form-control vehicle-select SelExample" name="vehicle_id" id="vehicle_id"
|
||||
<?= isset($sales['vehicle_id']) ? 'disabled' : 'required="true"' ?>>
|
||||
@ -451,47 +451,11 @@
|
||||
<script>
|
||||
productarray = [];
|
||||
$(document).ready(function() {
|
||||
// Function to fetch make and model information based on make and model IDs
|
||||
function fetchMakeAndModel(makeId, modelId) {
|
||||
// Make sure makeId and modelId are valid
|
||||
if (makeId !== '' && modelId !== '') {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST', // or 'GET' based on your server implementation
|
||||
dataType: 'json',
|
||||
data: {
|
||||
make_id: makeId,
|
||||
model_id: modelId,
|
||||
general: 1
|
||||
},
|
||||
success: function(response) {
|
||||
// console.log(response);
|
||||
// Populate make and model in the input field
|
||||
var makeAndModel = response.makeName + ' ' + response.modelName;
|
||||
$('#makeAndModel').val(makeAndModel);
|
||||
|
||||
if(response.product.length){
|
||||
productarray = response.product;
|
||||
}else{
|
||||
productarray = "No Product";
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error('Error fetching product information:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
productarray = [];
|
||||
console.error('Make ID or Model ID not found for the selected vehicle');
|
||||
}
|
||||
}
|
||||
|
||||
// Event listener for vehicle selection change
|
||||
$('.vehicle-select').change(function() {
|
||||
var vehicleId = $(this).val();
|
||||
console.log("**");
|
||||
console.log(vehicleId);
|
||||
|
||||
if (vehicleId !== '') {
|
||||
// Find the selected vehicle
|
||||
@ -927,7 +891,9 @@ $(document).ready(function() {
|
||||
var ifStatementCondition ="createclientName !== '' && createclientMobile !== '' && createclientType !== '' && reg_no !== '' && model !== '' && make !== ''";
|
||||
}
|
||||
|
||||
|
||||
const button = $('#saveVehcileBtn');
|
||||
button.prop('disabled', true).text('Processing...');
|
||||
|
||||
if (reg_no) {
|
||||
$.ajax({
|
||||
url: '<?= base_url("checkRegisterNo") ?>', // URL to your controller method for fetching models
|
||||
@ -938,6 +904,7 @@ $(document).ready(function() {
|
||||
if (response) {
|
||||
$('#reg_no').val("");
|
||||
toastr.warning("Register Number Already Added!");
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}else{
|
||||
if (eval(ifStatementCondition)) {
|
||||
|
||||
@ -958,30 +925,38 @@ $(document).ready(function() {
|
||||
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
$('#addVehicleModal').modal('hide');
|
||||
if (response.success && response.code == 200 ) {
|
||||
|
||||
toastr.success("Vehicle saved successfully!");
|
||||
localStorage.setItem('vehicle_id',response.vehicle_id)
|
||||
localStorage.setItem('vehicle_id',response.vehicle_id);
|
||||
$('#addVehicleModal').modal('hide');
|
||||
window.location.reload();
|
||||
|
||||
} else {
|
||||
}else if (response.success && response.code == 404 ) {
|
||||
$('#'+response.field).val("");
|
||||
toastr.warning(response.message);
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}else {
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while saving vehicle:', error);
|
||||
toastr.warning("Failed to save vehicle. Please try again");
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
toastr.warning("Please Fill All Data");
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error(error); // Log any errors to the console
|
||||
button.prop('disabled', false).text('Save Vehicle');
|
||||
}
|
||||
});
|
||||
|
||||
@ -1118,39 +1093,74 @@ $(document).on('click', '#selectClient', function() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$(window).on('load', function() {
|
||||
// This code will execute after the page has been reloaded
|
||||
vehicle_id = localStorage.getItem('vehicle_id');
|
||||
localStorage.removeItem('vehicle_id');
|
||||
if(vehicle_id) {
|
||||
if(vehicle_id) {
|
||||
var vehicleId = vehicle_id;
|
||||
if (vehicleId !== '') {
|
||||
// Find the selected client in the client data
|
||||
// var selectedClient = vehicles.find(function(vehicle) {
|
||||
// return vehicle.vehicle_id == vehicleId;
|
||||
// });
|
||||
var selectedClient = vehicles.find(function(vehicle) {
|
||||
return vehicle.vehicle_id == vehicleId;
|
||||
});
|
||||
var makeId = selectedClient.make;
|
||||
var modelId = selectedClient.model;
|
||||
|
||||
// console.log(selectedClient);
|
||||
fetchMakeAndModel(makeId, modelId);
|
||||
console.log(selectedClient);
|
||||
|
||||
// $('input[name="client_id"]').val(selectedClient.client_name);
|
||||
$('input[name="client_id"]').val(selectedClient.client_name);
|
||||
$('input[name="billing_address"]').val(selectedClient.address);
|
||||
// $('input[name="billing_address"]').val(selectedClient.address);
|
||||
// // $('input[name="billing_address"]').val(selectedClient.address);
|
||||
// $('input[name="city"]').val(selectedClient.city);
|
||||
// $('input[name="state"]').val(selectedClient.state);
|
||||
// $('input[name="country"]').val(selectedClient.country);
|
||||
// $('input[name="mobile_no"]').val(selectedClient.mobile_no);
|
||||
// $('input[name="postalcode"]').val(selectedClient.postal_code);
|
||||
$('input[name="city"]').val(selectedClient.city);
|
||||
$('input[name="state"]').val(selectedClient.state);
|
||||
$('input[name="country"]').val(selectedClient.country);
|
||||
$('input[name="mobile_no"]').val(selectedClient.mobile_no);
|
||||
$('input[name="postalcode"]').val(selectedClient.postal_code);
|
||||
}
|
||||
|
||||
$('#vehicle_id').val(vehicle_id).trigger('change');
|
||||
$('#vehicle_name').val(vehicle_id).trigger('change');
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function fetchMakeAndModel(makeId, modelId) {
|
||||
// Make sure makeId and modelId are valid
|
||||
if (makeId !== '' && modelId !== '') {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST', // or 'GET' based on your server implementation
|
||||
dataType: 'json',
|
||||
data: {
|
||||
make_id: makeId,
|
||||
model_id: modelId,
|
||||
general: 1
|
||||
},
|
||||
success: function(response) {
|
||||
// console.log(response);
|
||||
// Populate make and model in the input field
|
||||
var makeAndModel = response.makeName + ' ' + response.modelName;
|
||||
$('#makeAndModel').val(makeAndModel);
|
||||
|
||||
if(response.product.length){
|
||||
productarray = response.product;
|
||||
}else{
|
||||
productarray = "No Product";
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error
|
||||
console.error('Error fetching product information:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
productarray = [];
|
||||
console.error('Make ID or Model ID not found for the selected vehicle');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- script for set the product name id -->
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
</div>
|
||||
<div class="form-group col-md-7">
|
||||
<div class="form-group col-md-12">
|
||||
<h5 class="text-uppercase bg-light p-2"><i class="mdi mdi-account-circle mr-1"></i> Personal Info</h5>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
@ -78,8 +78,12 @@
|
||||
</div>
|
||||
</form>
|
||||
<div class="password_change card-body">
|
||||
<div class="form-group col-md-7">
|
||||
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="mdi mdi-account-circle mr-1"></i> Change Password</h5>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="mdi mdi-account-circle mr-1"></i> Change Password</h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
@ -128,7 +132,7 @@
|
||||
<button type="submit" class="btn btn-primary" id="submit_password" style="float: inline-end;" onclick="changePassword(this)">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Make<span class="text-danger">*</span></label>
|
||||
<?= isset($vehicle['client_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addMakeModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addMakeModal" title="Add Client"></i>' ?>
|
||||
<?= isset($vehicle['client_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addMakeModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addMakeModal" title="Add Make"></i>' ?>
|
||||
<select class="form-control SelExample" name="make" id="make" <?= isset($vehicle['make']) ? '' : 'required' ?>>
|
||||
<?= isset($vehicle['make']) ? '' : '<option value="">Select a Make</option>' ?>
|
||||
<?php foreach ($makeData as $value) : ?>
|
||||
@ -37,7 +37,7 @@
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Model<span class="text-danger">*</span></label>
|
||||
<?= isset($vehicle['client_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addModelModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addModelModal" title="Add Client"></i>' ?>
|
||||
<?= isset($vehicle['client_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addModelModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addModelModal" title="Add Modal"></i>' ?>
|
||||
<select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>>
|
||||
<?php if (isset($vehicle["model_name"])) : ?>
|
||||
<option value="<?= $vehicle["model"] ?>" >
|
||||
@ -310,6 +310,8 @@ $(document).ready(function() {
|
||||
var clientName = $('#clientName').val();
|
||||
var clientMobile = $('#clientMobile').val();
|
||||
var clientType = $('#clientType').val();
|
||||
const clientButton = $('#saveClientBtn');
|
||||
clientButton.prop('disabled', true).text('Processing...');
|
||||
if(clientName != '' && clientMobile != '' && clientType != ''){
|
||||
|
||||
// Send AJAX request to save the client
|
||||
@ -333,20 +335,24 @@ $(document).ready(function() {
|
||||
// Manually select the newly added option
|
||||
$("#clientData").val(response.clientData.client_id);
|
||||
$('input[name="mobile_no"]').val(response.clientData.mobile_no);
|
||||
clientButton.prop('disabled', false).text('Save Client');
|
||||
} else {
|
||||
// Client save operation failed, display error message
|
||||
toastr.warning("Failed to save client. Please try again");
|
||||
clientButton.prop('disabled', false).text('Save Client');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// AJAX request failed, display error message
|
||||
console.error('Error occurred while saving client:', error);
|
||||
toastr.warning("Failed to save client. Please try again");
|
||||
clientButton.prop('disabled', false).text('Save Client');
|
||||
}
|
||||
});
|
||||
|
||||
}else{
|
||||
toastr.warning("Please Fill All Datas");
|
||||
clientButton.prop('disabled', false).text('Save Client');
|
||||
}
|
||||
|
||||
|
||||
@ -361,6 +367,8 @@ $(document).ready(function() {
|
||||
$('#saveMakeBtn').click(function() {
|
||||
var make = $('#makes').val();
|
||||
var model = $('#models').val();
|
||||
const makeButton = $('#saveMakeBtn');
|
||||
makeButton.prop('disabled', true).text('Processing...');
|
||||
|
||||
if (make != '' && model != '') {
|
||||
$.ajax({
|
||||
@ -376,18 +384,22 @@ $('#saveMakeBtn').click(function() {
|
||||
// Handle success here, e.g., show a success message
|
||||
toastr.success("Make and model saved successfully");
|
||||
window.location.reload();
|
||||
makeButton.prop('disabled', false).text('Save Make');
|
||||
} else {
|
||||
// Handle failure here, e.g., show an error message
|
||||
toastr.error("Failed to save make and model");
|
||||
makeButton.prop('disabled', false).text('Save Make');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while saving make and model:', error);
|
||||
toastr.error("Failed to save make and model. Please try again");
|
||||
makeButton.prop('disabled', false).text('Save Make');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toastr.warning("Please fill in both make and model fields");
|
||||
makeButton.prop('disabled', false).text('Save Make');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@ -422,6 +434,9 @@ $('#saveModelBtn').click(function() {
|
||||
var makeId = $('#makeSelect').val();
|
||||
var model = $('#modelInput').val();
|
||||
console.log(model);
|
||||
const modalButton = $('#saveModelBtn');
|
||||
modalButton.prop('disabled', true).text('Processing...');
|
||||
modalButton.prop('disabled', false).text('Save Model');
|
||||
if (makeId != '' && model != '') {
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'save_model'?>',
|
||||
@ -435,17 +450,21 @@ $('#saveModelBtn').click(function() {
|
||||
$('#addModelModal').modal('hide');
|
||||
toastr.success("Model saved successfully");
|
||||
$('#model').append('<option value="' + response.model_id + '">' + response.model_value + '</option>');
|
||||
modalButton.prop('disabled', false).text('Save Model');
|
||||
} else {
|
||||
toastr.error("Failed to save model");
|
||||
modalButton.prop('disabled', false).text('Save Model');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error occurred while saving model:', error);
|
||||
toastr.error("Failed to save model. Please try again");
|
||||
modalButton.prop('disabled', false).text('Save Model');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toastr.warning("Please fill in both make and model fields");
|
||||
modalButton.prop('disabled', false).text('Save Model');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user