From 30045ecdbb896119ff54a0796cdd8d127fe499eb Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 5 Feb 2017 23:29:11 +0200 Subject: [PATCH] Working on #1234 --- app/Http/Controllers/InvoiceController.php | 10 +- app/Jobs/SendInvoiceEmail.php | 10 +- app/Ninja/Mailers/ContactMailer.php | 6 +- resources/lang/en/texts.php | 1 + resources/views/invoices/edit.blade.php | 2 + resources/views/invoices/email.blade.php | 104 +++++++++++++++--- .../views/partials/email_templates.blade.php | 8 +- .../views/partials/quill_toolbar.blade.php | 4 +- 8 files changed, 113 insertions(+), 32 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index bacc80d77399..3ceded3e85c4 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -359,7 +359,7 @@ class InvoiceController extends BaseController Session::flash('message', $message); if ($action == 'email') { - $this->emailInvoice($invoice, Input::get('pdfupload')); + $this->emailInvoice($invoice, Input::get('reminder'), Input::get('pdfupload'), Input::get('emailTemplate')); } return url($invoice->getRoute()); @@ -390,13 +390,13 @@ class InvoiceController extends BaseController } elseif ($action == 'convert') { return $this->convertQuote($request, $invoice->public_id); } elseif ($action == 'email') { - $this->emailInvoice($invoice, Input::get('pdfupload')); + $this->emailInvoice($invoice, Input::get('reminder'), Input::get('pdfupload'), Input::get('emailTemplate')); } return url($invoice->getRoute()); } - private function emailInvoice($invoice, $pdfUpload) + private function emailInvoice($invoice, $reminder = false, $pdfUpload = false, $template = false) { $entityType = $invoice->getEntityType(); $pdfUpload = Utils::decodePDF($pdfUpload); @@ -413,9 +413,9 @@ class InvoiceController extends BaseController } else { // TODO remove this with Laravel 5.3 (https://github.com/invoiceninja/invoiceninja/issues/1303) if (config('queue.default') === 'sync') { - $response = app('App\Ninja\Mailers\ContactMailer')->sendInvoice($invoice, false, $pdfUpload); + $response = app('App\Ninja\Mailers\ContactMailer')->sendInvoice($invoice, $reminder, $pdfUpload, $template); } else { - $this->dispatch(new SendInvoiceEmail($invoice, false, $pdfUpload)); + $this->dispatch(new SendInvoiceEmail($invoice, $reminder, $pdfUpload, $template)); $response = true; } } diff --git a/app/Jobs/SendInvoiceEmail.php b/app/Jobs/SendInvoiceEmail.php index e1ea2c39908c..a638b2b049c0 100644 --- a/app/Jobs/SendInvoiceEmail.php +++ b/app/Jobs/SendInvoiceEmail.php @@ -31,6 +31,11 @@ class SendInvoiceEmail extends Job implements ShouldQueue */ protected $pdfString; + /** + * @var array + */ + protected $template; + /** * Create a new job instance. * @@ -39,11 +44,12 @@ class SendInvoiceEmail extends Job implements ShouldQueue * @param bool $reminder * @param mixed $pdfString */ - public function __construct(Invoice $invoice, $reminder = false, $pdfString = false) + public function __construct(Invoice $invoice, $reminder = false, $pdfString = false, $template = false) { $this->invoice = $invoice; $this->reminder = $reminder; $this->pdfString = $pdfString; + $this->template = $template; } /** @@ -53,7 +59,7 @@ class SendInvoiceEmail extends Job implements ShouldQueue */ public function handle(ContactMailer $mailer) { - $mailer->sendInvoice($this->invoice, $this->reminder, $this->pdfString); + $mailer->sendInvoice($this->invoice, $this->reminder, $this->pdfString, $this->template); } /* diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 963bc82aa1cd..12143cb6deee 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -36,7 +36,7 @@ class ContactMailer extends Mailer * * @return bool|null|string */ - public function sendInvoice(Invoice $invoice, $reminder = false, $pdfString = false) + public function sendInvoice(Invoice $invoice, $reminder = false, $pdfString = false, $template = false) { if ($invoice->is_recurring) { return false; @@ -57,8 +57,8 @@ class ContactMailer extends Mailer } $account->loadLocalizationSettings($client); - $emailTemplate = $account->getEmailTemplate($reminder ?: $entityType); - $emailSubject = $account->getEmailSubject($reminder ?: $entityType); + $emailTemplate = !empty($template['body']) ? $template['body'] : $account->getEmailTemplate($reminder ?: $entityType); + $emailSubject = !empty($template['subject']) ? $template['subject'] : $account->getEmailSubject($reminder ?: $entityType); $sent = false; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 97d9c232ee5e..c5e58adde117 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2354,6 +2354,7 @@ $LANG = array( 'days_ago' => ':count day ago|:count days ago', 'sent_by' => 'Sent by :user', 'recipients' => 'Recipients', + 'today' => 'Today', ); diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index d7944a25ff49..087f053d4517 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -11,6 +11,8 @@ + + diff --git a/resources/views/partials/email_templates.blade.php b/resources/views/partials/email_templates.blade.php index 6731094b6417..333e790a4420 100644 --- a/resources/views/partials/email_templates.blade.php +++ b/resources/views/partials/email_templates.blade.php @@ -5,7 +5,7 @@ return ''; } - var passwordHtml = "{!! $account->isPro() && $account->enable_portal_password && $account->send_portal_password?'

