From 58c50edff75b1758af7a3540e8729c4a3f522cf4 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 6 Feb 2017 11:41:16 +0200 Subject: [PATCH] Working on #1234 --- app/Http/Controllers/InvoiceController.php | 15 ++- app/Models/Traits/SendsEmails.php | 12 +++ resources/lang/en/texts.php | 5 +- resources/views/invoices/edit.blade.php | 14 ++- resources/views/invoices/email.blade.php | 105 ++++++++++++++------ resources/views/invoices/knockout.blade.php | 6 +- 6 files changed, 110 insertions(+), 47 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 3ceded3e85c4..91d292a614e0 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('reminder'), Input::get('pdfupload'), Input::get('emailTemplate')); + $this->emailInvoice($invoice); } return url($invoice->getRoute()); @@ -390,16 +390,23 @@ class InvoiceController extends BaseController } elseif ($action == 'convert') { return $this->convertQuote($request, $invoice->public_id); } elseif ($action == 'email') { - $this->emailInvoice($invoice, Input::get('reminder'), Input::get('pdfupload'), Input::get('emailTemplate')); + $this->emailInvoice($invoice); } return url($invoice->getRoute()); } - private function emailInvoice($invoice, $reminder = false, $pdfUpload = false, $template = false) + private function emailInvoice($invoice) { + $reminder = Input::get('reminder'); + $template = Input::get('template'); + $pdfUpload = Utils::decodePDF(Input::get('pdfupload')); $entityType = $invoice->getEntityType(); - $pdfUpload = Utils::decodePDF($pdfUpload); + + if (filter_var(Input::get('save_as_default'), FILTER_VALIDATE_BOOLEAN)) { + $account = Auth::user()->account; + $account->setTemplateDefaults(Input::get('template_type'), $template['subject'], $template['body']); + } if (! Auth::user()->confirmed) { $errorMessage = trans(Auth::user()->registered ? 'texts.confirmation_required' : 'texts.registration_required'); diff --git a/app/Models/Traits/SendsEmails.php b/app/Models/Traits/SendsEmails.php index 4b0d9bbe464b..1bf1f5052142 100644 --- a/app/Models/Traits/SendsEmails.php +++ b/app/Models/Traits/SendsEmails.php @@ -154,6 +154,18 @@ trait SendsEmails return false; } + public function setTemplateDefaults($type, $subject, $body) + { + if ($subject) { + $this->{"email_subject_" . $type} = $subject; + } + + if ($body) { + $this->{"email_template_" . $type} = $body; + } + + $this->save(); + } public function getBccEmail() { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index c5e58adde117..9b788d723e76 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2347,14 +2347,13 @@ $LANG = array( 'inactivity_logout' => 'Due to inactivity, you have been automatically logged out.', 'mark_active' => 'Mark Active', 'send_automatically' => 'Send Automatically', - 'template' => 'Template', 'initial_email' => 'Initial Email', 'invoice_not_emailed' => 'This invoice hasn\'t been emailed.', 'quote_not_emailed' => 'This quote hasn\'t been emailed.', - 'days_ago' => ':count day ago|:count days ago', 'sent_by' => 'Sent by :user', 'recipients' => 'Recipients', - 'today' => 'Today', + 'save_as_default' => 'Save as default', + 'template' => 'Template', ); diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 087f053d4517..51cee3a4a7ce 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -20,9 +20,9 @@ float: left; } - .btn-info:disabled { - background-color: #e89259; - border-color: #e89259; + .btn-info:disabled { + background-color: #e89259 !important; + border-color: #e89259 !important; } #scrollable-dropdown-menu .tt-menu { @@ -750,7 +750,7 @@ -