jQuery.noConflict(),function(t){function e(t){return parseFloat(t.replace(",","."))}function r(t,e){if(0===t||0===e)return 0;var r=function(t){return Math.log(t)/Math.log(10)},n=function(t){return Math.pow(10,t)},a=1-Math.floor(Math.min(r(t),r(e))),o=t*n(a)*(e*n(a))/n(2*a);return isNaN(o)||!isFinite(o)?0:o}function n(t){return parseFloat(t.val().split("|")[1],10)}function a(a){t(".net_price_sum",a).val(r(e(t(".net_price",a).val()),e(t(".quantity",a).val())).toFixed(4)),function(a){var i=n(t(".vat_type",a)),c=isNaN(i)?0:i,p=function(r){if(t("input.discount",r).length>0){var n=e(t("input.discount",r).val());return isNaN(n)?0:n}return 0}(a),u=e(t(".net_price_sum",a).val())-p;t(".net_price_sum",a).val(u.toFixed(2));var s=r(u,c/100);t(".vat_sum",a).val(s.toFixed(2)),function(r){var n=e(t(".net_price_sum",r).val())+e(t(".vat_sum",r).val());t(".total_price",r).val((isNaN(n)?0:n).toFixed(2)),o(t(".vat_sum",r).parents("table"))}(a)}(a)}function o(r){var n,a,o=0;r.hasClass("after-correction")?(n=0,a=0,t("#before-correction .product_row .total_price").each((function(r,a){var o=e(t(a).val());n+=isNaN(o)?0:o})),t("#after-correction .product_row .total_price").each((function(r,n){var o=e(t(n).val());a+=isNaN(o)?0:o})),o=-n+a):t(".product_row .total_price").each((function(r,n){var a=e(t(n).val());o+=isNaN(a)?0:a})),t("[name=total_price]").val(o.toFixed(2))}t("body.post-type-inspire_invoice .products_metabox").on("input",".net_price, .quantity, input.discount, .net_price_sum, .vat_sum, .total_price",(function(){var e=t(this).val(),r=e.replace(/,/g,".").replace(/[^0-9.\-]/g,""),n=(r=r.replace(/(?!^)-/g,"")).split(".");n.length>2&&(r=n.shift()+"."+n.join("")),e!==r&&t(this).val(r)})).on("click",".remove_product",(function(e){if(e.preventDefault(),t(this).parents("table").hasClass("after-correction")){var r=t(this).parents(".product_row").index();t("table.before-correction tbody tr").eq(r).remove()}t(this).parents(".product_row").remove(),o(t(this).parents("table"))})).on("click",".add_product",(function(e){e.preventDefault();var r=t("#product_prototype").html();t(".products_container").append(r)})).on("click",".add_product_correction",(function(e){e.preventDefault();var r=t("#product_before_prototype").html(),n=t("#product_after_prototype").html();t(".products_before_container").append(r),t(".products_after_container").append(n)})).on("change",".refresh_net_price_sum",(function(e){a(t(this).parents(".product_row"))})).on("change",".refresh_product",(function(e){var r=t(this).parents(".product_row"),n=this.options[this.selectedIndex].dataset.price;r[0].querySelector("input[name='product[net_price][]").value=n,a(r)})).on("change",".refresh_vat_sum",(function(e){a(t(this).parents(".product_row"))})).on("change",".refresh_total_price",(function(e){var r=t(this).parents(".product_row");t(".total_price",r).trigger("change")})).on("change",".refresh_total",(function(r){var a,i,c,p;o(t(this).parents("table")),a=t(this).parents(".product_row"),t(".net_price",a).val((i=e(t(".total_price",a).val()),c=n(t(".vat_type",a)),p=e(t(".quantity",a).val()),0===c?i/p:0===i||0===c||0===p||isNaN(i)||isNaN(c)||isNaN(p)?0:i/(1+c/100)/p).toFixed(4)),t(".net_price",a).trigger("change")}))}(jQuery);