1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00
invoiceninja/app/Services/Quote/SendEmail.php
David Bomba f57339f185
Fixes and Refactors for Invoice Emails. (#3339)
* 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
2020-02-17 20:37:44 +11:00

44 lines
1.0 KiB
PHP

<?php
namespace App\Services\Quote;
use App\Helpers\Email\QuoteEmail;
use App\Jobs\Quote\EmailQuote;
use App\Models\Quote;
class SendEmail
{
public $quote;
public function __construct($quote)
{
$this->quote = $quote;
}
/**
* 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->quote->status_id == Quote::STATUS_DRAFT || Carbon::parse($this->quote->due_date) > now() ? 'invoice' : $this->quote->calculateTemplate();
}
$this->quote->invitations->each(function ($invitation){
if ($invitation->contact->send && $invitation->contact->email)
{
$email_builder = (new QuoteEmail())->build($invitation, $reminder_template);
EmailQuote::dispatchNow($email_builder, $invitation);
}
});
}
}