diff --git a/app/Events/InvoiceWasEmailed.php b/app/Events/InvoiceWasEmailed.php index 7083022512e5..db704915dd5b 100644 --- a/app/Events/InvoiceWasEmailed.php +++ b/app/Events/InvoiceWasEmailed.php @@ -17,13 +17,19 @@ class InvoiceWasEmailed extends Event */ public $invoice; + /** + * @var string + */ + public $notes; + /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice) + public function __construct(Invoice $invoice, $notes) { $this->invoice = $invoice; + $this->notes = $notes; } } diff --git a/app/Events/QuoteWasEmailed.php b/app/Events/QuoteWasEmailed.php index e52714ddaa91..b5b2cc8cce99 100644 --- a/app/Events/QuoteWasEmailed.php +++ b/app/Events/QuoteWasEmailed.php @@ -12,13 +12,19 @@ class QuoteWasEmailed extends Event use SerializesModels; public $quote; + /** + * @var string + */ + public $notes; + /** * Create a new event instance. * * @param $quote */ - public function __construct($quote) + public function __construct($quote, $notes) { $this->quote = $quote; + $this->notes = $notes; } } diff --git a/app/Jobs/SendNotificationEmail.php b/app/Jobs/SendNotificationEmail.php index bd8e893967dd..04fd4fd77c96 100644 --- a/app/Jobs/SendNotificationEmail.php +++ b/app/Jobs/SendNotificationEmail.php @@ -35,6 +35,11 @@ class SendNotificationEmail extends Job implements ShouldQueue */ protected $payment; + /** + * @var string + */ + protected $notes; + /** * Create a new job instance. @@ -46,12 +51,13 @@ class SendNotificationEmail extends Job implements ShouldQueue * @param mixed $type * @param mixed $payment */ - public function __construct($user, $invoice, $type, $payment) + public function __construct($user, $invoice, $type, $payment, $notes) { $this->user = $user; $this->invoice = $invoice; $this->type = $type; $this->payment = $payment; + $this->notes = $notes; } /** @@ -61,6 +67,6 @@ class SendNotificationEmail extends Job implements ShouldQueue */ public function handle(UserMailer $userMailer) { - $userMailer->sendNotification($this->user, $this->invoice, $this->type, $this->payment); + $userMailer->sendNotification($this->user, $this->invoice, $this->type, $this->payment, $this->notes); } } diff --git a/app/Listeners/NotificationListener.php b/app/Listeners/NotificationListener.php index 8772ef02e0ff..f0377c83f8f1 100644 --- a/app/Listeners/NotificationListener.php +++ b/app/Listeners/NotificationListener.php @@ -20,13 +20,13 @@ class NotificationListener * @param $type * @param null $payment */ - private function sendEmails($invoice, $type, $payment = null) + private function sendEmails($invoice, $type, $payment = null, $notes = false) { foreach ($invoice->account->users as $user) { if ($user->{"notify_{$type}"}) { - dispatch(new SendNotificationEmail($user, $invoice, $type, $payment)); + dispatch(new SendNotificationEmail($user, $invoice, $type, $payment, $notes)); } } } @@ -36,7 +36,7 @@ class NotificationListener */ public function emailedInvoice(InvoiceWasEmailed $event) { - $this->sendEmails($event->invoice, 'sent'); + $this->sendEmails($event->invoice, 'sent', null, $event->notes); dispatch(new SendPushNotification($event->invoice, 'sent')); } @@ -45,7 +45,7 @@ class NotificationListener */ public function emailedQuote(QuoteWasEmailed $event) { - $this->sendEmails($event->quote, 'sent'); + $this->sendEmails($event->quote, 'sent', null, $event->notes); dispatch(new SendPushNotification($event->quote, 'sent')); } diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 365c7b2c4cee..9e72bd12feb7 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -105,9 +105,9 @@ class ContactMailer extends Mailer if ($sent === true) { if ($invoice->isType(INVOICE_TYPE_QUOTE)) { - event(new QuoteWasEmailed($invoice)); + event(new QuoteWasEmailed($invoice, $reminder)); } else { - event(new InvoiceWasEmailed($invoice)); + event(new InvoiceWasEmailed($invoice, $reminder)); } } diff --git a/app/Ninja/Mailers/UserMailer.php b/app/Ninja/Mailers/UserMailer.php index 302e7d6b8ed2..e4698897195f 100644 --- a/app/Ninja/Mailers/UserMailer.php +++ b/app/Ninja/Mailers/UserMailer.php @@ -48,7 +48,8 @@ class UserMailer extends Mailer User $user, Invoice $invoice, $notificationType, - Payment $payment = null + Payment $payment = null, + $notes = false ) { if (! $user->email || $user->cannot('view', $invoice)) { return; @@ -81,6 +82,10 @@ class UserMailer extends Mailer 'client' => $client->getDisplayName(), ]); + if ($notes) { + $subject .= ' [' . trans('texts.notes_' . $notes) . ']'; + } + $this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data); }