Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- $(".price,.quantity").on("input", function () {
- let total = 0;
- let quantity = $(this).closest("tr").find(".quantity").val();
- let price = $(this).closest("tr").find(".price").val();
- if (quantity && price) {
- let total = quantity * price;
- let doThis = $(this).closest("tr").find(".total").val(total);
- subTotalSum();
- discountCalc();
- }
- });
- let subTotalSum = function () {
- let sum = 0;
- $(".total").each(function () {
- let num = $(this).val();
- if (num) {
- sum += parseFloat(num);
- }
- });
- $(".sub-total").val(sum);
- };
- let discountCalc = function () {
- let subTotal = $(".sub-total").val();
- let discountProcentage = $(".discount").val();
- let calc = (discountProcentage / 100).toFixed(2);
- let multiply = subTotal * calc;
- let discountFinal = subTotal - multiply;
- $(".all-total").val(discountFinal);
- };
- $(".btnAdd").click(function () {
- let $tableBody = $(".product-table").find("tbody");
- $trLast = $tableBody.find("tr:last");
- $trNew = $trLast.clone(true);
- $trNew.find("input[type=text]").val("");
- $trNew.find("input[type=number]").val("");
- $trLast.after($trNew);
- });
- $(".discount").keyup(function () {
- $(".total-discount").val($(".discount").val() + "%");
- discountCalc();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement