CHANGES_Vehicle_module_crud:GWM
This commit is contained in:
parent
61605a3d14
commit
94588d9d89
@ -306,9 +306,12 @@ public function delete_sales_product()
|
||||
];
|
||||
|
||||
// Attempt to insert the client data
|
||||
if ($ClientModel->insert($data)) {
|
||||
$id = $ClientModel->insert($data);
|
||||
if ($id) {
|
||||
$clientData = $ClientModel->where('client_id',$id)->first();
|
||||
|
||||
// If insertion succeeds, return success response
|
||||
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']);
|
||||
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','clientData'=>$clientData]);
|
||||
} else {
|
||||
// If insertion fails, return error response
|
||||
return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);
|
||||
|
||||
@ -24,11 +24,13 @@ class Vehicle extends BaseController
|
||||
{
|
||||
|
||||
$VehicleModel = new VehicleModel();
|
||||
$vehicle=$VehicleModel->getCustomerandVehicle();
|
||||
$data['vehicle']=$vehicle;
|
||||
$vehicle = $VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
|
||||
$data['vehicle'] = $vehicle;
|
||||
|
||||
$ClientModel = new ClientModel();
|
||||
$client=$ClientModel->findAll();
|
||||
$client = $ClientModel->where('branch_id', $this->session->get('logged_user_branch_id'))->findAll();
|
||||
$data['client']=$client;
|
||||
|
||||
return view('vehicle_list',$data);
|
||||
}
|
||||
|
||||
@ -41,16 +43,21 @@ class Vehicle extends BaseController
|
||||
$ClientModel = new ClientModel();
|
||||
$data['vehicle'] = [];
|
||||
$data['page_name']="Add vehicle";
|
||||
$client=$ClientModel->findAll();
|
||||
$client = $ClientModel->where('branch_id', $this->session->get('logged_user_branch_id'))->findAll();
|
||||
$data['client']=$client;
|
||||
|
||||
} else if ($vehicle_id !== '0') {
|
||||
|
||||
$data['page_name']="Edit vehicle";
|
||||
$VehicleModel = new VehicleModel();
|
||||
$vehicle=$VehicleModel->where('vehicle_id', $vehicle_id)->get()->getRowArray();
|
||||
$vehicle= $VehicleModel->select('vehicle.*, model.model_name as model_name')
|
||||
->join('model', 'model.model_id = vehicle.model')
|
||||
->where('vehicle.vehicle_id', $vehicle_id)
|
||||
->where('vehicle.branch_id', $this->session->get('logged_user_branch_id'))
|
||||
->get()->getRowArray();
|
||||
$data['vehicle']=$vehicle;
|
||||
$ClientModel = new ClientModel();
|
||||
$client=$ClientModel->findAll();
|
||||
$client=$ClientModel->where('branch_id', $this->session->get('logged_user_branch_id'))->findAll();
|
||||
$data['client']=$client;
|
||||
}
|
||||
$data['vehicle_id'] = $vehicle_id;
|
||||
@ -74,12 +81,12 @@ class Vehicle extends BaseController
|
||||
'city' => $this->request->getPost('city'),
|
||||
'state' => $this->request->getPost('state'),
|
||||
'postal_code' => $this->request->getPost('postalcode'),
|
||||
'country' => $this->request->getPost('country'),
|
||||
'make' => $this->request->getPost('make'),
|
||||
'model' => $this->request->getPost('model'),
|
||||
'reg_no' => $this->request->getPost('regno'),
|
||||
'colour' => $this->request->getPost('colour'),
|
||||
|
||||
'year_of_manufacturing' => $this->request->getPost('year_of_manufacturing'),
|
||||
'branch_id' => $this->session->get('logged_user_branch_id'),
|
||||
'isactive' => 1 // Assuming this is a default value or handled separately
|
||||
];
|
||||
// print_r($data);die;
|
||||
|
||||
@ -3,16 +3,20 @@ namespace App\Models;
|
||||
use CodeIgniter\Model;
|
||||
class VehicleModel extends Model
|
||||
{
|
||||
|
||||
|
||||
protected $table = 'vehicle';
|
||||
protected $primaryKey = 'vehicle_id';
|
||||
protected $allowedFields = ['vehicle_id','make','model','reg_no','colour','client_id','address','country','state','city','email','postal_code','mobile_no','isactive'];
|
||||
protected $allowedFields = ['branch_id','vehicle_id','make','model','reg_no','year_of_manufacturing','colour','client_id','address','country','state','city','email','postal_code','mobile_no','isactive'];
|
||||
|
||||
public function getCustomerandVehicle()
|
||||
public function getCustomerandVehicle($branch_id)
|
||||
{
|
||||
// Select required fields from both tables
|
||||
$this->select('vehicle.*, client.client_name');
|
||||
$this->select('vehicle.*, client.client_name , make.make as make_name , model.model_name as model_name');
|
||||
$this->join('client', 'client.client_id = vehicle.client_id');
|
||||
// Add condition to fetch only active sales orders
|
||||
$this->join('make', 'make.make_id = vehicle.make');
|
||||
$this->join('model', 'model.model_id = vehicle.model');
|
||||
$this->where('vehicle.branch_id', $branch_id);
|
||||
$this->where('vehicle.isactive', 1);
|
||||
|
||||
// Get the results
|
||||
|
||||
@ -487,10 +487,6 @@ function initializeSelect2() {
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Show the modal when the "add-circle-button" is clicked
|
||||
$('#add-circle-button').click(function() {
|
||||
$('#addClientModal').modal('show');
|
||||
});
|
||||
|
||||
// AJAX request to save client
|
||||
$('#saveClientBtn').click(function() {
|
||||
|
||||
@ -4,9 +4,8 @@
|
||||
<div class="page-title-box page-title-box-alt">
|
||||
<h4 class="page-title"><?php echo $page_name?></h4>
|
||||
<div class="page-title-right">
|
||||
<a href="<?= base_url() . "vehicle_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
|
||||
<ol class="breadcrumb m-0">
|
||||
|
||||
</li>
|
||||
<!-- <li class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
|
||||
<li class="breadcrumb-item active">Datatables</li> -->
|
||||
</ol>
|
||||
@ -25,7 +24,7 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Make</label>
|
||||
<select class="form-control SelExample" name="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>' ?>
|
||||
<?php foreach ($makeData as $value) : ?>
|
||||
<?php if ((int)$value["isactive"] === 1) : ?>
|
||||
@ -38,11 +37,21 @@
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Model</label>
|
||||
<input type="text" class="form-control" name="model" placeholder="Model"value="<?= isset($vehicle['model']) ? $vehicle['model'] : '' ?>" required>
|
||||
<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 class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Reg Number</label>
|
||||
<input type="text" class="form-control" name="regno" placeholder="Reg Number"value="<?= isset($vehicle['reg_no']) ? $vehicle['reg_no'] : '' ?>" required>
|
||||
<input type="text" class="form-control" name="regno" id="regno" placeholder="Reg Number"value="<?= isset($vehicle['reg_no']) ? $vehicle['reg_no'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Year of Manufacturing</label>
|
||||
<input type="text" class="form-control" name="year_of_manufacturing" placeholder="Manufacturing Year" value="<?= isset($vehicle['year_of_manufacturing']) ? $vehicle['year_of_manufacturing'] : '' ?>" maxlength="4" minlength="4"onkeypress = "return onlyNumbers(event)">
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Colour</label>
|
||||
@ -53,7 +62,8 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputEmail4" class="col-form-label">Client Name</label>
|
||||
<select class="form-control cleint-select" name="client_name" required data-toggle="select2" >
|
||||
<?= isset($vehicle['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>' ?>
|
||||
<select class="form-control cleint-select SelExample" id="clientData" name="client_name" required data-toggle="select2" >
|
||||
<option value="">Select a Client</option>
|
||||
<?php foreach ($client as $value) : ?>
|
||||
<?php if ((int)$value["isactive"] === 1) : ?>
|
||||
@ -62,39 +72,35 @@
|
||||
</option>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputEmail4" class="col-form-label">Email</label>
|
||||
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($vehicle['email']) ? $vehicle['email'] : '' ?>" readonly>
|
||||
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($vehicle['email']) ? $vehicle['email'] : '' ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputAddress" class="col-form-label">Mobile</label>
|
||||
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($vehicle['mobile_no']) ? $vehicle['mobile_no'] : '' ?>" required maxlength="10" minlength="10"readonly>
|
||||
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($vehicle['mobile_no']) ? $vehicle['mobile_no'] : '' ?>" required maxlength="10" minlength="10">
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputPassword4" class="col-form-label">Address</label>
|
||||
<input type="text" class="form-control" name="address" placeholder="Address"value="<?= isset($vehicle['address']) ? $vehicle['address'] : '' ?>" readonly>
|
||||
<input type="text" class="form-control" name="address" placeholder="Address"value="<?= isset($vehicle['address']) ? $vehicle['address'] : '' ?>" >
|
||||
</div>
|
||||
|
||||
|
||||
<input type="hidden" id="vehicle_id" name="vehicle_id" value="<?= isset($vehicle['vehicle_id']) ? $vehicle['vehicle_id'] : '' ?>"readonly>
|
||||
<input type="hidden" id="vehicle_id" name="vehicle_id" value="<?= isset($vehicle['vehicle_id']) ? $vehicle['vehicle_id'] : '' ?>">
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputPassword4" class="col-form-label">City</label>
|
||||
<input type="text" class="form-control" name="city" placeholder="City"value="<?= isset($vehicle['city']) ? $vehicle['city'] : '' ?>" readonly>
|
||||
<input type="text" class="form-control" name="city" placeholder="City"value="<?= isset($vehicle['city']) ? $vehicle['city'] : '' ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputPassword4" class="col-form-label">State</label>
|
||||
<input type="text" class="form-control" name="state" placeholder="State"value="<?= isset($vehicle['state']) ? $vehicle['state'] : '' ?>" readonly>
|
||||
<input type="text" class="form-control" name="state" placeholder="State"value="<?= isset($vehicle['state']) ? $vehicle['state'] : '' ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Postal Code</label>
|
||||
<input type="text" class="form-control" name="postalcode" placeholder="Postal Code"value="<?= isset($vehicle['postal_code']) ? $vehicle['postal_code'] : '' ?>" readonly maxlength="6" minlength="6">
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Country</label>
|
||||
<input type="text" class="form-control" name="country" placeholder="Country"value="<?= isset($vehicle['country']) ? $vehicle['country'] : '' ?>" readonly>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputPassword4" class="col-form-label">Pin Code</label>
|
||||
<input type="text" class="form-control" name="postalcode" placeholder="Pin Code"value="<?= isset($vehicle['postal_code']) ? $vehicle['postal_code'] : '' ?>" maxlength="6" minlength="6">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -107,6 +113,37 @@
|
||||
|
||||
<?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-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addClientModalLabel">Add New Client</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</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>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
$(document).ready(function() {
|
||||
@ -124,7 +161,6 @@ $(document).ready(function() {
|
||||
$('input[name="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="email"]').val(selectedClient.email);
|
||||
$('input[name="postalcode"]').val(selectedClient.postal_code);
|
||||
@ -134,9 +170,94 @@ $(document).ready(function() {
|
||||
|
||||
|
||||
$(".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('regno').addEventListener('input', function(event) {
|
||||
var inputText = event.target.value;
|
||||
event.target.value = inputText.toUpperCase();
|
||||
});
|
||||
|
||||
function onlyNumbers(event){
|
||||
var charcode;
|
||||
charcode = event.which || event.keyCode;
|
||||
if(charcode>= 48 && charcode <= 57)return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$('#saveClientBtn').click(function() {
|
||||
|
||||
|
||||
var clientName = $('#clientName').val();
|
||||
var clientMobile = $('#clientMobile').val();
|
||||
if(clientName != '' && clientMobile != ''){
|
||||
|
||||
// Send AJAX request to save the client
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'save_client'?>', // URL to your save_client method
|
||||
method: 'POST',
|
||||
data: {
|
||||
client_name: clientName,
|
||||
mobile_no: clientMobile
|
||||
},
|
||||
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');
|
||||
// Optionally, you can update the client dropdown or show a success message
|
||||
toastr.success("Client saved successfully!");
|
||||
console.log(response.clientData);
|
||||
$("#clientData").append('<option value="' + response.clientData.client_id + '">' + response.clientData.client_name + '</option>');
|
||||
// Manually select the newly added option
|
||||
$("#clientData").val(response.clientData.client_id).trigger('change');
|
||||
} else {
|
||||
// Client save operation failed, display error message
|
||||
toastr.warning("Failed to save client. 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");
|
||||
}
|
||||
});
|
||||
|
||||
}else{
|
||||
toastr.warning("Please Fill Name and Mobile data");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// Define the clients array and populate it with data
|
||||
|
||||
@ -29,14 +29,12 @@
|
||||
<thead>
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Client Name</th>
|
||||
<th>Mobile</th>
|
||||
<th>Email</th>
|
||||
<th>Make</th>
|
||||
<th>Model</th>
|
||||
<th>Reg No</th>
|
||||
<th>Colour</th>
|
||||
<th>Make & Model</th>
|
||||
<th>Manf Year</th>
|
||||
<th>Colour</th>
|
||||
<th>Client Name</th>
|
||||
<th>Mobile</th>
|
||||
<th>Actions</th>
|
||||
|
||||
</tr>
|
||||
@ -47,14 +45,12 @@
|
||||
<?php foreach ($vehicle as $value) :
|
||||
if ($value['isactive'] == 1) : ?>
|
||||
<tr>
|
||||
<td><?= $value['reg_no']; ?></td>
|
||||
<td><?= $value['make_name'].' '.$value['model_name']; ?></td>
|
||||
<td><?= $value['year_of_manufacturing']; ?></td>
|
||||
<td><?= $value['colour']; ?></td>
|
||||
<td><?= $value['client_name']; ?></td>
|
||||
<td><?= $value['mobile_no']; ?></td>
|
||||
<td><?= $value['email']; ?></td>
|
||||
<td><?= $value['make']; ?></td>
|
||||
<td><?= $value['model']; ?></td>
|
||||
|
||||
<td><?= $value['reg_no']; ?></td>
|
||||
<td><?= $value['colour']; ?></td>
|
||||
<td>
|
||||
<a href="<?= "new_vehicle/" . $value['vehicle_id']; ?>" class="edit-button"><i class="ri-pencil-line"></i></a>
|
||||
<a href="<?= "delete_vehicle/" . $value['vehicle_id']; ?>" class="delete-button"><i class="ri-delete-bin-line"></i></a>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user