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 = [ $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

@ -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

@ -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

@ -168,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">
@ -285,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({
@ -293,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
@ -319,7 +330,7 @@ $(document).ready(function() {
}); });
}else{ }else{
toastr.warning("Please Fill Name and Mobile data"); toastr.warning("Please Fill All Datas");
} }