From b463ccf79a6bb0943da1193b29d971f5331f0e94 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 1 Sep 2017 13:56:10 +0300 Subject: [PATCH] Improve PHP/JS checks --- resources/views/invoices/edit.blade.php | 10 +++++++--- resources/views/invoices/knockout.blade.php | 5 +---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 31ecf7d7b4f1..d3ecc5e6daa1 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -866,9 +866,13 @@ // check amounts are correct var phpBalance = invoice.balance; - var jsBalance = model.invoice().totals.rawTotal(); - if (phpBalance != jsBalance) { - window.onerror('Balances do not match | PHP: ' + phpBalance + ', JS: ' + jsBalance); + var koBalance = model.invoice().totals.rawTotal(); + var jsBalance = calculateAmounts(createInvoiceModel()).total_amount; + if (phpBalance == koBalance && koBalance == jsBalance) { + // do nothing + } else { + var invitationKey = invoice.invitations[0].invitation_key; + window.onerror(invitationKey + ': Balances do not match | PHP: ' + phpBalance + ', JS: ' + jsBalance + ', KO: ' + koBalance); } @else // set the default account tax rate diff --git a/resources/views/invoices/knockout.blade.php b/resources/views/invoices/knockout.blade.php index 3e1b6ab310b8..fc1db11b2965 100644 --- a/resources/views/invoices/knockout.blade.php +++ b/resources/views/invoices/knockout.blade.php @@ -554,10 +554,7 @@ function InvoiceModel(data) { total = NINJA.parseFloat(total) + customValue2; } - var paid = self.totals.rawPaidToDate(); - if (paid > 0) { - total -= paid; - } + total -= self.totals.rawPaidToDate(); return total; });