From 584c33de70e641ee55ca56dcade0f5abcf992a12 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 23 Oct 2025 08:50:31 +1100 Subject: [PATCH] Add number filters --- app/Filters/TaskFilters.php | 59 ++----------------------------------- 1 file changed, 3 insertions(+), 56 deletions(-) diff --git a/app/Filters/TaskFilters.php b/app/Filters/TaskFilters.php index b5a32d211f..132f890ed4 100644 --- a/app/Filters/TaskFilters.php +++ b/app/Filters/TaskFilters.php @@ -36,6 +36,7 @@ class TaskFilters extends QueryFilters return $this->builder->where(function ($query) use ($filter) { $query->where('description', 'like', '%'.$filter.'%') + ->orWhere("number", 'like', '%'.$filter.'%') ->orWhere('time_log', 'like', '%'.$filter.'%') ->orWhere('custom_value1', 'like', '%'.$filter.'%') ->orWhere('custom_value2', 'like', '%'.$filter.'%') @@ -138,14 +139,12 @@ class TaskFilters extends QueryFilters $dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc'; if ($sort_col[0] == 'client_id') { - return $this->builder->orderByRaw('ISNULL(client_id), client_id '. $dir) - ->orderBy(\App\Models\Client::select('name') + return $this->builder->orderBy(\App\Models\Client::select('name') ->whereColumn('clients.id', 'tasks.client_id'), $dir); } if ($sort_col[0] == 'user_id') { - return $this->builder->orderByRaw('ISNULL(user_id), user_id '. $dir) - ->orderBy(\App\Models\User::select('first_name') + return $this->builder->orderBy(\App\Models\User::select('first_name') ->whereColumn('users.id', 'tasks.user_id'), $dir); } @@ -166,33 +165,6 @@ class TaskFilters extends QueryFilters } - public function client_ids(string $client_ids = ''): Builder - { - if (strlen($client_ids) == 0) { - return $this->builder; - } - - return $this->builder->whereIn('client_id', $this->transformKeys(explode(',', $client_ids))); - } - - public function project_ids(string $project_ids = ''): Builder - { - if (strlen($project_ids) == 0) { - return $this->builder; - } - - return $this->builder->whereIn('project_id', $this->transformKeys(explode(',', $project_ids))); - } - - public function assigned_user_ids(string $assigned_user_ids = ''): Builder - { - if (strlen($assigned_user_ids) == 0) { - return $this->builder; - } - - return $this->builder->whereIn('assigned_user_id', $this->transformKeys(explode(',', $assigned_user_ids))); - } - public function assigned_user(string $user = ''): Builder { if (strlen($user) == 0) { @@ -223,31 +195,6 @@ class TaskFilters extends QueryFilters return $this->builder; } - /** - * Filter by date range - * - * @param string $date_range - * @return Builder - */ - public function date_range(string $date_range = ''): Builder - { - $parts = explode(",", $date_range); - - if (count($parts) != 2 || !in_array('calculated_start_date', \Illuminate\Support\Facades\Schema::getColumnListing($this->builder->getModel()->getTable()))) { - return $this->builder; - } - - try { - - $start_date = \Carbon\Carbon::parse($parts[0]); - $end_date = \Carbon\Carbon::parse($parts[1]); - - return $this->builder->whereBetween('calculated_start_date', [$start_date, $end_date]); - } catch (\Exception $e) { - return $this->builder; - } - - } /** * Filters the query by the users company ID.