mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 10:04:35 -04:00
Working on emails
This commit is contained in:
parent
dceff35f9a
commit
f6435ab030
@ -189,6 +189,7 @@ class CompanySettings extends BaseSettings
|
|||||||
public $enable_reminder1 = false;
|
public $enable_reminder1 = false;
|
||||||
public $enable_reminder2 = false;
|
public $enable_reminder2 = false;
|
||||||
public $enable_reminder3 = false;
|
public $enable_reminder3 = false;
|
||||||
|
public $enable_reminder_endless = false;
|
||||||
|
|
||||||
public $num_days_reminder1 = 0;
|
public $num_days_reminder1 = 0;
|
||||||
public $num_days_reminder2 = 0;
|
public $num_days_reminder2 = 0;
|
||||||
@ -256,6 +257,7 @@ class CompanySettings extends BaseSettings
|
|||||||
public $use_credits_payment = 'off'; //always, option, off
|
public $use_credits_payment = 'off'; //always, option, off
|
||||||
|
|
||||||
public static $casts = [
|
public static $casts = [
|
||||||
|
'enable_reminder_endless' => 'bool',
|
||||||
'use_credits_payment' => 'string',
|
'use_credits_payment' => 'string',
|
||||||
'recurring_invoice_number_pattern' => 'string',
|
'recurring_invoice_number_pattern' => 'string',
|
||||||
'recurring_invoice_number_counter' => 'int',
|
'recurring_invoice_number_counter' => 'int',
|
||||||
|
@ -20,26 +20,6 @@ class EmailBuilder
|
|||||||
public $view_link;
|
public $view_link;
|
||||||
public $view_text;
|
public $view_text;
|
||||||
|
|
||||||
private function parseTemplate(string $data, bool $is_markdown = true, $contact = null): string
|
|
||||||
{
|
|
||||||
//process variables
|
|
||||||
if (! empty($this->variables)) {
|
|
||||||
$data = str_replace(array_keys($this->variables), array_values($this->variables), $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
//process markdown
|
|
||||||
if ($is_markdown) {
|
|
||||||
$converter = new CommonMarkConverter([
|
|
||||||
'html_input' => 'allow',
|
|
||||||
'allow_unsafe_links' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$data = $converter->convertToHtml($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $footer
|
* @param $footer
|
||||||
* @return $this
|
* @return $this
|
||||||
|
@ -22,7 +22,7 @@ class InvoiceEmail extends EmailBuilder
|
|||||||
$contact = $invitation->contact;
|
$contact = $invitation->contact;
|
||||||
|
|
||||||
if (! $reminder_template) {
|
if (! $reminder_template) {
|
||||||
$reminder_template = $invoice->calculateTemplate();
|
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||||
}
|
}
|
||||||
|
|
||||||
$body_template = $client->getSetting('email_template_'.$reminder_template);
|
$body_template = $client->getSetting('email_template_'.$reminder_template);
|
||||||
|
@ -13,6 +13,7 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Helpers\Email\InvoiceEmail;
|
use App\Helpers\Email\InvoiceEmail;
|
||||||
use App\Http\Requests\Email\SendEmailRequest;
|
use App\Http\Requests\Email\SendEmailRequest;
|
||||||
|
use App\Jobs\Entity\EmailEntity;
|
||||||
use App\Jobs\Invoice\EmailInvoice;
|
use App\Jobs\Invoice\EmailInvoice;
|
||||||
use App\Jobs\Mail\EntitySentMailer;
|
use App\Jobs\Mail\EntitySentMailer;
|
||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
@ -116,9 +117,9 @@ class EmailController extends BaseController
|
|||||||
|
|
||||||
$entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj) {
|
$entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj) {
|
||||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||||
$when = now()->addSeconds(1);
|
|
||||||
|
|
||||||
$invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when));
|
EmailEntity::dispatchNow($invitation, $invitation->company);
|
||||||
|
//$invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ class PreviewController extends BaseController
|
|||||||
|
|
||||||
$entity_obj->load('client');
|
$entity_obj->load('client');
|
||||||
|
|
||||||
$html = new HtmlEngine(null, $entity_obj->invitations()->first(), request()->entity_type);
|
$html = new HtmlEngine($entity_obj->invitations()->first());
|
||||||
|
|
||||||
$design_namespace = 'App\Services\PdfMaker\Designs\\'.request()->design['name'];
|
$design_namespace = 'App\Services\PdfMaker\Designs\\'.request()->design['name'];
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ class PreviewController extends BaseController
|
|||||||
return response()->json(['message' => 'Invalid custom design object'], 400);
|
return response()->json(['message' => 'Invalid custom design object'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$html = new HtmlEngine(null, $invoice->invitations()->first(), 'invoice');
|
$html = new HtmlEngine($invoice->invitations()->first());
|
||||||
|
|
||||||
$design = new Design(Design::CUSTOM, ['custom_partials' => request()->design['design']]);
|
$design = new Design(Design::CUSTOM, ['custom_partials' => request()->design['design']]);
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class CreateEntityPdf implements ShouldQueue
|
|||||||
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
|
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
|
||||||
|
|
||||||
$design = Design::find($entity_design_id);
|
$design = Design::find($entity_design_id);
|
||||||
$html = new HtmlEngine(null, $this->invitation, $this->entity_string);
|
$html = new HtmlEngine($this->invitation);
|
||||||
|
|
||||||
if ($design->is_custom) {
|
if ($design->is_custom) {
|
||||||
$options = [
|
$options = [
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* @license https://opensource.org/licenses/AAL
|
* @license https://opensource.org/licenses/AAL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Jobs\Invoice;
|
namespace App\Jobs\Entity;
|
||||||
|
|
||||||
use App\DataMapper\Analytics\EmailInvoiceFailure;
|
use App\DataMapper\Analytics\EmailInvoiceFailure;
|
||||||
use App\Events\Invoice\InvoiceWasEmailed;
|
use App\Events\Invoice\InvoiceWasEmailed;
|
||||||
@ -26,6 +26,7 @@ use App\Models\InvoiceInvitation;
|
|||||||
use App\Models\QuoteInvitation;
|
use App\Models\QuoteInvitation;
|
||||||
use App\Models\RecurringInvoiceInvitation;
|
use App\Models\RecurringInvoiceInvitation;
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
|
use App\Utils\HtmlEngine;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -33,6 +34,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains;
|
use Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains;
|
||||||
use Turbo124\Beacon\Facades\LightLogs;
|
use Turbo124\Beacon\Facades\LightLogs;
|
||||||
|
|
||||||
@ -44,30 +46,43 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
|||||||
|
|
||||||
public $invitation;
|
public $invitation;
|
||||||
|
|
||||||
public $email_builder;
|
|
||||||
|
|
||||||
public $company;
|
public $company;
|
||||||
|
|
||||||
public $settings;
|
public $settings;
|
||||||
|
|
||||||
public $entity_string;
|
public $entity_string;
|
||||||
|
|
||||||
|
public $reminder_template;
|
||||||
|
|
||||||
|
public $entity;
|
||||||
|
|
||||||
|
public $html_engine;
|
||||||
|
|
||||||
|
public $email_entity_builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EmailEntity constructor.
|
* EmailEntity constructor.
|
||||||
* @param InvoiceEmail $email_builder
|
|
||||||
* @param Invitation $invitation
|
* @param Invitation $invitation
|
||||||
|
* @param Company $company
|
||||||
|
* @param ?string $reminder_template
|
||||||
*/
|
*/
|
||||||
public function __construct($email_builder, $invitation, Company $company)
|
public function __construct($invitation, Company $company, ?string $reminder_template = null)
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
|
|
||||||
$this->invitation = $invitation;
|
$this->invitation = $invitation;
|
||||||
|
|
||||||
$this->email_builder = $email_builder;
|
|
||||||
|
|
||||||
$this->settings = $invitation->contact->client->getMergedSettings();
|
$this->settings = $invitation->contact->client->getMergedSettings();
|
||||||
|
|
||||||
$this->entity_string = $this->resolveEntityString();
|
$this->entity_string = $this->resolveEntityString();
|
||||||
|
|
||||||
|
$this->entity = $invitation->{$this->entity_string};
|
||||||
|
|
||||||
|
$this->reminder_template = $reminder_template ?: $this->findReminderTemplate();
|
||||||
|
|
||||||
|
$this->html_engine = new HtmlEngine($invitation);
|
||||||
|
|
||||||
|
$this->email_entity_builder = $this->resolveEmailBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +93,7 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
info("email entity");
|
||||||
MultiDB::setDB($this->company->db);
|
MultiDB::setDB($this->company->db);
|
||||||
|
|
||||||
$this->setMailDriver();
|
$this->setMailDriver();
|
||||||
@ -87,7 +102,7 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
|||||||
Mail::to($this->invitation->contact->email, $this->invitation->contact->present()->name())
|
Mail::to($this->invitation->contact->email, $this->invitation->contact->present()->name())
|
||||||
->send(
|
->send(
|
||||||
new TemplateEmail(
|
new TemplateEmail(
|
||||||
$this->email_builder,
|
$this->email_entity_builder,
|
||||||
$this->invitation->contact->user,
|
$this->invitation->contact->user,
|
||||||
$this->invitation->contact->client
|
$this->invitation->contact->client
|
||||||
)
|
)
|
||||||
@ -97,13 +112,13 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count(Mail::failures()) > 0) {
|
if (count(Mail::failures()) > 0) {
|
||||||
$this->logMailError(Mail::failures(), $this->invoice->client);
|
$this->logMailError(Mail::failures(), $this->entity->client);
|
||||||
} else {
|
} else {
|
||||||
$this->entityEmailSucceeded();
|
$this->entityEmailSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark invoice sent */
|
/* Mark entity sent */
|
||||||
$this->invitation->invoice->service()->markSent()->save();
|
$this->entity->service()->markSent()->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function failed($exception = null)
|
public function failed($exception = null)
|
||||||
@ -111,7 +126,7 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
|||||||
info('the job failed');
|
info('the job failed');
|
||||||
|
|
||||||
$job_failure = new EmailInvoiceFailure();
|
$job_failure = new EmailInvoiceFailure();
|
||||||
$job_failure->string_metric5 = get_class($this);
|
$job_failure->string_metric5 = $this->entity_string;
|
||||||
$job_failure->string_metric6 = $exception->getMessage();
|
$job_failure->string_metric6 = $exception->getMessage();
|
||||||
|
|
||||||
LightLogs::create($job_failure)
|
LightLogs::create($job_failure)
|
||||||
@ -157,4 +172,16 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function findReminderTemplate()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveEmailBuilder()
|
||||||
|
{
|
||||||
|
$class = 'App\Mail\Engine\\' . ucfirst(Str::camel($this->entity_string)) . "EmailEngine";
|
||||||
|
|
||||||
|
return (new $class($this->invitation, $this->reminder_template))->build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
135
app/Mail/Engine/BaseEmailEngine.php
Normal file
135
app/Mail/Engine/BaseEmailEngine.php
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
<?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\Mail\Engine;
|
||||||
|
|
||||||
|
class BaseEmailEngine implements EngineInterface
|
||||||
|
{
|
||||||
|
public $footer;
|
||||||
|
|
||||||
|
public $variables;
|
||||||
|
|
||||||
|
public $contact;
|
||||||
|
|
||||||
|
public $subject;
|
||||||
|
|
||||||
|
public $body;
|
||||||
|
|
||||||
|
public $template_style;
|
||||||
|
|
||||||
|
public $attachments;
|
||||||
|
|
||||||
|
public $link;
|
||||||
|
|
||||||
|
public $text;
|
||||||
|
|
||||||
|
public function setFooter($footer)
|
||||||
|
{
|
||||||
|
$this->footer = $footer;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setVariables($variables)
|
||||||
|
{
|
||||||
|
$this->variables = $variables;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContact($contact)
|
||||||
|
{
|
||||||
|
$this->contact = $contact;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSubject($subject)
|
||||||
|
{
|
||||||
|
$this->subject = $subject;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBody($body)
|
||||||
|
{
|
||||||
|
$this->body = $body;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTemplate($template_style)
|
||||||
|
{
|
||||||
|
$this->template_style = $template_style;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAttachments($attachments)
|
||||||
|
{
|
||||||
|
$this->attachments = $attachments;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setViewLink($link)
|
||||||
|
{
|
||||||
|
$this->link = $link;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setViewText($text)
|
||||||
|
{
|
||||||
|
$this->text = $text;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSubject()
|
||||||
|
{
|
||||||
|
return $this->subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBody()
|
||||||
|
{
|
||||||
|
return $this->body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttachments()
|
||||||
|
{
|
||||||
|
return $this->attachments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFooter()
|
||||||
|
{
|
||||||
|
return $this->footer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
return $this->template_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getViewLink()
|
||||||
|
{
|
||||||
|
return $this->link;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getViewText()
|
||||||
|
{
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function build(){}
|
||||||
|
|
||||||
|
}
|
51
app/Mail/Engine/EngineInterface.php
Normal file
51
app/Mail/Engine/EngineInterface.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?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\Mail\Engine;
|
||||||
|
|
||||||
|
interface EngineInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setFooter($footer);
|
||||||
|
|
||||||
|
public function setVariables($variables);
|
||||||
|
|
||||||
|
public function setContact($contact);
|
||||||
|
|
||||||
|
public function setSubject($subject);
|
||||||
|
|
||||||
|
public function setBody($body);
|
||||||
|
|
||||||
|
public function setTemplate($template_style);
|
||||||
|
|
||||||
|
public function setAttachments($attachments);
|
||||||
|
|
||||||
|
public function setViewLink($link);
|
||||||
|
|
||||||
|
public function setViewText($text);
|
||||||
|
|
||||||
|
public function getSubject();
|
||||||
|
|
||||||
|
public function getBody();
|
||||||
|
|
||||||
|
public function getAttachments();
|
||||||
|
|
||||||
|
public function getFooter();
|
||||||
|
|
||||||
|
public function getTemplate();
|
||||||
|
|
||||||
|
public function getViewLink();
|
||||||
|
|
||||||
|
public function getViewText();
|
||||||
|
|
||||||
|
public function build();
|
||||||
|
|
||||||
|
}
|
90
app/Mail/Engine/InvoiceEmailEngine.php
Normal file
90
app/Mail/Engine/InvoiceEmailEngine.php
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?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\Mail\Engine;
|
||||||
|
|
||||||
|
use App\Utils\Number;
|
||||||
|
|
||||||
|
class InvoiceEmailEngine extends BaseEmailEngine
|
||||||
|
{
|
||||||
|
public $invitation;
|
||||||
|
|
||||||
|
public $client;
|
||||||
|
|
||||||
|
public $invoice;
|
||||||
|
|
||||||
|
public $contact;
|
||||||
|
|
||||||
|
public $reminder_template;
|
||||||
|
|
||||||
|
public function __construct($invitation, $reminder_template)
|
||||||
|
{
|
||||||
|
$this->invitation = $invitation;
|
||||||
|
$this->reminder_template = $reminder_template;
|
||||||
|
$this->client = $invitation->contact->client;
|
||||||
|
$this->invoice = $invitation->invoice;
|
||||||
|
$this->contact = $invitation->contact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function build()
|
||||||
|
{
|
||||||
|
|
||||||
|
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||||
|
|
||||||
|
/* Use default translations if a custom message has not been set*/
|
||||||
|
if (iconv_strlen($body_template) == 0) {
|
||||||
|
$body_template = trans(
|
||||||
|
'texts.invoice_message',
|
||||||
|
[
|
||||||
|
'invoice' => $this->invoice->number,
|
||||||
|
'company' => $this->invoice->company->present()->name(),
|
||||||
|
'amount' => Number::formatMoney($this->invoice->balance, $this->client),
|
||||||
|
],
|
||||||
|
null,
|
||||||
|
$this->client->locale()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||||
|
|
||||||
|
if (iconv_strlen($subject_template) == 0) {
|
||||||
|
|
||||||
|
$subject_template = trans(
|
||||||
|
'texts.invoice_subject',
|
||||||
|
[
|
||||||
|
'number' => $this->invoice->number,
|
||||||
|
'account' => $this->invoice->company->present()->name(),
|
||||||
|
],
|
||||||
|
null,
|
||||||
|
$this->client->locale()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setTemplate($this->client->getSetting('email_style'))
|
||||||
|
->setContact($this->contact)
|
||||||
|
->setVariables($this->invoice->makeValues($this->contact))//move make values into the htmlengine
|
||||||
|
->setSubject($subject_template)
|
||||||
|
->setBody($body_template)
|
||||||
|
->setFooter("<a href='{$this->invitation->getLink()}'>".ctrans('texts.view_invoice').'</a>')
|
||||||
|
->setViewLink($this->invitation->getLink())
|
||||||
|
->setViewText(ctrans('texts.view_invoice'));
|
||||||
|
|
||||||
|
if ($this->client->getSetting('pdf_email_attachment') !== false) {
|
||||||
|
$this->setAttachments($invitation->pdf_file_path());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -46,9 +46,7 @@ class TemplateEmail extends Mailable
|
|||||||
*/
|
*/
|
||||||
public function build()
|
public function build()
|
||||||
{
|
{
|
||||||
/*Alter Run Time Mailer configuration (driver etc etc) to regenerate the Mailer Singleton*/
|
|
||||||
|
|
||||||
//if using a system level template
|
|
||||||
$template_name = 'email.template.'.$this->build_email->getTemplate();
|
$template_name = 'email.template.'.$this->build_email->getTemplate();
|
||||||
|
|
||||||
$settings = $this->client->getMergedSettings();
|
$settings = $this->client->getMergedSettings();
|
||||||
|
@ -43,7 +43,7 @@ class SendEmail extends AbstractService
|
|||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
if (! $this->reminder_template) {
|
if (! $this->reminder_template) {
|
||||||
$this->reminder_template = $this->invoice->calculateTemplate();
|
$this->reminder_template = $this->invoice->calculateTemplate('invoice');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->invoice->invitations->each(function ($invitation) {
|
$this->invoice->invitations->each(function ($invitation) {
|
||||||
|
@ -65,7 +65,7 @@ class TriggeredActions extends AbstractService
|
|||||||
private function sendEmail()
|
private function sendEmail()
|
||||||
{
|
{
|
||||||
|
|
||||||
//$reminder_template = $this->invoice->calculateTemplate();
|
//$reminder_template = $this->invoice->calculateTemplate('invoice');
|
||||||
$reminder_template = 'payment';
|
$reminder_template = 'payment';
|
||||||
|
|
||||||
$this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($reminder_template) {
|
$this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($reminder_template) {
|
||||||
|
@ -41,7 +41,7 @@ class SendEmail
|
|||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
if (! $this->reminder_template) {
|
if (! $this->reminder_template) {
|
||||||
$this->reminder_template = $this->quote->calculateTemplate();
|
$this->reminder_template = $this->quote->calculateTemplate('quote');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->quote->invitations->each(function ($invitation) {
|
$this->quote->invitations->each(function ($invitation) {
|
||||||
|
@ -12,8 +12,11 @@
|
|||||||
|
|
||||||
namespace App\Utils;
|
namespace App\Utils;
|
||||||
|
|
||||||
use App\Designs\Designer;
|
|
||||||
use App\Models\Country;
|
use App\Models\Country;
|
||||||
|
use App\Models\CreditInvitation;
|
||||||
|
use App\Models\InvoiceInvitation;
|
||||||
|
use App\Models\QuoteInvitation;
|
||||||
|
use App\Models\RecurringInvoiceInvitation;
|
||||||
use App\Utils\Number;
|
use App\Utils\Number;
|
||||||
use App\Utils\Traits\MakesDates;
|
use App\Utils\Traits\MakesDates;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
@ -38,15 +41,14 @@ class HtmlEngine
|
|||||||
|
|
||||||
public $entity_string;
|
public $entity_string;
|
||||||
|
|
||||||
public $designer;
|
public function __construct($invitation)
|
||||||
|
|
||||||
public function __construct($designer, $invitation, $entity_string)
|
|
||||||
{
|
{
|
||||||
$this->designer = $designer;
|
|
||||||
|
|
||||||
$this->invitation = $invitation;
|
$this->invitation = $invitation;
|
||||||
|
|
||||||
$this->entity = $invitation->{$entity_string};
|
$this->entity_string = $this->resolveEntityString();
|
||||||
|
|
||||||
|
$this->entity = $invitation->{$this->entity_string};
|
||||||
|
|
||||||
$this->company = $invitation->company;
|
$this->company = $invitation->company;
|
||||||
|
|
||||||
@ -58,34 +60,32 @@ class HtmlEngine
|
|||||||
|
|
||||||
$this->entity_calc = $this->entity->calc();
|
$this->entity_calc = $this->entity->calc();
|
||||||
|
|
||||||
$this->entity_string = $entity_string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function build() :string
|
|
||||||
{
|
|
||||||
App::setLocale($this->client->preferredLocale());
|
|
||||||
|
|
||||||
$values_and_labels = $this->generateLabelsAndValues();
|
|
||||||
|
|
||||||
$this->designer->build();
|
|
||||||
|
|
||||||
$data = [];
|
|
||||||
$data['entity'] = $this->entity;
|
|
||||||
$data['lang'] = $this->client->preferredLocale();
|
|
||||||
$data['includes'] = $this->designer->getIncludes();
|
|
||||||
$data['header'] = $this->designer->getHeader();
|
|
||||||
$data['body'] = $this->designer->getBody();
|
|
||||||
$data['footer'] = $this->designer->getFooter();
|
|
||||||
|
|
||||||
$html = view('pdf.stub', $data)->render();
|
|
||||||
|
|
||||||
$html = $this->parseLabelsAndValues($values_and_labels['labels'], $values_and_labels['values'], $html);
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private function resolveEntityString()
|
||||||
|
{
|
||||||
|
switch ($this->invitation) {
|
||||||
|
case ($this->invitation instanceof InvoiceInvitation):
|
||||||
|
return 'invoice';
|
||||||
|
break;
|
||||||
|
case ($this->invitation instanceof CreditInvitation):
|
||||||
|
return 'credit';
|
||||||
|
break;
|
||||||
|
case ($this->invitation instanceof QuoteInvitation):
|
||||||
|
return 'quote';
|
||||||
|
break;
|
||||||
|
case ($this->invitation instanceof RecurringInvoiceInvitation):
|
||||||
|
return 'recurring_invoice';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function buildEntityDataArray() :array
|
public function buildEntityDataArray() :array
|
||||||
{
|
{
|
||||||
if (! $this->client->currency()) {
|
if (! $this->client->currency()) {
|
||||||
|
@ -100,7 +100,7 @@ class Phantom
|
|||||||
$design_id = $entity_obj->design_id ? $entity_obj->design_id : $this->decodePrimaryKey($entity_obj->client->getSetting($entity_design_id));
|
$design_id = $entity_obj->design_id ? $entity_obj->design_id : $this->decodePrimaryKey($entity_obj->client->getSetting($entity_design_id));
|
||||||
|
|
||||||
$design = Design::find($design_id);
|
$design = Design::find($design_id);
|
||||||
$html = new HtmlEngine(null, $invitation, $entity);
|
$html = new HtmlEngine($invitation);
|
||||||
|
|
||||||
if ($design->is_custom) {
|
if ($design->is_custom) {
|
||||||
$options = [
|
$options = [
|
||||||
|
@ -33,7 +33,7 @@ trait InvoiceEmailBuilder
|
|||||||
//$client = $this->client;
|
//$client = $this->client;
|
||||||
|
|
||||||
if (! $reminder_template) {
|
if (! $reminder_template) {
|
||||||
$reminder_template = $this->calculateTemplate();
|
$reminder_template = $this->calculateTemplate('invoice');
|
||||||
}
|
}
|
||||||
|
|
||||||
//Need to determine which email template we are producing
|
//Need to determine which email template we are producing
|
||||||
@ -78,8 +78,6 @@ trait InvoiceEmailBuilder
|
|||||||
{
|
{
|
||||||
$invoice_variables = $this->makeValues($contact);
|
$invoice_variables = $this->makeValues($contact);
|
||||||
|
|
||||||
//process variables
|
|
||||||
// $data = str_replace(array_keys($invoice_variables), array_values($invoice_variables), $template_data);
|
|
||||||
$data = strtr($template_data, $invoice_variables);
|
$data = strtr($template_data, $invoice_variables);
|
||||||
|
|
||||||
//process markdown
|
//process markdown
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Utils\Traits;
|
namespace App\Utils\Traits;
|
||||||
|
|
||||||
|
use App\Models\RecurringInvoice;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,7 +182,7 @@ trait MakesReminders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function calculateTemplate(): string
|
public function calculateTemplate(string $entity_string): string
|
||||||
{
|
{
|
||||||
//if invoice is currently a draft, or being marked as sent, this will be the initial email
|
//if invoice is currently a draft, or being marked as sent, this will be the initial email
|
||||||
$client = $this->client;
|
$client = $this->client;
|
||||||
@ -202,10 +203,58 @@ trait MakesReminders
|
|||||||
$client->getSetting('num_days_reminder3')
|
$client->getSetting('num_days_reminder3')
|
||||||
)) {
|
)) {
|
||||||
return 'reminder3';
|
return 'reminder3';
|
||||||
} else {
|
} elseif($client->getSetting('enable_reminder_endless') !== false && $this->checkEndlessReminder(
|
||||||
return 'invoice';
|
$this->last_sent_date,
|
||||||
|
$client->getSetting('endless_reminder_frequency_id')
|
||||||
|
)){
|
||||||
|
return 'endless_reminder';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $entity_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
//also implement endless reminders here
|
//also implement endless reminders here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function checkEndlessReminder($last_sent_date, $endless_reminder_frequency_id) :bool
|
||||||
|
{
|
||||||
|
if(Carbon::now()->startOfDay()->eq($this->addTimeInterval($endless_reminder_frequency_id)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addTimeInterval($endless_reminder_frequency_id) :?Carbon
|
||||||
|
{
|
||||||
|
if(!$this->next_send_date){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($endless_reminder_frequency_id) {
|
||||||
|
case RecurringInvoice::FREQUENCY_WEEKLY:
|
||||||
|
return Carbon::parse($this->next_send_date)->addWeek()->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_TWO_WEEKS:
|
||||||
|
return Carbon::parse($this->next_send_date)->addWeeks(2)->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
|
||||||
|
return Carbon::parse($this->next_send_date)->addWeeks(4)->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_MONTHLY:
|
||||||
|
return Carbon::parse($this->next_send_date)->addMonthNoOverflow()->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_TWO_MONTHS:
|
||||||
|
return Carbon::parse($this->next_send_date)->addMonthsNoOverflow(2)->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_THREE_MONTHS:
|
||||||
|
return Carbon::parse($this->next_send_date)->addMonthsNoOverflow(3)->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
|
||||||
|
return Carbon::parse($this->next_send_date)->addMonthsNoOverflow(4)->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_SIX_MONTHS:
|
||||||
|
return Carbon::parse($this->next_send_date)->addMonthsNoOverflow(6)->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_ANNUALLY:
|
||||||
|
return Carbon::parse($this->next_send_date)->addYear()->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_TWO_YEARS:
|
||||||
|
return Carbon::parse($this->next_send_date)->addYears(2)->startOfDay();
|
||||||
|
case RecurringInvoice::FREQUENCY_THREE_YEARS:
|
||||||
|
return Carbon::parse($this->next_send_date)->addYears(3)->startOfDay();
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ trait QuoteEmailBuilder
|
|||||||
//$client = $this->client;
|
//$client = $this->client;
|
||||||
|
|
||||||
if (! $reminder_template) {
|
if (! $reminder_template) {
|
||||||
$reminder_template = $this->calculateTemplate();
|
$reminder_template = $this->calculateTemplate('quote');
|
||||||
}
|
}
|
||||||
|
|
||||||
//Need to determine which email template we are producing
|
//Need to determine which email template we are producing
|
||||||
|
1254
composer.lock
generated
1254
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -37,7 +37,7 @@ class ExampleIntegrationTest extends TestCase
|
|||||||
$invoice = $this->invoice;
|
$invoice = $this->invoice;
|
||||||
$invitation = $invoice->invitations()->first();
|
$invitation = $invoice->invitations()->first();
|
||||||
|
|
||||||
$engine = new HtmlEngine(null, $invitation, 'invoice');
|
$engine = new HtmlEngine($invitation);
|
||||||
|
|
||||||
$design = new Design(
|
$design = new Design(
|
||||||
Design::CLEAN
|
Design::CLEAN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user