product-vehicle-vendor

This commit is contained in:
heama 2024-04-10 13:30:15 +05:30
parent e559698799
commit 598a7b2ee7
6 changed files with 231 additions and 16 deletions

View File

@ -42,6 +42,7 @@ $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");
$routes->post("save_make", "Products::save_make");
//end products//
//Sales order //

View File

@ -64,6 +64,7 @@ class Products extends BaseController
$ManufacturerModel = new ManufacturerModel();
$data['manufacturers']=$ManufacturerModel->findAll();
$data['page_name']="Add Product";
$data['vendorsProduct'] =[];
} else if ($product_id !== '0') {
$data['page_name']="Edit Product";
$ProductModel = new ProductModel();
@ -83,6 +84,18 @@ class Products extends BaseController
$data['vendors']=$VendorModel->findAll();
$ManufacturerModel = new ManufacturerModel();
$data['manufacturers']=$ManufacturerModel->findAll();
$vendorIds = json_decode($products['vendor'], true);
$vendors = [];
$VendorModel = new VendorModel();
foreach ($vendorIds as $vendorId) {
$vendor = $VendorModel->find($vendorId);
if ($vendor) {
$vendors[] = ['id' => $vendor['vendor_id'], 'name' => $vendor['vendor_name']];
}
}
$data['vendorsProduct'] = $vendors;
// print_r($data['vendors']);die;
$preferredVendorId = $products['prefered_vendor'];
// Pass the preferred vendor ID to the view
$data['preferredVendorId'] = $preferredVendorId; // print_r($data);die;
@ -235,4 +248,47 @@ public function get_models()
return $this->response->setJSON($models);
}
public function save_make() {
$response = []; // Initialize an empty array to hold the response data
// Assuming BikemakeModel and BikemodelsModel are properly defined
$BikemakeModel = new BikemakeModel();
$BikemodelsModel = new BikemodelsModel();
$make = $this->request->getPost('make');
$model = $this->request->getPost('model');
// Check if both make and model are provided
if (!empty($make) && !empty($model)) {
$data = [
'make' => $make
];
// Insert the make into the database
$BikemakeModel->insert($data);
$make_id = $BikemakeModel->getInsertID();
$modelData = [
'model_name' => $model,
'make_id' => $make_id,
];
// Insert the model into the database
$BikemodelsModel->insert($modelData);
// Set success status in the response
$response['success'] = true;
} else {
// If make or model is empty, set success status to false
$response['success'] = false;
}
// Send JSON response back to the client
return $this->response->setJSON($response);
}
}

View File

@ -7,6 +7,7 @@ use App\Models\VendorModel;
use App\Models\UsersModel;
use App\Models\BikemakeModel;
use App\Models\BikemodelsModel;
use App\Models\ManufacturerModel;
class Vendor extends BaseController
@ -36,10 +37,13 @@ class Vendor extends BaseController
if ($vendor_id === '0') {
$data['vendor'] = [];
$data['page_name'] = "Add Vendor";
$ManufacturerModel = new ManufacturerModel();
$data['manufacturers']=$ManufacturerModel->findAll();
} else {
$VendorModel = new VendorModel();
$vendor = $VendorModel->where('vendor_id', $vendor_id)->get()->getRowArray();
$ManufacturerModel = new ManufacturerModel();
$data['manufacturers']=$ManufacturerModel->findAll();
$data['vendor'] = $vendor;
$data['page_name'] = "Edit Vendor";
@ -66,6 +70,7 @@ class Vendor extends BaseController
'state' => $this->request->getPost('state'),
'postal_code' => $this->request->getPost('postalcode'),
'country' => $this->request->getPost('country'),
'vendortype' => $this->request->getPost('vendortype'),
'category' => $this->request->getPost('category'),
'contact_person_name1' => $this->request->getPost('contact_person_name1'),
'contact_person_name2' => $this->request->getPost('contact_person_name2'),
@ -73,9 +78,10 @@ class Vendor extends BaseController
'contact_person_mobile1' => $this->request->getPost('contact_person_mobile1'),
'contact_person_mobile2' => $this->request->getPost('contact_person_mobile2'),
'contact_person_mobile3' => $this->request->getPost('contact_person_mobile3'),
'contact_person_resignation1' => $this->request->getPost('contact_person_resignation1'),
'contact_person_resignation2' => $this->request->getPost('contact_person_resignation2'),
'contact_person_resignation3' => $this->request->getPost('contact_person_resignation3'),
'contact_person_designation1' => $this->request->getPost('contact_person_designation1'),
'contact_person_designation2' => $this->request->getPost('contact_person_designation2'),
'contact_person_designation3' => $this->request->getPost('contact_person_designation3'),
'manufacturer_id' => json_encode($this->request->getPost('manufacturer')),
'isactive' => 1 ,
'branch_id' => $this->session->get('logged_user_branch_id'),
];

View File

