diff --git a/app/View/Components/SearchString.php b/app/View/Components/SearchString.php index 51ef8500c..d7f615cad 100644 --- a/app/View/Components/SearchString.php +++ b/app/View/Components/SearchString.php @@ -4,6 +4,7 @@ namespace App\View\Components; use Illuminate\View\Component; use Illuminate\Support\Str; +use Symfony\Component\Routing\Exception\RouteNotFoundException; class SearchString extends Component { @@ -44,7 +45,11 @@ class SearchString extends Component if (!is_array($options)) { $column = $options; } - + + if (!$this->isFilter($column, $options)) { + continue; + } + $this->filters[] = [ 'key' => $this->getFilterKey($column, $options), 'value' => $this->getFilterName($column), @@ -58,6 +63,17 @@ class SearchString extends Component return view('components.search-string'); } + protected function isFilter($column, $options) + { + $filter = true; + + if (empty($this->getFilterUrl($column, $options)) && (!isset($options['date']) && !isset($options['boolean']))) { + $filter = false; + } + + return $filter; + } + protected function getFilterKey($column, $options) { if (isset($options['relationship'])) { @@ -71,20 +87,22 @@ class SearchString extends Component { if (strpos($column, '_id') !== false) { $column = str_replace('_id', '', $column); + } else if (strpos($column, '_code') !== false) { + $column = str_replace('_code', '', $column); } $plural = Str::plural($column, 2); if (trans_choice('general.' . $plural, 1) !== 'general.' . $plural) { return trans_choice('general.' . $plural, 1); - } elseif (trans_choice('search_string.colmuns.' . $plural, 1) !== 'search_string.colmuns.' . $plural) { - return trans_choice('search_string.colmuns.' . $plural, 1); + } elseif (trans_choice('search_string.columns.' . $plural, 1) !== 'search_string.columns.' . $plural) { + return trans_choice('search_string.columns.' . $plural, 1); } $name = trans('general.' . $column); if ($name == 'general.' . $column) { - $name = trans('search_string.colmuns.' . $column); + $name = trans('search_string.columns.' . $column); } return $name; @@ -98,6 +116,10 @@ class SearchString extends Component $type = 'boolean'; } + if (isset($options['date'])) { + $type = 'date'; + } + return $type; } @@ -105,7 +127,7 @@ class SearchString extends Component { $url = ''; - if (isset($options['boolean'])) { + if (isset($options['boolean']) || isset($options['date'])) { return $url; } @@ -128,7 +150,11 @@ class SearchString extends Component $plural = Str::plural($column, 2); - $url = route($url . $plural . '.index'); + try { + $url = route($url . $plural . '.index'); + } catch (\Exception $e) { + $url = ''; + } } return $url; diff --git a/config/search-string.php b/config/search-string.php index cf316c474..c8895694f 100644 --- a/config/search-string.php +++ b/config/search-string.php @@ -69,7 +69,9 @@ return [ 'number' => ['searchable' => true], 'bank_name' => ['searchable' => true], 'bank_address' => ['searchable' => true], - 'currency' => ['relationship' => true], + 'currency_code' => [ + 'route' => 'currencies.index' + ], 'enabled' => ['boolean' => true], ], ], @@ -87,16 +89,24 @@ return [ App\Models\Banking\Transaction::class => [ 'columns' => [ 'type', - 'account_id', + 'account_id' => [ + 'route' => 'accounts.index' + ], 'paid_at' => ['date' => true], 'amount', - 'currency_code', + 'currency_code' => [ + 'route' => 'currencies.index' + ], 'document_id', - 'contact_id', + 'contact_id' => [ + 'route' => 'customers.index' + ], 'description' => ['searchable' => true], 'payment_method', 'reference', - 'category_id', + 'category_id' => [ + 'route' => 'categories.index' + ], 'parent_id', ], ], @@ -123,6 +133,8 @@ return [ 'category_id' => [ 'route' => ['categories.index', 'search=type:item'] ], + 'sales_price', + 'purchase_price', ], ], @@ -135,7 +147,9 @@ return [ 'phone' => ['searchable' => true], 'address' => ['searchable' => true], 'website' => ['searchable' => true], - 'currency_code', + 'currency_code' => [ + 'route' => 'currencies.index' + ], 'reference', 'user_id', 'enabled' => ['boolean' => true], @@ -150,14 +164,20 @@ return [ 'billed_at' => ['date' => true], 'due_at' => ['date' => true], 'amount', - 'currency_code', - 'contact_id', + 'currency_code' => [ + 'route' => 'currencies.index' + ], + 'contact_id' => [ + 'route' => 'vendors.index' + ], 'contact_name' => ['searchable' => true], 'contact_email' => ['searchable' => true], 'contact_tax_number', 'contact_phone' => ['searchable' => true], 'contact_address' => ['searchable' => true], - 'category_id', + 'category_id' => [ + 'route' => 'categories.index' + ], 'parent_id', ], ], @@ -170,14 +190,20 @@ return [ 'invoiced_at' => ['date' => true], 'due_at' => ['date' => true], 'amount', - 'currency_code', - 'contact_id', + 'currency_code' => [ + 'route' => 'currencies.index' + ], + 'contact_id' => [ + 'route' => 'customer.index' + ], 'contact_name' => ['searchable' => true], 'contact_email' => ['searchable' => true], 'contact_tax_number', 'contact_phone' => ['searchable' => true], 'contact_address' => ['searchable' => true], - 'category_id', + 'category_id' => [ + 'route' => 'categories.index' + ], 'parent_id', ], ], diff --git a/resources/assets/js/components/AkauntingSearch.vue b/resources/assets/js/components/AkauntingSearch.vue index a69b0f896..cdbe637ea 100644 --- a/resources/assets/js/components/AkauntingSearch.vue +++ b/resources/assets/js/components/AkauntingSearch.vue @@ -17,6 +17,7 @@