PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.4
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.4
2.4.3 2.4.4 2.4.2 2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 All 60 releases
← All changes | assets/js/invoice-builder.js +37 -11 2.1.0 → 2.4.4 View file →
@@ -365,11 +365,15 @@
365 365 } else {
366 366 // Fallback to hardcoded calculation
367 367 var quantity = parseFloat($item.find('input[name*="[quantity]"]').val()) || 0;
368 368 var price = parseFloat($item.find('input[name*="[price]"]').val()) || 0;
369 - var adjustPercentage = parseFloat($item.find('input[name*="[adjust_percentage]"]').val()) || 0;
369 + var adjustPercentage = 0;
370 + // Only apply adjust percentage if the adjust field is enabled
371 + if (window.easyInvoice && window.easyInvoice.showAdjustField) {
372 + adjustPercentage = parseFloat($item.find('input[name*="[adjust_percentage]"]').val()) || 0;
373 + }
370 374 var baseTotal = quantity * price;
371 - var total = baseTotal * (1 + adjustPercentage / 100);
375 + var total = easyInvoiceRoundMoney(baseTotal * (1 + adjustPercentage / 100));
372 376
373 377 // Update the total field
374 378 var $totalField = $item.find('input[name*="[total]"]');
375 379 $totalField.val(total.toFixed(2));
@@ -397,11 +401,15 @@
397 401 } else {
398 402 // Fallback to hardcoded summary
399 403 var quantity = parseFloat($item.find('input[name*="[quantity]"]').val()) || 0;
400 404 var price = parseFloat($item.find('input[name*="[price]"]').val()) || 0;
401 - var adjustPercentage = parseFloat($item.find('input[name*="[adjust_percentage]"]').val()) || 0;
405 + var adjustPercentage = 0;
406 + // Only apply adjust percentage if the adjust field is enabled
407 + if (window.easyInvoice && window.easyInvoice.showAdjustField) {
408 + adjustPercentage = parseFloat($item.find('input[name*="[adjust_percentage]"]').val()) || 0;
409 + }
402 410 var baseTotal = quantity * price;
403 - var total = baseTotal * (1 + adjustPercentage / 100);
411 + var total = easyInvoiceRoundMoney(baseTotal * (1 + adjustPercentage / 100));
404 412
405 413 $item.find('.quantity-summary').text(quantity);
406 414 $item.find('.price-summary').text(price.toFixed(2));
407 415 $item.find('.total-summary').text(total.toFixed(2));
@@ -551,9 +559,9 @@
551 559 // Update client info fields
552 560 $('#client_name_display').text(client.name || '');
553 561 $('#client_email_display').text(client.email || '');
554 562 $('#client_phone_display').text(client.phone || '');
555 - $('#client_address_display').html((client.address || '').replace(/\n/g, '<br>'));
563 + $('#client_address_display').html(easyInvoiceAddressHtml(client.address));
556 564
557 565 // Show client info section
558 566 $('#client_info').show();
559 567 return;
@@ -575,9 +583,9 @@
575 583 // Update client info fields
576 584 $('#client_name_display').text(client.name);
577 585 $('#client_email_display').text(client.email);
578 586 $('#client_phone_display').text(client.phone || '');
579 - $('#client_address_display').html(client.address.replace(/\n/g, '<br>') || '');
587 + $('#client_address_display').html(easyInvoiceAddressHtml(client.address));
580 588
581 589 // Show client info section
582 590 $('#client_info').show();
583 591 } else {
@@ -1027,8 +1035,10 @@
1027 1035
1028 1036 // Add a small delay to ensure total calculation is complete
1029 1037 setTimeout(function() {
1030 1038 // Re-calculate total to ensure it's correct
1039 + // Store reference to the correct context
1040 + var self = this;
1031 1041 self.calculateItemTotal($item);
1032 1042
1033 1043 // Update totals
1034 1044 if (window.EasyInvoicePayment && typeof window.EasyInvoicePayment.updateTotals === 'function') {
@@ -1033,9 +1043,9 @@
1033 1043 // Update totals
1034 1044 if (window.EasyInvoicePayment && typeof window.EasyInvoicePayment.updateTotals === 'function') {
1035 1045 window.EasyInvoicePayment.updateTotals();
1036 1046 }
1037 - }, 100);
1047 + }.bind(this), 100);
1038 1048
1039 1049 },
1040 1050
1041 1051 // Load invoice data when in edit mode
@@ -1052,9 +1062,9 @@
1052 1062 // Set client info if available
1053 1063 if (easyInvoice.clientData) {
1054 1064 $('#client_name_display').text(easyInvoice.clientData.name || '');
1055 1065 $('#client_email_display').text(easyInvoice.clientData.email || '');
1056 - $('#client_address_display').html((easyInvoice.clientData.address || '').replace(/\n/g, '<br>'));
1066 + $('#client_address_display').html(easyInvoiceAddressHtml(easyInvoice.clientData.address));
1057 1067 $('#client_info').show();
1058 1068 }
1059 1069
1060 1070 // Set items
@@ -1245,9 +1255,13 @@
1245 1255 calculateFieldValue: function(fieldName, $item) {
1246 1256 if (fieldName === 'total') {
1247 1257 var quantity = parseFloat(this.getFieldValue('quantity', $item)) || 0;
1248 1258 var price = parseFloat(this.getFieldValue('price', $item)) || 0;
1249 - var adjustPercentage = parseFloat(this.getFieldValue('adjust_percentage', $item)) || 0;
1259 + var adjustPercentage = 0;
1260 + // Only apply adjust percentage if the adjust field is enabled
1261 + if (window.easyInvoice && window.easyInvoice.showAdjustField) {
1262 + adjustPercentage = parseFloat(this.getFieldValue('adjust_percentage', $item)) || 0;
1263 + }
1250 1264 var baseTotal = quantity * price;
1251 1265 var total = baseTotal * (1 + adjustPercentage / 100);
1252 1266 return total;
1253 1267 }
@@ -1369,10 +1383,22 @@
1369 1383 this.setupClientSelection();
1370 1384 }
1371 1385 };
1372 1386
1387 +// Address text -> HTML with line breaks, escaped: the address is what the
1388 +// client typed into their portal profile, so it must never reach .html() raw.
1389 +// Half-up rounding to cents, matching PHP round($x, 2) (7 x 1.005 is 7.04, not
1390 +// the 7.03 that toFixed() gives from binary floats).
1391 +function easyInvoiceRoundMoney(v) {
1392 + return Number(Math.round(Number((parseFloat(v) || 0) + 'e2')) + 'e-2');
1393 +}
1394 +
1395 +function easyInvoiceAddressHtml(address) {
1396 + return jQuery('<div>').text(address || '').html().replace(/\n/g, '<br>');
1397 +}
1398 +
1373 1399 // Initialize invoice builder when document is ready
1374 - jQuery(document).ready(function($) {
1400 +jQuery(document).ready(function($) {
1375 1401 // Initialize the invoice builder
1376 1402 if (typeof EasyInvoiceBuilder !== 'undefined') {
1377 1403 EasyInvoiceBuilder.init();
1378 1404 }
@@ -1392,5 +1418,5 @@
1392 1418 }
1393 1419 }, 1000);
1394 1420 });
1395 1421
1396 -})(jQuery);
1422 +})(jQuery);