From f21444be90b23b7ee8d7caaacf99b80447c1365e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 7 Sep 2023 12:07:46 +1000 Subject: [PATCH] Add events for email notifications --- app/Mail/Admin/EntitySentObject.php | 6 +++--- app/Services/Credit/SendEmail.php | 11 +++++++++-- app/Services/Quote/SendEmail.php | 10 ++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/Mail/Admin/EntitySentObject.php b/app/Mail/Admin/EntitySentObject.php index da2c1030fbc1..e1ae21c90de9 100644 --- a/app/Mail/Admin/EntitySentObject.php +++ b/app/Mail/Admin/EntitySentObject.php @@ -73,7 +73,7 @@ class EntitySentObject ); $mail_obj->data = [ 'title' => $mail_obj->subject, - 'message' => ctrans( + 'content' => ctrans( $this->template_body, [ 'amount' => $mail_obj->amount, @@ -98,7 +98,7 @@ class EntitySentObject $mail_obj->markdown = 'email.admin.generic'; $mail_obj->tag = $this->company->company_key; } - + nlog($mail_obj); return $mail_obj; } @@ -186,7 +186,7 @@ class EntitySentObject return [ 'title' => $this->getSubject(), - 'message' => $this->getMessage(), + 'content' => $this->getMessage(), 'url' => $this->invitation->getAdminLink($this->use_react_url), 'button' => ctrans("texts.view_{$this->entity_type}"), 'signature' => $settings->email_signature, diff --git a/app/Services/Credit/SendEmail.php b/app/Services/Credit/SendEmail.php index 40ce3240f438..f17f5f902dc7 100644 --- a/app/Services/Credit/SendEmail.php +++ b/app/Services/Credit/SendEmail.php @@ -11,8 +11,10 @@ namespace App\Services\Credit; -use App\Jobs\Entity\EmailEntity; +use App\Utils\Ninja; use App\Models\ClientContact; +use App\Jobs\Entity\EmailEntity; +use App\Events\Credit\CreditWasEmailed; class SendEmail { @@ -40,12 +42,17 @@ class SendEmail $this->reminder_template = $this->credit->calculateTemplate('credit'); } + $this->credit->service()->markSent()->save(); + $this->credit->invitations->each(function ($invitation) { if (! $invitation->contact->trashed() && $invitation->contact->email) { EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template)->delay(2); } }); - $this->credit->service()->markSent()->save(); + if ($this->credit->invitations->count() >= 1) { + event(new CreditWasEmailed($this->credit->invitations->first(), $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), 'credit')); + } + } } diff --git a/app/Services/Quote/SendEmail.php b/app/Services/Quote/SendEmail.php index 445d321ff97c..d157792aa0c6 100644 --- a/app/Services/Quote/SendEmail.php +++ b/app/Services/Quote/SendEmail.php @@ -11,8 +11,10 @@ namespace App\Services\Quote; -use App\Jobs\Entity\EmailEntity; +use App\Utils\Ninja; use App\Models\ClientContact; +use App\Jobs\Entity\EmailEntity; +use App\Events\Quote\QuoteWasEmailed; class SendEmail { @@ -42,15 +44,15 @@ class SendEmail $this->reminder_template = $this->quote->calculateTemplate('quote'); } - $this->quote->service()->markSent()->save(); $this->quote->invitations->each(function ($invitation) { if (! $invitation->contact->trashed() && $invitation->contact->email) { EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template); - - // MailEntity::dispatch($invitation, $invitation->company->db, $mo); } }); + + + } }