diff --git a/app/Listeners/Credit/CreditCreatedNotification.php b/app/Listeners/Credit/CreditCreatedNotification.php index 5c7b0350412b..6a982dfe46ae 100644 --- a/app/Listeners/Credit/CreditCreatedNotification.php +++ b/app/Listeners/Credit/CreditCreatedNotification.php @@ -44,11 +44,6 @@ class CreditCreatedNotification implements ShouldQueue $credit = $event->credit; - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($credit, 'credit'))->build()); - $nmo->company = $credit->company; - $nmo->settings = $credit->company->settings; - /* We loop through each user and determine whether they need to be notified */ foreach ($event->company->company_users as $company_user) { /* The User */ @@ -64,9 +59,15 @@ class CreditCreatedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($credit, 'credit'))->build()); + $nmo->company = $credit->company; + $nmo->settings = $credit->company->settings; $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + + $nmo = null; } /* Override the methods in the Notification Class */ diff --git a/app/Listeners/Credit/CreditEmailedNotification.php b/app/Listeners/Credit/CreditEmailedNotification.php index 1d04798b81c6..5b6aafe2e6e7 100644 --- a/app/Listeners/Credit/CreditEmailedNotification.php +++ b/app/Listeners/Credit/CreditEmailedNotification.php @@ -44,11 +44,6 @@ class CreditEmailedNotification implements ShouldQueue $credit->last_sent_date = now(); $credit->saveQuietly(); - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'credit', $event->template))->build()); - $nmo->company = $credit->company; - $nmo->settings = $credit->company->settings; - foreach ($event->invitation->company->company_users as $company_user) { $user = $company_user->user; @@ -60,9 +55,15 @@ class CreditEmailedNotification implements ShouldQueue // if (($key = array_search('mail', $methods))) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'credit', $event->template))->build()); + $nmo->company = $credit->company; + $nmo->settings = $credit->company->settings; $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + + $nmo = null; } } } diff --git a/app/Listeners/Invoice/InvoiceCreatedNotification.php b/app/Listeners/Invoice/InvoiceCreatedNotification.php index 1022a2f50713..749cdc101b1c 100644 --- a/app/Listeners/Invoice/InvoiceCreatedNotification.php +++ b/app/Listeners/Invoice/InvoiceCreatedNotification.php @@ -44,11 +44,6 @@ class InvoiceCreatedNotification implements ShouldQueue $invoice = $event->invoice; - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($invoice, 'invoice'))->build()); - $nmo->company = $invoice->company; - $nmo->settings = $invoice->company->settings; - /* We loop through each user and determine whether they need to be notified */ foreach ($event->company->company_users as $company_user) { /* The User */ @@ -68,10 +63,16 @@ class InvoiceCreatedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($invoice, 'invoice'))->build()); + $nmo->company = $invoice->company; + $nmo->settings = $invoice->company->settings; $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + $nmo = null; + /* This prevents more than one notification being sent */ $first_notification_sent = false; } diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index e9012e0a8f31..f2b4c77fc80a 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -46,10 +46,6 @@ class InvoiceEmailedNotification implements ShouldQueue $invoice->last_sent_date = now(); $invoice->saveQuietly(); - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'invoice', $event->template))->build()); - $nmo->company = $invoice->company; - $nmo->settings = $invoice->company->settings; /* We loop through each user and determine whether they need to be notified */ foreach ($event->invitation->company->company_users as $company_user) { @@ -66,10 +62,15 @@ class InvoiceEmailedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'invoice', $event->template))->build()); + $nmo->company = $invoice->company; + $nmo->settings = $invoice->company->settings; $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); - + + $nmo = null; /* This prevents more than one notification being sent */ $first_notification_sent = false; } diff --git a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php index 85005e4503e0..670139ef6b91 100644 --- a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php +++ b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php @@ -45,13 +45,7 @@ class InvoiceFailedEmailNotification $first_notification_sent = true; $invoice = $event->invitation->invoice; - // $invoice->update(['last_sent_date' => now()]); - - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityFailedSendObject($event->invitation, 'invoice', $event->template, $event->message))->build()); - $nmo->company = $invoice->company; - $nmo->settings = $invoice->company->settings; - + foreach ($event->invitation->company->company_users as $company_user) { $user = $company_user->user; @@ -60,10 +54,16 @@ class InvoiceFailedEmailNotification if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntityFailedSendObject($event->invitation, 'invoice', $event->template, $event->message))->build()); + $nmo->company = $invoice->company; + $nmo->settings = $invoice->company->settings; $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + $nmo = null; + $first_notification_sent = false; } } diff --git a/app/Listeners/Misc/InvitationViewedListener.php b/app/Listeners/Misc/InvitationViewedListener.php index 885b4c9c7b2b..c27ae85ca103 100644 --- a/app/Listeners/Misc/InvitationViewedListener.php +++ b/app/Listeners/Misc/InvitationViewedListener.php @@ -58,11 +58,6 @@ class InvitationViewedListener implements ShouldQueue $entity_name = 'purchase_order'; } - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityViewedObject($invitation, $entity_name))->build()); - $nmo->company = $invitation->company; - $nmo->settings = $invitation->company->settings; - foreach ($invitation->company->company_users as $company_user) { $entity_viewed = "{$entity_name}_viewed"; $entity_viewed_all = "{$entity_name}_viewed_all"; @@ -73,8 +68,16 @@ class InvitationViewedListener implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntityViewedObject($invitation, $entity_name))->build()); + $nmo->company = $invitation->company; + $nmo->settings = $invitation->company->settings; + $nmo->to_user = $company_user->user; (new NinjaMailerJob($nmo))->handle(); + + $nmo = null; } } } diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index 5dbe0374e519..9db966cffc5d 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -51,11 +51,6 @@ class PaymentNotification implements ShouldQueue $payment = $event->payment; - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityPaidObject($payment))->build()); - $nmo->company = $event->company; - $nmo->settings = $event->company->settings; - /*User notifications*/ foreach ($payment->company->company_users as $company_user) { $user = $company_user->user; @@ -73,9 +68,16 @@ class PaymentNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntityPaidObject($payment))->build()); + $nmo->company = $event->company; + $nmo->settings = $event->company->settings; $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + + $nmo = null; + } } diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderAcceptedListener.php b/app/Listeners/PurchaseOrder/PurchaseOrderAcceptedListener.php index 2803f82379a6..e4cd1c170757 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderAcceptedListener.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderAcceptedListener.php @@ -41,11 +41,7 @@ class PurchaseOrderAcceptedListener implements ShouldQueue $purchase_order = $event->purchase_order; - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new PurchaseOrderAcceptedObject($purchase_order, $event->company))->build()); - $nmo->company = $event->company; - $nmo->settings = $event->company->settings; - + /* We loop through each user and determine whether they need to be notified */ foreach ($event->company->company_users as $company_user) { /* The User */ @@ -62,10 +58,16 @@ class PurchaseOrderAcceptedListener implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new PurchaseOrderAcceptedObject($purchase_order, $event->company))->build()); + $nmo->company = $event->company; + $nmo->settings = $event->company->settings; + $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + $nmo = null; /* This prevents more than one notification being sent */ $first_notification_sent = false; } diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php index 61178815573f..057743942d93 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php @@ -45,11 +45,7 @@ class PurchaseOrderCreatedListener implements ShouldQueue $purchase_order = $event->purchase_order; - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($purchase_order, 'purchase_order'))->build()); - $nmo->company = $purchase_order->company; - $nmo->settings = $purchase_order->company->settings; - + /* We loop through each user and determine whether they need to be notified */ foreach ($event->company->company_users as $company_user) { /* The User */ @@ -69,10 +65,16 @@ class PurchaseOrderCreatedListener implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($purchase_order, 'purchase_order'))->build()); + $nmo->company = $purchase_order->company; + $nmo->settings = $purchase_order->company->settings; + $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + $nmo = null; /* This prevents more than one notification being sent */ $first_notification_sent = false; } diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderEmailedNotification.php b/app/Listeners/PurchaseOrder/PurchaseOrderEmailedNotification.php index 82c3b3b0cf18..61aa8787c917 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderEmailedNotification.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderEmailedNotification.php @@ -46,11 +46,6 @@ class PurchaseOrderEmailedNotification implements ShouldQueue $purchase_order->last_sent_date = now(); $purchase_order->saveQuietly(); - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'purchase_order', 'purchase_order'))->build()); - $nmo->company = $purchase_order->company; - $nmo->settings = $purchase_order->company->settings; - /* We loop through each user and determine whether they need to be notified */ foreach ($event->invitation->company->company_users as $company_user) { /* The User */ @@ -66,10 +61,16 @@ class PurchaseOrderEmailedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'purchase_order', 'purchase_order'))->build()); + $nmo->company = $purchase_order->company; + $nmo->settings = $purchase_order->company->settings; $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + $nmo = null; + /* This prevents more than one notification being sent */ $first_notification_sent = false; } diff --git a/app/Listeners/Quote/QuoteApprovedNotification.php b/app/Listeners/Quote/QuoteApprovedNotification.php index adedab41f90c..c6c0c61c8aa5 100644 --- a/app/Listeners/Quote/QuoteApprovedNotification.php +++ b/app/Listeners/Quote/QuoteApprovedNotification.php @@ -43,11 +43,7 @@ class QuoteApprovedNotification implements ShouldQueue $quote = $event->quote; - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new QuoteApprovedObject($quote, $event->company))->build()); - $nmo->company = $quote->company; - $nmo->settings = $quote->company->settings; - + /* We loop through each user and determine whether they need to be notified */ foreach ($event->company->company_users as $company_user) { /* The User */ @@ -64,10 +60,17 @@ class QuoteApprovedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new QuoteApprovedObject($quote, $event->company))->build()); + $nmo->company = $quote->company; + $nmo->settings = $quote->company->settings; + $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + $nmo = null; + /* This prevents more than one notification being sent */ $first_notification_sent = false; } diff --git a/app/Listeners/Quote/QuoteCreatedNotification.php b/app/Listeners/Quote/QuoteCreatedNotification.php index 5af1a1943e69..06b697e95930 100644 --- a/app/Listeners/Quote/QuoteCreatedNotification.php +++ b/app/Listeners/Quote/QuoteCreatedNotification.php @@ -44,11 +44,7 @@ class QuoteCreatedNotification implements ShouldQueue $quote = $event->quote; - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($quote, 'quote'))->build()); - $nmo->company = $quote->company; - $nmo->settings = $quote->company->settings; - + /* We loop through each user and determine whether they need to be notified */ foreach ($event->company->company_users as $company_user) { /* The User */ @@ -68,10 +64,17 @@ class QuoteCreatedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($quote, 'quote'))->build()); + $nmo->company = $quote->company; + $nmo->settings = $quote->company->settings; + $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + $nmo = null; + /* This prevents more than one notification being sent */ $first_notification_sent = false; } diff --git a/app/Listeners/Quote/QuoteEmailedNotification.php b/app/Listeners/Quote/QuoteEmailedNotification.php index 828941ced506..2a1c3788feb0 100644 --- a/app/Listeners/Quote/QuoteEmailedNotification.php +++ b/app/Listeners/Quote/QuoteEmailedNotification.php @@ -45,11 +45,6 @@ class QuoteEmailedNotification implements ShouldQueue $quote->last_sent_date = now(); $quote->saveQuietly(); - $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'quote', $event->template))->build()); - $nmo->company = $quote->company; - $nmo->settings = $quote->company->settings; - foreach ($event->invitation->company->company_users as $company_user) { $user = $company_user->user; @@ -58,9 +53,15 @@ class QuoteEmailedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'quote', $event->template))->build()); + $nmo->company = $quote->company; + $nmo->settings = $quote->company->settings; $nmo->to_user = $user; (new NinjaMailerJob($nmo))->handle(); + + $nmo = null; } } } diff --git a/app/Mail/Admin/EntityCreatedObject.php b/app/Mail/Admin/EntityCreatedObject.php index c75c3ec73316..df2463154ce5 100644 --- a/app/Mail/Admin/EntityCreatedObject.php +++ b/app/Mail/Admin/EntityCreatedObject.php @@ -70,7 +70,7 @@ class EntityCreatedObject ); $mail_obj->markdown = 'email.admin.generic'; - $mail_obj->tag = $this->company->company_key; + // $mail_obj->tag = $this->company->company_key; $mail_obj->data = [ 'title' => $mail_obj->subject, 'message' => ctrans( @@ -97,7 +97,7 @@ class EntityCreatedObject $mail_obj->subject = $this->getSubject(); $mail_obj->data = $this->getData(); $mail_obj->markdown = 'email.admin.generic'; - $mail_obj->tag = $this->entity->company->company_key; + // $mail_obj->tag = $this->entity->company->company_key; } return $mail_obj; diff --git a/app/Mail/Admin/EntityNotificationMailer.php b/app/Mail/Admin/EntityNotificationMailer.php index 7735e2ad5e4b..29b175426ba5 100644 --- a/app/Mail/Admin/EntityNotificationMailer.php +++ b/app/Mail/Admin/EntityNotificationMailer.php @@ -36,9 +36,6 @@ class EntityNotificationMailer extends Mailable { return $this->from(config('mail.from.address'), config('mail.from.name')) ->subject($this->mail_obj->subject) - ->markdown($this->mail_obj->markdown, $this->mail_obj->data) - ->withSymfonyMessage(function ($message) { - $message->getHeaders()->addTextHeader('Tag', $this->mail_obj->tag); - }); + ->markdown($this->mail_obj->markdown, $this->mail_obj->data); } } diff --git a/app/Mail/User/UserNotificationMailer.php b/app/Mail/User/UserNotificationMailer.php index 276a64191c94..0e5c13156daa 100644 --- a/app/Mail/User/UserNotificationMailer.php +++ b/app/Mail/User/UserNotificationMailer.php @@ -41,9 +41,6 @@ class UserNotificationMailer extends Mailable 'title' => $this->mail_obj->data['title'], 'body' => $this->mail_obj->data['message'], ]) - ->view($this->mail_obj->markdown, $this->mail_obj->data) - ->withSymfonyMessage(function ($message) { - $message->getHeaders()->addTextHeader('Tag', $this->mail_obj->tag); - }); + ->view($this->mail_obj->markdown, $this->mail_obj->data); } } diff --git a/app/Notifications/BaseNotification.php b/app/Notifications/BaseNotification.php deleted file mode 100644 index 6985f8c731ce..000000000000 --- a/app/Notifications/BaseNotification.php +++ /dev/null @@ -1,153 +0,0 @@ -line('The introduction to the notification.') - ->action('Notification Action', url('/')) - ->line('Thank you for using our application!'); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } - - public function buildMailMessageSettings(MailMessage $mail_message) :MailMessage - { - $mail_message->subject($this->generateEmailEntityHtml($this->entity, $this->subject, $this->contact)); - - if (strlen($this->settings->reply_to_email) > 1) { - $mail_message->replyTo($this->settings->reply_to_email); - } - - if (strlen($this->settings->bcc_email) > 1) { - $mail_message->bcc($this->settings->bcc_email); - } - - if ($this->settings->pdf_email_attachment) { - $mail_message->attach(TempFile::path($this->invitation->pdf_file_path()), ['as' => basename($this->invitation->pdf_file_path())]); - } - - foreach ($this->entity->documents as $document) { - $mail_message->attach(TempFile::path($document->generateUrl()), ['as' => $document->name]); - } - - if ($this->entity instanceof Invoice && $this->settings->ubl_email_attachment) { - $ubl_string = (new Createubl($this->entity))->handle(); - $mail_message->attachData($ubl_string, $this->entity->getFileName('xml')); - } - - return $mail_message->withSymfonyMessage(function ($message) { - $message->getHeaders()->addTextHeader('Tag', $this->invitation->company->company_key); - }); - } - - public function buildMailMessageData() :array - { - $body = $this->generateEmailEntityHtml($this->entity, $this->body, $this->contact); - - $design_style = $this->settings->email_style; - - if ($design_style == 'custom') { - $email_style_custom = $this->settings->email_style_custom; - $body = strtr($email_style_custom, "$body", $body); - } - - $data = [ - 'body' => $body, - 'design' => $design_style, - 'footer' => '', - 'title' => '', - 'company' => '', - 'view_link' => $this->invitation->getLink(), - 'view_text' => ctrans('texts.view_'.$this->entity_string), - 'logo' => $this->entity->company->present()->logo(), - 'signature' => $this->settings->email_signature, - 'settings' => $this->settings, - 'whitelabel' => $this->entity->company->account->isPaid() ? true : false, - ]; - - return $data; - } - - public function getTemplateView() - { - switch ($this->settings->email_style) { - case 'plain': - return 'email.template.plain'; - break; - case 'custom': - return 'email.template.custom'; - break; - case 'light': - return 'email.template.light'; - break; - case 'dark': - return 'email.template.dark'; - break; - default: - return 'email.admin.generic_email'; - break; - } - } -}