From 79fa054c32f9c58c7cc27539755365535f3c0aec Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 1 Aug 2016 12:17:53 +0200 Subject: Error when sending email when invoice is not generated yet --- classes/Offer.php | 7 ++++++- include/ajax-email-offer.php | 9 +++++++-- js/businessadmin.js | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/classes/Offer.php b/classes/Offer.php index 7d8e8b8..a4d6b7f 100644 --- a/classes/Offer.php +++ b/classes/Offer.php @@ -273,11 +273,16 @@ class Offer extends Model{ * @return Mailer The mailer */ public function mailer() { + $file = $this->getInvoiceFile(); + if (is_null($file)) { + throw new Exception("The invoice for this offer has not been generated yet."); + } + $mailer = new Mailer($this->pdo); $mailer->setOffer($this); $lang = $this->getContact()->language; - $mailer->addAttachment($this->getInvoiceFile()->getFilenamePath()); + $mailer->addAttachment($file->getFilenamePath()); $mailer->Subject = Correspondence::__('mail-offer-subject', $lang); $mailer->Body = Correspondence::__r('mail-offer', $lang, $this); diff --git a/include/ajax-email-offer.php b/include/ajax-email-offer.php index c8a09c0..0f3476b 100644 --- a/include/ajax-email-offer.php +++ b/include/ajax-email-offer.php @@ -19,8 +19,13 @@ require_once(__DIR__ . '/../login-ajax.php'); -$_offer = new Offer($_pdo, $_REQUEST['id']); -$_mailer = $_offer->mailer(); +try { + $_offer = new Offer($_pdo, $_REQUEST['id']); + $_mailer = $_offer->mailer(); +} catch (Exception $e) { + http_response_code(500); + die($e->getMessage()); +} function format_email($address) { if ($address[1] != '') { diff --git a/js/businessadmin.js b/js/businessadmin.js index 1d00fa9..ecd132d 100644 --- a/js/businessadmin.js +++ b/js/businessadmin.js @@ -159,7 +159,7 @@ function offerEmail(offerId) { modalBody.html(data); }, error: function(jqxhr, stat, err) { - modalBody.html(''); + modalBody.html(''); } }); } -- cgit v1.2.3