From 976773ce7bda6d605d7adf2234a3c25310b0a636 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 27 May 2015 23:20:35 +0300 Subject: [PATCH] Enabled setting custom invoice item labels --- app/Http/Controllers/AccountController.php | 8 +++++ app/Http/Controllers/InvoiceController.php | 6 ++-- app/Models/Account.php | 8 ++++- app/Ninja/Repositories/InvoiceRepository.php | 1 + ...05_27_170808_add_custom_invoice_labels.php | 35 +++++++++++++++++++ public/css/built.css | 2 +- public/css/style.css | 2 +- resources/lang/en/texts.php | 4 ++- .../views/accounts/invoice_design.blade.php | 30 ++++++++++++++++ .../views/accounts/invoice_settings.blade.php | 8 ++--- resources/views/invoices/edit.blade.php | 8 ++--- 11 files changed, 98 insertions(+), 14 deletions(-) create mode 100644 database/migrations/2015_05_27_170808_add_custom_invoice_labels.php diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 91f7ac62690c..9362b7eb41a7 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -209,6 +209,7 @@ class AccountController extends BaseController $data['invoice'] = $invoice; $data['invoiceDesigns'] = InvoiceDesign::availableDesigns(); + $data['invoiceLabels'] = json_decode($account->invoice_labels); } else if ($subSection == ACCOUNT_EMAIL_TEMPLATES) { $data['invoiceEmail'] = $account->getEmailTemplate(ENTITY_INVOICE); $data['quoteEmail'] = $account->getEmailTemplate(ENTITY_QUOTE); @@ -334,6 +335,13 @@ class AccountController extends BaseController if (Input::has('font_size')) { $account->font_size = intval(Input::get('font_size')); } + + $labels = []; + foreach (['item', 'description', 'unit_cost', 'quantity'] as $field) { + $labels[$field] = trim(Input::get("labels_{$field}")); + } + $account->invoice_labels = json_encode($labels); + $account->save(); Session::flash('message', trans('texts.updated_settings')); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index c1e9afda49a9..d35fbf7efdad 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -228,7 +228,7 @@ class InvoiceController extends BaseController ]; } } - + $data = array( 'isConverted' => $invoice->quote_invoice_id ? true : false, 'showBreadcrumbs' => false, @@ -367,7 +367,9 @@ class InvoiceController extends BaseController 6 => 'Six months', 7 => 'Annually', ), - 'recurringHelp' => $recurringHelp + 'recurringHelp' => $recurringHelp, + 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), + ]; } diff --git a/app/Models/Account.php b/app/Models/Account.php index 9989227851b7..3f159fffa286 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -212,6 +212,8 @@ class Account extends Eloquent public function getInvoiceLabels() { $data = []; + $custom = (array) json_decode($this->invoice_labels); + $fields = [ 'invoice', 'invoice_date', @@ -241,7 +243,11 @@ class Account extends Eloquent ]; foreach ($fields as $field) { - $data[$field] = trans("texts.$field"); + if (isset($custom[$field]) && $custom[$field]) { + $data[$field] = $custom[$field]; + } else { + $data[$field] = trans("texts.$field"); + } } return $data; diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 97ba3e6ea720..63c208de7399 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -378,6 +378,7 @@ class InvoiceRepository if (isset($item['task_public_id']) && $item['task_public_id']) { $task = Task::scope($item['task_public_id'])->where('invoice_id', '=', null)->firstOrFail(); $task->invoice_id = $invoice->id; + $task->client_id = $invoice->client_id; $task->save(); } else if ($item['product_key']) { $product = Product::findProductByKey(trim($item['product_key'])); diff --git a/database/migrations/2015_05_27_170808_add_custom_invoice_labels.php b/database/migrations/2015_05_27_170808_add_custom_invoice_labels.php new file mode 100644 index 000000000000..24415d381b02 --- /dev/null +++ b/database/migrations/2015_05_27_170808_add_custom_invoice_labels.php @@ -0,0 +1,35 @@ +text('invoice_labels')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('accounts', function($table) + { + $table->dropColumn('invoice_labels'); + }); + + } + +} diff --git a/public/css/built.css b/public/css/built.css index 253e6f877baf..77420cf91582 100644 --- a/public/css/built.css +++ b/public/css/built.css @@ -3227,7 +3227,7 @@ div.checkbox > label { } div.alert { - z-index: 0; + z-index: 1; } .alert-hide { diff --git a/public/css/style.css b/public/css/style.css index 920b49adf649..3ffbd7538c59 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -843,7 +843,7 @@ div.checkbox > label { } div.alert { - z-index: 0; + z-index: 1; } .alert-hide { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 88fca80c2c87..c425f8031181 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -667,7 +667,9 @@ return array( 'create_task' => 'Create Task', 'stopped_task' => 'Successfully stopped task', 'invoice_task' => 'Invoice Task', - + 'invoice_labels' => 'Invoice Labels', + 'prefix' => 'Prefix', + 'counter' => 'Counter', ); diff --git a/resources/views/accounts/invoice_design.blade.php b/resources/views/accounts/invoice_design.blade.php index 255676e1eb8a..13efe002ecf7 100644 --- a/resources/views/accounts/invoice_design.blade.php +++ b/resources/views/accounts/invoice_design.blade.php @@ -42,6 +42,19 @@ NINJA.secondaryColor = $('#secondary_color').val(); NINJA.fontSize = parseInt($('#font_size').val()); + var fields = ['item', 'description', 'unit_cost', 'quantity']; + invoiceLabels.old = {}; + for (var i=0; ihide_quantity)) !!} {!! Former::populateField('hide_paid_to_date', intval($account->hide_paid_to_date)) !!} + @foreach ($invoiceLabels as $field => $value) + {!! Former::populateField("labels_{$field}", $value) !!} + @endforeach
@@ -96,6 +112,20 @@
+
+
+

