mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
* Working on emailing invoices * Working on emailing and displaying email * Working on emailing and displaying email * Email invoices * Fixes for html emails * Ensure valid client prior to store * Ensure client exists when storing an entity * Update variable name send -> send_email for client_contacts * Mailable download files * Extend timeouts of password protected routes when a protected route is hit * Add default portal design to company settings * Minor fixes * Fixes for Tests * Fixes for invoicing emails * Refactors for InvoiceEmail * Implement abstractservice * Refactors for services * Refactors for emails * Fixes for Invoice Emails
58 lines
1.5 KiB
PHP
58 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;
|
|
|
|
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 && $invitation->contact->email) {
|
|
EmailInvoice::dispatch($email_builder, $invitation, $invitation->company);
|
|
}
|
|
});
|
|
}
|
|
}
|