This commit is contained in:
heama 2024-04-09 10:46:59 +05:30
parent f4a5ab80ef
commit 6b69034ee3
7 changed files with 218 additions and 96 deletions

View File

@ -50,7 +50,7 @@ $routes->get("new_sale/(:any)", "Sales::new_sale/$1");
$routes->get("delete_sale/(:any)", "Sales::delete_sale/$1");
$routes->post("delete_sales_product", "Sales::delete_sales_product");
$routes->get("download_invoice/(:any)", "Sales::download_invoice/$1");
$routes->post("save_client", "Sales::save_client");
$routes->post("save_vehicle", "Sales::save_vehicle");
//end salle order//
//Client//

View File

@ -6,6 +6,8 @@ use App\Models\SalesOrderModel;
use App\Models\SalesOrderProductModel;
use App\Models\ProductModel;
use App\Models\ClientModel;
use App\Models\BikeMakeModel;
use App\Models\VehicleModel;
use Mpdf\Mpdf;
class Sales extends BaseController
{
@ -23,7 +25,7 @@ class Sales extends BaseController
$SalesOrderModel = new SalesOrderModel();
$sales=$SalesOrderModel->getSalesOrdersWithProducts($this->session->get('logged_user_branch_id'));
$data['sales']=$sales;
// print_r($sales);die;
return view('sales_list',$data);
}
@ -39,13 +41,18 @@ class Sales extends BaseController
$client=$ClientModel
->where('isactive',1)
->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
// print_r($client);die;
$VehicleModel = new VehicleModel();
$vehicle = $VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
// ->where('isactive',1)
// ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
// print_r($vehicle);die;
$ProductModel = new ProductModel();
$product=$ProductModel
->where('isactive',1)
->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['product']=$product;
$data['client']=$client;
$data['vehicle']=$vehicle;
} else if ($sales_order_id !== '0') {
$data['page_name']="Edit Sale Order";
$ClientModel = new ClientModel();
@ -58,14 +65,19 @@ $sales_product=$SalesProductOrderModel->where('sales_order_id', $sales_order_id)
$data['sales_product']=$sales_product;
$data['client']=$client;
// print_r($sales_product);die;
$VehicleModel = new VehicleModel();
$vehicle=$VehicleModel
->where('isactive',1)
->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['vehicle']=$vehicle;
$ProductModel = new ProductModel();
$product=$ProductModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['product']=$product;
}
// print_r($data);die;
$data['sales_order_id'] = $sales_order_id;
$bikeMakeModel = new BikeMakeModel();
$data['makeData'] =$bikeMakeModel->findAll();
return view('sales_order_form',$data);
}
@ -78,7 +90,8 @@ $data['product']=$product;
// Prepare data for sales order
$data = [
'client_id' => $this->request->getPost('client_id'),
'client_name' => $this->request->getPost('client_id'),
'vehicle_id'=>$this->request->getPost('vehicle_id'),
'billing_address' => $this->request->getPost('billing_address'),
'billing_city' => $this->request->getPost('city'),
'mobile_no' => $this->request->getPost('mobile_no'),
@ -88,13 +101,13 @@ $data['product']=$product;
'terms_condition' => $this->request->getPost('terms_condition'),
'subtotal' => $this->request->getPost('sub_total'),
'tax' => $this->request->getPost('invoice_tax'),
'discount'=> $this->request->getPost('discount'),
'total'=> $this->request->getPost('grand_total'),
'status'=> $this->request->getPost('status'),
'isactive' => 1, // Assuming this is a default value or handled separately
'branch_id'=> $this->session->get('logged_user_branch_id'),
];
// print_r($data);die;
// print_r($data);die;
// Insert or update sales order
$sales_order_id = $this->request->getPost('sales_order_id');
if (!empty($sales_order_id)) {
@ -280,38 +293,36 @@ public function delete_sales_product()
// Output the PDF to the browser for download
$mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
}
public function save_client(){
public function save_vehicle(){
// Load ClientModel
$ClientModel = new ClientModel();
$VehicleModel = new VehicleModel();
// Validate inputs
$validationRules = [
'client_name' => 'required|max_length[100]',
'mobile_no' => 'required' // Assuming mobile number is 10 digits long
];
if (!$this->validate($validationRules)) {
// If validation fails, return validation errors
return $this->response->setJSON(['success' => false, 'errors' => $this->validator->getErrors()]);
}
// If validation passes, proceed to save the client
$data = [
'client_name' => $this->request->getPost('client_name'),
'client_id' => $this->request->getPost('client_id'),
'mobile_no' => $this->request->getPost('mobile_no'),
'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
];
// Attempt to insert the client data
$id = $ClientModel->insert($data);
$id = $VehicleModel->insert($data);
if ($id) {
$clientData = $ClientModel->where('client_id',$id)->first();
$vehicleData = $VehicleModel->where('vehicle_id',$id)->first();
// If insertion succeeds, return success response
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','clientData'=>$clientData]);
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData]);
} else {
// If insertion fails, return error response
return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);

