builder; } return $this->builder->where(function ($query) use ($filter) { $query->where('amount', 'like', '%'.$filter.'%') ->orWhere('date', 'like', '%'.$filter.'%') ->orWhere('custom_value1', 'like', '%'.$filter.'%') ->orWhere('custom_value2', 'like', '%'.$filter.'%') ->orWhere('custom_value3', 'like', '%'.$filter.'%') ->orWhere('custom_value4', 'like', '%'.$filter.'%'); }); } /** * Returns a list of payments that can be matched to bank transactions */ public function match_transactions($value = 'true'): Builder { if($value == 'true'){ return $this->builder ->where('is_deleted',0) ->where(function ($query){ $query->whereNull('transaction_id') ->orWhere("transaction_id","") ->company(); }); } return $this->builder; } public function number(string $number = ''): Builder { if (strlen($number) == 0) { return $this->builder; } return $this->builder->where('number', $number); } /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); if (!is_array($sort_col) || count($sort_col) != 2) { return $this->builder; } return $this->builder->orderBy($sort_col[0], $sort_col[1]); } /** * Filters the query by the users company ID. * * @return Illuminate\Database\Query\Builder */ public function entityFilter(): Builder { if (auth()->guard('contact')->user()) { return $this->contactViewFilter(); } else { return $this->builder->company(); } } /** * We need additional filters when showing invoices for the * client portal. Need to automatically exclude drafts and cancelled invoices. * * @return Builder */ private function contactViewFilter(): Builder { return $this->builder ->whereCompanyId(auth()->guard('contact')->user()->company->id) ->whereIsDeleted(false); } }