Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic

This commit is contained in:
heama 2024-04-10 14:44:13 +05:30
commit 3077462ec3
4 changed files with 218 additions and 99 deletions

View File

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

View File

@ -6,7 +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\BikemodelsModel;
use App\Models\BikemakeModel;
use App\Models\VehicleModel;
use Mpdf\Mpdf;
class Sales extends BaseController
@ -16,8 +17,10 @@ class Sales extends BaseController
{
$this->session = session();
$this->BikemodelsModel = new BikemodelsModel();
$this->BikemakeModel = new BikemakeModel();
}
}
public function sales_order_index()
{
@ -322,13 +325,38 @@ public function delete_sales_product()
// Load ClientModel
$VehicleModel = new VehicleModel();
// Validate inputs
// If validation passes, proceed to save the client
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
];
}
}else{
$data = [
'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'),
@ -338,6 +366,12 @@ public function delete_sales_product()
'state'=>'Tamil Nadu',
'isactive' => 1
];
}
// Attempt to insert the client data
$id = $VehicleModel->insert($data);
@ -359,7 +393,7 @@ public function get_vehicle_products(){
public function getProducts()
public function getProducts()
{
// Retrieve make_id and model_id from the request
$makeId = $this->request->getPost('make_id');
@ -376,13 +410,14 @@ public function get_vehicle_products(){
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->findAll();
if($product){
$modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name;
$makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make;
if($product){
// Send JSON response
return $this->response->setJSON($product);
return $this->response->setJSON(['product'=>$product , 'modelName'=>$modelName ,'makeName'=>$makeName] );
} else {
// 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

View File

@ -28,37 +28,43 @@
<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 vehicle-select SelExample" name="vehicle_id" <?= isset($sales['vehicle_id']) ? '' : 'required' ?>>
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
<?php foreach ($vehicle as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<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>
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
<?php foreach ($vehicle as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<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">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>
<input type="text" class="form-control" name="client_id" placeholder="Client"value="<?= isset($sales['client_name']) ? $sales['client_name'] : '' ?>" readonly>
</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>
<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 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> -->
<option value="Created" <?= isset($sales['status']) && $sales['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
<option value="Paid" <?= isset($sales['status']) && $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
</select>
</div>
<div class="form-group col-md-4">
<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> -->
<option value="Created" <?= isset($sales['status']) && $sales['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
<option value="Paid" <?= isset($sales['status']) && $sales['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
</select>
</div>
</div><br>
</div><br>
<h4 class="header-title">Billing Address Details :</h4><br>
<div class="form-row">
<div class="form-group col-md-3">
@ -228,63 +234,90 @@
</button>
</div>
<div class="modal-body">
<form id="addClientForm">
<form >
<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>
<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 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"> -->
<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">
<input type="text" value="select" id="formType" hidden>
<div class="form-group col-md-12 select">
<label for="clientName">Client Name</label>
<select class="form-control cleint-select SelExample" name="client_id" id=clientName <?= isset($sales['client_id']) ? '' : 'required' ?>>
<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) : ?>
<option value="<?= $value["client_id"] ?>">
<?= $value["mobile_no"] .' - '. $value["client_name"]; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?= 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">
<div class="form-group col-md-12 select">
<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 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>
</form>
</div>
@ -329,7 +362,10 @@ $(document).ready(function() {
vehicle_id: vehicleId
},
success: function(response) {
productarray = response;
console.log(response);
productarray = response.product;
makeAndModel = response.makeName+' '+response.modelName;
$('#makeAndModel').val(makeAndModel);
},
error: function(xhr, status, error) {
// Handle error
@ -547,14 +583,13 @@ $(document).ready(function() {
$('.vehicle-select').change(function() {
var vehicleId = $(this).val();
// console.log(vehicleId);
if (vehicleId !== '') {
// Find the selected client in the client data
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);
@ -581,11 +616,11 @@ $(document).ready(function() {
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);
$('input[id="clientMobile"]').val(selectedClients.mobile_no);
}
});
@ -625,13 +660,30 @@ $(document).ready(function() {
// AJAX request to save client
$('#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 model = $('#model').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
$.ajax({
@ -642,24 +694,24 @@ $(document).ready(function() {
mobile_no: clientMobile,
reg_no:reg_no,
model:model,
make:make
make:make,
createclientName:createclientName,
createclientMobile:createclientMobile,
createclientType:createclientType,
formType:formType,
},
success: function(response) {
// Check if the operation was successful
if (response.success) {
// Client saved successfully, close the modal and do any additional actions
$('#addVehicleModal').modal('hide');
// Optionally, you can update the client dropdown or show a success message
toastr.success("Vehicle saved successfully!");
window.location.reload(); // Reload the page
window.location.reload();
} else {
// Client save operation failed, display error message
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 vehicle:', error);
toastr.warning("Failed to save vehicle. Please try again");
}
@ -712,7 +764,27 @@ document.getElementById('reg_no').addEventListener('input', function(event) {
</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

@ -166,7 +166,16 @@
</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>
<input type="text" class="form-control" id="clientMobile" placeholder="Enter mobile number" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
</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>
</div>
@ -285,7 +294,8 @@ $(document).ready(function() {
var clientName = $('#clientName').val();
var clientMobile = $('#clientMobile').val();
if(clientName != '' && clientMobile != ''){
var clientType = $('#clientType').val();
if(clientName != '' && clientMobile != '' && clientType != ''){
// Send AJAX request to save the client
$.ajax({
@ -293,7 +303,8 @@ $(document).ready(function() {
method: 'POST',
data: {
client_name: clientName,
mobile_no: clientMobile
mobile_no: clientMobile,
client_type : clientType,
},
success: function(response) {
// Check if the operation was successful
@ -319,7 +330,7 @@ $(document).ready(function() {
});
}else{
toastr.warning("Please Fill Name and Mobile data");
toastr.warning("Please Fill All Datas");
}