View File

@ -5,14 +5,14 @@ class SalesOrderModel extends Model
{
protected $table = 'sales_order';
protected $primaryKey = 'sales_order_id';
protected $allowedFields = ['sales_order_id','client_id','order_number','branch_id','status','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive'];
protected $allowedFields = ['sales_order_id','client_name','vehicle_id','order_number','branch_id','status','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive'];
//
public function getSalesPdf($sales_order_id){
return $this->db->table('sales_order')
->where('sales_order_id', $sales_order_id)
->join('client as C','C.client_id= sales_order.client_id','left')
->join('branches as B','B.branch_id = sales_order.branch_id','left')
->select('sales_order.*,C.client_name,C.mobile_no,C.address,C.city,C.state')
->select('sales_order.*')
->select('B.branch_name ,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.mobile_no as company_mobile_no')
->get()
@ -22,11 +22,11 @@ class SalesOrderModel extends Model
public function getSalesOrdersWithProducts($logged_user_branch_id)
{
// Select required fields from both tables
$this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,client.client_name');
$this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,vehicle.reg_no');
// Join the sales_order_product table based on sales_order_id
$this->join('sales_order_product', 'sales_order_product.sales_order_id = sales_order.sales_order_id');
$this->join('client', 'client.client_id = sales_order.client_id');
$this->join('vehicle', 'vehicle.vehicle_id = sales_order.vehicle_id');
// Group by sales_order_id to get count of products per sales order
$this->groupBy('sales_order.sales_order_id');

View File

@ -12,7 +12,7 @@ class VehicleModel extends Model
public function getCustomerandVehicle($branch_id)
{
// Select required fields from both tables
$this->select('vehicle.*, client.client_name , make.make as make_name , model.model_name as model_name');
$this->select('vehicle.*, client.client_name ,client.address,client.city,client.state,client.postal_code, make.make as make_name , model.model_name as model_name');
$this->join('client', 'client.client_id = vehicle.client_id');
$this->join('make', 'make.make_id = vehicle.make');
$this->join('model', 'model.model_id = vehicle.model');

View File

@ -214,7 +214,7 @@ p {
<th>MRP</th>
<th>Qty</th>
<th>Discount</th>
<th>Total</th>
</tr>
</thead>
@ -230,7 +230,7 @@ p {
<td><?= $item->product_name ?></td>
<td><?= number_format($item->net_price, 2, '.', ',') ?></td>
<td><?= $item->qty ?></td>
<td><?= $item->discount_type == '₹' ? $item->discount_type.$item->discount : $item->discount.$item->discount_type; ?></td>
<td><?= number_format($item->amount, 2, '.', ',') ?></td>
@ -252,13 +252,7 @@ p {
<?php if ($value->discount!=0): ?>
<!-- Set Balance if status is draft and paid is 0 -->
<tr>
<td colspan="5" align="right">Discount : &nbsp;&nbsp;<?= number_format($value->discount, 2, '.', ',') ?></td>
</tr>
<?php endif; ?>
<tr>
<td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->total, 2, '.', ',') ?></td>
</tr>
@ -277,11 +271,7 @@ p {
<div class="terms">
<?php if ($value->discount!=0): ?>
<br><p >"You have saved ₹<?= $value->discount; ?>- in this purchase"</p><br>
<?php endif; ?>
<p style=text-align:left><?= $value->terms_condition;?></p>
</div>

View File

@ -40,6 +40,7 @@
<tr>
<th>Order Number</th>
<th>Reg No</th>
<th>Client Name</th>
<th>Client Mobile</th>
<th>Quantity</th>
@ -61,6 +62,7 @@
if ($value['isactive'] == 1) : ?>
<tr>
<td><?= $value['order_number']; ?></td>
<td><?= $value['reg_no']; ?></td>
<td><?= $value['client_name']; ?></td>
<td><?= $value['mobile_no']; ?></td>
<td><?= $value['product_count']; ?></td>

View File

@ -25,23 +25,31 @@
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputEmail4" class="col-form-label">Client Name<span class="text-danger">*</span></label>
<?= isset($sales['client_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addClientModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addClientModal" title="Add Client"></i>' ?>
<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>' ?>
<select class="form-control cleint-select SelExample" name="client_id" <?= isset($sales['client_id']) ? '' : 'required' ?>>
<select class="form-control vehicle-select SelExample" name="vehicle_id" <?= isset($sales['vehicle_id']) ? '' : 'required' ?>>
<?= isset($sales['client_id']) ? '' : '<option value="">Select a Client</option>' ?>
<?php foreach ($client as $value) : ?>
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
<?php foreach ($vehicle as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["client_id"] ?>" <?= isset($sales['client_id']) && $sales['client_id'] == $value["client_id"] ? 'selected' : '' ?>>
<?= $value["mobile_no"].' - '.$value["client_name"]; ?>
<option value="<?= $value["vehicle_id"] ?>" <?= isset($sales['vehicle_id']) && $sales['vehicle_id'] == $value["vehicle_id"] ? 'selected' : '' ?>>
<?= $value["reg_no"]?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-6">
<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'] : '' ?>" >
</div>
<div class="form-group col-md-6">
<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)" required>
</div>
<div class="form-group col-md-6">
<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" >
<!-- <option value="">Select a Status</option> -->
@ -53,7 +61,7 @@
</div><br>
<h4 class="header-title">Billing Address Details :</h4><br>
<div class="form-row">
<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">Address<span class="text-danger"></span></label>
<input type="text" class="form-control" name="billing_address" placeholder="Address"value="<?= isset($sales['billing_address']) ? $sales['billing_address'] : '' ?>" >
</div>
@ -61,24 +69,21 @@
<input type="hidden" id="sales_order_id" name="sales_order_id" value="<?= isset($sales['sales_order_id']) ? $sales['sales_order_id'] : '' ?>"readonly>
<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">City<span class="text-danger"></span></label>
<input type="text" class="form-control" name="city" placeholder="City"value="<?= isset($sales['billing_city']) ? $sales['billing_city'] : 'Chennai' ?>" >
</div>
<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">State<span class="text-danger"></span></label>
<input type="text" class="form-control" name="state" placeholder="State"value="<?= isset($sales['billing_state']) ? $sales['billing_state'] : 'Tamil Nadu' ?>" >
</div>
<div class="form-group col-md-6">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">Pin Code<span class="text-danger"></span></label>
<input type="text" class="form-control" name="postalcode" placeholder="Pin Code"value="<?= isset($sales['billing_postal_code']) ? $sales['billing_postal_code'] : '' ?>" maxlength="6" minlength="6" >
</div>
<div class="form-group col-md-6">
<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)" required>
</div>
</div>
<div class="form-row" id="itemTableContainer">
@ -93,7 +98,7 @@
<th>Qty</th>
<th>Rate</th>
<th>Tax</th>
<th style="text-align: center !important" colspan="2">Discount</th>
<!-- <th style="text-align: center !important" colspan="2">Discount</th> -->
<th>Amount</th>
<th hidden></th>
<th></th>
@ -127,7 +132,7 @@
<td style="width:10%;">
<input type="text" class="form-control item-tax" name="item-tax[]" value="<?= isset($salechild['tax']) ? $salechild['tax'] : '' ?>">
</td>
<td style="width:12%;">
<!-- <td style="width:12%;">
<input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" value="<?= isset($salechild['discount']) ? $salechild['discount'] : '' ?>">
</td>
<td style="width:10%;">
@ -135,12 +140,12 @@
<option value="" <?= isset($salechild['discount_type']) && $salechild['discount_type'] == '₹' ? 'selected' : '' ?>>₹</option>
<option value="%" <?= isset($salechild['discount_type']) && $salechild['discount_type'] == '%' ? 'selected' : '' ?>>%</option>
</select>
</td>
</td> -->
<td style="width:12%;">
<input type="text" class="form-control item-amount" name="amount[]" value="<?= isset($salechild['amount']) ? $salechild['amount'] : '' ?>">
</td>
<td hidden><input type="hidden" value="<?= isset($salechild['sales_order_product_id']) ? $salechild['sales_order_product_id'] : '' ?>"name="sales_order_product_id[]"></td>
<td>
<td style="width:12%;">
<center><i class="fa fa-trash remove-item"></i></center>
</td>
</tr>
@ -177,10 +182,10 @@
<div class="form-group">
<!-- <div class="form-group">
<label for="discount">Discount Amount</label>
<input type="number" class="form-control" id="discount" name="discount" onchange="calculateGrandTotal(this.value)" min="0" readonly value="<?= isset($sales['discount']) ? $sales['discount'] : '' ?>" >
</div>
</div> -->
<div class="form-group">
<label for="grandtotal">Total</label>
<input type="text" class="form-control" id="grandtotal" name="grand_total" readonly value="<?= isset($sales['total']) ? $sales['total'] : '' ?>">
@ -213,30 +218,79 @@
</div>
<?php include('layout/footer.php'); ?>
</div>
<div class="modal fade" id="addClientModal" tabindex="-1" role="dialog" aria-labelledby="addClientModalLabel" aria-hidden="true">
<div class="modal fade" id="addVehicleModal" tabindex="-1" role="dialog" aria-labelledby="addVehicleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addClientModalLabel">Add New Client</h5>
<h5 class="modal-title" id="addVehicleModalLabel">Add New Vehicle</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">Client Name</label>
<input type="text" class="form-control" id="clientName" placeholder="Enter client name"required>
<div class="form-row">
<div class="form-group col-md-6">
<!-- <div class="form-group"> -->
<label for="inputPassword4" class="col-form-label">Make</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) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["make_id"] ?>" <?= isset($vehicle['make']) && $vehicle['make'] == $value["make_id"] ? 'selected' : '' ?>>
<?= $value["make"]; ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Model</label>
<select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>>
<?php if (isset($vehicle["model_name"])) : ?>
<option value="<?= $vehicle["model"] ?>" >
<?= $vehicle["model_name"]; ?>
</option>
<?php endif; ?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<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>
</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>' ?>
<?php foreach ($client as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["client_id"] ?>" <?= isset($sales['client_id']) && $sales['client_id'] == $value["client_id"] ? 'selected' : '' ?>>
<?= $value["client_name"]; ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-12">
<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="mobile" name="mobile"placeholder="Enter mobile number" maxlength="10" minlength="10"onkeypress = "return onlyNumbers(event)"required>
</div>
</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="saveClientBtn">Save Client</button>
<button type="button" class="btn btn-primary" id="saveVehcileBtn">Save Vehicle</button>
</div>
</div>
</div>
@ -386,12 +440,10 @@ $(document).ready(function() {
'<td style="width:10%;"><input type="number" class="form-control item-quantity"min="0" name="quantity[]"/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]"readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax"name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" /></td>' +
'<td style="width:10%;"><select class="form-control item-discount-type"name="discount_type[]"><option value="₹">₹</option><option value="%">%</option></select></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount"name="amount[]"/></td>' +
'<td hidden><input type="hidden"></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center></td>' +
'<td ><center><i class="fa fa-trash remove-item"></i></center></td>' +
'</tr>';
$('#itemTable tbody').append(newRow);
@ -437,16 +489,20 @@ $(document).on('click', '.remove-item', function() {
});
$(document).ready(function() {
// Event listener for customer selection change
$('.cleint-select').change(function() {
$('.vehicle-select').change(function() {
var clientId = $(this).val();
if (clientId !== '') {
var vehicleId = $(this).val();
// console.log(vehicleId);
if (vehicleId !== '') {
// Find the selected client in the client data
var selectedClient = clients.find(function(client) {
return client.client_id == clientId;
var selectedClient = vehicles.find(function(vehicle) {
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="billing_address"]').val(selectedClient.address);
$('input[name="billing_address"]').val(selectedClient.address);
$('input[name="city"]').val(selectedClient.city);
$('input[name="state"]').val(selectedClient.state);
@ -457,9 +513,32 @@ $(document).ready(function() {
});
});
</script>
<script>
$(document).ready(function() {
// Event listener for customer selection change
$('.cleint-select').change(function() {
var clientId = $(this).val();
// console.log(vehicleId);
if (clientId !== '') {
// Find the selected client in the client data
var selectedClients = clients.find(function(client) {
return client.client_id == clientId;
});
console.log(selectedClients);
// Populate the billing address, city, state, country, and postal code fields
$('input[name="mobile"]').val(selectedClients.mobile_no);
}
});
});
</script>
<script>
// Define the clients array and populate it with data
var vehicles = <?php echo json_encode($vehicle); ?>;
var clients = <?php echo json_encode($client); ?>;
</script>
<script>
@ -489,44 +568,50 @@ function initializeSelect2() {
$(document).ready(function() {
// AJAX request to save client
$('#saveClientBtn').click(function() {
$('#saveVehcileBtn').click(function() {
var clientName = $('#clientName').val();
var clientMobile = $('#clientMobile').val();
if(clientName != '' && clientMobile != ''){
var clientMobile = $('#mobile').val();
var reg_no = $('#reg_no').val();
var model = $('#model').val();
var make = $('#make').val();
if(clientName != '' && clientMobile != ''&&reg_no != '' && model != '' && make != ''){
// Send AJAX request to save the client
$.ajax({
url: '<?php echo base_url().'save_client'?>', // URL to your save_client method
url: '<?php echo base_url().'save_vehicle'?>', // URL to your save_client method
method: 'POST',
data: {
client_name: clientName,
mobile_no: clientMobile
client_id: clientName,
mobile_no: clientMobile,
reg_no:reg_no,
model:model,
make:make
},
success: function(response) {
// Check if the operation was successful
if (response.success) {
// Client saved successfully, close the modal and do any additional actions
$('#addClientModal').modal('hide');
$('#addVehicleModal').modal('hide');
// Optionally, you can update the client dropdown or show a success message
toastr.success("Client saved successfully!");
toastr.success("Vehicle saved successfully!");
window.location.reload(); // Reload the page
} else {
// Client save operation failed, display error message
toastr.warning("Failed to save client. Please try again");
toastr.warning("Failed to save vehicle. Please try again");
}
},
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");
console.error('Error occurred while saving vehicle:', error);
toastr.warning("Failed to save vehicle. Please try again");
}
});
}else{
toastr.warning("Please Fill Name and Mobile data");
toastr.warning("Please Fill All Data");
}
@ -534,9 +619,43 @@ $(document).ready(function() {
});
</script>
<script>
$(".SelExample").select2();
// Event listener for change in make select dropdown
$("#make").on('change', function() {
var selected_makes = $(this).val(); // Get an array of selected make IDs
// AJAX request to fetch models based on selected make IDs
$.ajax({
url: '<?= base_url("fetch_models") ?>', // URL to your controller method for fetching models
type: 'POST',
dataType: 'json',
data: { selected_makes: [selected_makes] },
success: function(response) {
// Clear existing options in model select dropdown
$("#model").empty();
$("#model").append('<option value=""> Select a Model </option>');
// Populate model select dropdown with fetched models
$.each(response, function(index, model) {
$("#model").append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
});
// Refresh select2 to reflect changes
$("#model").trigger('change');
},
error: function(xhr, status, error) {
console.error(error); // Log any errors to the console
}
});
});
document.getElementById('reg_no').addEventListener('input', function(event) {
var inputText = event.target.value;
event.target.value = inputText.toUpperCase();
});
</script>