2020-02-15 10:01:15 +01:00
|
|
|
<?php
|
2020-02-15 10:06:30 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
namespace App\Services\Invoice;
|
|
|
|
|
|
|
|
use App\Helpers\Email\InvoiceEmail;
|
|
|
|
use App\Jobs\Invoice\EmailInvoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Models\ClientContact;
|
2020-02-15 10:01:15 +01:00
|
|
|
use App\Models\Invoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Services\AbstractService;
|
2020-02-15 10:01:15 +01:00
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
class SendEmail extends AbstractService
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-02-15 10:06:30 +01:00
|
|
|
protected $invoice;
|
2020-02-15 10:01:15 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
public function __construct(Invoice $invoice, $reminder_template = null, ClientContact $contact = null)
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
|
|
|
$this->invoice = $invoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
|
|
|
|
$this->reminder_template = $reminder_template;
|
|
|
|
|
|
|
|
$this->contact = $contact;
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
2020-02-15 10:06:30 +01:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
/**
|
|
|
|
* Builds the correct template to send
|
|
|
|
* @param string $reminder_template The template name ie reminder1
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-02-17 10:37:44 +01:00
|
|
|
public function run()
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-02-17 10:37:44 +01:00
|
|
|
if (!$this->reminder_template) {
|
|
|
|
$this->reminder_template = $this->invoice->calculateTemplate();
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->invoice->invitations->each(function ($invitation) {
|
2020-02-17 10:37:44 +01:00
|
|
|
$email_builder = (new InvoiceEmail())->build($invitation, $this->reminder_template);
|
2020-02-15 10:01:15 +01:00
|
|
|
|
2020-04-30 13:45:47 +02:00
|
|
|
if ($invitation->contact->send_email && $invitation->contact->email) {
|
2020-02-15 13:27:24 +01:00
|
|
|
EmailInvoice::dispatch($email_builder, $invitation, $invitation->company);
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|