2020-02-15 10:01:15 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: michael.hampton
|
|
|
|
* Date: 14/02/2020
|
|
|
|
* Time: 19:51
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Helpers\Email;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Models\InvoiceInvitation;
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
class InvoiceEmail extends EmailBuilder
|
|
|
|
{
|
2020-02-15 12:49:31 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
public function build(InvoiceInvitation $invitation, $reminder_template)
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-02-17 10:37:44 +01:00
|
|
|
$client = $invitation->contact->client;
|
|
|
|
$invoice = $invitation->invoice;
|
|
|
|
$contact = $invitation->contact;
|
2020-02-15 10:01:15 +01:00
|
|
|
|
2020-02-15 12:49:31 +01:00
|
|
|
if(!$reminder_template)
|
|
|
|
$reminder_template = $invoice->calculateTemplate();
|
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
$body_template = $client->getSetting('email_template_' . $reminder_template);
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
/* Use default translations if a custom message has not been set*/
|
|
|
|
if (iconv_strlen($body_template) == 0) {
|
|
|
|
$body_template = trans('texts.invoice_message',
|
2020-02-17 10:37:44 +01:00
|
|
|
['invoice' => $invoice->number, 'company' => $invoice->company->present()->name()], null,
|
2020-02-15 10:01:15 +01:00
|
|
|
$invoice->client->locale());
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject_template = $client->getSetting('email_subject_' . $reminder_template);
|
|
|
|
|
|
|
|
if (iconv_strlen($subject_template) == 0) {
|
|
|
|
if ($reminder_template == 'quote') {
|
|
|
|
$subject_template = trans('texts.invoice_subject',
|
|
|
|
[
|
2020-02-17 10:37:44 +01:00
|
|
|
'invoice' => $invoice->present()->invoice_number(),
|
|
|
|
'account' => $invoice->company->present()->name()
|
2020-02-15 10:01:15 +01:00
|
|
|
],
|
|
|
|
null, $invoice->client->locale());
|
|
|
|
} else {
|
|
|
|
$subject_template = trans('texts.reminder_subject',
|
|
|
|
[
|
2020-02-17 10:37:44 +01:00
|
|
|
'invoice' => $invoice->present()->invoice_number(),
|
|
|
|
'account' => $invoice->company->present()->name()
|
2020-02-15 10:01:15 +01:00
|
|
|
],
|
|
|
|
null, $invoice->client->locale());
|
|
|
|
}
|
|
|
|
}
|
2020-02-17 10:37:44 +01:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
$this->setTemplate($invoice->client->getSetting('email_style'))
|
|
|
|
->setContact($contact)
|
|
|
|
->setVariables($invoice->makeValues($contact))
|
|
|
|
->setSubject($subject_template)
|
|
|
|
->setBody($body_template)
|
2020-02-17 10:37:44 +01:00
|
|
|
->setFooter("<a href='{$invitation->getLink()}'>{$invitation->getLink()}</a>");
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
if ($client->getSetting('pdf_email_attachment') !== false) {
|
|
|
|
$this->setAttachments($invoice->pdf_file_path());
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|