From a6c100eb476943e2bbceb7e441c2a83b897e7e27 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 9 May 2017 09:42:33 +0300 Subject: [PATCH] Support relabeling po number and due date --- app/Http/Controllers/AccountController.php | 17 ++++++++++++- app/Models/Invoice.php | 5 ++++ app/Models/Traits/PresentsInvoice.php | 24 +++++++++++++++++++ .../views/accounts/invoice_design.blade.php | 4 +++- resources/views/emails/design2_html.blade.php | 6 ++++- resources/views/emails/design3_html.blade.php | 6 ++++- resources/views/invoices/edit.blade.php | 4 ++-- 7 files changed, 60 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 08ff6d39bb04..58a28f569c1b 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -956,7 +956,22 @@ class AccountController extends BaseController $account->page_size = Input::get('page_size'); $labels = []; - foreach (['item', 'description', 'unit_cost', 'quantity', 'line_total', 'terms', 'balance_due', 'partial_due', 'subtotal', 'paid_to_date', 'discount', 'tax'] as $field) { + foreach ([ + 'item', + 'description', + 'unit_cost', + 'quantity', + 'line_total', + 'terms', + 'balance_due', + 'partial_due', + 'subtotal', + 'paid_to_date', + 'discount', + 'tax', + 'po_number', + 'due_date', + ] as $field) { $labels[$field] = Input::get("labels_{$field}"); } $account->invoice_labels = json_encode($labels); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 1e368997091d..87c3d3112ea0 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1504,6 +1504,11 @@ class Invoice extends EntityModel implements BalanceAffecting ->orderBy('id', 'desc') ->get(); } + + public function getDueDateLabel() + { + return $this->isQuote() ? 'valid_until' : 'due_date'; + } } Invoice::creating(function ($invoice) { diff --git a/app/Models/Traits/PresentsInvoice.php b/app/Models/Traits/PresentsInvoice.php index 073d2479c462..52afd90968e8 100644 --- a/app/Models/Traits/PresentsInvoice.php +++ b/app/Models/Traits/PresentsInvoice.php @@ -162,6 +162,28 @@ trait PresentsInvoice return $fields; } + public function hasCustomLabel($field) + { + $custom = (array) json_decode($this->invoice_labels); + + return isset($custom[$field]) && $custom[$field]; + } + + public function getLabel($field, $override = false) + { + $custom = (array) json_decode($this->invoice_labels); + + if (isset($custom[$field]) && $custom[$field]) { + return $custom[$field]; + } else { + if ($override) { + $field = $override; + } + return $this->isEnglish() ? uctrans("texts.$field") : trans("texts.$field"); + } + + } + /** * @return array */ @@ -239,6 +261,8 @@ trait PresentsInvoice 'work_phone', 'invoice_total', 'outstanding', + 'invoice_due_date', + 'quote_due_date', ]; foreach ($fields as $field) { diff --git a/resources/views/accounts/invoice_design.blade.php b/resources/views/accounts/invoice_design.blade.php index 63eda69b27c6..633f25b19237 100644 --- a/resources/views/accounts/invoice_design.blade.php +++ b/resources/views/accounts/invoice_design.blade.php @@ -215,14 +215,16 @@ {!! Former::text('labels_quantity')->label('quantity') !!} {!! Former::text('labels_line_total')->label('line_total') !!} {!! Former::text('labels_terms')->label('terms') !!} + {!! Former::text('labels_subtotal')->label('subtotal') !!}
- {!! Former::text('labels_subtotal')->label('subtotal') !!} {!! Former::text('labels_discount')->label('discount') !!} {!! Former::text('labels_paid_to_date')->label('paid_to_date') !!} {!! Former::text('labels_balance_due')->label('balance_due') !!} {!! Former::text('labels_partial_due')->label('partial_due') !!} {!! Former::text('labels_tax')->label('tax') !!} + {!! Former::text('labels_po_number')->label('po_number') !!} + {!! Former::text('labels_due_date')->label('due_date') !!}
diff --git a/resources/views/emails/design2_html.blade.php b/resources/views/emails/design2_html.blade.php index 33f489d091af..b203784ecdfc 100644 --- a/resources/views/emails/design2_html.blade.php +++ b/resources/views/emails/design2_html.blade.php @@ -25,7 +25,11 @@ @if ($invoice->isQuote()) {{ strtoupper(trans('texts.valid_until')) }} {{ $account->formatDate($invoice->due_date) }} @else - {{ strtoupper(trans('texts.due_by', ['date' => $account->formatDate($invoice->due_date)])) }} + @if ($account->hasCustomLabel('due_date')) + {{ $account->getLabel('due_date') }} {{ $account->formatDate($invoice->due_date) }} + @else + {{ strtoupper(trans('texts.due_by', ['date' => $account->formatDate($invoice->due_date)])) }} + @endif @endif
@endif diff --git a/resources/views/emails/design3_html.blade.php b/resources/views/emails/design3_html.blade.php index 0c89d0cbc036..7ccba719cca0 100644 --- a/resources/views/emails/design3_html.blade.php +++ b/resources/views/emails/design3_html.blade.php @@ -25,7 +25,11 @@ @if ($invoice->isQuote()) {{ strtoupper(trans('texts.valid_until')) }} {{ $account->formatDate($invoice->due_date) }} @else - {{ strtoupper(trans('texts.due_by', ['date' => $account->formatDate($invoice->due_date)])) }} + @if ($account->hasCustomLabel('due_date')) + {{ $account->getLabel('due_date') }} {{ $account->formatDate($invoice->due_date) }} + @else + {{ strtoupper(trans('texts.due_by', ['date' => $account->formatDate($invoice->due_date)])) }} + @endif @endif
@endif diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 07ee7d9d75c8..f035c3966591 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -153,7 +153,7 @@
{!! Former::text('invoice_date')->data_bind("datePicker: invoice_date, valueUpdate: 'afterkeydown'")->label(trans("texts.{$entityType}_date")) ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))->appendIcon('calendar')->addGroupClass('invoice_date') !!} - {!! Former::text('due_date')->data_bind("datePicker: due_date, valueUpdate: 'afterkeydown'")->label(trans("texts.{$entityType}_due_date")) + {!! Former::text('due_date')->data_bind("datePicker: due_date, valueUpdate: 'afterkeydown'")->label($account->getLabel($invoice->getDueDateLabel())) ->placeholder($invoice->exists || $invoice->isQuote() ? ' ' : $account->present()->dueDatePlaceholder()) ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))->appendIcon('calendar')->addGroupClass('due_date') !!} {!! Former::text('partial')->data_bind("value: partial, valueUpdate: 'afterkeydown'")->onkeyup('onPartialChange()') @@ -209,7 +209,7 @@
- {!! Former::text('po_number')->label(trans('texts.po_number_short'))->data_bind("value: po_number, valueUpdate: 'afterkeydown'") !!} + {!! Former::text('po_number')->label($account->getLabel('po_number', 'po_number_short'))->data_bind("value: po_number, valueUpdate: 'afterkeydown'") !!} {!! Former::text('discount')->data_bind("value: discount, valueUpdate: 'afterkeydown'") ->addGroupClass('discount-group')->type('number')->min('0')->step('any')->append( Former::select('is_amount_discount')->addOption(trans('texts.discount_percent'), '0')