FIX_CHANGE_CONFLICT_CODE_MERAGE:AADHAVAN

This commit is contained in:
aadhavan valli 2024-04-10 16:57:36 +05:30
commit 426409cc9e
12 changed files with 776 additions and 116 deletions

View File

@ -42,6 +42,9 @@ $routes->get("new_product/(:any)", "Products::new_product/$1");
$routes->get("delete_product/(:any)", "Products::delete_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_vendors_by_model", "Products::get_vendors_by_model");
$routes->post("get_models", "Products::get_models"); $routes->post("get_models", "Products::get_models");
$routes->get("get_makes", "Products::get_makes");
$routes->post("save_make", "Products::save_make");
$routes->post("save_model", "Products::save_model");
//end products// //end products//
//Sales order // //Sales order //
@ -120,3 +123,5 @@ $routes->get("new_purchase/(:any)", "Purchase::new_purchase/$1");
$routes->get('get_vendor/(:any)', 'Purchase::get_vendor/$1'); $routes->get('get_vendor/(:any)', 'Purchase::get_vendor/$1');
$routes->post("add_purchase", "Purchase::add_purchase"); $routes->post("add_purchase", "Purchase::add_purchase");
$routes->get("delete_purchase/(:any)", "Purchase::delete_purchase/$1"); $routes->get("delete_purchase/(:any)", "Purchase::delete_purchase/$1");
// Reorder Level//
$routes->get('reorder_level_index', 'Reorderlevel::reorder_level_index');

View File

@ -124,6 +124,7 @@ class Client extends BaseController
$data = [ $data = [
'client_name' => $this->request->getPost('client_name'), 'client_name' => $this->request->getPost('client_name'),
'mobile_no' => $this->request->getPost('mobile_no'), 'mobile_no' => $this->request->getPost('mobile_no'),
'client_type' => $this->request->getPost('client_type'),
'branch_id'=> $this->session->get('logged_user_branch_id'), 'branch_id'=> $this->session->get('logged_user_branch_id'),
'city'=>'Chennai', 'city'=>'Chennai',
'state'=>'Tamil Nadu', 'state'=>'Tamil Nadu',

View File

@ -68,6 +68,7 @@ class Products extends BaseController
$ManufacturerModel = new ManufacturerModel(); $ManufacturerModel = new ManufacturerModel();
$data['manufacturers']=$ManufacturerModel->findAll(); $data['manufacturers']=$ManufacturerModel->findAll();
$data['page_name']="Add Product"; $data['page_name']="Add Product";
$data['vendorsProduct'] =[];
} else if ($product_id !== '0') { } else if ($product_id !== '0') {
$data['page_name']="Edit Product"; $data['page_name']="Edit Product";
$ProductModel = new ProductModel(); $ProductModel = new ProductModel();
@ -87,6 +88,18 @@ class Products extends BaseController
$data['vendors']=$VendorModel->findAll(); $data['vendors']=$VendorModel->findAll();
$ManufacturerModel = new ManufacturerModel(); $ManufacturerModel = new ManufacturerModel();
$data['manufacturers']=$ManufacturerModel->findAll(); $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']; $preferredVendorId = $products['prefered_vendor'];
// Pass the preferred vendor ID to the view // Pass the preferred vendor ID to the view
$data['preferredVendorId'] = $preferredVendorId; // print_r($data);die; $data['preferredVendorId'] = $preferredVendorId; // print_r($data);die;
@ -239,4 +252,77 @@ public function get_models()
return $this->response->setJSON($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);
}
public function get_makes()
{
$BikeMakeModel = new BikeMakeModel(); // Adjust this according to your actual model name
$makes = $BikeMakeModel->findAll();
return $this->response->setJSON($makes);
}
public function save_model() {
$response = [];
$BikemodelsModel = new BikemodelsModel();
$make_id = $this->request->getPost('make_id');
$model = $this->request->getPost('modelvalue');
if (!empty($make_id) && !empty($model)) {
$modelData = [
'model_name' => $model,
'make_id' => $make_id,
];
$BikemodelsModel->insert($modelData);
$response['success'] = true;
} else {
$response['success'] = false;
}
return $this->response->setJSON($response);
}
} }

View File

