1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Support custom fields with defined options

This commit is contained in:
Hillel Coren 2018-01-17 12:19:46 +02:00
parent 5eedd23447
commit dae4df2a3e
20 changed files with 260 additions and 87 deletions

View File

@ -1087,6 +1087,25 @@ class Utils
}
}
public static function getCustomLabel($value)
{
if (strpos($value, '|') !== false) {
return explode('|', $value)[0];
} else {
return $value;
}
}
public static function getCustomValues($value)
{
if (strpos($value, '|') !== false) {
$values = explode(',', explode('|', $value)[1]);
return array_combine($values, $values);
} else {
return $value;
}
}
public static function formatWebsite($link)
{
if (! $link) {

View File

@ -2,6 +2,8 @@
namespace App\Models\Traits;
use Utils;
/**
* Class PresentsInvoice.
*/
@ -362,7 +364,7 @@ trait PresentsInvoice
'product.custom_value1' => 'custom_invoice_item_label1',
'product.custom_value2' => 'custom_invoice_item_label2',
] as $field => $property) {
$data[$field] = e($this->$property) ?: trans('texts.custom_field');
$data[$field] = e(Utils::getCustomLabel($this->$property)) ?: trans('texts.custom_field');
}
return $data;

View File

@ -264,4 +264,56 @@ class AccountPresenter extends Presenter
return $url;
}
public function customClientLabel1()
{
return Utils::getCustomLabel($this->entity->custom_client_label1);
}
public function customClientLabel2()
{
return Utils::getCustomLabel($this->entity->custom_client_label2);
}
public function customContactLabel1()
{
return Utils::getCustomLabel($this->entity->custom_contact_label1);
}
public function customContactLabel2()
{
return Utils::getCustomLabel($this->entity->custom_contact_label2);
}
public function customInvoiceLabel1()
{
return Utils::getCustomLabel($this->entity->custom_invoice_label1);
}
public function customInvoiceLabel2()
{
return Utils::getCustomLabel($this->entity->custom_invoice_label2);
}
public function customInvoiceTextLabel1()
{
return Utils::getCustomLabel($this->entity->custom_invoice_text_label1);
}
public function customInvoiceTextLabel2()
{
return Utils::getCustomLabel($this->entity->custom_invoice_text_label1);
}
public function customProductLabel1()
{
return Utils::getCustomLabel($this->entity->custom_invoice_item_label1);
}
public function customProductLabel2()
{
return Utils::getCustomLabel($this->entity->custom_invoice_item_label2);
}
}

View File

