From e6cad704ef48552ff562af4a8231c6c60ff65e81 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 3 Sep 2017 21:10:11 +0300 Subject: [PATCH] Compare PHP/JS when PDF is first shown --- resources/views/invoices/edit.blade.php | 30 +++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 09e296e5acad..baad843aae60 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -864,17 +864,6 @@ } } model.invoice().addItem(); // add blank item - - // check amounts are correct - var phpBalance = invoice.balance; - 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 @if ($account->invoice_taxes) @@ -1160,6 +1149,7 @@ } var origInvoiceNumber = false; + var checkedInvoiceBalances = false; function getPDFString(cb, force) { @if (! $invoice->id && $account->credit_number_counter > 0) var total = model.invoice().totals.rawTotal(); @@ -1173,12 +1163,28 @@ } @endif + var invoice = createInvoiceModel(); + if (! checkedInvoiceBalances) { + // check amounts are correct + checkedInvoiceBalances = true; + var phpBalance = invoice.balance; + var koBalance = model.invoice().totals.rawTotal(); + var jsBalance = calculateAmounts(invoice).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); + } + } + @if ( ! $account->live_preview) return; @endif - var invoice = createInvoiceModel(); + var design = getDesignJavascript(); if (!design) return; + generatePDF(invoice, design, force, cb); }