2020-02-15 10:01:15 +01:00
|
|
|
<?php
|
2020-07-01 03:06:40 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-07-01 03:06:40 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-07-01 03:06:40 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-07-01 03:06:40 +02:00
|
|
|
*/
|
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
namespace App\Services\Quote;
|
|
|
|
|
2020-10-28 00:02:32 +01:00
|
|
|
use App\Jobs\Entity\EmailEntity;
|
2020-05-09 00:35:49 +02:00
|
|
|
use App\Models\ClientContact;
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Builds the correct template to send.
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return void
|
2020-02-15 10:01:15 +01:00
|
|
|
*/
|
2020-08-19 04:55:58 +02:00
|
|
|
public function run()
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $this->reminder_template) {
|
2020-10-27 12:57:12 +01:00
|
|
|
$this->reminder_template = $this->quote->calculateTemplate('quote');
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->quote->invitations->each(function ($invitation) {
|
2021-10-05 06:20:44 +02:00
|
|
|
if (!$invitation->contact->trashed() && $invitation->contact->email) {
|
2020-11-05 11:14:30 +01:00
|
|
|
EmailEntity::dispatchNow($invitation, $invitation->company, $this->reminder_template);
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
});
|
2020-08-19 04:55:58 +02:00
|
|
|
|
|
|
|
$this->quote->service()->markSent();
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
}
|