@ -143,10 +143,10 @@ class AccountRepository
// include custom client fields in search
if ($account->custom_client_label1) {
$data[$account->custom_client_label1] = [];
$data[$account->present()->customClientLabel1] = [];
}
if ($account->custom_client_label2) {
$data[$account->custom_client_label2] = [];
$data[$account->present()->customClientLabel2] = [];
}
if ($user->hasPermission('view_all')) {
@ -176,14 +176,14 @@ class AccountRepository
}
if ($client->custom_value1) {
$data[$account->custom_client_label1][] = [
$data[$account->present()->customClientLabel1][] = [
'value' => "{$client->custom_value1}: " . $client->getDisplayName(),
'tokens' => $client->custom_value1,
'url' => $client->present()->url,
];
}
if ($client->custom_value2) {
$data[$account->custom_client_label2][] = [
$data[$account->present()->customClientLabel2][] = [
'value' => "{$client->custom_value2}: " . $client->getDisplayName(),
'tokens' => $client->custom_value2,
'url' => $client->present()->url,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -646,13 +646,13 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
if (field == 'custom_value1') {
if (invoice.has_custom_item_value1) {
value = account.custom_invoice_item_label1;
value = NINJA.getCustomLabel(account.custom_invoice_item_label1);
} else {
continue;
}
} else if (field == 'custom_value2') {
if (invoice.has_custom_item_value2) {
value = account.custom_invoice_item_label2;
value = NINJA.getCustomLabel(account.custom_invoice_item_label2);
} else {
continue;
}
@ -1136,22 +1136,22 @@ NINJA.renderField = function(invoice, field, twoColumn) {
value = contact.phone;
} else if (field == 'client.custom_value1') {
if (account.custom_client_label1 && client.custom_value1) {
label = account.custom_client_label1;
label = NINJA.getCustomLabel(account.custom_client_label1);
value = client.custom_value1;
}
} else if (field == 'client.custom_value2') {
if (account.custom_client_label2 && client.custom_value2) {
label = account.custom_client_label2;
label = NINJA.getCustomLabel(account.custom_client_label2);
value = client.custom_value2;
}
} else if (field == 'contact.custom_value1') {
if (account.custom_contact_label1 && contact.custom_value1) {
label = account.custom_contact_label1;
label = NINJA.getCustomLabel(account.custom_contact_label1);
value = contact.custom_value1;
}
} else if (field == 'contact.custom_value2') {
if (account.custom_contact_label2 && contact.custom_value2) {
label = account.custom_contact_label2;
label = NINJA.getCustomLabel(account.custom_contact_label2);
value = contact.custom_value2;
}
} else if (field == 'account.company_name') {
@ -1222,12 +1222,12 @@ NINJA.renderField = function(invoice, field, twoColumn) {
}
} else if (field == 'invoice.custom_text_value1') {
if (invoice.custom_text_value1 && account.custom_invoice_text_label1) {
label = invoice.account.custom_invoice_text_label1;
label = NINJA.getCustomLabel(invoice.account.custom_invoice_text_label1);
value = invoice.is_recurring ? processVariables(invoice.custom_text_value1) : invoice.custom_text_value1;
}
} else if (field == 'invoice.custom_text_value2') {
if (invoice.custom_text_value2 && account.custom_invoice_text_label2) {
label = invoice.account.custom_invoice_text_label2;
label = NINJA.getCustomLabel(invoice.account.custom_invoice_text_label2);
value = invoice.is_recurring ? processVariables(invoice.custom_text_value2) : invoice.custom_text_value2;
}
} else if (field == 'invoice.balance_due') {
@ -1478,3 +1478,11 @@ NINJA.parseRegExpLine = function(line, regExp, formatter, groupText)
return line;
}
NINJA.getCustomLabel = function(value) {
if (value && value.indexOf('|') > 0) {
return value.split('|')[0];
} else {
return value;
}
}

View File

@ -2651,6 +2651,7 @@ $LANG = array(
'return_to_login' => 'Return to Login',
'convert_products_tip' => 'Note: add a custom field named ":name" to see the exchange rate.',
'amount_greater_than_balance' => 'The amount is greater than the invoice balance, a credit will be created with the remaining amount.',
'custom_fields_tip' => 'Use <code>Label|Option1,Option2</code> to show a select box.'
);

View File

@ -242,7 +242,7 @@
->label(trans('texts.field_label')) !!}
{!! Former::text('custom_client_label2')
->label(trans('texts.field_label'))
->help(trans('texts.custom_client_fields_helps')) !!}
->help(trans('texts.custom_client_fields_helps') . ' ' . trans('texts.custom_fields_tip')) !!}
</div>
</div>
@ -253,7 +253,7 @@
->label(trans('texts.field_label')) !!}
{!! Former::text('custom_contact_label2')
->label(trans('texts.field_label'))
->help(trans('texts.custom_contact_fields_help')) !!}
->help(trans('texts.custom_contact_fields_help') . ' ' . trans('texts.custom_fields_tip')) !!}
</div>
</div>
@ -280,7 +280,7 @@
->label(trans('texts.field_label')) !!}
{!! Former::text('custom_invoice_item_label2')
->label(trans('texts.field_label'))
->help(trans('texts.custom_product_fields_help')) !!}
->help(trans('texts.custom_product_fields_help') . ' ' . trans('texts.custom_fields_tip')) !!}
</div>
</div>
@ -291,7 +291,7 @@
->label(trans('texts.field_label')) !!}
{!! Former::text('custom_invoice_text_label2')
->label(trans('texts.field_label'))
->help(trans('texts.custom_invoice_fields_helps')) !!}
->help(trans('texts.custom_invoice_fields_helps') . ' ' . trans('texts.custom_fields_tip')) !!}
{!! Former::text('custom_invoice_label1')
->label(trans('texts.surcharge_label'))

View File

@ -29,10 +29,16 @@
@if ($account->hasFeature(FEATURE_INVOICE_SETTINGS))
@if ($account->custom_invoice_item_label1)
{!! Former::text('custom_value1')->label(e($account->custom_invoice_item_label1)) !!}
@include('partials.custom_field', [
'field' => 'custom_value1',
'label' => $account->custom_invoice_item_label1
])
@endif
@if ($account->custom_invoice_item_label2)
{!! Former::text('custom_value2')->label(e($account->custom_invoice_item_label2)) !!}
@include('partials.custom_field', [
'field' => 'custom_value2',
'label' => $account->custom_invoice_item_label2
])
@endif
@endif

View File

@ -53,10 +53,16 @@
@if (Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS))
@if ($customLabel1)
{!! Former::text('custom_value1')->label(e($customLabel1)) !!}
@include('partials.custom_field', [
'field' => 'custom_value1',
'label' => $customLabel1
])
@endif
@if ($customLabel2)
{!! Former::text('custom_value2')->label(e($customLabel2)) !!}
@include('partials.custom_field', [
'field' => 'custom_value2',
'label' => $customLabel2
])
@endif
@endif
@ -154,14 +160,20 @@
@if (Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS))
@if ($account->custom_contact_label1)
{!! Former::text('custom_contact1')->data_bind("value: custom_value1, valueUpdate: 'afterkeydown',
attr: {name: 'contacts[' + \$index() + '][custom_value1]'}")
->label(e($account->custom_contact_label1)) !!}
@include('partials.custom_field', [
'field' => 'custom_contact1',
'label' => $account->custom_contact_label1,
'databind' => "value: custom_value1, valueUpdate: 'afterkeydown',
attr: {name: 'contacts[' + \$index() + '][custom_value1]'}",
])
@endif
@if ($account->custom_contact_label2)
{!! Former::text('custom_contact2')->data_bind("value: custom_value2, valueUpdate: 'afterkeydown',
attr: {name: 'contacts[' + \$index() + '][custom_value2]'}")
->label(e($account->custom_contact_label2)) !!}
@include('partials.custom_field', [
'field' => 'custom_contact2',
'label' => $account->custom_contact_label2,
'databind' => "value: custom_value2, valueUpdate: 'afterkeydown',
attr: {name: 'contacts[' + \$index() + '][custom_value2]'}",
])
@endif
@endif

View File

@ -99,10 +99,10 @@
@endif
@if ($client->account->custom_client_label1 && $client->custom_value1)
{{ $client->account->custom_client_label1 . ': ' . $client->custom_value1 }}<br/>
{{ $client->account->present()->customClientLabel1 . ': ' . $client->custom_value1 }}<br/>
@endif
@if ($client->account->custom_client_label2 && $client->custom_value2)
{{ $client->account->custom_client_label2 . ': ' . $client->custom_value2 }}<br/>
{{ $client->account->present()->customClientLabel2 . ': ' . $client->custom_value2 }}<br/>
@endif
@if ($client->work_phone)
@ -172,10 +172,10 @@
@endif
@if ($client->account->custom_contact_label1 && $contact->custom_value1)
{{ $client->account->custom_contact_label1 . ': ' . $contact->custom_value1 }}<br/>
{{ $client->account->present()->customContactLabel1() . ': ' . $contact->custom_value1 }}<br/>
@endif
@if ($client->account->custom_contact_label2 && $contact->custom_value2)
{{ $client->account->custom_contact_label2 . ': ' . $contact->custom_value2 }}<br/>
{{ $client->account->present()->customContactLabel2() . ': ' . $contact->custom_value2 }}<br/>
@endif
@if (Auth::user()->confirmed && $client->account->enable_client_portal)

View File

@ -25,20 +25,20 @@
<td>{{ trans('texts.public_notes') }}</td>
<td>{{ trans('texts.private_notes') }}</td>
@if ($account->custom_client_label1)
<td>{{ $account->custom_client_label1 }}</td>
<td>{{ $account->present()->customClientLabel1 }}</td>
@endif
@if ($account->custom_client_label2)
<td>{{ $account->custom_client_label2 }}</td>
<td>{{ $account->present()->customClientLabel2 }}</td>
@endif
<td>{{ trans('texts.first_name') }}</td>
<td>{{ trans('texts.last_name') }}</td>
<td>{{ trans('texts.email') }}</td>
<td>{{ trans('texts.phone') }}</td>
@if ($account->custom_contact_label1)
<td>{{ $account->custom_contact_label1 }}</td>
<td>{{ $account->present()->customContactLabel1 }}</td>
@endif
@if ($account->custom_contact_label2)
<td>{{ $account->custom_contact_label2 }}</td>
<td>{{ $account->present()->customContactLabel2 }}</td>
@endif
</tr>

View File

@ -8,10 +8,10 @@
<td>{{ trans('texts.email') }}</td>
<td>{{ trans('texts.phone') }}</td>
@if ($account->custom_contact_label1)
<td>{{ $account->custom_contact_label1 }}</td>
<td>{{ $account->present()->customContactLabel1 }}</td>
@endif
@if ($account->custom_contact_label2)
<td>{{ $account->custom_contact_label2 }}</td>
<td>{{ $account->present()->customContactLabel2 }}</td>
@endif
</tr>

View File

@ -18,24 +18,24 @@
<td>{{ trans('texts.public_notes') }}</td>
<td>{{ trans('texts.private_notes') }}</td>
@if ($account->custom_invoice_label1)
<td>{{ $account->custom_invoice_label1 }}</td>
<td>{{ $account->present()->customInvoiceLabel1 }}</td>
@endif
@if ($account->custom_invoice_label2)
<td>{{ $account->custom_invoice_label2 }}</td>
<td>{{ $account->present()->customInvoiceLabel2 }}</td>
@endif
@if ($account->custom_invoice_text_label1)
<td>{{ $account->custom_invoice_text_label1 }}</td>
<td>{{ $account->present()->customInvoiceTextLabel1 }}</td>
@endif
@if ($account->custom_invoice_text_label2)
<td>{{ $account->custom_invoice_text_label2 }}</td>
<td>{{ $account->present()->customInvoiceTextLabel1 }}</td>
@endif
<td>{{ trans('texts.item_product') }}</td>
<td>{{ trans('texts.item_notes') }}</td>
@if ($account->custom_invoice_item_label1)
<td>{{ $account->custom_invoice_item_label1 }}</td>
<td>{{ $account->present()->customProductLabel1 }}</td>
@endif
@if ($account->custom_invoice_item_label2)
<td>{{ $account->custom_invoice_item_label2 }}</td>
<td>{{ $account->present()->customProductLabel2 }}</td>
@endif
<td>{{ trans('texts.item_cost') }}</td>
<td>{{ trans('texts.item_quantity') }}</td>
@ -77,10 +77,10 @@
@if ($account->custom_invoice_label2)
<td>{{ $invoice->custom_value2 }}</td>
@endif
@if ($account->custom_invoice_label1)
@if ($account->custom_invoice_text_label1)
<td>{{ $invoice->custom_text_value1 }}</td>
@endif
@if ($account->custom_invoice_label2)
@if ($account->custom_invoice_text_label2)
<td>{{ $invoice->custom_text_value2 }}</td>
@endif
<td>{{ $item->product_key }}</td>

View File

@ -5,6 +5,12 @@
<td>{{ trans('texts.product') }}</td>
<td>{{ trans('texts.notes') }}</td>
<td>{{ trans('texts.cost') }}</td>
@if ($account->custom_invoice_item_label1)
<td>{{ $account->present()->customProductLabel1 }}</td>
@endif
@if ($account->custom_invoice_item_label2)
<td>{{ $account->present()->customProductLabel2 }}</td>
@endif
</tr>
@foreach ($products as $product)
@ -15,5 +21,14 @@
<td>{{ $product->product_key }}</td>
<td>{{ $product->notes }}</td>
<td>{{ $product->cost }}</td>
@if ($account->custom_invoice_item_label1)
@endif
@if ($account->custom_invoice_item_label1)
<td>{{ $product->custom_value1 }}</td>
@endif
@if ($account->custom_invoice_item_label2)
<td>{{ $product->custom_value2 }}</td>
@endif
</tr>
@endforeach

View File

@ -57,7 +57,6 @@
window.loadedSearchData = true;
trackEvent('/activity', '/search');
var request = $.get('{{ URL::route('get_search_data') }}', function(data) {
console.log(data);
$('#search').typeahead({
hint: true,
highlight: true,
@ -67,9 +66,9 @@
name: 'data',
limit: 3,
display: 'value',
source: searchData(data['{{ Auth::user()->account->custom_client_label1 }}'], 'tokens'),
source: searchData(data['{{ Auth::user()->account->present()->customClientLabel1 }}'], 'tokens'),
templates: {
header: '&nbsp;<span style="font-weight:600;font-size:16px">{{ Auth::user()->account->custom_client_label1 }}</span>'
header: '&nbsp;<span style="font-weight:600;font-size:16px">{{ Auth::user()->account->present()->customClientLabel1 }}</span>'
}
}
@endif
@ -78,9 +77,9 @@
name: 'data',
limit: 3,
display: 'value',
source: searchData(data['{{ Auth::user()->account->custom_client_label2 }}'], 'tokens'),
source: searchData(data['{{ Auth::user()->account->present()->customClientLabel2 }}'], 'tokens'),
templates: {
header: '&nbsp;<span style="font-weight:600;font-size:16px">{{ Auth::user()->account->custom_client_label2 }}</span>'
header: '&nbsp;<span style="font-weight:600;font-size:16px">{{ Auth::user()->account->present()->customClientLabel2 }}</span>'
}
}
@endif

View File

@ -225,7 +225,11 @@
@endif
@if ($account->showCustomField('custom_invoice_text_label1', $invoice))
{!! Former::text('custom_text_value1')->label(e($account->custom_invoice_text_label1) ?: ' ')->data_bind("value: custom_text_value1, valueUpdate: 'afterkeydown'") !!}
@include('partials.custom_field', [
'field' => 'custom_text_value1',
'label' => $account->custom_invoice_text_label1,
'databind' => "value: custom_text_value1, valueUpdate: 'afterkeydown'",
])
@endif
</div>
@ -273,7 +277,11 @@
) !!}
@if ($account->showCustomField('custom_invoice_text_label2', $invoice))
{!! Former::text('custom_text_value2')->label(e($account->custom_invoice_text_label2) ?: ' ')->data_bind("value: custom_text_value2, valueUpdate: 'afterkeydown'") !!}
@include('partials.custom_field', [
'field' => 'custom_text_value2',
'label' => $account->custom_invoice_text_label2,
'databind' => "value: custom_text_value2, valueUpdate: 'afterkeydown'",
])
@endif
@if ($entityType == ENTITY_INVOICE)
@ -617,14 +625,18 @@
@if (Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS))
@if ($account->custom_client_label1)
{!! Former::text('client[custom_value1]')
->label(e($account->custom_client_label1))
->data_bind("value: custom_value1, valueUpdate: 'afterkeydown'") !!}
@include('partials.custom_field', [
'field' => 'client[custom_value1]',
'label' => $account->custom_client_label1,
'databind' => "value: custom_value1, valueUpdate: 'afterkeydown'",
])
@endif
@if ($account->custom_client_label2)
{!! Former::text('client[custom_value2]')
->label(e($account->custom_client_label2))
->data_bind("value: custom_value2, valueUpdate: 'afterkeydown'") !!}
@include('partials.custom_field', [
'field' => 'client[custom_value2]',
'label' => $account->custom_client_label2,
'databind' => "value: custom_value1, valueUpdate: 'afterkeydown'",
])
@endif
@endif
@ -677,14 +689,20 @@
@endif
@if (Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS))
@if ($account->custom_contact_label1)
{!! Former::text('custom_contact1')->data_bind("value: custom_value1, valueUpdate: 'afterkeydown',
attr: {name: 'client[contacts][' + \$index() + '][custom_value1]'}")
->label(e($account->custom_contact_label1)) !!}
@include('partials.custom_field', [
'field' => 'custom_contact1',
'label' => $account->custom_contact_label1,
'databind' => "value: custom_value1, valueUpdate: 'afterkeydown',
attr: {name: 'client[contacts][' + \$index() + '][custom_value1]'}",
])
@endif
@if ($account->custom_contact_label2)
{!! Former::text('custom_contact2')->data_bind("value: custom_value2, valueUpdate: 'afterkeydown',
attr: {name: 'client[contacts][' + \$index() + '][custom_value2]'}")
->label(e($account->custom_contact_label2)) !!}
@include('partials.custom_field', [
'field' => 'custom_contact2',
'label' => $account->custom_contact_label2,
'databind' => "value: custom_value2, valueUpdate: 'afterkeydown',
attr: {name: 'client[contacts][' + \$index() + '][custom_value2]'}",
])
@endif
@endif
<div class="form-group">

View File

@ -10,10 +10,10 @@
<th style="min-width:120px;width:25%">{{ $invoiceLabels[$isTasks ? 'service' : 'item'] }}</th>
<th style="width:100%">{{ $invoiceLabels['description'] }}</th>
@if ($account->showCustomField('custom_invoice_item_label1'))
<th style="min-width:120px">{{ $account->custom_invoice_item_label1 }}</th>
<th style="min-width:120px">{{ $account->present()->customProductLabel1 }}</th>
@endif
@if ($account->showCustomField('custom_invoice_item_label2'))
<th style="min-width:120px">{{ $account->custom_invoice_item_label2 }}</th>
<th style="min-width:120px">{{ $account->present()->customProductLabel2 }}</th>
@endif
<th style="min-width:120px">{{ $invoiceLabels[$isTasks ? 'rate' : 'unit_cost'] }}</th>
<th style="min-width:120px;display:{{ $account->hasInvoiceField($isTasks ? 'task' : 'product', $isTasks ? 'product.hours' : 'product.quantity') ? 'table-cell' : 'none' }}">{{ $invoiceLabels[$isTasks ? 'hours' : 'quantity'] }}</th>
@ -44,12 +44,24 @@
</td>
@if ($account->showCustomField('custom_invoice_item_label1'))
<td>
<input data-bind="value: custom_value1, valueUpdate: 'afterkeydown', attr: {name: 'invoice_items[{{ $isTasks ? 'T' : '' }}' + $index() + '][custom_value1]'}" class="form-control invoice-item"/>
@include('partials.custom_field', [
'field' => 'custom_invoice_item_label1',
'label' => $account->custom_invoice_item_label1,
'databind' => "value: custom_value1, valueUpdate: 'afterkeydown',
attr: {name: 'invoice_items[" . ($isTasks ? 'T' : '') . "' + \$index() + '][custom_value1]'}",
'raw' => true,
])
</td>
@endif
@if ($account->showCustomField('custom_invoice_item_label2'))
<td>
<input data-bind="value: custom_value2, valueUpdate: 'afterkeydown', attr: {name: 'invoice_items[{{ $isTasks ? 'T' : '' }}' + $index() + '][custom_value2]'}" class="form-control invoice-item"/>
@include('partials.custom_field', [
'field' => 'custom_invoice_item_label2',
'label' => $account->custom_invoice_item_label2,
'databind' => "value: custom_value2, valueUpdate: 'afterkeydown',
attr: {name: 'invoice_items[" . ($isTasks ? 'T' : '') . "' + \$index() + '][custom_value2]'}",
'raw' => true,
])
</td>
@endif
<td>

View File

@ -0,0 +1,29 @@
@if (empty($raw))
@if (strpos($label, '|') !== false)
{!! Former::select($field)
->label(Utils::getCustomLabel($label))
->addOption('', '')
->options(Utils::getCustomValues($label))
->data_bind(empty($databind) ? '' : $databind) !!}
@else
{!! Former::text($field)
->label(e($label))
->data_bind(empty($databind) ? '' : $databind) !!}
@endif
@else
@if (strpos($label, '|') !== false)
{!! Former::select($field)
->label(Utils::getCustomLabel($label))
->addOption('', '')
->options(Utils::getCustomValues($label))
->data_bind(empty($databind) ? '' : $databind)
->addClass('form-control invoice-item')
->raw() !!}
@else
{!! Former::text($field)
->label(e($label))
->data_bind(empty($databind) ? '' : $databind)
->addClass('form-control invoice-item')
->raw() !!}
@endif
@endif