1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for previewing email templates

This commit is contained in:
David Bomba 2020-09-17 08:22:23 +10:00
parent 03e9bf0bc7
commit 6a0f958c2e
4 changed files with 21 additions and 4 deletions

View File

@ -237,6 +237,7 @@ class HtmlEngine
$data['$client.email'] = &$data['$email'];
$data['$client.balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];
$data['$client_balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];
$data['$paid_to_date'] = ['value' => Number::formatMoney($this->client->paid_to_date, $this->client), 'label' => ctrans('texts.paid_to_date')];
$data['$contact.full_name'] = ['value' => $this->contact->present()->name(), 'label' => ctrans('texts.name')];

View File

@ -88,12 +88,23 @@ class TemplateEngine
private function setTemplates()
{
if (strlen($this->subject) == 0 && strlen($this->template) > 1) {
$subject_template = str_replace('template', 'subject', $this->template);
$this->subject = EmailTemplateDefaults::getDefaultTemplate($subject_template, $this->settings_entity->locale());
if(strlen($this->settings_entity->getSetting($subject_template)) > 1)
$this->subject = $this->settings_entity->getSetting($subject_template);
else
$this->subject = EmailTemplateDefaults::getDefaultTemplate($subject_template, $this->settings_entity->locale());
}
if (strlen($this->body) == 0 && strlen($this->template) > 1) {
$this->body = EmailTemplateDefaults::getDefaultTemplate($this->template, $this->settings_entity->locale());
if(strlen($this->settings_entity->getSetting($this->template)) > 1)
$this->body = $this->settings_entity->getSetting($this->template);
else
$this->body = EmailTemplateDefaults::getDefaultTemplate($this->template, $this->settings_entity->locale());
}
return $this;
@ -131,9 +142,12 @@ class TemplateEngine
private function entityValues($contact)
{
$data = $this->entity_obj->buildLabelsAndValues($contact);
// $arrKeysLength = array_map('strlen', array_keys($data));
// array_multisort($arrKeysLength, SORT_DESC, $data);
$this->body = strtr($this->body, $data['labels']);
$this->body = strtr($this->body, $data['values']);
$this->body = str_replace("\n", "<br>", $this->body);
$this->subject = strtr($this->subject, $data['labels']);
$this->subject = strtr($this->subject, $data['values']);

View File

@ -313,8 +313,9 @@ trait MakesInvoiceValues
$data['$email'] = ['value' => isset($contact) ? $contact->email : 'no contact email on record', 'label' => ctrans('texts.email')];
$data['$client_name'] = ['value' => $this->present()->clientName() ?: '&nbsp;', 'label' => ctrans('texts.client_name')];
$data['$client.name'] = &$data['$client_name'];
$data['$client.balance'] = ['value' => $this->client->balance, 'label' => ctrans('texts.balance')];
$data['$client.balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];
$data['$client_balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];
$data['$paid_to_date'] = ['value' => $this->client->paid_to_date, 'label' => ctrans('texts.paid_to_date')];
$data['$client.address1'] = &$data['$address1'];

View File

@ -135,6 +135,7 @@ trait MakesTemplateData
$data['$country'] = ['value' => 'USA', 'label' => ctrans('texts.country')];
$data['$email'] = ['value' => 'user@example.com', 'label' => ctrans('texts.email')];
$data['$client_name'] = ['value' => 'Joe Denkins', 'label' => ctrans('texts.client_name')];
$data['$client.balance'] = ['value' => '$100', 'label' => ctrans('texts.account_balance')];
$data['$client.name'] = &$data['$client_name'];
$data['$client.address1'] = &$data['$address1'];
$data['$client.address2'] = &$data['$address2'];