CHANGE_service_module_addtotal:ss
This commit is contained in:
parent
ad8e8c2895
commit
1bec144563
@ -79,10 +79,10 @@ class Service extends BaseController
|
||||
$data['make'] = $BikemakeModel->findAll();
|
||||
$data['models'] = [];
|
||||
$service=$ServiceModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
|
||||
echo $this->session->get('logged_user_branch_id');die;
|
||||
// echo json_encode($service);die;
|
||||
// echo $this->session->get('logged_user_branch_id');die;
|
||||
$data['service']=$service;
|
||||
$product=$ProductModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
|
||||
// echo json_encode($service);die;
|
||||
$data['product']=$product;
|
||||
$data['page_name']="Add Service";
|
||||
} else if ($service_id !== '0') {
|
||||
|
||||
@ -62,7 +62,7 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="model" class="col-form-label">Product<span class="text-danger">*</span></label>
|
||||
<select class="form-control SelExample" name="product_id[]" required multiple>
|
||||
<select class="form-control SelExample" id="productSelect" name="product_id[]" required multiple>
|
||||
<option value="">Select a Product</option>
|
||||
<option value="0" <?= isset($services['product_id']) && in_array(0, json_decode($services['product_id'])) ? 'selected' : '' ?>>None</option>
|
||||
<?php foreach ($product as $value) : ?>
|
||||
@ -76,12 +76,12 @@
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="model" class="col-form-label">Service<span class="text-danger">*</span></label>
|
||||
<select class="form-control SelExample" name="sub_service_id[]" required multiple>
|
||||
<select class="form-control SelExample" id="serviceSelected" name="sub_service_id[]" required multiple>
|
||||
<option value="">Select a Service</option>
|
||||
<option value="0" <?= isset($services['sub_service_id']) && in_array(0, json_decode($services['sub_service_id'])) ? 'selected' : '' ?>>None</option>
|
||||
<?php foreach ($service as $value) : ?>
|
||||
<?php if ((int)$value["isactive"] === 1) : ?>
|
||||
<option value="<?= $value["product_id"] ?>" <?= isset($services['sub_service_id']) && in_array($value['sub_service_id'], json_decode($services['sub_service_id'])) ? 'selected' : '' ?>>
|
||||
<option value="<?= $value["service_id"] ?>" <?= isset($services['sub_service_id']) && in_array($value['sub_service_id'], json_decode($services['sub_service_id'])) ? 'selected' : '' ?>>
|
||||
<?= $value["service_name"]; ?>
|
||||
</option>
|
||||
<?php endif; ?>
|
||||
@ -94,11 +94,11 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputEmail4" class="col-form-label">Labour Cost<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="labour_cost" placeholder="Labour Cost" value="<?= isset($services['labour_cost']) ? $services['labour_cost'] : '' ?>" required>
|
||||
<input type="text" class="form-control" name="labour_cost" id="labour_cost" placeholder="Labour Cost" value="<?= isset($services['labour_cost']) ? $services['labour_cost'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Total Price<span class="text-danger">*</span></label>
|
||||
<input type="number" class="form-control" name="price" placeholder="Price"value="<?= isset($services['price']) ? $services['price'] : '' ?>" required>
|
||||
<input type="number" class="form-control" name="price" id="price" placeholder="Price"value="<?= isset($services['price']) ? $services['price'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Tax</label>
|
||||
@ -273,6 +273,104 @@ document.getElementById('category').addEventListener('change', function() {
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<input id="productCost" value="0" hidden>
|
||||
<script>
|
||||
data = <?php echo json_encode($product) ?>;
|
||||
$('#productSelect').change(function() {
|
||||
console.log('jsfd');
|
||||
if(this.value != 0) {
|
||||
// Get the selected options
|
||||
var selectedOptions = this.selectedOptions;
|
||||
|
||||
// Initialize sum
|
||||
var sum = 0;
|
||||
|
||||
for (var i = 0; i < selectedOptions.length; i++) {
|
||||
var productId = selectedOptions[i].value;
|
||||
var price = getPriceForProductId(productId);
|
||||
sum += parseInt(price);
|
||||
}
|
||||
$('#productCost').val(parseInt(sum));
|
||||
console.log(sum);
|
||||
|
||||
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val());
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + labour_cost;
|
||||
console.log("New value of #serviceCost:", add);
|
||||
$('#price').val(add);
|
||||
}
|
||||
else if(this.value == '') {
|
||||
$('#productCost').val(0);
|
||||
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val());
|
||||
add = parseInt($('#productCost').val()) + parseInt($('#serviceCost').val()) + labour_cost;
|
||||
console.log("New value of #serviceCost:", add);
|
||||
$('#price').val(add);
|
||||
}
|
||||
});
|
||||
|
||||
// Function to fetch the price for a product
|
||||
function getPriceForProductId(productId) {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
if (data[i].product_id === productId) {
|
||||
// Return the purchase_cost if the product_id matches
|
||||
return data[i].purchase_cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<input id="serviceCost" value="0" hidden>
|
||||
<script>
|
||||
servicedata = <?php echo json_encode($service) ?>;
|
||||
$('#serviceSelected').change(function() {
|
||||
console.log(this.value);
|
||||
if(this.value != 0) {
|
||||
// Get the selected options
|
||||
var selectedOptions = this.selectedOptions;
|
||||
// Initialize sum
|
||||
var ssum = 0;
|
||||
|
||||
for (var i = 0; i < selectedOptions.length; i++) {
|
||||
var serviceId = selectedOptions[i].value;
|
||||
var sprice = getPriceForServiceId(serviceId);
|
||||
ssum += parseInt(sprice);
|
||||
}
|
||||
$('#serviceCost').val(parseInt(ssum));
|
||||
console.log(ssum);
|
||||
|
||||
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val()) + labour_cost;
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val());
|
||||
console.log("New value of #serviceCost:", add);
|
||||
$('#price').val(add);
|
||||
}
|
||||
else if(this.value == '') {
|
||||
$('#serviceCost').val(0);
|
||||
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val()) + labour_cost;
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val());
|
||||
console.log("New value of #serviceCost:", add);
|
||||
$('#price').val(add);
|
||||
}
|
||||
});
|
||||
|
||||
// Function to fetch the price for a product
|
||||
function getPriceForServiceId(serviceId) {
|
||||
console.log(serviceId);
|
||||
for (var i = 0; i < servicedata.length; i++) {
|
||||
if (servicedata[i].service_id === serviceId) {
|
||||
// Return the purchase_cost if the product_id matches
|
||||
return servicedata[i].price;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$('#labour_cost').on('keyup change', function() {
|
||||
var newValue = ($(this).val() == '') ? 0 : $(this).val();
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + parseInt(newValue);
|
||||
$('#price').val(add);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<style>
|
||||
.select2-container .select2-selection--multiple .select2-selection__choice{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user