1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/app/Services/Credit/SendEmail.php
2020-10-28 10:02:32 +11:00

61 lines
1.6 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Credit;
use App\Helpers\Email\CreditEmail;
use App\Jobs\Entity\EmailEntity;
use App\Jobs\Credit\EmailCredit;
use App\Models\ClientContact;
use App\Models\Credit;
class SendEmail
{
public $credit;
protected $reminder_template;
protected $contact;
public function __construct($credit, $reminder_template = null, ClientContact $contact = null)
{
$this->credit = $credit;
$this->reminder_template = $reminder_template;
$this->contact = $contact;
}
/**
* Builds the correct template to send.
* @param string $this->reminder_template The template name ie reminder1
* @return array
*/
public function run()
{
if (! $this->reminder_template) {
$this->reminder_template = $this->credit->calculateTemplate('credit');
}
$this->credit->invitations->each(function ($invitation) {
if ($invitation->contact->send_email && $invitation->contact->email) {
$email_builder = (new CreditEmail())->build($invitation, $this->reminder_template);
// EmailCredit::dispatchNow($email_builder, $invitation, $invitation->company);
EmailEntity::dispatchNow($invitation, $invitation->company);
}
});
$this->credit->service()->markSent();
}
}