From 0d11fc174a04700cb941ed158a9fdf989b607396 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 20 Jan 2023 17:18:53 +1100 Subject: [PATCH] Send payment emails to all contacts on invitation --- app/Services/Payment/SendEmail.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Services/Payment/SendEmail.php b/app/Services/Payment/SendEmail.php index 828023381385..93d5b03fc817 100644 --- a/app/Services/Payment/SendEmail.php +++ b/app/Services/Payment/SendEmail.php @@ -32,12 +32,27 @@ class SendEmail */ public function run() { - $this->payment->load('company', 'client.contacts'); + $this->payment->load('company', 'client.contacts','invoices'); $contact = $this->payment->client->contacts()->first(); - if ($contact?->email) - EmailPayment::dispatch($this->payment, $this->payment->company, $contact)->delay(now()->addSeconds(8)); + // if ($contact?->email) + // EmailPayment::dispatch($this->payment, $this->payment->company, $contact)->delay(now()->addSeconds(2)); + + + $this->payment->invoices->sortByDesc('id')->first(function ($invoice){ + + $invoice->invitations->each(function ($invitation) { + + if(!$invitation->contact->trashed() && $invitation->contact->email) { + + EmailPayment::dispatch($this->payment, $this->payment->company, $invitation->contact)->delay(now()->addSeconds(2)); + + } + + }); + + }); } }