1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Support searching by custom client fields

This commit is contained in:
Hillel Coren 2016-03-14 10:09:18 +02:00
parent e7df1f5e7c
commit ed7cbf1d2b
3 changed files with 56 additions and 6 deletions

View File

@ -123,7 +123,8 @@ class AccountController extends BaseController
public function getSearchData()
{
$data = $this->accountRepo->getSearchData();
$account = Auth::user()->account;
$data = $this->accountRepo->getSearchData($account);
return Response::json($data);
}

View File

@ -70,16 +70,16 @@ class AccountRepository
return $account;
}
public function getSearchData()
public function getSearchData($account)
{
$data = $this->getAccountSearchData();
$data = $this->getAccountSearchData($account);
$data['navigation'] = $this->getNavigationSearchData();
return $data;
}
private function getAccountSearchData()
private function getAccountSearchData($account)
{
$data = [
'clients' => [],
@ -88,6 +88,14 @@ class AccountRepository
'quotes' => [],
];
// include custom client fields in search
if ($account->custom_client_label1) {
$data[$account->custom_client_label1] = [];
}
if ($account->custom_client_label2) {
$data[$account->custom_client_label2] = [];
}
$clients = Client::scope()
->with('contacts', 'invoices')
->get();
@ -96,6 +104,22 @@ class AccountRepository
if ($client->name) {
$data['clients'][] = [
'value' => $client->name,
'tokens' => $client->name,
'url' => $client->present()->url,
];
}
if ($client->custom_value1) {
$data[$account->custom_client_label1][] = [
'value' => "{$client->custom_value1}: " . $client->getDisplayName(),
'tokens' => $client->custom_value1,
'url' => $client->present()->url,
];
}
if ($client->custom_value2) {
$data[$account->custom_client_label2][] = [
'value' => "{$client->custom_value2}: " . $client->getDisplayName(),
'tokens' => $client->custom_value2,
'url' => $client->present()->url,
];
}
@ -104,12 +128,14 @@ class AccountRepository
if ($contact->getFullName()) {
$data['contacts'][] = [
'value' => $contact->getDisplayName(),
'tokens' => $contact->getDisplayName(),
'url' => $client->present()->url,
];
}
if ($contact->email) {
$data[trans('texts.contacts')][] = [
$data['contacts'][] = [
'value' => $contact->email,
'tokens' => $contact->email,
'url' => $client->present()->url,
];
}
@ -119,6 +145,7 @@ class AccountRepository
$entityType = $invoice->getEntityType();
$data["{$entityType}s"][] = [
'value' => $invoice->getDisplayName() . ': ' . $client->getDisplayName(),
'tokens' => $invoice->getDisplayName() . ': ' . $client->getDisplayName(),
'url' => $invoice->present()->url,
];
}
@ -156,6 +183,7 @@ class AccountRepository
$features[] = ['new_tax_rate', '/tax_rates/create'];
$features[] = ['new_product', '/products/create'];
$features[] = ['new_user', '/users/create'];
$features[] = ['custom_fields', '/settings/invoice_settings'];
$settings = array_merge(Account::$basicSettings, Account::$advancedSettings);
@ -169,6 +197,7 @@ class AccountRepository
foreach ($features as $feature) {
$data[] = [
'value' => trans('texts.' . $feature[0]),
'tokens' => trans('texts.' . $feature[0]),
'url' => URL::to($feature[1])
];
}

View File

@ -274,11 +274,31 @@
hint: true,
highlight: true,
}
@if (Auth::check() && Auth::user()->account->custom_client_label1)
,{
name: 'data',
display: 'value',
source: searchData(data['{{ Auth::user()->account->custom_client_label1 }}'], 'tokens'),
templates: {
header: '&nbsp;<span style="font-weight:600;font-size:16px">{{ Auth::user()->account->custom_client_label1 }}</span>'
}
}
@endif
@if (Auth::check() && Auth::user()->account->custom_client_label2)
,{
name: 'data',
display: 'value',
source: searchData(data['{{ Auth::user()->account->custom_client_label2 }}'], 'tokens'),
templates: {
header: '&nbsp;<span style="font-weight:600;font-size:16px">{{ Auth::user()->account->custom_client_label2 }}</span>'
}
}
@endif
@foreach (['clients', 'contacts', 'invoices', 'quotes', 'navigation'] as $type)
,{
name: 'data',
display: 'value',
source: searchData(data['{{ $type }}'], 'value', true),
source: searchData(data['{{ $type }}'], 'tokens', true),
templates: {
header: '&nbsp;<span style="font-weight:600;font-size:16px">{{ trans("texts.{$type}") }}</span>'
}