From 3a57185e8bdb1ba08098a1ff88b08ee62631d121 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sat, 2 Sep 2017 22:03:45 +0300 Subject: [PATCH] Confusing quote/invoice due amount in emails #1571 --- app/Constants.php | 10 ++++-- app/Http/Controllers/AccountController.php | 7 ++-- app/Models/AccountEmailSettings.php | 10 ++++++ app/Models/Traits/SendsEmails.php | 7 +++- app/Ninja/Presenters/InvoicePresenter.php | 8 +++++ app/Services/TemplateService.php | 2 ++ resources/lang/en/texts.php | 4 +-- .../templates_and_reminders.blade.php | 6 ++-- .../views/partials/email_templates.blade.php | 36 ++++++++++--------- 9 files changed, 61 insertions(+), 29 deletions(-) diff --git a/app/Constants.php b/app/Constants.php index 1cb133869d66..5c802ac0ea16 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -416,9 +416,13 @@ if (! defined('APP_NAME')) { define('GATEWAY_TYPE_CUSTOM', 6); define('GATEWAY_TYPE_TOKEN', 'token'); - define('REMINDER1', 'reminder1'); - define('REMINDER2', 'reminder2'); - define('REMINDER3', 'reminder3'); + define('TEMPLATE_INVOICE', 'invoice'); + define('TEMPLATE_QUOTE', 'quote'); + define('TEMPLATE_PARTIAL', 'partial'); + define('TEMPLATE_PAYMENT', 'payment'); + define('TEMPLATE_REMINDER1', 'reminder1'); + define('TEMPLATE_REMINDER2', 'reminder2'); + define('TEMPLATE_REMINDER3', 'reminder3'); define('RESET_FREQUENCY_DAILY', 1); define('RESET_FREQUENCY_WEEKLY', 2); diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 7a43000b6346..8f2a0500e3a3 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -20,6 +20,7 @@ use App\Models\PaymentTerm; use App\Models\Product; use App\Models\TaxRate; use App\Models\User; +use App\Models\AccountEmailSettings; use App\Ninja\Mailers\ContactMailer; use App\Ninja\Mailers\UserMailer; use App\Ninja\Repositories\AccountRepository; @@ -653,7 +654,7 @@ class AccountController extends BaseController $data['account'] = $account; $data['templates'] = []; $data['defaultTemplates'] = []; - foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_PAYMENT, REMINDER1, REMINDER2, REMINDER3] as $type) { + foreach (AccountEmailSettings::$templates as $type) { $data['templates'][$type] = [ 'subject' => $account->getEmailSubject($type), 'template' => $account->getEmailTemplate($type), @@ -800,7 +801,7 @@ class AccountController extends BaseController if (Auth::user()->account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) { $account = Auth::user()->account; - foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_PAYMENT, REMINDER1, REMINDER2, REMINDER3] as $type) { + foreach (AccountEmailSettings::$templates as $type) { $subjectField = "email_subject_{$type}"; $subject = Input::get($subjectField, $account->getEmailSubject($type)); $account->account_email_settings->$subjectField = ($subject == $account->getDefaultEmailSubject($type) ? null : $subject); @@ -810,7 +811,7 @@ class AccountController extends BaseController $account->account_email_settings->$bodyField = ($body == $account->getDefaultEmailTemplate($type) ? null : $body); } - foreach ([REMINDER1, REMINDER2, REMINDER3] as $type) { + foreach ([TEMPLATE_REMINDER1, TEMPLATE_REMINDER2, TEMPLATE_REMINDER3] as $type) { $enableField = "enable_{$type}"; $account->$enableField = Input::get($enableField) ? true : false; $account->{"num_days_{$type}"} = Input::get("num_days_{$type}"); diff --git a/app/Models/AccountEmailSettings.php b/app/Models/AccountEmailSettings.php index 8de75d1d3451..5fafc0d7a608 100644 --- a/app/Models/AccountEmailSettings.php +++ b/app/Models/AccountEmailSettings.php @@ -35,4 +35,14 @@ class AccountEmailSettings extends Eloquent 'late_fee3_percent', ]; + public static $templates = [ + TEMPLATE_INVOICE, + TEMPLATE_QUOTE, + //TEMPLATE_PARTIAL, + TEMPLATE_PAYMENT, + TEMPLATE_REMINDER1, + TEMPLATE_REMINDER2, + TEMPLATE_REMINDER3, + ]; + } diff --git a/app/Models/Traits/SendsEmails.php b/app/Models/Traits/SendsEmails.php index 0d9abb2c7b43..b2f7c42a6848 100644 --- a/app/Models/Traits/SendsEmails.php +++ b/app/Models/Traits/SendsEmails.php @@ -22,7 +22,12 @@ trait SendsEmails $entityType = 'reminder'; } - return trans("texts.{$entityType}_subject", ['invoice' => '$invoice', 'account' => '$account', 'quote' => '$quote']); + return trans("texts.{$entityType}_subject", [ + 'invoice' => '$invoice', + 'account' => '$account', + 'quote' => '$quote', + 'number' => '$number', + ]); } /** diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index baa3a0e1894d..3ffd3430342e 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -38,6 +38,14 @@ class InvoicePresenter extends EntityPresenter return $account->formatMoney($invoice->balance, $invoice->client); } + public function partial() + { + $invoice = $this->entity; + $account = $invoice->account; + + return $account->formatMoney($invoice->partial, $invoice->client); + } + public function requestedAmount() { $invoice = $this->entity; diff --git a/app/Services/TemplateService.php b/app/Services/TemplateService.php index bb370b555b2b..d25665277e38 100644 --- a/app/Services/TemplateService.php +++ b/app/Services/TemplateService.php @@ -54,6 +54,8 @@ class TemplateService '$balance' => $invoice->present()->balance, '$invoice' => $invoice->invoice_number, '$quote' => $invoice->invoice_number, + '$number' => $invoice->invoice_number, + '$partial' => $invoice->present()->partial, '$link' => $invitation->getLink(), '$password' => $passwordHTML, '$viewLink' => $invitation->getLink().'$password', diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 49f2012dac28..2407fa1cd7b0 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -238,7 +238,7 @@ $LANG = array( 'confirmation_subject' => 'Invoice Ninja Account Confirmation', 'confirmation_header' => 'Account Confirmation', 'confirmation_message' => 'Please access the link below to confirm your account.', - 'invoice_subject' => 'New invoice :invoice from :account', + 'invoice_subject' => 'New invoice :number from :account', 'invoice_message' => 'To view your invoice for :amount, click the link below.', 'payment_subject' => 'Payment Received', 'payment_message' => 'Thank you for your payment of :amount.', @@ -337,7 +337,7 @@ $LANG = array( 'deleted_quote' => 'Successfully deleted quote', 'deleted_quotes' => 'Successfully deleted :count quotes', 'converted_to_invoice' => 'Successfully converted quote to invoice', - 'quote_subject' => 'New quote :quote from :account', + 'quote_subject' => 'New quote :number from :account', 'quote_message' => 'To view your quote for :amount, click the link below.', 'quote_link_message' => 'To view your client quote click the link below:', 'notification_quote_sent_subject' => 'Quote :invoice was sent to :client', diff --git a/resources/views/accounts/templates_and_reminders.blade.php b/resources/views/accounts/templates_and_reminders.blade.php index e857f0964d39..f89ddd0d8e90 100644 --- a/resources/views/accounts/templates_and_reminders.blade.php +++ b/resources/views/accounts/templates_and_reminders.blade.php @@ -26,13 +26,13 @@ {!! Former::vertical_open()->addClass('warn-on-exit') !!} - @foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_PAYMENT, REMINDER1, REMINDER2, REMINDER3] as $type) + @foreach (App\Models\AccountEmailSettings::$templates as $type) @foreach (['subject', 'template'] as $field) {{ Former::populateField("email_{$field}_{$type}", $templates[$type][$field]) }} @endforeach @endforeach - @foreach ([REMINDER1, REMINDER2, REMINDER3] as $type) + @foreach ([TEMPLATE_REMINDER1, TEMPLATE_REMINDER2, TEMPLATE_REMINDER3] as $type) @foreach (['enable', 'num_days', 'direction', 'field'] as $field) {{ Former::populateField("{$field}_{$type}", $account->{"{$field}_{$type}"}) }} @endforeach @@ -148,7 +148,7 @@