@ -0,0 +1,32 @@
<?php
namespace App\Controllers;
use App\Models\ProductModel;
class Reorderlevel extends BaseController
{
public $session;
public function __construct()
{
$this->session = session();
}
public function reorder_level_index()
{
$productModel = new ProductModel();
$reorder = $productModel->where('qty_stock <= purchase_order_level')->findAll();
// print_r($reorder);die;
$data['reorder']=$reorder;
return view('reorder_level_list',$data);
}
}
?>

View File

@ -6,7 +6,8 @@ use App\Models\SalesOrderModel;
use App\Models\SalesOrderProductModel; use App\Models\SalesOrderProductModel;
use App\Models\ProductModel; use App\Models\ProductModel;
use App\Models\ClientModel; use App\Models\ClientModel;
use App\Models\BikeMakeModel; use App\Models\BikemodelsModel;
use App\Models\BikemakeModel;
use App\Models\VehicleModel; use App\Models\VehicleModel;
use Mpdf\Mpdf; use Mpdf\Mpdf;
class Sales extends BaseController class Sales extends BaseController
@ -16,6 +17,8 @@ class Sales extends BaseController
{ {
$this->session = session(); $this->session = session();
$this->BikemodelsModel = new BikemodelsModel();
$this->BikemakeModel = new BikemakeModel();
} }
@ -322,13 +325,38 @@ public function delete_sales_product()
// Load ClientModel // Load ClientModel
$VehicleModel = new VehicleModel(); $VehicleModel = new VehicleModel();
// Validate inputs if($this->request->getPost('formType') == 'create')
{
$ClientModel = new ClientModel();
$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_id = $ClientModel->insert($client);
if($client_id){
$data = [
'client_id' => $client_id,
'mobile_no' => $this->request->getPost('createclientMobile'),
'reg_no' => $this->request->getPost('reg_no'),
'model' => $this->request->getPost('model'),
'make' => $this->request->getPost('make'),
'branch_id'=> $this->session->get('logged_user_branch_id'),
'city'=>'Chennai',
'state'=>'Tamil Nadu',
'isactive' => 1
];
}
// If validation passes, proceed to save the client }else{
$data = [ $data = [
'client_id' => $this->request->getPost('client_id'), 'client_id' => $this->request->getPost('client_id'),
'mobile_no' => $this->request->getPost('mobile_no'), 'mobile_no' => $this->request->getPost('mobile_no'),
'reg_no' => $this->request->getPost('reg_no'), 'reg_no' => $this->request->getPost('reg_no'),
'model' => $this->request->getPost('model'), 'model' => $this->request->getPost('model'),
@ -339,6 +367,12 @@ public function delete_sales_product()
'isactive' => 1 'isactive' => 1
]; ];
}
// Attempt to insert the client data // Attempt to insert the client data
$id = $VehicleModel->insert($data); $id = $VehicleModel->insert($data);
if ($id) { if ($id) {
@ -376,13 +410,14 @@ public function get_vehicle_products(){
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->findAll(); ->findAll();
$modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name;
$makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make;
if($product){ if($product){
// Send JSON response // Send JSON response
return $this->response->setJSON($product); return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] );
} else { } else {
// If product is not found, return an empty response or appropriate message // If product is not found, return an empty response or appropriate message
return $this->response->setJSON([]); return $this->response->setJSON(['product'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]);
} }
} }
// Check if product exists // Check if product exists

View File

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

View File

