From d175fc872a00a3c3729fef15a543acbcf8ce58ae Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 29 May 2016 19:32:45 +0300 Subject: [PATCH] Don't render pdf if not attached and fix typo --- app/Models/Account.php | 2 +- app/Ninja/Mailers/ContactMailer.php | 6 +++--- resources/views/invoices/edit.blade.php | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Models/Account.php b/app/Models/Account.php index e54b01bdd01e..5dd8a12c1851 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1317,7 +1317,7 @@ class Account extends Eloquent return Utils::isEmpty($entity->$field) ? false : true; } - public function attatchPDF() + public function attachPDF() { return $this->hasFeature(FEATURE_PDF_ATTACHMENT) && $this->pdf_email_attachment; } diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 9d4b3c509111..12662a606ed6 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -59,7 +59,7 @@ class ContactMailer extends Mailer $sent = false; - if ($account->attatchPDF() && !$pdfString) { + if ($account->attachPDF() && !$pdfString) { $pdfString = $invoice->getPDFString(); } @@ -156,7 +156,7 @@ class ContactMailer extends Mailer 'documents' => $documentStrings, ]; - if ($account->attatchPDF()) { + if ($account->attachPDF()) { $data['pdfString'] = $pdfString; $data['pdfFileName'] = $invoice->getFileName(); } @@ -235,7 +235,7 @@ class ContactMailer extends Mailer 'entityType' => ENTITY_INVOICE, ]; - if ($account->attatchPDF()) { + if ($account->attachPDF()) { $data['pdfString'] = $invoice->getPDFString(); $data['pdfFileName'] = $invoice->getFileName(); } diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 19a677da1aae..66a0b2b86a2a 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -1209,8 +1209,13 @@ if (confirm('{!! trans("texts.confirm_email_$entityType") !!}' + '\n\n' + getSendToEmails())) { var accountLanguageId = parseInt({{ $account->language_id ?: '0' }}); var clientLanguageId = parseInt(model.invoice().client().language_id()) || 0; + var attachPDF = {{ $account->attachPDF() ? 'true' : 'false' }}; + + // if they aren't attaching the pdf no need to generate it + if ( ! attachPDF) { + submitAction('email'); // if the client's language is different then we can't use the browser version of the PDF - if (clientLanguageId && clientLanguageId != accountLanguageId) { + } else if (clientLanguageId && clientLanguageId != accountLanguageId) { submitAction('email'); } else { preparePdfData('email');