mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 05:32:39 +01:00
f7650d0692
* 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>
41 lines
1.1 KiB
PHP
41 lines
1.1 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();
|
|
}
|
|
|
|
$email_builder = (new QuoteEmail())->build($this->quote, $reminder_template, $contact);
|
|
|
|
$this->quote->invitations->each(function ($invitation) use ($email_builder) {
|
|
if ($invitation->contact->send_invoice && $invitation->contact->email) {
|
|
EmailQuote::dispatchNow($email_builder, $invitation);
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
}
|