This commit is contained in:
heama 2024-04-09 14:09:51 +05:30
parent 52e4ab8ec0
commit a435dc7e98
22 changed files with 133 additions and 38 deletions

View File

@ -51,6 +51,7 @@ $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_vehicle", "Sales::save_vehicle");
$routes->post("getProducts", "Sales::getProducts");
//end salle order//
//Client//

View File

@ -53,13 +53,37 @@ class Sales extends BaseController
$data['product']=$product;
$data['client']=$client;
$data['vehicle']=$vehicle;
} else if ($sales_order_id !== '0') {
} else if ($sales_order_id !== '0')
{
$data['page_name']="Edit Sale Order";
$ClientModel = new ClientModel();
$client=$ClientModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$SalesOrderModel = new SalesOrderModel();
$sales=$SalesOrderModel->where('sales_order_id', $sales_order_id)->get()->getRowArray();
$data['sales']=$sales;
$VehicleModel = new VehicleModel();
$vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$sales['vehicle_id'])
->where('branch_id',$this->session->get('logged_user_branch_id'))
->first();
$makeId = $vehicles['make'];
$modelId = $vehicles['model'];
// Encode the modelId before searching
$encodedModelId = json_encode([$modelId]);
// Load the ProductModel
$productModel = new ProductModel();
// Query the database to find the product based on make_id and model_id
$product = $productModel->where('make_id', $makeId)
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->findAll();
$data['product']=$product;
$SalesProductOrderModel = new SalesOrderProductModel();
$sales_product=$SalesProductOrderModel->where('sales_order_id', $sales_order_id)->findAll();
$data['sales_product']=$sales_product;
@ -70,9 +94,8 @@ $VehicleModel = new 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;
@ -328,5 +351,40 @@ public function delete_sales_product()
return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);
}
}
public function get_vehicle_products(){
}
}
public function getProducts()
{
// Retrieve make_id and model_id from the request
$makeId = $this->request->getPost('make_id');
$modelId = $this->request->getPost('model_id');
// Encode the modelId before searching
$encodedModelId = json_encode([$modelId]);
// Load the ProductModel
$productModel = new ProductModel();
// Query the database to find the product based on make_id and model_id
$product = $productModel->where('make_id', $makeId)
->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
->findAll();
if($product){
// Send JSON response
return $this->response->setJSON($product);
} else {
// If product is not found, return an empty response or appropriate message
return $this->response->setJSON([]);
}
}
// Check if product exists
}

View File

@ -43,11 +43,11 @@
</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'] : '' ?>" >
<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">
<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>
<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>
@ -298,6 +298,51 @@
<script>
productarray = [];
$(document).ready(function() {
// Event listener for vehicle selection change
$('.vehicle-select').change(function() {
var vehicleId = $(this).val();
if (vehicleId !== '') {
// Find the selected vehicle
var selectedVehicle = vehicles.find(function(vehicle) {
return vehicle.vehicle_id == vehicleId;
});
// Extract makeId from the selected vehicle
var makeId = selectedVehicle.make;
var modelId = selectedVehicle.model;
console.log(modelId);
// Make sure makeId exists
if (makeId !== undefined) {
// Perform AJAX request to fetch product information
$.ajax({
url: '<?php echo base_url().'getProducts'?>', // Replace with the actual backend endpoint
method: 'POST', // or 'GET' based on your server implementation
dataType: 'json',
data: {
make_id: makeId,
model_id:modelId,
vehicle_id: vehicleId
},
success: function(response) {
productarray = response;
},
error: function(xhr, status, error) {
// Handle error
console.error('Error fetching product information:', error);
}
});
} else {
console.error('Make ID not found for the selected vehicle');
}
}
});
});
<?php
$product_json = json_encode($product);
?>
@ -435,19 +480,29 @@ $(document).ready(function() {
// Event listener for "Add More Item" button
$('#addItem').click(function() {
var newRow = '<tr>' +
'<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option><?php foreach ($product as $value) : if ((int)$value["isactive"] === 1) : ?><option value="<?= $value["product_id"] ?>"><?= $value["product_name"]; ?></option><?php endif; endforeach; ?></select></td>' +
'<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="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>' +
'</tr>';
console.log(productarray);
var newRow = '<tr>' + '<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
$('#itemTable tbody').append(newRow);
for (var i = 0; i < productarray.length; i++)
{
var product = productarray[i];
newRow += '<option value="' + product.product_id + '">' + product.product_name + '</option>';
}
newRow += '</select></td>' +
'<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="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>' +
'</tr>';
$('#itemTable tbody').append(newRow);
initializeSelect2();
});
// Event listener for removing item
@ -498,7 +553,7 @@ $(document).ready(function() {
var selectedClient = vehicles.find(function(vehicle) {
return vehicle.vehicle_id == vehicleId;
});
console.log(selectedClient);
// console.log(selectedClient);
// Populate the billing address, city, state, country, and postal code fields
$('input[name="client_id"]').val(selectedClient.client_name);

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712314543;_ci_previous_url|s:64:"http://localhost/the_mechanic/public/index.php/sales_order_index";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712306960;_ci_previous_url|s:60:"http://localhost/the_mechanic/public/index.php/new_product/0";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712307617;_ci_previous_url|s:60:"http://localhost/the_mechanic/public/index.php/new_product/0";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712304798;_ci_previous_url|s:61:"http://localhost/the_mechanic/public/index.php/business_index";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712309483;_ci_previous_url|s:60:"http://localhost/the_mechanic/public/index.php/new_product/0";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712307938;_ci_previous_url|s:57:"http://localhost/the_mechanic/public/index.php/new_sale/0";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712300415;_ci_previous_url|s:47:"http://localhost/the_mechanic/public/index.php/";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712308723;_ci_previous_url|s:60:"http://localhost/the_mechanic/public/index.php/new_product/0";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712305179;_ci_previous_url|s:59:"http://localhost/the_mechanic/public/index.php/client_index";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712303843;_ci_previous_url|s:47:"http://localhost/the_mechanic/public/index.php/";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712310681;_ci_previous_url|s:57:"http://localhost/the_mechanic/public/index.php/new_sale/0";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712309802;_ci_previous_url|s:64:"http://localhost/the_mechanic/public/index.php/sales_order_index";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712306111;_ci_previous_url|s:59:"http://localhost/the_mechanic/public/index.php/client_index";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712304392;_ci_previous_url|s:54:"http://localhost/the_mechanic/public/index.php/log_out";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712310116;_ci_previous_url|s:60:"http://localhost/the_mechanic/public/index.php/new_product/2";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712306659;_ci_previous_url|s:59:"http://localhost/the_mechanic/public/index.php/client_index";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712305539;_ci_previous_url|s:59:"http://localhost/the_mechanic/public/index.php/client_index";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712311493;_ci_previous_url|s:57:"http://localhost/the_mechanic/public/index.php/new_sale/0";logged_user|s:1:"1";logged_user_branch_id|s:1:"1";logged_user_business_id|s:1:"2";logged_user_role|s:13:"Store Manager";logged_user_name|s:9:"Sales Man";

View File

@ -1 +0,0 @@
__ci_last_regenerate|i:1712299949;_ci_previous_url|s:47:"http://localhost/the_mechanic/public/index.php/";