diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 3309923c50f9..cceb1853bbb4 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -208,8 +208,9 @@ class AccountController extends \BaseController } elseif ($section == ACCOUNT_IMPORT_EXPORT) { return View::make('accounts.import_export'); } elseif ($section == ACCOUNT_ADVANCED_SETTINGS) { + $account = Auth::user()->account; $data = [ - 'account' => Auth::user()->account, + 'account' => $account, 'feature' => $subSection, ]; @@ -242,6 +243,11 @@ class AccountController extends \BaseController $data['invoice'] = $invoice; $data['invoiceDesigns'] = InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId()) ->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(); + } else if ($subSection == ACCOUNT_EMAIL_TEMPLATES) { + $data['invoiceEmail'] = $account->getEmailTemplate(ENTITY_INVOICE); + $data['quoteEmail'] = $account->getEmailTemplate(ENTITY_QUOTE); + $data['paymentEmail'] = $account->getEmailTemplate(ENTITY_PAYMENT); + $data['emailFooter'] = $account->getEmailFooter(); } return View::make("accounts.{$subSection}", $data); @@ -273,12 +279,31 @@ class AccountController extends \BaseController return AccountController::saveInvoiceSettings(); } elseif ($subSection == ACCOUNT_INVOICE_DESIGN) { return AccountController::saveInvoiceDesign(); + } elseif ($subSection == ACCOUNT_EMAIL_TEMPLATES) { + return AccountController::saveEmailTemplates(); } } elseif ($section == ACCOUNT_PRODUCTS) { return AccountController::saveProducts(); } } + private function saveEmailTemplates() + { + if (Auth::user()->account->isPro()) { + $account = Auth::user()->account; + + $account->email_template_invoice = Input::get('email_template_invoice', $account->getEmailTemplate(ENTITY_INVOICE)); + $account->email_template_quote = Input::get('email_template_quote', $account->getEmailTemplate(ENTITY_QUOTE)); + $account->email_template_payment = Input::get('email_template_payment', $account->getEmailTemplate(ENTITY_PAYMENT)); + + $account->save(); + + Session::flash('message', trans('texts.updated_settings')); + } + + return Redirect::to('company/advanced_settings/email_templates'); + } + private function saveProducts() { $account = Auth::user()->account; @@ -288,7 +313,6 @@ class AccountController extends \BaseController $account->save(); Session::flash('message', trans('texts.updated_settings')); - return Redirect::to('company/products'); } diff --git a/app/database/migrations/2015_02_12_102940_add_email_templates.php b/app/database/migrations/2015_02_12_102940_add_email_templates.php new file mode 100644 index 000000000000..756466a79113 --- /dev/null +++ b/app/database/migrations/2015_02_12_102940_add_email_templates.php @@ -0,0 +1,38 @@ +text('email_template_invoice')->nullable(); + $table->text('email_template_quote')->nullable(); + $table->text('email_template_payment')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('accounts', function($table) + { + $table->dropColumn('email_template_invoice'); + $table->dropColumn('email_template_quote'); + $table->dropColumn('email_template_payment'); + }); + } + +} diff --git a/app/lang/da/texts.php b/app/lang/da/texts.php index daa2395f9990..747a5c4eda6d 100644 --- a/app/lang/da/texts.php +++ b/app/lang/da/texts.php @@ -499,5 +499,17 @@ return array( 'select_versiony' => 'Select version', 'view_history' => 'View History', + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', + ); diff --git a/app/lang/de/texts.php b/app/lang/de/texts.php index 3c87fcaf3faa..3d5e33a3eb82 100644 --- a/app/lang/de/texts.php +++ b/app/lang/de/texts.php @@ -489,5 +489,17 @@ return array( 'select_versiony' => 'Version auswählen', 'view_history' => 'Historie anzeigen', + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', + ); diff --git a/app/lang/en/texts.php b/app/lang/en/texts.php index 934b741ea23c..39908b5e78e4 100644 --- a/app/lang/en/texts.php +++ b/app/lang/en/texts.php @@ -503,5 +503,10 @@ return array( 'restore_user' => 'Restore User', 'restored_user' => 'Successfully restored user', 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', ); diff --git a/app/lang/es/texts.php b/app/lang/es/texts.php index ea0f84d14630..e15ed8c80ebb 100644 --- a/app/lang/es/texts.php +++ b/app/lang/es/texts.php @@ -469,5 +469,17 @@ return array( 'select_versiony' => 'Select version', 'view_history' => 'View History', + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', + ); \ No newline at end of file diff --git a/app/lang/fr/texts.php b/app/lang/fr/texts.php index 83832dfde5fd..7abc939fff16 100644 --- a/app/lang/fr/texts.php +++ b/app/lang/fr/texts.php @@ -490,5 +490,17 @@ return array( 'select_versiony' => 'Choix de la verison', 'view_history' => 'Consulter l\'historique', + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', + ); \ No newline at end of file diff --git a/app/lang/it/texts.php b/app/lang/it/texts.php index a1332c3ad927..b21af7c3dcd5 100644 --- a/app/lang/it/texts.php +++ b/app/lang/it/texts.php @@ -492,5 +492,17 @@ return array( 'select_versiony' => 'Select version', 'view_history' => 'View History', + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', + ); diff --git a/app/lang/lt/texts.php b/app/lang/lt/texts.php index d67d743a495a..4e673fc5229f 100644 --- a/app/lang/lt/texts.php +++ b/app/lang/lt/texts.php @@ -499,6 +499,18 @@ return array( 'current_version' => 'Current version', 'select_versiony' => 'Select version', 'view_history' => 'View History', + + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', ); diff --git a/app/lang/nb_NO/texts.php b/app/lang/nb_NO/texts.php index e93105b736d8..5e19acc1fc06 100644 --- a/app/lang/nb_NO/texts.php +++ b/app/lang/nb_NO/texts.php @@ -498,6 +498,18 @@ return array( 'select_versiony' => 'Select version', 'view_history' => 'View History', + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', + ); \ No newline at end of file diff --git a/app/lang/nl/texts.php b/app/lang/nl/texts.php index 3243fd07dfd9..793566e479a6 100644 --- a/app/lang/nl/texts.php +++ b/app/lang/nl/texts.php @@ -493,6 +493,18 @@ return array( 'select_versiony' => 'Select version', 'view_history' => 'View History', + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', + ); \ No newline at end of file diff --git a/app/lang/pt_BR/texts.php b/app/lang/pt_BR/texts.php index 83751837ccb3..4673a0d6d111 100644 --- a/app/lang/pt_BR/texts.php +++ b/app/lang/pt_BR/texts.php @@ -480,6 +480,18 @@ return array( 'select_versiony' => 'Select version', 'view_history' => 'View History', + 'edit_payment' => 'Edit Payment', + 'updated_payment' => 'Successfully updated payment', + 'deleted' => 'Deleted', + 'restore_user' => 'Restore User', + 'restored_user' => 'Successfully restored user', + 'show_deleted_users' => 'Show deleted users', + 'email_templates' => 'Email Templates', + 'invoice_email' => 'Invoice Email', + 'payment_email' => 'Payment Email', + 'quote_email' => 'Quote Email', + 'reset_all' => 'Reset All', + ); diff --git a/app/models/Account.php b/app/models/Account.php index 651543539a1b..40ad5e677a81 100755 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -302,4 +302,36 @@ class Account extends Eloquent return $this; } + + public function getEmailTemplate($entityType, $message = false) + { + $field = "email_template_$entityType"; + $template = $this->$field; + + if ($template) { + return $template; + } + + $template = "
\$client,
\r\n" . + "" . trans("texts.{$entityType}_message", ['amount' => '$amount']) . "
\r\n"; + + if ($entityType != ENTITY_PAYMENT) { + $template .= "\r\n"; + } + + if ($message) { + $template .= "$message
\r\n"; + } + + return $template . "\$footer
"; + } + + public function getEmailFooter() + { + if ($this->email_footer) { + return $this->email_footer; + } else { + return "" . trans('texts.email_signature') . "
\$account
+ + {{ Former::legend('quote_email') }} +
+ + {{ Former::legend('payment_email') }} +
+ + @if (Auth::user()->isPro()) + {{ Former::actions( + Button::lg_success_submit(trans('texts.save'))->append_with_icon('floppy-disk') + ) }} + @else + + @endif + + {{ Former::close() }} + + + +@stop diff --git a/app/views/accounts/nav_advanced.blade.php b/app/views/accounts/nav_advanced.blade.php index e24ea16f09fb..513c05dffdd2 100644 --- a/app/views/accounts/nav_advanced.blade.php +++ b/app/views/accounts/nav_advanced.blade.php @@ -1,6 +1,7 @@