Support relabeling po number and due date

This commit is contained in:
Hillel Coren 2017-05-09 09:42:33 +03:00
parent 4abefb86fc
commit a6c100eb47
7 changed files with 60 additions and 6 deletions

View File

@ -956,7 +956,22 @@ class AccountController extends BaseController
$account->page_size = Input::get('page_size'); $account->page_size = Input::get('page_size');
$labels = []; $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}"); $labels[$field] = Input::get("labels_{$field}");
} }
$account->invoice_labels = json_encode($labels); $account->invoice_labels = json_encode($labels);

View File

@ -1504,6 +1504,11 @@ class Invoice extends EntityModel implements BalanceAffecting
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->get(); ->get();
} }
public function getDueDateLabel()
{
return $this->isQuote() ? 'valid_until' : 'due_date';
}
} }
Invoice::creating(function ($invoice) { Invoice::creating(function ($invoice) {

View File

@ -162,6 +162,28 @@ trait PresentsInvoice
return $fields; 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 * @return array
*/ */
@ -239,6 +261,8 @@ trait PresentsInvoice
'work_phone', 'work_phone',
'invoice_total', 'invoice_total',
'outstanding', 'outstanding',
'invoice_due_date',
'quote_due_date',
]; ];
foreach ($fields as $field) { foreach ($fields as $field) {

View File

@ -215,14 +215,16 @@
{!! Former::text('labels_quantity')->label('quantity') !!} {!! Former::text('labels_quantity')->label('quantity') !!}
{!! Former::text('labels_line_total')->label('line_total') !!} {!! Former::text('labels_line_total')->label('line_total') !!}
{!! Former::text('labels_terms')->label('terms') !!} {!! Former::text('labels_terms')->label('terms') !!}
{!! Former::text('labels_subtotal')->label('subtotal') !!}
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{!! Former::text('labels_subtotal')->label('subtotal') !!}
{!! Former::text('labels_discount')->label('discount') !!} {!! Former::text('labels_discount')->label('discount') !!}
{!! Former::text('labels_paid_to_date')->label('paid_to_date') !!} {!! Former::text('labels_paid_to_date')->label('paid_to_date') !!}
{!! Former::text('labels_balance_due')->label('balance_due') !!} {!! Former::text('labels_balance_due')->label('balance_due') !!}
{!! Former::text('labels_partial_due')->label('partial_due') !!} {!! Former::text('labels_partial_due')->label('partial_due') !!}
{!! Former::text('labels_tax')->label('tax') !!} {!! Former::text('labels_tax')->label('tax') !!}
{!! Former::text('labels_po_number')->label('po_number') !!}
{!! Former::text('labels_due_date')->label('due_date') !!}
</div> </div>
</div> </div>

View File

@ -25,7 +25,11 @@
@if ($invoice->isQuote()) @if ($invoice->isQuote())
{{ strtoupper(trans('texts.valid_until')) }} {{ $account->formatDate($invoice->due_date) }} {{ strtoupper(trans('texts.valid_until')) }} {{ $account->formatDate($invoice->due_date) }}
@else @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
</span><br /> </span><br />
@endif @endif

View File

@ -25,7 +25,11 @@
@if ($invoice->isQuote()) @if ($invoice->isQuote())
{{ strtoupper(trans('texts.valid_until')) }} {{ $account->formatDate($invoice->due_date) }} {{ strtoupper(trans('texts.valid_until')) }} {{ $account->formatDate($invoice->due_date) }}
@else @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
</span><br /> </span><br />
@endif @endif

View File

@ -153,7 +153,7 @@
<div data-bind="visible: !is_recurring()"> <div data-bind="visible: !is_recurring()">
{!! Former::text('invoice_date')->data_bind("datePicker: invoice_date, valueUpdate: 'afterkeydown'")->label(trans("texts.{$entityType}_date")) {!! 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') !!} ->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()) ->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') !!} ->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()') {!! Former::text('partial')->data_bind("value: partial, valueUpdate: 'afterkeydown'")->onkeyup('onPartialChange()')
@ -209,7 +209,7 @@
</div> </div>
</div> </div>
</span> </span>
{!! 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'") {!! Former::text('discount')->data_bind("value: discount, valueUpdate: 'afterkeydown'")
->addGroupClass('discount-group')->type('number')->min('0')->step('any')->append( ->addGroupClass('discount-group')->type('number')->min('0')->step('any')->append(
Former::select('is_amount_discount')->addOption(trans('texts.discount_percent'), '0') Former::select('is_amount_discount')->addOption(trans('texts.discount_percent'), '0')