mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
* Emails * change to user service * refactor emails * refactor emails * refactor emails * refactor emails * emails * emails * emails * emails * emails * emails * emails * emails * emails * emails * Update EmailPayment.php * Update SendEmail.php * Update SendEmail.php * Update SendEmail.php * Update and rename BuildEmail.php to EmailBuilder.php * Create InvoiceEmail * Create QuoteEmail.php * Rename InvoiceEmail to InvoiceEmail.php * Create PaymentEmail.php * Update SendEmail.php * Update SendEmail.php * Update SendEmail.php * Update SendEmail.php * Update InvoiceEmail.php * Update EmailInvoice.php * Update SendEmail.php * Update TemplateEmail.php * Update EmailBuilder.php * Update InvoiceEmail.php * Update QuoteEmail.php * Update PaymentEmail.php * Update InvoiceEmail.php * Update QuoteEmail.php * Update QuoteInvitation.php * Update EmailQuote.php * Update SendEmail.php * Update SendEmail.php * Update PaymentService.php * Update PaymentEmail.php * Update PaymentEmail.php * Update PaymentEmail.php * Update EmailBuilder.php * Update PaymentEmail.php * Update EmailPayment.php * Update SendEmail.php * Update InvoiceService.php * Update SendEmail.php * Update PaymentService.php * Update SendEmail.php * Update QuoteService.php * Update EmailPayment.php Co-authored-by: David Bomba <turbo124@gmail.com>
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Invoice;
|
|
|
|
use App\Helpers\Email\InvoiceEmail;
|
|
use App\Jobs\Invoice\EmailInvoice;
|
|
use App\Models\Invoice;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class SendEmail
|
|
{
|
|
|
|
public $invoice;
|
|
|
|
public function __construct($invoice)
|
|
{
|
|
$this->invoice = $invoice;
|
|
}
|
|
|
|
/**
|
|
* Builds the correct template to send
|
|
* @param string $reminder_template The template name ie reminder1
|
|
* @return array
|
|
*/
|
|
public function run($reminder_template = null, $contact = null): array
|
|
{
|
|
if (!$reminder_template) {
|
|
$reminder_template = $this->invoice->status_id == Invoice::STATUS_DRAFT || Carbon::parse($this->invoice->due_date) > now() ? 'invoice' : $this->invoice->calculateTemplate();
|
|
}
|
|
|
|
$email_builder = (new InvoiceEmail())->build($this->invoice, $reminder_template, $contact);
|
|
|
|
$this->invoice->invitations->each(function ($invitation) use ($email_builder) {
|
|
if ($invitation->contact->send_invoice && $invitation->contact->email) {
|
|
EmailInvoice::dispatchNow($email_builder, $invitation);
|
|
}
|
|
});
|
|
}
|
|
}
|