@ -174,6 +174,13 @@
<span> Manufacturer </span> <span> Manufacturer </span>
</a> </a>
</li> </li>
<li>
<a href="<?php echo base_url('reorder_level_index') ?>">
<i class="fas fa-angle-double-up"></i>
<span> Reorder Level Products </span>
</a>
<?php if(session()->get('logged_user_role') == 'Floor Manager' || <?php if(session()->get('logged_user_role') == 'Floor Manager' ||

View File

@ -25,7 +25,8 @@
<h4 class="header-title">Product Details :</h4><br> <h4 class="header-title">Product Details :</h4><br>
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-4"> <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> <select class="form-control SelExample" id="make" name="make" required>
<option value="">Select a Make</option> <option value="">Select a Make</option>
@ -38,7 +39,7 @@
</select> </select>
</div> </div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label for="model" class="col-form-label">Model<span class="text-danger">*</span></label> <label for="model" class="col-form-label">Model<span class="text-danger">*</span><i type="button" class="fe-plus-circle" id="addModelModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addModelModal" title="Add Client"></i></label>
<select class="form-control SelExample" id="model" name="model[]" required multiple> <select class="form-control SelExample" id="model" name="model[]" required multiple>
<!-- Options for model will be populated dynamically via AJAX --> <!-- Options for model will be populated dynamically via AJAX -->
<?php if(isset($models) && !empty($models)): ?> <?php if(isset($models) && !empty($models)): ?>
@ -95,9 +96,9 @@
<label for="preferred_vendor" class="col-form-label">Preferred Vendor<span class="text-danger">*</span></label> <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> <select class="form-control" id="preferred_vendor" name="prefered_vendor" required>
<!-- Loop through vendors and set selected attribute if ID matches preferredVendorId --> <!-- Loop through vendors and set selected attribute if ID matches preferredVendorId -->
<?php foreach ($vendors as $vendor): ?> <?php foreach ($vendorsProduct as $vendor): ?>
<option value="<?= $vendor['vendor_id'] ?>" <?= ( $vendor['vendor_id'] == $preferredVendorId) ? 'selected' : '' ?>> <option value="<?= $vendor['id'] ?>" <?= (isset($preferredVendorId) && $vendor['id'] == $preferredVendorId) ? 'selected' : '' ?>>
<?= $vendor['vendor_name'] ?> <?= $vendor['name'] ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
@ -187,6 +188,66 @@
</div> </div>
</div> </div>
<?php include('layout/footer.php'); ?> <?php include('layout/footer.php'); ?>
<!-- Make popup -->
<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>
<!-- Modal popup -->
<div class="modal fade" id="addModelModal" tabindex="-1" role="dialog" aria-labelledby="addModelModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModelModalLabel">Add New Model</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="addModelForm">
<div class="form-group">
<label for="makeSelect">Make</label>
<select class="form-control" id="makeSelect" required>
<!-- Options will be populated dynamically via JavaScript -->
</select>
</div>
<div class="form-group">
<label for="modelInput">Model</label>
<input type="text" class="form-control" id="modelInput" 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="saveModelBtn">Save Model</button>
</div>
</div>
</div>
</div>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
@ -364,14 +425,14 @@ function updatePreferredVendorDropdown() {
// Populate preferred vendor options based on selected vendors // Populate preferred vendor options based on selected vendors
selectedVendors.forEach(function(vendorId) { selectedVendors.forEach(function(vendorId) {
var vendorName = $('#vendor option[value="' + vendorId + '"]').text(); 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 // Call the function initially
$(document).ready(function() { $(document).ready(function() {
// Update the preferred vendor dropdown initially // Update the preferred vendor dropdown initially
updatePreferredVendorDropdown(); // updatePreferredVendorDropdown();
// Update the preferred vendor dropdown when vendors selection changes // Update the preferred vendor dropdown when vendors selection changes
$('#vendor').change(function() { $('#vendor').change(function() {
@ -381,3 +442,111 @@ $(document).ready(function() {
</script> </script>
<!-- Save a make and model fun -->
<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>
<!-- Save Modal Funxtion -->
<script>
// Populate make dropdown in the add model modal
function populateMakeDropdown() {
$.ajax({
url: '<?php echo base_url('get_makes') ?>', // URL to your CodeIgniter controller method to fetch makes
type: 'GET',
dataType: 'json',
success: function(response) {
$('#makeSelect').empty().append('<option value="">Select Make</option>');
response.forEach(function(make) {
$('#makeSelect').append('<option value="' + make.make_id + '">' + make.make + '</option>');
});
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
}
});
}
// Call the function to populate make dropdown initially
$(document).ready(function() {
populateMakeDropdown();
});
// Save model function
$('#saveModelBtn').click(function() {
var makeId = $('#makeSelect').val();
var model = $('#modelInput').val();
console.log(model);
if (makeId != '' && model != '') {
$.ajax({
url: '<?php echo base_url().'save_model'?>',
method: 'POST',
data: {
make_id: makeId,
modelvalue: model
},
success: function(response) {
if (response.success) {
$('#addModelModal').modal('hide');
toastr.success("Model saved successfully");
window.location.reload();
} else {
toastr.error("Failed to save model");
}
},
error: function(xhr, status, error) {
console.error('Error occurred while saving model:', error);
toastr.error("Failed to save 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

@ -0,0 +1,73 @@
<?php include('layout/header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Product List </h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<!-- <h4 class="header-title">Business List</h4> -->
<table id="datatable-buttons" class="table table-striped dt-responsive nowrap w-100"
style="width:100% !important;">
<thead>
<tr>
<th>Product Name</th>
<th>Unit Price</th>
<th>Qty in Stock</th>
<th>Purchase Order Level</th>
<th>Purchase Re-Order Level</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($reorder as $value) :
?>
<tr>
<td><?= $value['product_name']; ?></td>
<td><?= number_format($value['unit_price']); ?></td>
<td><?= $value['qty_stock']; ?></td>
<td><?= $value['purchase_order_level']; ?></td>
<td><?= $value['reorder_level']; ?></td>
<!-- Call the model method -->
<td>
</td>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div> <!-- end card -->
</div> <!-- end col -->
</div>
<?php include('layout/footer.php'); ?>

View File

@ -28,7 +28,6 @@
<label for="inputEmail4" class="col-form-label">Vehicle<span class="text-danger">*</span></label> <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 Client"></i>' ?>
<select class="form-control vehicle-select SelExample" name="vehicle_id" <?= isset($sales['vehicle_id']) ? '' : 'required' ?>> <select class="form-control vehicle-select SelExample" name="vehicle_id" <?= isset($sales['vehicle_id']) ? '' : 'required' ?>>
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?> <?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
@ -41,15 +40,21 @@
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Make and Model</label>
<input type="text" class="form-control" id="makeAndModel" readonly>
</div>
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Client Name<span class="text-danger"></span></label> <label for="inputPassword4" class="col-form-label">Client Name<span class="text-danger"></span></label>
<input type="text" class="form-control" name="client_id" placeholder="Client"value="<?= isset($sales['client_name']) ? $sales['client_name'] : '' ?>" readonly> <input type="text" class="form-control" name="client_id" placeholder="Client"value="<?= isset($sales['client_name']) ? $sales['client_name'] : '' ?>" readonly>
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Mobile No<span class="text-danger">*</span></label> <label for="inputPassword4" class="col-form-label">Mobile No<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($sales['mobile_no']) ? $sales['mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" readonly> <input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($sales['mobile_no']) ? $sales['mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" readonly>
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span></label> <label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span></label>
<select class="form-control status-select" name="status" required data-toggle="select2" > <select class="form-control status-select" name="status" required data-toggle="select2" >
<!-- <option value="">Select a Status</option> --> <!-- <option value="">Select a Status</option> -->
@ -57,8 +62,9 @@
<option value="Paid" <?= isset($sales['status']) && $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option> <option value="Paid" <?= isset($sales['status']) && $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
</select> </select>
</div> </div>
</div><br> </div><br>
<h4 class="header-title">Billing Address Details :</h4><br> <h4 class="header-title">Billing Address Details :</h4><br>
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-3"> <div class="form-group col-md-3">
@ -228,7 +234,7 @@
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form id="addClientForm"> <form >
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<!-- <div class="form-group"> --> <!-- <div class="form-group"> -->
@ -245,6 +251,7 @@
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Model</label> <label for="inputPassword4" class="col-form-label">Model</label>
<select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>> <select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>>
@ -256,35 +263,61 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-row">
<div class="form-row">
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<label for="inputPassword4" class="col-form-label">Reg Number</label> <label for="inputPassword4" class="col-form-label">Reg Number</label>
<input type="text" class="form-control" name="reg_no" id="reg_no" placeholder="Reg Number"value="<?= isset($vehicle['reg_no']) ? $vehicle['reg_no'] : '' ?>" required> <input type="text" class="form-control" name="reg_no" id="reg_no" placeholder="Reg Number"value="<?= isset($vehicle['reg_no']) ? $vehicle['reg_no'] : '' ?>" required>
</div> </div>
</div> </div>
<div class="form-row">
<div class="form-group col-md-12">
<!-- <div class="form-group"> -->
<label for="clientName">Client Name</label>
<select class="form-control cleint-select SelExample" name="client_id" id=clientName <?= isset($sales['client_id']) ? '' : 'required' ?>>
<?= isset($sales['client_id']) ? '' : '<option value="">Select a Client</option>' ?> <div class="form-row">
<input type="text" value="select" id="formType" hidden>
<div class="form-group col-md-12 select">
<label for="clientName">Client Name</label>
<i type="button" class="fe-user-plus" id="createClient" style="font-size: 18px;" ></i>
<select class="form-control cleint-select SelExample" id="clientName" required>
<option value="">Select a Client</option>
<?php foreach ($client as $value) : ?> <?php foreach ($client as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?> <option value="<?= $value["client_id"] ?>">
<option value="<?= $value["client_id"] ?>" <?= isset($sales['client_id']) && $sales['client_id'] == $value["client_id"] ? 'selected' : '' ?>> <?= $value["mobile_no"] .' - '. $value["client_name"]; ?>
<?= $value["client_name"]; ?>
</option> </option>
<?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
<div class="form-group col-md-12"> <div class="form-group col-md-12 select">
<label for="clientMobile">Mobile</label> <label for="clientMobile">Mobile</label>
<input type="text" class="form-control" id="mobile" name="mobile"placeholder="Enter mobile number" maxlength="10" minlength="10"onkeypress = "return onlyNumbers(event)"required> <input type="text" class="form-control" id="clientMobile" placeholder="Enter mobile number" maxlength="10" minlength="10"onkeypress = "return onlyNumbers(event)"required>
</div> </div>
<div class="form-group col-md-12 create" style="display:none;">
<label for="create-clientName">Client Name</label>
<i type="button" class="fe-user-check" id="selectClient" style="font-size: 18px;" ></i>
<input type="text" class="form-control" id="create-clientName" placeholder="Enter client name" required>
</div>
<div class="form-group col-md-6 create" style="display:none;">
<label for="create-clientMobile">Mobile</label>
<input type="text" class="form-control" id="create-clientMobile" placeholder="Enter mobile number" maxlength="10" minlength="10"onkeypress = "return onlyNumbers(event)"required>
</div>
<div class="form-group col-md-6 create" style="display:none;">
<label for="create-clientType">Client Type</label>
<select class="form-control status-select" id="create-clientType" required >
<option value="">Select a Type</option>
<option value="Direct" >Direct</option>
<option value="Mechanic" >Mechanic</option>
<option value="Exp" >Exp</option>
</select>
</div>
</div> </div>
</form> </form>
</div> </div>
@ -329,7 +362,10 @@ $(document).ready(function() {
vehicle_id: vehicleId vehicle_id: vehicleId
}, },
success: function(response) { success: function(response) {
productarray = response; console.log(response);
productarray = response.product;
makeAndModel = response.makeName+' '+response.modelName;
$('#makeAndModel').val(makeAndModel);
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
// Handle error // Handle error
@ -547,14 +583,13 @@ $(document).ready(function() {
$('.vehicle-select').change(function() { $('.vehicle-select').change(function() {
var vehicleId = $(this).val(); var vehicleId = $(this).val();
// console.log(vehicleId);
if (vehicleId !== '') { if (vehicleId !== '') {
// Find the selected client in the client data // Find the selected client in the client data
var selectedClient = vehicles.find(function(vehicle) { var selectedClient = vehicles.find(function(vehicle) {
return vehicle.vehicle_id == vehicleId; return vehicle.vehicle_id == vehicleId;
}); });
// console.log(selectedClient);
// Populate the billing address, city, state, country, and postal code fields
$('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);
@ -581,11 +616,11 @@ $(document).ready(function() {
var selectedClients = clients.find(function(client) { var selectedClients = clients.find(function(client) {
return client.client_id == clientId; return client.client_id == clientId;
}); });
console.log(selectedClients);
// Populate the billing address, city, state, country, and postal code fields // Populate the billing address, city, state, country, and postal code fields
$('input[name="mobile"]').val(selectedClients.mobile_no); $('input[id="clientMobile"]').val(selectedClients.mobile_no);
} }
}); });
@ -625,13 +660,30 @@ $(document).ready(function() {
// AJAX request to save client // AJAX request to save client
$('#saveVehcileBtn').click(function() { $('#saveVehcileBtn').click(function() {
var formType = $('#formType').val();
console.log(formType);
var clientName = $('#clientName').val();
var clientMobile = $('#mobile').val();
var reg_no = $('#reg_no').val(); var reg_no = $('#reg_no').val();
var model = $('#model').val(); var model = $('#model').val();
var make = $('#make').val(); var make = $('#make').val();
if(clientName != '' && clientMobile != ''&&reg_no != '' && model != '' && make != ''){
var clientName = $('#clientName').val();
var clientMobile = $('#clientMobile').val();
var createclientName = $('#create-clientName').val();
var createclientMobile = $('#create-clientMobile').val();
var createclientType = $('#create-clientType').val();
if (formType == 'select')
{
var ifStatementCondition = "clientName !== '' && clientMobile !== '' && reg_no !== '' && model !== '' && make !== ''";
} else {
var ifStatementCondition = "createclientName !== '' && createclientMobile !== '' && createclientType !== '' && reg_no !== '' && model !== '' && make !== ''";
}
console.log(ifStatementCondition);
if( eval(ifStatementCondition) ){
// Send AJAX request to save the client // Send AJAX request to save the client
$.ajax({ $.ajax({
@ -642,24 +694,24 @@ $(document).ready(function() {
mobile_no: clientMobile, mobile_no: clientMobile,
reg_no:reg_no, reg_no:reg_no,
model:model, model:model,
make:make make:make,
createclientName:createclientName,
createclientMobile:createclientMobile,
createclientType:createclientType,
formType:formType,
}, },
success: function(response) { success: function(response) {
// Check if the operation was successful
if (response.success) { if (response.success) {
// Client saved successfully, close the modal and do any additional actions
$('#addVehicleModal').modal('hide'); $('#addVehicleModal').modal('hide');
// Optionally, you can update the client dropdown or show a success message
toastr.success("Vehicle saved successfully!"); toastr.success("Vehicle saved successfully!");
window.location.reload(); // Reload the page window.location.reload();
} else { } else {
// Client save operation failed, display error message
toastr.warning("Failed to save vehicle. Please try again"); toastr.warning("Failed to save vehicle. Please try again");
} }
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
// AJAX request failed, display error message
console.error('Error occurred while saving vehicle:', error); console.error('Error occurred while saving vehicle:', error);
toastr.warning("Failed to save vehicle. Please try again"); toastr.warning("Failed to save vehicle. Please try again");
} }
@ -712,7 +764,27 @@ document.getElementById('reg_no').addEventListener('input', function(event) {
</script> </script>
<script>
$(document).on('click', '#createClient', function() {
$('.create').show();
$('.select').hide();
$('#formType').val('create');
$('#clientName').val('');
$('#clientMobile').val('');
});
$(document).on('click', '#selectClient', function() {
$('.select').show();
$('.create').hide();
$('#formType').val('select');
$('#create-clientName').val('');
$('#create-clientMobile').val('');
$('#create-clientType').val('');
});
</script>

View File

@ -23,7 +23,7 @@
<h4 class="header-title">Vehicle Details :</h4> <h4 class="header-title">Vehicle Details :</h4>
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-4"> <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' ?>> <select class="form-control SelExample" name="make" id="make" <?= isset($vehicle['make']) ? '' : 'required' ?>>
<?= isset($vehicle['make']) ? '' : '<option value="">Select a Make</option>' ?> <?= isset($vehicle['make']) ? '' : '<option value="">Select a Make</option>' ?>
<?php foreach ($makeData as $value) : ?> <?php foreach ($makeData as $value) : ?>
@ -36,7 +36,7 @@
</select> </select>
</div> </div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Model<span class="text-danger">*</span></label> <label for="inputPassword4" class="col-form-label">Model<span class="text-danger">*</span><i type="button" class="fe-plus-circle" id="addModelModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addModelModal" title="Add Client"></i></label>
<select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>> <select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>>
<?php if (isset($vehicle["model_name"])) : ?> <?php if (isset($vehicle["model_name"])) : ?>
<option value="<?= $vehicle["model"] ?>" > <option value="<?= $vehicle["model"] ?>" >
@ -119,7 +119,36 @@
<?php include('layout/footer.php'); ?> <?php include('layout/footer.php'); ?>
</div> </div>
<!-- ADD MAKE -->
<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 fade" id="addClientModal" tabindex="-1" role="dialog" aria-labelledby="addClientModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
@ -139,6 +168,15 @@
<label for="clientMobile">Mobile</label> <label for="clientMobile">Mobile</label>
<input type="text" class="form-control" id="clientMobile" placeholder="Enter mobile number" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required> <input type="text" class="form-control" id="clientMobile" placeholder="Enter mobile number" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
</div> </div>
<div class="form-group">
<label for="clientType">Client Type</label>
<select class="form-control status-select" id="clientType" required >
<option value="">Select a Type</option>
<option value="Direct" >Direct</option>
<option value="Mechanic" >Mechanic</option>
<option value="Exp" >Exp</option>
</select>
</div>
</form> </form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
@ -148,6 +186,37 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Modal popup -->
<div class="modal fade" id="addModelModal" tabindex="-1" role="dialog" aria-labelledby="addModelModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModelModalLabel">Add New Model</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="addModelForm">
<div class="form-group">
<label for="makeSelect">Make</label>
<select class="form-control" id="makeSelect" required>
<!-- Options will be populated dynamically via JavaScript -->
</select>
</div>
<div class="form-group">
<label for="modelInput">Model</label>
<input type="text" class="form-control" id="modelInput" 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="saveModelBtn">Save Model</button>
</div>
</div>
</div>
</div>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
<script> <script>
@ -225,7 +294,8 @@ $(document).ready(function() {
var clientName = $('#clientName').val(); var clientName = $('#clientName').val();
var clientMobile = $('#clientMobile').val(); var clientMobile = $('#clientMobile').val();
if(clientName != '' && clientMobile != ''){ var clientType = $('#clientType').val();
if(clientName != '' && clientMobile != '' && clientType != ''){
// Send AJAX request to save the client // Send AJAX request to save the client
$.ajax({ $.ajax({
@ -233,7 +303,8 @@ $(document).ready(function() {
method: 'POST', method: 'POST',
data: { data: {
client_name: clientName, client_name: clientName,
mobile_no: clientMobile mobile_no: clientMobile,
client_type : clientType,
}, },
success: function(response) { success: function(response) {
// Check if the operation was successful // Check if the operation was successful
@ -259,7 +330,7 @@ $(document).ready(function() {
}); });
}else{ }else{
toastr.warning("Please Fill Name and Mobile data"); toastr.warning("Please Fill All Datas");
} }
@ -269,7 +340,98 @@ $(document).ready(function() {
// Define the clients array and populate it with data // Define the clients array and populate it with data
var clients = <?php echo json_encode($client); ?>; var clients = <?php echo json_encode($client); ?>;
</script> </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>
<!-- aDD MODEL FUNCTION -->
<script>
// Populate make dropdown in the add model modal
function populateMakeDropdown() {
$.ajax({
url: '<?php echo base_url('get_makes') ?>', // URL to your CodeIgniter controller method to fetch makes
type: 'GET',
dataType: 'json',
success: function(response) {
$('#makeSelect').empty().append('<option value="">Select Make</option>');
response.forEach(function(make) {
$('#makeSelect').append('<option value="' + make.make_id + '">' + make.make + '</option>');
});
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
}
});
}
// Call the function to populate make dropdown initially
$(document).ready(function() {
populateMakeDropdown();
});
// Save model function
$('#saveModelBtn').click(function() {
var makeId = $('#makeSelect').val();
var model = $('#modelInput').val();
console.log(model);
if (makeId != '' && model != '') {
$.ajax({
url: '<?php echo base_url().'save_model'?>',
method: 'POST',
data: {
make_id: makeId,
modelvalue: model
},
success: function(response) {
if (response.success) {
$('#addModelModal').modal('hide');
toastr.success("Model saved successfully");
window.location.reload();
} else {
toastr.error("Failed to save model");
}
},
error: function(xhr, status, error) {
console.error('Error occurred while saving model:', error);
toastr.error("Failed to save model. Please try again");
}
});
} else {
toastr.warning("Please fill in both make and model fields");
}
});
</script>
<style> <style>
.select2-container--default .select2-results__option--highlighted[aria-selected]{ .select2-container--default .select2-results__option--highlighted[aria-selected]{
color:#ffffff; color:#ffffff;

View File

@ -55,8 +55,20 @@
</select> </select>
</div> </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>