Jan 1, 2024
0
Level 1
Multiple Row Products and Edit
This is a POS page. I added multiple products. Then I changed the cutting charge for one product, but the cutting charge for all products was updated.
- My editModal
<div id="editModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
<div role="document" class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 id="modal_header" class="modal-title"></h5>
<button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true"><i class="dripicons-cross"></i></span></button>
</div>
<div class="modal-body">
<form>
<div class="row modal-element">
<div class="col-md-4 form-group">
<label>{{trans('file.Quantity')}}</label>
<input type="text" name="edit_qty" class="form-control numkey">
</div>
<div class="col-md-4 form-group">
<label>{{trans('file.Unit Discount')}}</label>
<input type="text" name="edit_discount" class="form-control numkey">
</div>
<div class="col-md-4 form-group">
<label>{{trans('file.Unit Price')}}</label>
<input type="text" name="edit_unit_price" class="form-control numkey" step="any">
</div>
<?php
$tax_name_all[] = 'No Tax';
$tax_rate_all[] = 0;
foreach($lims_tax_list as $tax) {
$tax_name_all[] = $tax->name;
$tax_rate_all[] = $tax->rate;
}
?>
<div class="col-md-4 form-group">
<label>{{trans('file.Tax Rate')}}</label>
<select name="edit_tax_rate" class="form-control selectpicker">
@foreach($tax_name_all as $key => $name)
<option value="{{$key}}">{{$name}}</option>
@endforeach
</select>
</div>
<div id="edit_unit" class="col-md-4 form-group">
<label>{{trans('file.Product Unit')}}</label>
<select name="edit_unit" class="form-control selectpicker">
</select>
</div>
<div class="col-md-4 form-group">
<label>{{trans('file.Cutting Charge')}}</label>
<input type="text" name="cutting_charge" id="cutting_charge" class="form-control numkey">
</div>
</div>
<button type="button" name="update_btn" class="btn btn-primary">{{trans('file.update')}}</button>
</form>
</div>
</div>
</div>
</div>
- My function
function calculateRowProductData(quantity) {
if(product_type[pos] == 'standard')
unitConversion();
else
row_product_price = product_price[rowindex];
if (tax_method[rowindex] == 1) {
var net_unit_price = row_product_price - product_discount[rowindex];
var tax = net_unit_price * quantity * (tax_rate[rowindex] / 100);
var sub_total = (net_unit_price * quantity) + tax;
if(parseFloat(quantity))
var sub_total_unit = sub_total / quantity;
else
var sub_total_unit = sub_total;
}
else {
var sub_total_unit = row_product_price - product_discount[rowindex];
var net_unit_price = (100 / (100 + tax_rate[rowindex])) * sub_total_unit;
var tax = (sub_total_unit - net_unit_price) * quantity;
var sub_total = sub_total_unit * quantity;
}
// Add cutting charge calculation
var cutting_charge = parseFloat($('input[name="cutting_charge"]').val()) || 0;
sub_total += cutting_charge * quantity;
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.discount-value').val((product_discount[rowindex] * quantity).toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.tax-rate').val(tax_rate[rowindex].toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.net_unit_price').val(net_unit_price.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.tax-value').val(tax.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.product-price').text(sub_total_unit.toFixed({{$general_setting->decimal}}));
// Update the display of subtotal in the table
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.sub-total').text(sub_total.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.subtotal-value').val(sub_total.toFixed({{$general_setting->decimal}}));
localStorageProductDiscount.splice(rowindex, 1, (product_discount[rowindex] * quantity).toFixed({{$general_setting->decimal}}));
localStorageTaxRate.splice(rowindex, 1, tax_rate[rowindex].toFixed({{$general_setting->decimal}}));
localStorageNetUnitPrice.splice(rowindex, 1, net_unit_price.toFixed({{$general_setting->decimal}}));
localStorageTaxValue.splice(rowindex, 1, tax.toFixed({{$general_setting->decimal}}));
localStorageSubTotalUnit.splice(rowindex, 1, sub_total_unit.toFixed({{$general_setting->decimal}}));
localStorageSubTotal.splice(rowindex, 1, sub_total.toFixed({{$general_setting->decimal}}));
localStorage.setItem("localStorageProductDiscount", localStorageProductDiscount);
localStorage.setItem("localStorageTaxRate", localStorageTaxRate);
localStorage.setItem("localStorageNetUnitPrice", localStorageNetUnitPrice);
localStorage.setItem("localStorageTaxValue", localStorageTaxValue);
localStorage.setItem("localStorageSubTotalUnit", localStorageSubTotalUnit);
localStorage.setItem("localStorageSubTotal", localStorageSubTotal);
calculateTotal();
}
Please or to participate in this conversation.