changes in calculation
This commit is contained in:
parent
f2f818a62b
commit
4d6ffb80ca
@ -219,24 +219,27 @@ class Service extends BaseController
|
||||
return $this->response->setJSON([]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_product_by_cc(){
|
||||
$cc_id = $this->request->getPost('cc_id');
|
||||
$products = [];
|
||||
$model_ids = $this->BikemodelsModel->select('model_id')->where('cubic_capacity_id', $cc_id)->asArray()->findAll();
|
||||
|
||||
foreach ($model_ids as $model) {
|
||||
$modelId = $model['model_id'];
|
||||
// echo $modelId;
|
||||
$product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
|
||||
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
|
||||
->where('JSON_CONTAINS(products.models_id, \'["' . $modelId . '"]\')', null, false)
|
||||
->where('products.isactive', 1)
|
||||
->findAll();
|
||||
// echo( $this->ProductModel->getLastQuery()->getQuery());
|
||||
$products = array_merge($products, $product);
|
||||
}
|
||||
$products = array_unique($products, SORT_REGULAR);
|
||||
$mid[] = 0; // default zero. because general..
|
||||
foreach($model_ids as $model){
|
||||
$mid[] = $model['model_id'];
|
||||
}
|
||||
$products = [];
|
||||
foreach ($mid as $id) {
|
||||
$sql = "SELECT products.*, manufacturer.manufacturer_name
|
||||
FROM products
|
||||
JOIN manufacturer ON manufacturer.manufacturer_id = products.manufacturer_id
|
||||
WHERE JSON_CONTAINS(products.models_id, ?)
|
||||
AND products.isactive = 1";
|
||||
|
||||
$result = $this->ProductModel->query($sql, ['"' . $id . '"'])->getResult();
|
||||
$products = array_merge($products, $result);
|
||||
}
|
||||
|
||||
return $this->response->setJSON($products);
|
||||
}
|
||||
|
||||
@ -90,8 +90,8 @@
|
||||
<label for="inputEmail4" class="col-form-label">Type<span class="text-danger">*</span></label>
|
||||
<select class="form-control type-select SelExample" name="type" id="type" data-toggle="select2" required>
|
||||
<option value="" <?= (isset($jobs['type']) && $jobs['type'] == '') ? 'selected' : '' ?>>Select Type</option>
|
||||
<option value="With General" <?= (isset($jobs['type']) && $jobs['type'] == "With General") ?'selected' : '' ?>>With General</option>
|
||||
<option value="Without General" <?= (isset($jobs['type']) && $jobs['type'] == "Without General") ? 'selected' : '' ?>>Without General</option>
|
||||
<option value="General" <?= (isset($jobs['type']) && $jobs['type'] == "General") ?'selected' : '' ?>>General</option>
|
||||
<option value="Complaints" <?= (isset($jobs['type']) && $jobs['type'] == "Complaints") ? 'selected' : '' ?>>Complaints</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
@ -312,7 +312,7 @@
|
||||
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Complaint</h4>
|
||||
</a>
|
||||
<a class="btn" id="addCustomComplaint">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Customer Complaint</h4>
|
||||
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Additional Complaint</h4>
|
||||
</a>
|
||||
<a class="btn" id="addOutsource">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Outsource</h4>
|
||||
|
||||
@ -232,7 +232,7 @@
|
||||
</td>
|
||||
<td style="width:8%;">
|
||||
<input type="text" class="form-control item-tax" name="item-tax[]"
|
||||
value="<?= isset($salechild['tax']) ? $salechild['tax'] : '' ?>" onchange="updateTaxAmount(this)">
|
||||
value="<?= isset($salechild['tax']) ? $salechild['tax'] : '' ?>" onchange="updateTaxAmount(this)" readonly>
|
||||
</td>
|
||||
<td style="width:13%;">
|
||||
<?php if (isset($salechild['tax']) && isset($result) ) {
|
||||
@ -241,7 +241,7 @@
|
||||
$tax_amount=0 ;
|
||||
}
|
||||
?>
|
||||
<input type="text" class="form-control" name="tax-amount[]" value="<?= number_format($tax_amount,2); ?>" readonly>
|
||||
<input type="text" class="form-control tax-amount" name="tax-amount[]" value="<?= number_format($tax_amount,2); ?>" readonly>
|
||||
</td>
|
||||
<!-- <td style="width:12%;">
|
||||
<input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" value="<?= isset($salechild['discount']) ? $salechild['discount'] : '' ?>">
|
||||
@ -254,7 +254,7 @@
|
||||
</td> -->
|
||||
<td style="width:13%;">
|
||||
<input type="text" class="form-control item-amount" name="amount[]"
|
||||
value="<?= isset($salechild['amount']) ? $salechild['amount'] : '' ?>" readonly>
|
||||
value="<?= isset($salechild['amount']) ? $salechild['amount'] : '' ?>" >
|
||||
</td>
|
||||
<td hidden><input type="hidden"
|
||||
value="<?= isset($salechild['sales_order_product_id']) ? $salechild['sales_order_product_id'] : '' ?>"
|
||||
@ -532,11 +532,46 @@ $(document).ready(function() {
|
||||
|
||||
var amount = rate * quantity;
|
||||
var taxamount = amount * tax / 100;
|
||||
$(row).find('.tax-amount').val(parseFloat(taxamount).toFixed(2));
|
||||
var finalamt = amount + taxamount;
|
||||
|
||||
$(row).find('.item-amount').val(parseFloat(finalamt).toFixed(2));
|
||||
}
|
||||
|
||||
function calculateTotalAmount(row) {
|
||||
|
||||
|
||||
// Retrieve CGST and SGST values from the database for the selected product
|
||||
var productId = $(row).find('select[name="item_details[]"]').val();
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
|
||||
var cgst = parseFloat(product.cgst);
|
||||
var sgst = parseFloat(product.sgst);
|
||||
var tax = cgst + sgst;
|
||||
|
||||
var quantity = $(row).find('.item-quantity').val();
|
||||
var final_amount = $(row).find('.item-amount').val();
|
||||
|
||||
var taxRate = tax/100;
|
||||
// console.log(taxRate);
|
||||
|
||||
var amt = final_amount/((1+taxRate));
|
||||
// console.log(amt);
|
||||
$(row).find('.item-result').val(parseFloat(amt).toFixed(2));
|
||||
|
||||
var taxAmount = final_amount-amt;
|
||||
// console.log(taxAmount);
|
||||
$(row).find('.tax-amount').val(parseFloat(taxAmount).toFixed(2));
|
||||
|
||||
var rate = amt / quantity;
|
||||
// console.log(rate);
|
||||
$(row).find('.item-rate').val(parseFloat(rate).toFixed(2));
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="item_details[]"]', function() {
|
||||
var productId = $(this).val();
|
||||
@ -545,7 +580,7 @@ $(document).ready(function() {
|
||||
|
||||
if(productId == 0){
|
||||
$(this).closest('tr').find('.item-quantity').prop('readonly', true);
|
||||
$(this).closest('tr').find('.item-amount').prop('readonly', false);
|
||||
// $(this).closest('tr').find('.item-amount').prop('readonly', false);
|
||||
}
|
||||
|
||||
// Find product details from JSON
|
||||
@ -577,21 +612,21 @@ $(document).ready(function() {
|
||||
$(document).on('keyup', '.item-amount', function()
|
||||
{
|
||||
|
||||
var total_amount = $(this).val();
|
||||
// var total_amount = $(this).val();
|
||||
|
||||
var totalTax = $(this).closest('tr').find('.item-tax').val();
|
||||
// var totalTax = $(this).closest('tr').find('.item-tax').val();
|
||||
|
||||
var unitPrice = total_amount / parseFloat((totalTax / 100) + 1);
|
||||
// var unitPrice = total_amount / parseFloat((totalTax / 100) + 1);
|
||||
|
||||
|
||||
var unitPrice = parseFloat(unitPrice).toFixed(2);
|
||||
var taxAmt = total_amount - unitPrice;
|
||||
var taxAmt = parseFloat(taxAmt).toFixed(2)
|
||||
|
||||
$(this).closest('tr').find('.tax-amount').val(taxAmt);
|
||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
$(this).closest('tr').find('.item-result').val(unitPrice);
|
||||
// var unitPrice = parseFloat(unitPrice).toFixed(2);
|
||||
// var taxAmt = total_amount - unitPrice;
|
||||
// var taxAmt = parseFloat(taxAmt).toFixed(2)
|
||||
|
||||
// $(this).closest('tr').find('.tax-amount').val(taxAmt);
|
||||
// $(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
// $(this).closest('tr').find('.item-result').val(unitPrice);
|
||||
calculateTotalAmount($(this).closest('tr'));
|
||||
updateCalculations();
|
||||
|
||||
});
|
||||
@ -727,7 +762,7 @@ $(document).ready(function() {
|
||||
'<td style="width:14%;"><input type="text" class="form-control item-result" readonly /></td>' +
|
||||
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
|
||||
'<td style="width:13%;"><input type="text" class="form-control tax-amount" name="tax-amount[]" readonly /></td>' +
|
||||
'<td style="width:13%;"><input type="text" class="form-control item-amount" name="amount[]" readonly/></td>' +
|
||||
'<td style="width:13%;"><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>';
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
</div>
|
||||
<div class="form-group col-md-3" id="cc_hide" <?= (!isset($services['category']) || $services['category'] == 0) ? 'style="display: none;"' : '' ?>>
|
||||
<label for="cubiccapacity" class="col-form-label">Cubic Capacity<span class="text-danger">*</span></label>
|
||||
<select class="form-control" id="cubiccapacity" name="cubiccapacity" style="height:32px" required>
|
||||
<select class="form-control" id="cubiccapacity" name="cubiccapacity" style="height:32px">
|
||||
<option value="">Select</option>
|
||||
<?php foreach ($cubiccapacity as $item): ?>
|
||||
<option value="<?= $item['id'] ?>" <?php if (isset($services['cubic_capacity_id']) && (($services['cubic_capacity_id'] === $item['id']))) echo "selected"; ?>><?= $item['value'] ?></option>
|
||||
@ -93,24 +93,28 @@
|
||||
<div class="form-group col-md-4"></div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Unit Price (Including Tax) with General<span class="text-danger">*</span></label>
|
||||
<!-- <label for="inputPassword4" class="col-form-label">Unit Price (Including Tax) with General<span class="text-danger">*</span></label> -->
|
||||
<label for="inputPassword4" class="col-form-label">Unit Price (Including Tax) General<span class="text-danger">*</span></label>
|
||||
<input type="number" class="form-control" name="wg_price_withtax" id="PriceWithTaxAndGeneral" placeholder="Total Price" step="0.01" min="0" value="<?= isset($services['wg_price']) ? $services['wg_price'] : '' ; ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputEmail4" class="col-form-label">Labour Cost with General <span class="text-danger">*</span></label>
|
||||
<!-- <label for="inputEmail4" class="col-form-label">Labour Cost with General <span class="text-danger">*</span></label> -->
|
||||
<label for="inputEmail4" class="col-form-label">Labour Cost General <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="wg_labour_cost" id="labour_cost" placeholder="Labour Cost" value="<?= isset($services['wg_labour_cost']) ? $services['wg_labour_cost'] : '' ?>" required readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4"></div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Unit Price (Including Tax) without General<span class="text-danger">*</span></label>
|
||||
<!-- <label for="inputPassword4" class="col-form-label">Unit Price (Including Tax) without General<span class="text-danger">*</span></label> -->
|
||||
<label for="inputPassword4" class="col-form-label">Unit Price (Including Tax) Complaints<span class="text-danger">*</span></label>
|
||||
<input type="number" class="form-control" name="wog_price_withtax" id="PriceWithOutTaxWithGeneral" placeholder="Total Price" step="0.01" min="0" value="<?= isset($services['wog_price']) ? $services['wog_price'] : ''; ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputEmail4" class="col-form-label">Labour Cost without General <span class="text-danger">*</span></label>
|
||||
<!-- <label for="inputEmail4" class="col-form-label">Labour Cost without General <span class="text-danger">*</span></label> -->
|
||||
<label for="inputEmail4" class="col-form-label">Labour Cost Complaints <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="wog_labour_cost" id="labour_cost" placeholder="Labour Cost" value="<?= isset($services['wog_labour_cost']) ? $services['wog_labour_cost'] : '' ?>" required readonly>
|
||||
</div>
|
||||
|
||||
@ -311,14 +315,16 @@ $(document).ready(function() {
|
||||
if (service_id != 0) {
|
||||
|
||||
var category = <?php echo isset($services['category']) ? json_encode($services['category']) : 'null'; ?>;
|
||||
if (category == 1) {
|
||||
if (parseInt(category) == 1) {
|
||||
$('#cc_hide').css('display', 'block');
|
||||
$('#service_hide').css('display' ,'block');
|
||||
$('#cubiccapacity').attr('required', false).attr('readonly', true);
|
||||
$('#cubiccapacity').attr('required', true).attr('readonly', false);
|
||||
// $('#serviceSelected').attr('required', true).attr('readonly', false);
|
||||
} else {
|
||||
$('#cc_hide').css('display', 'none');
|
||||
$('#service_hide').css('display' ,'none');
|
||||
$('#cubiccapacity').attr('required', true).attr('readonly', false);
|
||||
$('#cubiccapacity').attr('required', false).attr('readonly', true);
|
||||
$('#serviceSelected').attr('required', false);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -334,8 +340,8 @@ document.getElementById('category').addEventListener('change', function() {
|
||||
var ccSelect = document.getElementById('cubiccapacity');
|
||||
var serviceSelected = document.getElementById('serviceSelected');
|
||||
var productSelect = document.getElementById('productSelect');
|
||||
|
||||
if (this.value == '1') { // 1 ==> Standalone
|
||||
if (parseInt(this.value) == 1) {
|
||||
// 1 ==> Standalone
|
||||
// customFields.style.display = 'block';
|
||||
// $('#make_hide').css('display' , 'block');
|
||||
// $('#model_hide').css('display' ,'block');
|
||||
@ -343,7 +349,7 @@ document.getElementById('category').addEventListener('change', function() {
|
||||
$('#service_hide').css('display' ,'block');
|
||||
$('#cubiccapacity').val('');
|
||||
$('#productSelect').empty();
|
||||
ccSelect.setAttribute('required', 'required');
|
||||
$('#cubiccapacity').attr('required', true).attr('readonly', false);
|
||||
// makeSelect.setAttribute('required', 'required');
|
||||
// modelSelect.setAttribute('required', 'required');
|
||||
// serviceSelected.setAttribute('required', 'required');
|
||||
@ -355,10 +361,10 @@ document.getElementById('category').addEventListener('change', function() {
|
||||
$('#service_hide').css('display' ,'none');
|
||||
$('#cubiccapacity').val('');
|
||||
$('#productSelect').empty();
|
||||
ccSelect.removeAttribute('required');
|
||||
$('#cubiccapacity').attr('required', false).attr('readonly', true);
|
||||
$('#serviceSelected').attr('required', false);
|
||||
// makeSelect.removeAttribute('required');
|
||||
// modelSelect.removeAttribute('required');
|
||||
serviceSelected.removeAttribute('required');
|
||||
$.ajax({
|
||||
url: '<?php echo base_url('product_list_for_service') ?>', // URL to your CodeIgniter controller method
|
||||
type: 'GET',
|
||||
|
||||
@ -23,8 +23,8 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Service Name</th>
|
||||
<th>Price With General</th>
|
||||
<th>Price WithOut General</th>
|
||||
<th>General Service Price</th>
|
||||
<th>Complaint Price</th>
|
||||
<th>Tax</th>
|
||||
<th>Description</th>
|
||||
<th>Action</th>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user