StocksNew/public/assets/js/pages/invoicecreate.init.js

1 line
13 KiB
JavaScript
Raw Normal View History

2024-08-27 12:03:06 +00:00
var paymentSign="$";function otherPayment(){var e=document.getElementById("choices-payment-currency").value;paymentSign=e,Array.from(document.getElementsByClassName("product-line-price")).forEach(function(e){isUpdate=e.value.slice(1),e.value=paymentSign+isUpdate}),recalculateCart()}Array.from(document.getElementsByClassName("product-line-price")).forEach(function(e){e.value=paymentSign+"0.00"});var isPaymentEl=document.getElementById("choices-payment-currency"),choices=new Choices(isPaymentEl,{searchEnabled:!1});function isData(){var e=document.getElementsByClassName("plus"),t=document.getElementsByClassName("minus");e&&Array.from(e).forEach(function(n){n.onclick=function(e){var t;parseInt(n.previousElementSibling.value)<10&&(e.target.previousElementSibling.value++,e=n.parentElement.parentElement.previousElementSibling.querySelector(".product-price").value,t=n.parentElement.parentElement.nextElementSibling.querySelector(".product-line-price"),updateQuantity(n.parentElement.querySelector(".product-quantity").value,e,t))}}),t&&Array.from(t).forEach(function(n){n.onclick=function(e){var t;1<parseInt(n.nextElementSibling.value)&&(e.target.nextElementSibling.value--,e=n.parentElement.parentElement.previousElementSibling.querySelector(".product-price").value,t=n.parentElement.parentElement.nextElementSibling.querySelector(".product-line-price"),updateQuantity(n.parentElement.querySelector(".product-quantity").value,e,t))}})}document.querySelector("#profile-img-file-input").addEventListener("change",function(){var e=document.querySelector(".user-profile-image"),t=document.querySelector(".profile-img-file-input").files[0],n=new FileReader;n.addEventListener("load",function(){e.src=n.result},!1),t&&n.readAsDataURL(t)}),flatpickr("#date-field",{enableTime:!0,dateFormat:"d M, Y, h:i K"}),isData();var count=1;function new_link(){count++;var e=document.createElement("tr"),t=(e.id=count,e.className="product",'<tr><th scope="row" class="product-id">'+count+'</th><td class="text-start"><div class="mb-2"><input class="form-control bg-light border-0" type="text" id="productName-'+count+'" placeholder="Product Name"></div><textarea class="form-control bg-light border-0" id="productDetails-'+count+'" rows="2" placeholder="Product Details"></textarea></div></td><td><input class="form-control bg-light border-0 product-price" type="number" id="productRate-'+count+'" step="0.01" placeholder="$0.00"></td><td><div class="input-step"><button type="button" class="minus"></button><input type="number" class="product-quantity" id="product-qty-'+count+'" value="0" readonly><button type="button" class="plus">+</button></div></td><td class="text-end"><div><input type="text" class="form-control bg-light border-0 product-line-price" id="productPrice-'+count+'" value="$0.00" placeholder="$0.00" /></div></td><td class="product-removal"><a class="btn btn-success">Delete</a></td></tr>'),t=(e.innerHTML=document.getElementById("newForm").innerHTML+t,document.getElementById("newlink").appendChild(e),document.querySelectorAll("[data-trigger]"));Array.from(t).forEach(function(e){new Choices(e,{placeholderValue:"This is a placeholder set in the config",searchPlaceholderValue:"This is a search placeholder"})}),isData(),remove(),amountKeyup(),resetRow()}remove();var taxRate=.125,shippingRate=65,discountRate=.15;function remove(){Array.from(document.querySelectorAll(".product-removal a")).forEach(function(e){e.addEventListener("click",function(e){removeItem(e),resetRow()})})}function resetRow(){Array.from(document.getElementById("newlink").querySelectorAll("tr")).forEach(function(e,t){t+=1;e.querySelector(".product-id").innerHTML=t})}function recalculateCart(){var t=0,e=(Array.from(document.getElementsByClassName("product")).forEach(function(e){Array.from(e.getElementsByClassName("product-line-price")).forEach(function(e){e.value&&(t+=parseFloat(e.value.slice(1)))})}),t*taxRate),n=t*discountRate,o=0<t?shippingRate:0,a=t+e+o-n;document.getElementById("cart-subtotal").value=paymentSign+t.toFixed(2),document.getElementById("cart-tax").value=paymentSign+e.toFixed(2),do