@ -1,5 +1,5 @@
<?php include('layout/header.php'); ?>
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
@ -25,7 +25,8 @@
<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>
<label for="make" class="col-form-label">Make<span class="text-danger">*</span><i type="button" class="fe-plus-circle" id="addMakeModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addMakeModal" title="Add Client"></i></label>
<select class="form-control SelExample" id="make" name="make" required>
<option value="">Select a Make</option>
@ -95,9 +96,9 @@
<label for="preferred_vendor" class="col-form-label">Preferred Vendor<span class="text-danger">*</span></label>
<select class="form-control" id="preferred_vendor" name="prefered_vendor" required>
<!-- Loop through vendors and set selected attribute if ID matches preferredVendorId -->
<?php foreach ($vendors as $vendor): ?>
<option value="<?= $vendor['vendor_id'] ?>" <?= ( $vendor['vendor_id'] == $preferredVendorId) ? 'selected' : '' ?>>
<?= $vendor['vendor_name'] ?>
<?php foreach ($vendorsProduct as $vendor): ?>
<option value="<?= $vendor['id'] ?>" <?= (isset($preferredVendorId) && $vendor['id'] == $preferredVendorId) ? 'selected' : '' ?>>
<?= $vendor['name'] ?>
</option>
<?php endforeach; ?>
</select>
@ -187,7 +188,34 @@
</div>
</div>
<?php include('layout/footer.php'); ?>
<div class="modal fade" id="addMakeModal" tabindex="-1" role="dialog" aria-labelledby="addMakeModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addMakeModalLabel">Add New Make</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="addClientForm">
<div class="form-group">
<label for="clientName">Make</label>
<input type="text" class="form-control" id="makes" placeholder="Enter Make"required>
</div>
<div class="form-group">
<label for="clientMobile">Model</label>
<input type="text" class="form-control" id="models" placeholder="Enter Model"required>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="saveMakeBtn">Save Make</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
// Check SGST checkbox by default
@ -364,14 +392,14 @@ function updatePreferredVendorDropdown() {
// Populate preferred vendor options based on selected vendors
selectedVendors.forEach(function(vendorId) {
var vendorName = $('#vendor option[value="' + vendorId + '"]').text();
$('#preferred_vendor').append('<option value="' + vendorId + '" >' + vendorName + '</option>');
$('#preferred_vendor').append('<option value="' + vendorId + '" selected>' + vendorName + '</option>');
});
}
// Call the function initially
$(document).ready(function() {
// Update the preferred vendor dropdown initially
updatePreferredVendorDropdown();
// updatePreferredVendorDropdown();
// Update the preferred vendor dropdown when vendors selection changes
$('#vendor').change(function() {
@ -381,3 +409,53 @@ $(document).ready(function() {
</script>
<script>
$('#saveMakeBtn').click(function() {
var make = $('#makes').val();
var model = $('#models').val();
if (make != '' && model != '') {
$.ajax({
url: '<?php echo base_url().'save_make'?>',
method: 'POST',
data: {
make: make,
model: model
},
success: function(response) {
if (response.success) {
$('#addMakeModalButton').modal('hide');
// Handle success here, e.g., show a success message
toastr.success("Make and model saved successfully");
window.location.reload();
} else {
// Handle failure here, e.g., show an error message
toastr.error("Failed to save make and model");
}
},
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");
}
});
} else {
toastr.warning("Please fill in both make and model fields");
}
});
</script>
<style>
.select2-container--default .select2-results__option--highlighted[aria-selected]{
color:#ffffff;
background: #526dee!important;
}
.select2-container .select2-selection--single{
height: 36px;
border:1px solid #ced4da;
}
.select2-container--default .select2-selection--single .select2-selection__rendered{
line-height: 36px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow{
top:4px;
}
</style>

View File

@ -23,7 +23,7 @@
<h4 class="header-title">Vehicle Details :</h4>
<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>
<label for="inputPassword4" class="col-form-label">Make<span class="text-danger">*</span><i type="button" class="fe-plus-circle" id="addMakeModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addMakeModal" title="Add Client"></i></label>
<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) : ?>
@ -119,7 +119,35 @@
<?php include('layout/footer.php'); ?>
</div>
<div class="modal fade" id="addMakeModal" tabindex="-1" role="dialog" aria-labelledby="addMakeModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addMakeModalLabel">Add New Make</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="addClientForm">
<div class="form-group">
<label for="clientName">Make</label>
<input type="text" class="form-control" id="makes" placeholder="Enter Make"required>
</div>
<div class="form-group">
<label for="clientMobile">Model</label>
<input type="text" class="form-control" id="models" placeholder="Enter Model"required>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="saveMakeBtn">Save Make</button>
</div>
</div>
</div>
</div>
<!-- Client Modal -->
<div class="modal fade" id="addClientModal" tabindex="-1" role="dialog" aria-labelledby="addClientModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
@ -269,7 +297,41 @@ $(document).ready(function() {
// Define the clients array and populate it with data
var clients = <?php echo json_encode($client); ?>;
</script>
<!-- Mkae Modal ajax -->
<script>
$('#saveMakeBtn').click(function() {
var make = $('#makes').val();
var model = $('#models').val();
if (make != '' && model != '') {
$.ajax({
url: '<?php echo base_url().'save_make'?>',
method: 'POST',
data: {
make: make,
model: model
},
success: function(response) {
if (response.success) {
$('#addMakeModalButton').modal('hide');
// Handle success here, e.g., show a success message
toastr.success("Make and model saved successfully");
window.location.reload();
} else {
// Handle failure here, e.g., show an error message
toastr.error("Failed to save make and model");
}
},
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");
}
});
} else {
toastr.warning("Please fill in both make and model fields");
}
});
</script>
<style>
.select2-container--default .select2-results__option--highlighted[aria-selected]{
color:#ffffff;

View File

@ -55,10 +55,22 @@
</select>
</div>
<div class="form-group col-md-4">
<label for="manufacturer" class="col-form-label">Manufacturer<span class="text-danger">*</span></label>
<select class="form-control SelExample" id="manufacturer" name="manufacturer[]" required multiple>
<option value="">Select a Manufacturer</option>
<?php if(isset($manufacturers) && !empty($manufacturers)): ?>
<?php foreach($manufacturers as $value): ?>
<option value="<?= $value['manufacturer_id'] ?>" <?= isset($vendor['manufacturer_id']) && in_array($value['manufacturer_id'], json_decode($vendor['manufacturer_id'], true)) ? 'selected' : '' ?>>
<?= $value['manufacturer_name'] ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<br>