Rafalsky/HomeFinance

View on GitHub
wallet/web/js/transactions/form.min.js

Summary

Maintainability
A
0 mins
Test Coverage
$receiptTable=$("table#receipt-table");$receiptTable.on("change","input.product-name",function(){if((parseInt($(this).closest("tr").find("td.product-id").html()))!=$receiptTable.find("tr.product-record").length){return}$.ajax({type:"POST",url:"/transaction/new-row/",data:{rowNumber:$receiptTable.find("tr").length},success:function(a){$("table#receipt-table input.product-name").last().closest("tr").after(a);setSelectize()}})});$receiptTable.on("change","input.product-count, input.product-price",function(){var b=$(this).closest("tr").find("input.product-count").val();var a=$(this).closest("tr").find("input.product-price").val();console.log(b);console.log(a);if(b&&a){$(this).closest("tr").find("input.product-total-price").val(+b+ +a).trigger("change")}});$receiptTable.on("change","input.product-total-price",function(){var a=0;$("input.product-total-price").each(function(){var b=$(this).val().replace(/,/g,".");if(!isNaN(b)){a=Number(a)+Number(b)}});$("#totalPrice").html(parseFloat(Math.round(a*100)/100).toFixed(2))});$receiptTable.on("click",".remove-row",function(){if($receiptTable.find("tbody tr").length==1){return}$tr=$(this).closest("tr");var a=parseInt($tr.find("td.product-id").html());$tr.remove();$receiptTable.find("td.product-id").each(function(){$id=parseInt($(this).html());if($id>a){$(this).text($id-1)}})});function setSelectize(){$("select.selectize").selectize({create:true})}setSelectize();