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)},o=function(t){return Math.pow(10,t)},a=1-Math.floor(Math.min(r(t),r(e))),n=t*o(a)*(e*o(a))/o(2*a);return isNaN(n)||!isFinite(n)?0:n}function o(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 c=o(t(".vat_type",a)),i=0;t(".discount",a).length>0&&(i=e(t(".discount",a).val()));var p=e(t(".net_price_sum",a).val());i>0&&(p-=i,t(".net_price_sum",a).val(p.toFixed(2)));var u=r(p,(isNaN(c)?0:c)/100);t(".vat_sum",a).val(u.toFixed(2)),function(r){var o=e(t(".vat_sum",r).val())+e(t(".net_price_sum",r).val());t(".total_price",r).val((isNaN(o)?0:o).toFixed(2)),n(t(".vat_sum",r).parents("table"))}(a)}(a)}function n(r){var o,a,n=0;r.hasClass("after-correction")?(o=0,a=0,t("#before-correction .product_row .total_price").each((function(r,a){var n=e(t(a).val());o+=isNaN(n)?0:n})),t("#after-correction .product_row .total_price").each((function(r,o){var n=e(t(o).val());a+=isNaN(n)?0:n})),n=-o+a):t(".product_row .total_price").each((function(r,o){var a=e(t(o).val());n+=isNaN(a)?0:a})),t("[name=total_price]").val(n.toFixed(2))}t("body.post-type-inspire_invoice .products_metabox").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(),n(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(),o=t("#product_after_prototype").html();t(".products_before_container").append(r),t(".products_after_container").append(o)})).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"),o=this.options[this.selectedIndex].dataset.price;r[0].querySelector("input[name='product[net_price][]").value=o,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,c,i,p;n(t(this).parents("table")),a=t(this).parents(".product_row"),t(".net_price",a).val((c=e(t(".total_price",a).val()),i=o(t(".vat_type",a)),p=e(t(".quantity",a).val()),0===i?c/p:0===c||0===i||0===p||isNaN(c)||isNaN(i)||isNaN(p)?0:c/(1+i/100)/p).toFixed(4)),t(".net_price",a).trigger("change")}))}(jQuery);