diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index a0fb51b74654..abefe0b5f745 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -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); } diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index ff85efb76eba..0e08fbba5d06 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -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,20 +104,38 @@ 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, + ]; } foreach ($client->contacts as $contact) { 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]) ]; } diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index de405212392c..09525079e371 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -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: ' {{ Auth::user()->account->custom_client_label1 }}' + } + } + @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: ' {{ Auth::user()->account->custom_client_label2 }}' + } + } + @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: ' {{ trans("texts.{$type}") }}' }