1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Services/Invoice/SendEmail.php

53 lines
1.4 KiB
PHP
Raw Normal View History

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