1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Services/Invoice/SendEmail.php
2023-06-03 22:49:48 +10:00

41 lines
1.1 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Invoice;
use App\Jobs\Entity\EmailEntity;
use App\Models\ClientContact;
use App\Models\Invoice;
use App\Services\AbstractService;
class SendEmail extends AbstractService
{
public function __construct(protected Invoice $invoice, protected $reminder_template = null, protected ?ClientContact $contact = null)
{
}
/**
* Builds the correct template to send.
*/
public function run()
{
if (! $this->reminder_template) {
$this->reminder_template = $this->invoice->calculateTemplate('invoice');
}
$this->invoice->invitations->each(function ($invitation) {
if (! $invitation->contact->trashed() && $invitation->contact->email) {
EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template)->delay(10);
}
});
}
}