From bf85aa7ddd24e36df5fb36dfa1151853f23ea0ef Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 29 Sep 2015 13:21:57 +0300 Subject: [PATCH] Bug fixes --- app/Console/Commands/SendRecurringInvoices.php | 3 --- app/Exceptions/Handler.php | 3 ++- app/Http/Controllers/InvoiceController.php | 4 ++-- app/Models/Invoice.php | 16 ++++++++-------- app/Ninja/Mailers/ContactMailer.php | 4 ++++ app/Ninja/Repositories/InvoiceRepository.php | 4 ++++ app/Services/PaymentService.php | 4 ++-- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php index ed0e1589b7dd..38a4a8bb929c 100644 --- a/app/Console/Commands/SendRecurringInvoices.php +++ b/app/Console/Commands/SendRecurringInvoices.php @@ -42,9 +42,6 @@ class SendRecurringInvoices extends Command if ($invoice && !$invoice->isPaid()) { $recurInvoice->account->loadLocalizationSettings($invoice->client); - if ($invoice->account->pdf_email_attachment) { - $invoice->updateCachedPDF(); - } $this->mailer->sendInvoice($invoice); } } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index ca85b3862934..177382ae67b6 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -49,7 +49,8 @@ class Handler extends ExceptionHandler { } // In production, except for maintenance mode, we'll show a custom error screen - if (Utils::isNinjaProd() && $e->getStatusCode() != 503) { + //if (Utils::isNinjaProd() && $e->getStatusCode() != 503) { + if (Utils::isNinjaProd()) { $data = [ 'error' => get_class($e), 'hideHeader' => true, diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 7e7b659f850a..aaacbfb3a69a 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -527,10 +527,10 @@ class InvoiceController extends BaseController Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url); } - if ($invoice->account->pdf_email_attachment) { + if ($invoice->account->pdf_email_attachment && !$invoice->is_recurring) { $pdfUpload = Input::get('pdfupload'); if (!empty($pdfUpload) && strpos($pdfUpload, 'data:application/pdf;base64,') === 0) { - $invoice->updateCachedPDF(Input::get('pdfupload')); + $invoice->updateCachedPDF($pdfUpload); } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 7e0f1ced2db6..417a227db84f 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1,5 +1,6 @@ invitations[0]; - $key = $invitation->getLink(); + $link = $invitation->getLink(); $curl = curl_init(); $jsonEncodedData = json_encode([ - 'targetUrl' => SITE_URL . "/view/{$key}/?phantomjs=true", + 'targetUrl' => "{$link}?phantomjs=true", 'requestType' => 'raw', + 'delayTime' => 3000, ]); - + $opts = [ CURLOPT_URL => PHANTOMJS_CLOUD . env('PHANTOMJS_CLOUD_KEY'), CURLOPT_RETURNTRANSFER => true, @@ -304,14 +306,12 @@ class Invoice extends EntityModel curl_setopt_array($curl, $opts); $encodedString = strip_tags(curl_exec($curl)); curl_close($curl); - - if (!$encodedString) { - return false; - } } $encodedString = str_replace('data:application/pdf;base64,', '', $encodedString); - file_put_contents($this->getPDFPath(), base64_decode($encodedString)); + if ($encodedString = base64_decode($encodedString)) { + file_put_contents($this->getPDFPath(), $encodedString); + } } } diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 35af63248360..a90dc5dbe72f 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -21,6 +21,10 @@ class ContactMailer extends Mailer $client = $invoice->client; $account = $invoice->account; + if ($invoice->trashed() || $client->trashed()) { + return false; + } + $account->loadLocalizationSettings($client); $view = 'invoice'; diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 7e4f1c314441..529b9d29957f 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -655,6 +655,10 @@ class InvoiceRepository } } + if ($recurInvoice->account->pdf_email_attachment) { + $invoice->updateCachedPDF(); + } + return $invoice; } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 572d52ae7e8a..b7981e8e7958 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -128,14 +128,14 @@ class PaymentService { 'billingCity' => $client->city, 'billingPostcode' => $client->postal_code, 'billingState' => $client->state, - 'billingCountry' => $client->country->iso_3166_2, + 'billingCountry' => $client->country ? $client->country->iso_3166_2 : '', 'billingPhone' => $contact->phone, 'shippingAddress1' => $client->address1, 'shippingAddress2' => $client->address2, 'shippingCity' => $client->city, 'shippingPostcode' => $client->postal_code, 'shippingState' => $client->state, - 'shippingCountry' => $client->country->iso_3166_2, + 'shippingCountry' => $client->country ? $client->country->iso_3166_2 : '', 'shippingPhone' => $contact->phone, ]; }