2020-02-15 10:01:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Quote;
|
|
|
|
|
|
|
|
use App\Helpers\Email\QuoteEmail;
|
|
|
|
use App\Jobs\Quote\EmailQuote;
|
2020-05-09 00:35:49 +02:00
|
|
|
use App\Models\ClientContact;
|
2020-02-15 10:01:15 +01:00
|
|
|
use App\Models\Quote;
|
|
|
|
|
|
|
|
class SendEmail
|
|
|
|
{
|
|
|
|
public $quote;
|
|
|
|
|
2020-05-09 00:35:49 +02:00
|
|
|
protected $reminder_template;
|
|
|
|
|
|
|
|
protected $contact;
|
|
|
|
|
|
|
|
public function __construct($quote, $reminder_template = null, ClientContact $contact = null)
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
|
|
|
$this->quote = $quote;
|
2020-05-09 00:35:49 +02:00
|
|
|
|
|
|
|
$this->reminder_template = $reminder_template;
|
|
|
|
|
|
|
|
$this->contact = $contact;
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the correct template to send
|
2020-05-09 00:35:49 +02:00
|
|
|
* @param string $this->reminder_template The template name ie reminder1
|
2020-02-15 10:01:15 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2020-05-09 00:35:49 +02:00
|
|
|
public function run(): array
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-05-09 00:35:49 +02:00
|
|
|
if (!$this->reminder_template) {
|
|
|
|
$this->reminder_template = $this->quote->calculateTemplate();
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->quote->invitations->each(function ($invitation) {
|
2020-04-30 13:45:47 +02:00
|
|
|
if ($invitation->contact->send_email && $invitation->contact->email) {
|
2020-05-09 00:35:49 +02:00
|
|
|
$email_builder = (new QuoteEmail())->build($invitation, $this->reminder_template);
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
EmailQuote::dispatchNow($email_builder, $invitation);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|