1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Services/Invoice/SendEmail.php
David Bomba d9d2e21f93
Subscriptions (#3682)
* Working on subscriptions

* Implement return type in models

* Subscription implementation

* Improvements to handling importation of large accountS

* Loggin imports

* Activate collector

* Improve memory usage of import script

* Quote actions

* Send Quotes

* Fixes for seg faults!

* Minor fixes

* Fixes for client contact scopes
2020-05-09 08:35:49 +10:00

59 lines
1.5 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\Invoice;
use App\Helpers\Email\InvoiceEmail;
use App\Jobs\Invoice\EmailInvoice;
use App\Models\ClientContact;
use App\Models\Invoice;
use App\Services\AbstractService;
use Illuminate\Support\Carbon;
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
* @param string $reminder_template The template name ie reminder1
* @return array
*/
public function run()
{
if (!$this->reminder_template) {
$this->reminder_template = $this->invoice->calculateTemplate();
}
$this->invoice->invitations->each(function ($invitation) {
$email_builder = (new InvoiceEmail())->build($invitation, $this->reminder_template);
if ($invitation->contact->send_email && $invitation->contact->email) {
EmailInvoice::dispatch($email_builder, $invitation, $invitation->company);
}
});
}
}