'.trans('texts.password').': XXXXXXXXX

':'' !!}"; + var passwordHtml = "{!! $account->isPro() && $account->enable_portal_password && $account->send_portal_password?'
'.trans('texts.password').': XXXXXXXXX
':'' !!}"; @if ($account->isPro()) var documentsHtml = "{!! trans('texts.email_documents_header').'

' !!}"; @@ -19,16 +19,16 @@ 'dueDate': "{{ $account->formatDate($account->getDateTime()) }}", 'invoiceDate': "{{ $account->formatDate($account->getDateTime()) }}", 'client': invoice ? getClientDisplayName(invoice.client) : 'Client Name', - 'amount': invoice ? formatMoneyInvoice(invoice.amount, invoice) : formatMoneyAccount(100, account), + 'amount': invoice ? formatMoneyInvoice(parseFloat(invoice.partial) || parseFloat(invoice.balance_amount), invoice) : formatMoneyAccount(100, account), 'contact': invoice ? getContactDisplayName(invoice.client.contacts[0]) : 'Contact Name', 'firstName': invoice ? invoice.client.contacts[0].first_name : 'First Name', 'invoice': invoice ? invoice.invoice_number : '0001', 'quote': invoice ? invoice.invoice_number : '0001', 'password': passwordHtml, 'documents': documentsHtml, - 'viewLink': "{{ URL::to('/view/...') }}$password", + 'viewLink': '{{ link_to('#', url('/view/...')) }}$password', 'viewButton': '{!! Form::flatButton('view_invoice', '#0b4d78') !!}$password', - 'paymentLink': "{{ URL::to('/payment/...') }}$password", + 'paymentLink': '{{ link_to('#', url('/payment/...')) }}$password', 'paymentButton': '{!! Form::flatButton('pay_now', '#36c157') !!}$password', 'autoBill': '{{ trans('texts.auto_bill_notification_placeholder') }}', 'portalLink': "{{ URL::to('/client/portal/...') }}", diff --git a/resources/views/partials/quill_toolbar.blade.php b/resources/views/partials/quill_toolbar.blade.php index f20c1d295d0b..1b4bb9d83dee 100644 --- a/resources/views/partials/quill_toolbar.blade.php +++ b/resources/views/partials/quill_toolbar.blade.php @@ -1,4 +1,4 @@ -
+