1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-18 09:04:35 +01:00
invoiceninja/app/Services/Credit/SendEmail.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2020-10-28 00:02:32 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-10-28 00:02:32 +01:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Credit;
use App\Helpers\Email\CreditEmail;
use App\Jobs\Credit\EmailCredit;
2020-11-25 15:19:52 +01:00
use App\Jobs\Entity\EmailEntity;
2020-10-28 00:02:32 +01:00
use App\Models\ClientContact;
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.
2020-10-28 11:10:49 +01:00
* @return void
2020-10-28 00:02:32 +01:00
*/
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);
2020-11-05 11:14:30 +01:00
EmailEntity::dispatchNow($invitation, $invitation->company, $this->reminder_template);
2020-10-28 00:02:32 +01:00
}
});
$this->credit->service()->markSent();
}
}