{!! trans('texts.invoice_labels') !!}

+
+
+ + {!! Former::text('labels_item')->label(trans('texts.item')) !!} + {!! Former::text('labels_description')->label(trans('texts.description')) !!} + {!! Former::text('labels_unit_cost')->label(trans('texts.unit_cost')) !!} + {!! Former::text('labels_quantity')->label(trans('texts.quantity')) !!} + +
+
+

{!! trans('texts.invoice_options') !!}

diff --git a/resources/views/accounts/invoice_settings.blade.php b/resources/views/accounts/invoice_settings.blade.php index cb95cc05d5c8..b46bdfd17b0c 100644 --- a/resources/views/accounts/invoice_settings.blade.php +++ b/resources/views/accounts/invoice_settings.blade.php @@ -74,8 +74,8 @@

{!! trans('texts.invoice_number') !!}

- {!! Former::text('invoice_number_prefix')->label(trans('texts.invoice_number_prefix')) !!} - {!! Former::text('invoice_number_counter')->label(trans('texts.invoice_number_counter')) !!} + {!! Former::text('invoice_number_prefix')->label(trans('texts.prefix')) !!} + {!! Former::text('invoice_number_counter')->label(trans('texts.counter')) !!}
@@ -85,8 +85,8 @@

{!! trans('texts.quote_number') !!}

- {!! Former::text('quote_number_prefix')->label(trans('texts.quote_number_prefix')) !!} - {!! Former::text('quote_number_counter')->label(trans('texts.quote_number_counter')) + {!! Former::text('quote_number_prefix')->label(trans('texts.prefix')) !!} + {!! Former::text('quote_number_counter')->label(trans('texts.counter')) ->append(Former::checkbox('share_counter')->raw()->onclick('setQuoteNumberEnabled()') . ' ' . trans('texts.share_invoice_counter')) !!}
diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index e2152bd53c90..041001652d83 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -150,10 +150,10 @@ - {{ trans('texts.item') }} - {{ trans('texts.description') }} - {{ trans('texts.unit_cost') }} - {{ trans('texts.quantity') }} + {{ $invoiceLabels['item'] }} + {{ $invoiceLabels['description'] }} + {{ $invoiceLabels['unit_cost'] }} + {{ $invoiceLabels['quantity'] }} {{ trans('texts.tax') }} {{ trans('texts.line_total') }}