invoiceninja/app/Services/Quote/SendEmail.php

53 lines
1.3 KiB
PHP
Raw Normal View History

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