Files
firefly-iii/app/Support/Search/OperatorQuerySearch.php

2871 lines
102 KiB
PHP
Raw Normal View History

2020-08-09 18:58:18 +02:00
<?php
2021-01-29 18:50:35 +01:00
/*
* OperatorQuerySearch.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-09-18 12:16:47 +02:00
declare(strict_types=1);
2020-08-09 18:58:18 +02:00
namespace FireflyIII\Support\Search;
use Carbon\Carbon;
2025-01-03 09:15:52 +01:00
use FireflyIII\Enums\AccountTypeEnum;
2023-12-01 05:15:59 +01:00
use FireflyIII\Enums\SearchDirection;
use FireflyIII\Enums\StringPosition;
2020-08-09 18:58:18 +02:00
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
2020-08-18 17:48:27 +02:00
use FireflyIII\Models\Account;
2020-08-22 12:24:01 +02:00
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\TransactionCurrency;
2020-08-09 18:58:18 +02:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
2025-02-23 12:35:13 +01:00
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
2025-05-04 17:41:26 +02:00
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\ParseDateString;
use FireflyIII\Support\Search\QueryParser\FieldNode;
2025-05-04 17:41:26 +02:00
use FireflyIII\Support\Search\QueryParser\Node;
use FireflyIII\Support\Search\QueryParser\NodeGroup;
2025-05-04 17:41:26 +02:00
use FireflyIII\Support\Search\QueryParser\QueryParserInterface;
use FireflyIII\Support\Search\QueryParser\StringNode;
2020-08-09 18:58:18 +02:00
use FireflyIII\User;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use LogicException;
use TypeError;
2020-08-09 18:58:18 +02:00
/**
2020-08-22 13:01:37 +02:00
* Class OperatorQuerySearch
2023-12-22 20:12:38 +01:00
*
2025-01-03 18:16:27 +01:00
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
2020-08-09 18:58:18 +02:00
*/
class OperatorQuerySearch implements SearchInterface
2020-08-09 18:58:18 +02:00
{
2025-05-04 17:41:26 +02:00
protected Carbon $date;
2025-05-04 13:50:20 +02:00
private readonly AccountRepositoryInterface $accountRepository;
private readonly BillRepositoryInterface $billRepository;
private readonly BudgetRepositoryInterface $budgetRepository;
private readonly CategoryRepositoryInterface $categoryRepository;
2025-05-04 17:41:26 +02:00
private GroupCollectorInterface $collector;
2025-05-04 13:50:20 +02:00
private readonly CurrencyRepositoryInterface $currencyRepository;
2025-05-04 17:41:26 +02:00
private array $excludeTags;
private array $includeAnyTags;
2024-03-06 07:16:01 +01:00
// added to fix #8632
2025-05-04 17:41:26 +02:00
private array $includeTags;
private array $invalidOperators;
private int $limit;
2025-05-04 13:50:20 +02:00
private readonly Collection $operators;
2025-05-04 17:41:26 +02:00
private int $page;
private array $prohibitedWords;
2025-05-04 13:50:20 +02:00
private readonly float $startTime;
private readonly TagRepositoryInterface $tagRepository;
private readonly array $validOperators;
2025-05-04 17:41:26 +02:00
private array $words;
2020-08-09 18:58:18 +02:00
2020-08-18 17:48:27 +02:00
/**
2020-08-22 13:01:37 +02:00
* OperatorQuerySearch constructor.
2020-08-18 17:48:27 +02:00
*/
2020-08-09 18:58:18 +02:00
public function __construct()
{
2023-10-29 06:33:43 +01:00
app('log')->debug('Constructed OperatorQuerySearch');
2022-10-30 14:24:37 +01:00
$this->operators = new Collection();
2020-08-09 18:58:18 +02:00
$this->page = 1;
$this->words = [];
$this->excludeTags = [];
2024-03-06 07:01:21 +01:00
$this->includeAnyTags = [];
$this->includeTags = [];
$this->prohibitedWords = [];
2021-06-30 20:02:19 +02:00
$this->invalidOperators = [];
$this->limit = 25;
$this->validOperators = array_keys(config('search.operators'));
2020-08-09 18:58:18 +02:00
$this->startTime = microtime(true);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->categoryRepository = app(CategoryRepositoryInterface::class);
$this->budgetRepository = app(BudgetRepositoryInterface::class);
$this->billRepository = app(BillRepositoryInterface::class);
$this->tagRepository = app(TagRepositoryInterface::class);
2020-08-22 12:24:01 +02:00
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
2020-08-09 18:58:18 +02:00
}
public function getInvalidOperators(): array
{
return $this->invalidOperators;
}
2020-08-09 18:58:18 +02:00
public function getModifiers(): Collection
{
2020-08-22 12:25:00 +02:00
return $this->getOperators();
2020-08-22 12:24:01 +02:00
}
public function getOperators(): Collection
{
return $this->operators;
2020-08-09 18:58:18 +02:00
}
public function getWordsAsString(): string
{
return implode(' ', $this->words);
}
/**
* @throws FireflyException
2020-08-09 18:58:18 +02:00
*/
public function hasModifiers(): bool
{
throw new FireflyException('Not implemented');
2020-08-09 18:58:18 +02:00
}
/**
2020-08-18 17:48:27 +02:00
* @throws FireflyException
2020-08-09 18:58:18 +02:00
*/
2023-11-04 11:31:14 +01:00
public function parseQuery(string $query): void
2020-08-09 18:58:18 +02:00
{
2025-01-05 08:03:15 +01:00
app('log')->debug(sprintf('Now in parseQuery("%s")', $query));
/** @var QueryParserInterface $parser */
2024-12-31 10:16:27 +01:00
$parser = app(QueryParserInterface::class);
2025-05-04 13:50:20 +02:00
app('log')->debug(sprintf('Using %s as implementation for QueryParserInterface', $parser::class));
2023-12-20 19:35:52 +01:00
2021-10-02 18:45:42 +02:00
try {
$parsedQuery = $parser->parse($query);
} catch (LogicException|TypeError $e) {
2023-10-29 06:32:00 +01:00
app('log')->error($e->getMessage());
app('log')->error(sprintf('Could not parse search: "%s".', $query));
2023-12-20 19:35:52 +01:00
2023-01-20 22:08:18 +01:00
throw new FireflyException(sprintf('Invalid search value "%s". See the logs.', e($query)), 0, $e);
2021-10-02 18:45:42 +02:00
}
2020-08-18 17:48:27 +02:00
app('log')->debug(sprintf('Found %d node(s) at top-level', count($parsedQuery->getNodes())));
2025-01-03 00:07:57 +01:00
$this->handleSearchNode($parsedQuery, $parsedQuery->isProhibited(false));
// add missing information
$this->collector->withBillInformation();
2020-08-09 18:58:18 +02:00
$this->collector->setSearchWords($this->words);
$this->collector->excludeSearchWords($this->prohibitedWords);
2020-08-09 18:58:18 +02:00
}
2023-12-20 19:35:52 +01:00
/**
2020-08-09 18:58:18 +02:00
* @throws FireflyException
2023-12-22 20:12:38 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
2020-08-09 18:58:18 +02:00
*/
2025-01-05 07:40:30 +01:00
private function handleSearchNode(Node $node, bool $flipProhibitedFlag): void
2020-08-09 18:58:18 +02:00
{
2025-05-04 13:50:20 +02:00
app('log')->debug(sprintf('Now in handleSearchNode(%s)', $node::class));
2023-12-20 19:35:52 +01:00
2024-12-31 10:16:27 +01:00
switch (true) {
case $node instanceof StringNode:
2025-01-03 00:07:57 +01:00
$this->handleStringNode($node, $flipProhibitedFlag);
2024-12-31 10:16:27 +01:00
break;
2023-12-20 19:35:52 +01:00
case $node instanceof FieldNode:
2025-01-03 00:07:57 +01:00
$this->handleFieldNode($node, $flipProhibitedFlag);
2024-12-31 10:16:27 +01:00
break;
2023-12-20 19:35:52 +01:00
case $node instanceof NodeGroup:
2025-01-03 00:07:57 +01:00
$this->handleNodeGroup($node, $flipProhibitedFlag);
2020-12-20 06:56:27 +01:00
break;
2023-12-20 19:35:52 +01:00
2020-08-09 18:58:18 +02:00
default:
2025-05-04 13:50:20 +02:00
app('log')->error(sprintf('Cannot handle node %s', $node::class));
2025-05-04 13:50:20 +02:00
throw new FireflyException(sprintf('Firefly III search can\'t handle "%s"-nodes', $node::class));
2024-12-31 10:16:27 +01:00
}
}
2023-12-20 19:35:52 +01:00
2025-01-05 07:40:30 +01:00
private function handleStringNode(StringNode $node, bool $flipProhibitedFlag): void
{
$string = $node->getValue();
2025-01-03 00:07:57 +01:00
$prohibited = $node->isProhibited($flipProhibitedFlag);
if ($prohibited) {
app('log')->debug(sprintf('Exclude string "%s" from search string', $string));
$this->prohibitedWords[] = $string;
}
if (!$prohibited) {
app('log')->debug(sprintf('Add string "%s" to search string', $string));
$this->words[] = $string;
}
}
2024-12-31 10:16:27 +01:00
/**
* @throws FireflyException
*/
2025-01-05 07:40:30 +01:00
private function handleFieldNode(FieldNode $node, bool $flipProhibitedFlag): void
2024-12-31 10:16:27 +01:00
{
$operator = strtolower($node->getOperator());
$value = $node->getValue();
2025-01-03 00:07:57 +01:00
$prohibited = $node->isProhibited($flipProhibitedFlag);
2023-12-20 19:35:52 +01:00
$context = config(sprintf('search.operators.%s.needs_context', $operator));
2024-12-31 10:16:27 +01:00
// is an operator that needs no context, and value is false, then prohibited = true.
if ('false' === $value && in_array($operator, $this->validOperators, true) && false === $context && !$prohibited) {
$prohibited = true;
$value = 'true';
2024-12-31 10:16:27 +01:00
}
// if the operator is prohibited, but the value is false, do an uno reverse
if ('false' === $value && $prohibited && in_array($operator, $this->validOperators, true) && false === $context) {
$prohibited = false;
$value = 'true';
2024-12-31 10:16:27 +01:00
}
2024-12-31 10:16:27 +01:00
// must be valid operator:
$inArray = in_array($operator, $this->validOperators, true);
if ($inArray) {
2025-01-05 07:40:30 +01:00
if ($this->updateCollector($operator, $value, $prohibited)) {
2024-12-31 10:16:27 +01:00
$this->operators->push([
'type' => self::getRootOperator($operator),
'value' => $value,
2024-12-31 10:16:27 +01:00
'prohibited' => $prohibited,
]);
app('log')->debug(sprintf('Added operator type "%s"', $operator));
}
}
if (!$inArray) {
2024-12-31 10:16:27 +01:00
app('log')->debug(sprintf('Added INVALID operator type "%s"', $operator));
$this->invalidOperators[] = [
'type' => $operator,
2025-01-05 07:40:30 +01:00
'value' => $value,
2024-12-31 10:16:27 +01:00
];
2020-08-09 18:58:18 +02:00
}
}
/**
2020-08-18 17:48:27 +02:00
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.ExcessiveMethodLength")
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
2020-08-09 18:58:18 +02:00
*/
2023-06-21 12:34:58 +02:00
private function updateCollector(string $operator, string $value, bool $prohibited): bool
2020-08-09 18:58:18 +02:00
{
2022-09-24 18:06:01 +02:00
if ($prohibited) {
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Operator "%s" is now "%s"', $operator, sprintf('-%s', $operator)));
2023-06-21 12:34:58 +02:00
$operator = sprintf('-%s', $operator);
2023-05-29 13:56:55 +02:00
}
2020-08-22 12:24:01 +02:00
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Now in updateCollector("%s", "%s")', $operator, $value));
2020-08-22 12:24:01 +02:00
2023-06-21 12:34:58 +02:00
// check if alias, replace if necessary:
$operator = self::getRootOperator($operator);
2023-05-29 13:56:55 +02:00
2023-06-21 12:34:58 +02:00
switch ($operator) {
default:
2023-10-29 06:32:00 +01:00
app('log')->error(sprintf('No such operator: %s', $operator));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
throw new FireflyException(sprintf('Unsupported search operator: "%s"', $operator));
2023-12-20 19:35:52 +01:00
// some search operators are ignored, basically:
2023-06-21 12:34:58 +02:00
case 'user_action':
2023-10-29 06:31:27 +01:00
app('log')->info(sprintf('Ignore search operator "%s"', $operator));
2023-05-29 13:56:55 +02:00
return false;
2023-12-20 19:35:52 +01:00
//
// all account related searches:
//
2023-06-21 12:34:58 +02:00
case 'account_is':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::IS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_is':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::IS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::CONTAINS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::CONTAINS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::ENDS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::ENDS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::STARTS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::BOTH, StringPosition::STARTS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_nr_is':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::IS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_nr_is':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::IS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_nr_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::CONTAINS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_nr_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::CONTAINS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_nr_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::ENDS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_nr_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::ENDS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_nr_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::STARTS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_nr_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::BOTH, StringPosition::STARTS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::STARTS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::STARTS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::ENDS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::ENDS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_is':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::IS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_is':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::IS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_nr_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::STARTS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_nr_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::STARTS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_nr_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::ENDS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_nr_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::ENDS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_nr_is':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::IS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_nr_is':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::IS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_nr_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::CONTAINS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_nr_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::SOURCE, StringPosition::CONTAINS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::CONTAINS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::SOURCE, StringPosition::CONTAINS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'source_account_id':
$account = $this->accountRepository->find((int) $value);
2023-06-21 12:34:58 +02:00
if (null !== $account) {
$this->collector->setSourceAccounts(new Collection([$account]));
}
if (null === $account) {
// since the source does not exist, cannot return results:
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_account_id':
$account = $this->accountRepository->find((int) $value);
2023-06-21 12:34:58 +02:00
if (null !== $account) {
$this->collector->excludeSourceAccounts(new Collection([$account]));
}
if (null === $account) {
// since the source does not exist, cannot return results:
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'journal_id':
$parts = explode(',', $value);
2023-06-21 12:34:58 +02:00
$this->collector->setJournalIds($parts);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-journal_id':
$parts = explode(',', $value);
2023-06-21 12:34:58 +02:00
$this->collector->excludeJournalIds($parts);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'id':
$parts = explode(',', $value);
2023-06-21 12:34:58 +02:00
$this->collector->setIds($parts);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-id':
$parts = explode(',', $value);
2023-06-21 12:34:58 +02:00
$this->collector->excludeIds($parts);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::STARTS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::STARTS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::ENDS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::ENDS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_nr_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::STARTS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_nr_starts':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::STARTS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_nr_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::ENDS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_nr_ends':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::ENDS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_nr_is':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::IS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_nr_is':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::IS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_is':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::IS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_is':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::IS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_nr_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::CONTAINS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_nr_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccountNr($value, SearchDirection::DESTINATION, StringPosition::CONTAINS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::CONTAINS);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_contains':
2023-12-01 05:15:59 +01:00
$this->searchAccount($value, SearchDirection::DESTINATION, StringPosition::CONTAINS, true);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_account_id':
$account = $this->accountRepository->find((int) $value);
2023-06-21 12:34:58 +02:00
if (null !== $account) {
$this->collector->setDestinationAccounts(new Collection([$account]));
}
if (null === $account) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_account_id':
$account = $this->accountRepository->find((int) $value);
2023-06-21 12:34:58 +02:00
if (null !== $account) {
$this->collector->excludeDestinationAccounts(new Collection([$account]));
}
if (null === $account) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_id':
$parts = explode(',', $value);
$collection = new Collection();
2023-06-21 12:34:58 +02:00
foreach ($parts as $accountId) {
2024-12-22 08:43:12 +01:00
$account = $this->accountRepository->find((int) $accountId);
2023-06-21 12:34:58 +02:00
if (null !== $account) {
$collection->push($account);
}
}
if ($collection->count() > 0) {
$this->collector->setAccounts($collection);
}
if (0 === $collection->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_id':
$parts = explode(',', $value);
$collection = new Collection();
2023-06-21 12:34:58 +02:00
foreach ($parts as $accountId) {
2024-12-22 08:43:12 +01:00
$account = $this->accountRepository->find((int) $accountId);
2023-06-21 12:34:58 +02:00
if (null !== $account) {
$collection->push($account);
}
}
if ($collection->count() > 0) {
$this->collector->setNotAccounts($collection);
}
if (0 === $collection->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// cash account
//
2023-06-21 12:34:58 +02:00
case 'source_is_cash':
$account = $this->getCashAccount();
2023-06-21 12:34:58 +02:00
$this->collector->setSourceAccounts(new Collection([$account]));
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-source_is_cash':
$account = $this->getCashAccount();
2023-06-21 12:34:58 +02:00
$this->collector->excludeSourceAccounts(new Collection([$account]));
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'destination_is_cash':
$account = $this->getCashAccount();
2023-06-21 12:34:58 +02:00
$this->collector->setDestinationAccounts(new Collection([$account]));
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-destination_is_cash':
$account = $this->getCashAccount();
2023-06-21 12:34:58 +02:00
$this->collector->excludeDestinationAccounts(new Collection([$account]));
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'account_is_cash':
$account = $this->getCashAccount();
2023-06-21 12:34:58 +02:00
$this->collector->setAccounts(new Collection([$account]));
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-account_is_cash':
$account = $this->getCashAccount();
2023-06-21 12:34:58 +02:00
$this->collector->excludeAccounts(new Collection([$account]));
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// description
//
2023-06-21 12:34:58 +02:00
case 'description_starts':
$this->collector->descriptionStarts([$value]);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-description_starts':
$this->collector->descriptionDoesNotStart([$value]);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'description_ends':
$this->collector->descriptionEnds([$value]);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-description_ends':
$this->collector->descriptionDoesNotEnd([$value]);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'description_contains':
$this->words[] = $value;
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-description_contains':
$this->prohibitedWords[] = $value;
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'description_is':
$this->collector->descriptionIs($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-description_is':
$this->collector->descriptionIsNot($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// currency
//
2023-06-21 12:34:58 +02:00
case 'currency_is':
$currency = $this->findCurrency($value);
2025-05-27 17:06:15 +02:00
if ($currency instanceof TransactionCurrency) {
2023-06-21 12:34:58 +02:00
$this->collector->setCurrency($currency);
}
2025-05-27 17:06:15 +02:00
if (!$currency instanceof TransactionCurrency) {
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-currency_is':
$currency = $this->findCurrency($value);
2025-05-27 17:06:15 +02:00
if ($currency instanceof TransactionCurrency) {
2023-06-21 12:34:58 +02:00
$this->collector->excludeCurrency($currency);
}
2025-05-27 17:06:15 +02:00
if (!$currency instanceof TransactionCurrency) {
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'foreign_currency_is':
$currency = $this->findCurrency($value);
2025-05-27 17:06:15 +02:00
if ($currency instanceof TransactionCurrency) {
2023-06-21 12:34:58 +02:00
$this->collector->setForeignCurrency($currency);
}
2025-05-27 17:06:15 +02:00
if (!$currency instanceof TransactionCurrency) {
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-foreign_currency_is':
$currency = $this->findCurrency($value);
2025-05-27 17:06:15 +02:00
if ($currency instanceof TransactionCurrency) {
2023-06-21 12:34:58 +02:00
$this->collector->excludeForeignCurrency($currency);
}
2025-05-27 17:06:15 +02:00
if (!$currency instanceof TransactionCurrency) {
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// attachments
//
2023-06-21 12:34:58 +02:00
case 'has_attachments':
case '-has_no_attachments':
2023-10-29 06:33:43 +01:00
app('log')->debug('Set collector to filter on attachments.');
2023-06-21 12:34:58 +02:00
$this->collector->hasAttachments();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'has_no_attachments':
case '-has_attachments':
2023-10-29 06:33:43 +01:00
app('log')->debug('Set collector to filter on NO attachments.');
2023-06-21 12:34:58 +02:00
$this->collector->hasNoAttachments();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// categories
2023-06-21 12:34:58 +02:00
case '-has_any_category':
case 'has_no_category':
$this->collector->withoutCategory();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-has_no_category':
case 'has_any_category':
$this->collector->withCategory();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'category_is':
$category = $this->categoryRepository->findByName($value);
2023-06-21 12:34:58 +02:00
if (null !== $category) {
$this->collector->setCategory($category);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
$this->collector->findNothing();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-category_is':
$category = $this->categoryRepository->findByName($value);
2023-06-21 12:34:58 +02:00
if (null !== $category) {
$this->collector->excludeCategory($category);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'category_ends':
$result = $this->categoryRepository->categoryEndsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setCategories($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-category_ends':
$result = $this->categoryRepository->categoryEndsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeCategories($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'category_starts':
$result = $this->categoryRepository->categoryStartsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setCategories($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-category_starts':
$result = $this->categoryRepository->categoryStartsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeCategories($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'category_contains':
$result = $this->categoryRepository->searchCategory($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setCategories($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-category_contains':
$result = $this->categoryRepository->searchCategory($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeCategories($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// budgets
//
2023-06-21 12:34:58 +02:00
case '-has_any_budget':
case 'has_no_budget':
$this->collector->withoutBudget();
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'has_any_budget':
case '-has_no_budget':
$this->collector->withBudget();
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'budget_contains':
$result = $this->budgetRepository->searchBudget($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setBudgets($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-budget_contains':
$result = $this->budgetRepository->searchBudget($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeBudgets($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'budget_is':
$budget = $this->budgetRepository->findByName($value);
2023-06-21 12:34:58 +02:00
if (null !== $budget) {
$this->collector->setBudget($budget);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
$this->collector->findNothing();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-budget_is':
$budget = $this->budgetRepository->findByName($value);
2023-06-21 12:34:58 +02:00
if (null !== $budget) {
$this->collector->excludeBudget($budget);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
$this->collector->findNothing();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'budget_ends':
$result = $this->budgetRepository->budgetEndsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setBudgets($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-budget_ends':
$result = $this->budgetRepository->budgetEndsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeBudgets($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'budget_starts':
$result = $this->budgetRepository->budgetStartsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setBudgets($result);
2023-05-29 13:56:55 +02:00
}
2023-06-21 12:34:58 +02:00
if (0 === $result->count()) {
2023-05-29 13:56:55 +02:00
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-budget_starts':
$result = $this->budgetRepository->budgetStartsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeBudgets($result);
2023-05-29 13:56:55 +02:00
}
2023-06-21 12:34:58 +02:00
if (0 === $result->count()) {
2023-05-29 13:56:55 +02:00
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// bill
//
2023-06-21 12:34:58 +02:00
case '-has_any_bill':
case 'has_no_bill':
$this->collector->withoutBill();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-has_no_bill':
case 'has_any_bill':
$this->collector->withBill();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'bill_contains':
$result = $this->billRepository->searchBill($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setBills($result);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
$this->collector->findNothing();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-bill_contains':
$result = $this->billRepository->searchBill($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeBills($result);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
$this->collector->findNothing();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'bill_is':
$bill = $this->billRepository->findByName($value);
2023-06-21 12:34:58 +02:00
if (null !== $bill) {
$this->collector->setBill($bill);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
$this->collector->findNothing();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-bill_is':
$bill = $this->billRepository->findByName($value);
2023-06-21 12:34:58 +02:00
if (null !== $bill) {
$this->collector->excludeBills(new Collection([$bill]));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
$this->collector->findNothing();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'bill_ends':
$result = $this->billRepository->billEndsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setBills($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-bill_ends':
$result = $this->billRepository->billEndsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeBills($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'bill_starts':
$result = $this->billRepository->billStartsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->setBills($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-bill_starts':
$result = $this->billRepository->billStartsWith($value, 1337);
2023-06-21 12:34:58 +02:00
if ($result->count() > 0) {
$this->collector->excludeBills($result);
}
if (0 === $result->count()) {
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// tags
//
2023-06-21 12:34:58 +02:00
case '-has_any_tag':
case 'has_no_tag':
$this->collector->withoutTags();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-has_no_tag':
case 'has_any_tag':
$this->collector->hasAnyTag();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-tag_is_not':
case 'tag_is':
$result = $this->tagRepository->findByTag($value);
2023-06-21 12:34:58 +02:00
if (null !== $result) {
$this->includeTags[] = $result->id;
$this->includeTags = array_unique($this->includeTags);
2023-06-21 12:34:58 +02:00
}
// no tags found means search must result in nothing.
if (null === $result) {
2023-10-29 06:31:27 +01:00
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
case 'tag_contains':
$tags = $this->tagRepository->searchTag($value);
if (0 === $tags->count()) {
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
$this->collector->findNothing();
}
if ($tags->count() > 0) {
2024-03-06 07:01:21 +01:00
// changed from includeTags to includeAnyTags for #8632
$ids = array_values($tags->pluck('id')->toArray());
$this->includeAnyTags = array_unique(array_merge($this->includeAnyTags, $ids));
}
2023-12-20 19:35:52 +01:00
break;
2023-12-20 19:35:52 +01:00
case 'tag_starts':
$tags = $this->tagRepository->tagStartsWith($value);
if (0 === $tags->count()) {
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
$this->collector->findNothing();
}
if ($tags->count() > 0) {
2024-03-06 07:01:21 +01:00
// changed from includeTags to includeAnyTags for #8632
$ids = array_values($tags->pluck('id')->toArray());
$this->includeAnyTags = array_unique(array_merge($this->includeAnyTags, $ids));
}
2023-12-20 19:35:52 +01:00
break;
2023-12-20 19:35:52 +01:00
case '-tag_starts':
$tags = $this->tagRepository->tagStartsWith($value);
if (0 === $tags->count()) {
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
$this->collector->findNothing();
}
if ($tags->count() > 0) {
$ids = array_values($tags->pluck('id')->toArray());
$this->excludeTags = array_unique(array_merge($this->includeTags, $ids));
}
2023-12-20 19:35:52 +01:00
break;
2023-12-20 19:35:52 +01:00
case 'tag_ends':
$tags = $this->tagRepository->tagEndsWith($value);
if (0 === $tags->count()) {
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
$this->collector->findNothing();
}
if ($tags->count() > 0) {
$ids = array_values($tags->pluck('id')->toArray());
$this->includeTags = array_unique(array_merge($this->includeTags, $ids));
}
2023-12-20 19:35:52 +01:00
break;
2023-12-20 19:35:52 +01:00
case '-tag_ends':
$tags = $this->tagRepository->tagEndsWith($value);
if (0 === $tags->count()) {
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
$this->collector->findNothing();
}
if ($tags->count() > 0) {
$ids = array_values($tags->pluck('id')->toArray());
$this->excludeTags = array_unique(array_merge($this->includeTags, $ids));
}
2023-12-20 19:35:52 +01:00
break;
2023-12-20 19:35:52 +01:00
case '-tag_contains':
$tags = $this->tagRepository->searchTag($value)->keyBy('id');
if (0 === $tags->count()) {
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
$this->collector->findNothing();
}
if ($tags->count() > 0) {
$ids = array_values($tags->pluck('id')->toArray());
$this->excludeTags = array_unique(array_merge($this->excludeTags, $ids));
}
2023-12-20 19:35:52 +01:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-tag_is':
case 'tag_is_not':
$result = $this->tagRepository->findByTag($value);
2023-12-03 08:28:50 +01:00
if (null !== $result) {
$this->excludeTags[] = $result->id;
$this->excludeTags = array_unique($this->excludeTags);
2023-06-21 12:34:58 +02:00
}
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// notes
//
2023-06-21 12:34:58 +02:00
case 'notes_contains':
$this->collector->notesContain($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-notes_contains':
$this->collector->notesDoNotContain($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'notes_starts':
$this->collector->notesStartWith($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-notes_starts':
$this->collector->notesDontStartWith($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'notes_ends':
$this->collector->notesEndWith($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-notes_ends':
$this->collector->notesDontEndWith($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'notes_is':
$this->collector->notesExactly($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-notes_is':
$this->collector->notesExactlyNot($value);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-any_notes':
case 'no_notes':
$this->collector->withoutNotes();
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'any_notes':
case '-no_notes':
$this->collector->withAnyNotes();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'reconciled':
$this->collector->isReconciled();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-reconciled':
$this->collector->isNotReconciled();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// amount
//
2023-06-21 12:34:58 +02:00
case 'amount_is':
// strip comma's, make dots.
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Original value "%s"', $value));
$value = str_replace(',', '.', $value);
$amount = app('steam')->positive($value);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
2023-06-21 12:34:58 +02:00
$this->collector->amountIs($amount);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-amount_is':
// strip comma's, make dots.
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Original value "%s"', $value));
$value = str_replace(',', '.', $value);
$amount = app('steam')->positive($value);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
2023-06-21 12:34:58 +02:00
$this->collector->amountIsNot($amount);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-06-21 12:34:58 +02:00
2023-12-20 19:35:52 +01:00
case 'foreign_amount_is':
2023-06-21 12:34:58 +02:00
// strip comma's, make dots.
$value = str_replace(',', '.', $value);
2023-06-21 12:34:58 +02:00
$amount = app('steam')->positive($value);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
2023-06-21 12:34:58 +02:00
$this->collector->foreignAmountIs($amount);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-06-21 12:34:58 +02:00
2023-12-20 19:35:52 +01:00
case '-foreign_amount_is':
2023-06-21 12:34:58 +02:00
// strip comma's, make dots.
$value = str_replace(',', '.', $value);
2023-06-21 12:34:58 +02:00
$amount = app('steam')->positive($value);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
2023-06-21 12:34:58 +02:00
$this->collector->foreignAmountIsNot($amount);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-amount_more':
case 'amount_less':
// strip comma's, make dots.
$value = str_replace(',', '.', $value);
2023-06-21 12:34:58 +02:00
$amount = app('steam')->positive($value);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
2023-06-21 12:34:58 +02:00
$this->collector->amountLess($amount);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-foreign_amount_more':
case 'foreign_amount_less':
// strip comma's, make dots.
$value = str_replace(',', '.', $value);
2023-06-21 12:34:58 +02:00
$amount = app('steam')->positive($value);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
2023-06-21 12:34:58 +02:00
$this->collector->foreignAmountLess($amount);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-amount_less':
case 'amount_more':
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Now handling operator "%s"', $operator));
2023-06-21 12:34:58 +02:00
// strip comma's, make dots.
$value = str_replace(',', '.', $value);
$amount = app('steam')->positive($value);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
2023-06-21 12:34:58 +02:00
$this->collector->amountMore($amount);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-foreign_amount_less':
case 'foreign_amount_more':
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Now handling operator "%s"', $operator));
2023-06-21 12:34:58 +02:00
// strip comma's, make dots.
$value = str_replace(',', '.', $value);
$amount = app('steam')->positive($value);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
2023-06-21 12:34:58 +02:00
$this->collector->foreignAmountMore($amount);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// transaction type
//
2023-06-21 12:34:58 +02:00
case 'transaction_type':
$this->collector->setTypes([ucfirst($value)]);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-transaction_type':
$this->collector->excludeTypes([ucfirst($value)]);
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
//
// dates
//
2023-06-21 12:34:58 +02:00
case '-date_on':
case 'date_on':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactDateParams($range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'date_before':
case '-date_after':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setDateBeforeParams($range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'date_after':
case '-date_before':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setDateAfterParams($range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
case 'interest_date_on':
case '-interest_date_on':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactMetaDateParams('interest_date', $range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'interest_date_before':
case '-interest_date_after':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateBeforeParams('interest_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'interest_date_after':
case '-interest_date_before':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateAfterParams('interest_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
case 'book_date_on':
case '-book_date_on':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactMetaDateParams('book_date', $range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'book_date_before':
case '-book_date_after':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateBeforeParams('book_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'book_date_after':
case '-book_date_before':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateAfterParams('book_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
case 'process_date_on':
case '-process_date_on':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactMetaDateParams('process_date', $range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'process_date_before':
case '-process_date_after':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateBeforeParams('process_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'process_date_after':
case '-process_date_before':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateAfterParams('process_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
case 'due_date_on':
case '-due_date_on':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactMetaDateParams('due_date', $range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'due_date_before':
case '-due_date_after':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateBeforeParams('due_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'due_date_after':
case '-due_date_before':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateAfterParams('due_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
case 'payment_date_on':
case '-payment_date_on':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactMetaDateParams('payment_date', $range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'payment_date_before':
case '-payment_date_after':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateBeforeParams('payment_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'payment_date_after':
case '-payment_date_before':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateAfterParams('payment_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
case 'invoice_date_on':
case '-invoice_date_on':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactMetaDateParams('invoice_date', $range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'invoice_date_before':
case '-invoice_date_after':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateBeforeParams('invoice_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'invoice_date_after':
case '-invoice_date_before':
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setMetaDateAfterParams('invoice_date', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
case 'created_at_on':
case '-created_at_on':
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactObjectDateParams('created_at', $range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'created_at_before':
case '-created_at_after':
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setObjectDateBeforeParams('created_at', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'created_at_after':
case '-created_at_before':
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setObjectDateAfterParams('created_at', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
case 'updated_at_on':
case '-updated_at_on':
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setExactObjectDateParams('updated_at', $range, $prohibited);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'updated_at_before':
case '-updated_at_after':
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setObjectDateBeforeParams('updated_at', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'updated_at_after':
case '-updated_at_before':
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
$range = $this->parseDateRange($operator, $value);
2023-06-21 12:34:58 +02:00
$this->setObjectDateAfterParams('updated_at', $range);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
return false;
2023-12-20 19:35:52 +01:00
//
// external URL
//
2023-06-21 12:34:58 +02:00
case '-any_external_url':
case 'no_external_url':
$this->collector->withoutExternalUrl();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-no_external_url':
case 'any_external_url':
$this->collector->withExternalUrl();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-any_external_id':
case 'no_external_id':
$this->collector->withoutExternalId();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-no_external_id':
case 'any_external_id':
$this->collector->withExternalId();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2022-03-29 14:59:58 +02:00
2023-06-21 12:34:58 +02:00
case 'external_url_is':
$this->collector->setExternalUrl($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-external_url_is':
$this->collector->excludeExternalUrl($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'external_url_contains':
$this->collector->externalUrlContains($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-external_url_contains':
$this->collector->externalUrlDoesNotContain($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'external_url_starts':
$this->collector->externalUrlStarts($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-external_url_starts':
$this->collector->externalUrlDoesNotStart($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'external_url_ends':
$this->collector->externalUrlEnds($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-external_url_ends':
$this->collector->externalUrlDoesNotEnd($value);
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
//
// other fields
//
2023-06-21 12:34:58 +02:00
case 'external_id_is':
$this->collector->setExternalId($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-external_id_is':
$this->collector->excludeExternalId($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'recurrence_id':
$this->collector->setRecurrenceId($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-recurrence_id':
$this->collector->excludeRecurrenceId($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'external_id_contains':
$this->collector->externalIdContains($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-external_id_contains':
$this->collector->externalIdDoesNotContain($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'external_id_starts':
$this->collector->externalIdStarts($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-external_id_starts':
$this->collector->externalIdDoesNotStart($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'external_id_ends':
$this->collector->externalIdEnds($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-external_id_ends':
$this->collector->externalIdDoesNotEnd($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-06-21 12:34:58 +02:00
case 'internal_reference_is':
$this->collector->setInternalReference($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-internal_reference_is':
$this->collector->excludeInternalReference($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'internal_reference_contains':
$this->collector->internalReferenceContains($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-internal_reference_contains':
$this->collector->internalReferenceDoesNotContain($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'internal_reference_starts':
$this->collector->internalReferenceStarts($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-internal_reference_starts':
$this->collector->internalReferenceDoesNotStart($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'internal_reference_ends':
$this->collector->internalReferenceEnds($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-internal_reference_ends':
$this->collector->internalReferenceDoesNotEnd($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-06-21 12:34:58 +02:00
case 'attachment_name_is':
$this->collector->attachmentNameIs($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-attachment_name_is':
$this->collector->attachmentNameIsNot($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'attachment_name_contains':
$this->collector->attachmentNameContains($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-attachment_name_contains':
$this->collector->attachmentNameDoesNotContain($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'attachment_name_starts':
$this->collector->attachmentNameStarts($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-attachment_name_starts':
$this->collector->attachmentNameDoesNotStart($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'attachment_name_ends':
$this->collector->attachmentNameEnds($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-attachment_name_ends':
$this->collector->attachmentNameDoesNotEnd($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-06-21 12:34:58 +02:00
case 'attachment_notes_are':
$this->collector->attachmentNotesAre($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-attachment_notes_are':
$this->collector->attachmentNotesAreNot($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'attachment_notes_contains':
$this->collector->attachmentNotesContains($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-attachment_notes_contains':
$this->collector->attachmentNotesDoNotContain($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'attachment_notes_starts':
$this->collector->attachmentNotesStarts($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-attachment_notes_starts':
$this->collector->attachmentNotesDoNotStart($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'attachment_notes_ends':
$this->collector->attachmentNotesEnds($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-attachment_notes_ends':
$this->collector->attachmentNotesDoNotEnd($value);
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exists':
$this->collector->exists();
2023-12-20 19:35:52 +01:00
2023-05-29 13:56:55 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case '-exists':
$this->collector->findNothing();
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'sepa_ct_is':
$this->collector->setSepaCT($value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case 'source_balance_gte':
case '-source_balance_lt':
$this->collector->accountBalanceIs('source', '>=', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case '-source_balance_gte':
case 'source_balance_lt':
$this->collector->accountBalanceIs('source', '<', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case 'source_balance_gt':
case '-source_balance_lte':
$this->collector->accountBalanceIs('source', '>', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case '-source_balance_gt':
case 'source_balance_lte':
$this->collector->accountBalanceIs('source', '<=', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case 'source_balance_is':
$this->collector->accountBalanceIs('source', '==', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case '-source_balance_is':
$this->collector->accountBalanceIs('source', '!=', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case 'destination_balance_gte':
case '-destination_balance_lt':
$this->collector->accountBalanceIs('destination', '>=', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case '-destination_balance_gte':
case 'destination_balance_lt':
$this->collector->accountBalanceIs('destination', '<', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case 'destination_balance_gt':
case '-destination_balance_lte':
$this->collector->accountBalanceIs('destination', '>', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case '-destination_balance_gt':
case 'destination_balance_lte':
$this->collector->accountBalanceIs('destination', '<=', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case 'destination_balance_is':
$this->collector->accountBalanceIs('destination', '==', $value);
2024-12-23 08:22:54 +01:00
break;
2024-12-23 08:22:54 +01:00
case '-destination_balance_is':
$this->collector->accountBalanceIs('destination', '!=', $value);
2023-12-20 19:35:52 +01:00
break;
2023-06-21 12:34:58 +02:00
}
2023-12-20 19:35:52 +01:00
return true;
2023-06-21 12:34:58 +02:00
}
/**
* @throws FireflyException
*/
public static function getRootOperator(string $operator): string
{
$original = $operator;
// if the string starts with "-" (not), we can remove it and recycle
// the configuration from the original operator.
if (str_starts_with($operator, '-')) {
$operator = substr($operator, 1);
}
$config = config(sprintf('search.operators.%s', $operator));
if (null === $config) {
throw new FireflyException(sprintf('No configuration for search operator "%s"', $operator));
}
if (true === $config['alias']) {
$return = $config['alias_for'];
if (str_starts_with($original, '-')) {
$return = sprintf('-%s', $config['alias_for']);
}
app('log')->debug(sprintf('"%s" is an alias for "%s", so return that instead.', $original, $return));
return $return;
}
app('log')->debug(sprintf('"%s" is not an alias.', $operator));
return $original;
}
2023-06-21 12:34:58 +02:00
/**
* searchDirection: 1 = source (default), 2 = destination, 3 = both
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
* @SuppressWarnings("PHPMD.NPathComplexity")
2023-06-21 12:34:58 +02:00
*/
2023-12-01 05:15:59 +01:00
private function searchAccount(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void
2023-06-21 12:34:58 +02:00
{
2023-12-01 11:21:04 +01:00
app('log')->debug(sprintf('searchAccount("%s", %s, %s)', $value, $stringPosition->name, $searchDirection->name));
2023-06-21 12:34:58 +02:00
// search direction (default): for source accounts
2025-01-03 09:15:52 +01:00
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::REVENUE->value];
2023-06-21 12:34:58 +02:00
$collectorMethod = 'setSourceAccounts';
if ($prohibited) {
$collectorMethod = 'excludeSourceAccounts';
}
// search direction: for destination accounts
2023-12-01 05:15:59 +01:00
if (SearchDirection::DESTINATION === $searchDirection) { // destination
2023-06-21 12:34:58 +02:00
// destination can be
2025-01-03 09:15:52 +01:00
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value];
2023-06-21 12:34:58 +02:00
$collectorMethod = 'setDestinationAccounts';
if ($prohibited) {
$collectorMethod = 'excludeDestinationAccounts';
}
}
// either account could be:
2023-12-01 05:15:59 +01:00
if (SearchDirection::BOTH === $searchDirection) {
2025-01-03 09:15:52 +01:00
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value, AccountTypeEnum::REVENUE->value];
2023-06-21 12:34:58 +02:00
$collectorMethod = 'setAccounts';
if ($prohibited) {
$collectorMethod = 'excludeAccounts';
}
}
// string position (default): starts with:
$stringMethod = 'str_starts_with';
2023-06-21 12:34:58 +02:00
// string position: ends with:
2023-12-01 05:15:59 +01:00
if (StringPosition::ENDS === $stringPosition) {
2023-06-21 12:34:58 +02:00
$stringMethod = 'str_ends_with';
}
2023-12-01 05:15:59 +01:00
if (StringPosition::CONTAINS === $stringPosition) {
2023-06-21 12:34:58 +02:00
$stringMethod = 'str_contains';
}
2023-12-01 05:15:59 +01:00
if (StringPosition::IS === $stringPosition) {
2023-06-21 12:34:58 +02:00
$stringMethod = 'stringIsEqual';
}
// get accounts:
$accounts = $this->accountRepository->searchAccount($value, $searchTypes, 1337);
if (0 === $accounts->count() && false === $prohibited) {
2023-10-29 06:33:43 +01:00
app('log')->debug('Found zero accounts, search for non existing account, NO results will be returned.');
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
return;
}
if (0 === $accounts->count() && true === $prohibited) {
app('log')->debug('Found zero accounts, but the search is negated, so effectively we ignore the search parameter.');
return;
}
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Found %d accounts, will filter.', $accounts->count()));
$filtered = $accounts->filter(
static fn (Account $account) => $stringMethod(strtolower($account->name), strtolower($value))
2023-06-21 12:34:58 +02:00
);
if (0 === $filtered->count()) {
2023-10-29 06:33:43 +01:00
app('log')->debug('Left with zero accounts, so cannot find anything, NO results will be returned.');
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
return;
}
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Left with %d, set as %s().', $filtered->count(), $collectorMethod));
2023-12-20 19:35:52 +01:00
$this->collector->{$collectorMethod}($filtered); // @phpstan-ignore-line
2023-06-21 12:34:58 +02:00
}
/**
* TODO make enums
2023-06-21 12:34:58 +02:00
* searchDirection: 1 = source (default), 2 = destination, 3 = both
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
* @SuppressWarnings("PHPMD.NPathComplexity")
2023-06-21 12:34:58 +02:00
*/
2023-12-01 05:15:59 +01:00
private function searchAccountNr(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void
2023-06-21 12:34:58 +02:00
{
2023-12-02 07:05:34 +01:00
app('log')->debug(sprintf('searchAccountNr(%s, %d, %d)', $value, $searchDirection->name, $stringPosition->name));
2023-06-21 12:34:58 +02:00
// search direction (default): for source accounts
2025-01-03 09:15:52 +01:00
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::REVENUE->value];
2023-06-21 12:34:58 +02:00
$collectorMethod = 'setSourceAccounts';
if (true === $prohibited) {
$collectorMethod = 'excludeSourceAccounts';
}
// search direction: for destination accounts
2023-12-01 05:15:59 +01:00
if (SearchDirection::DESTINATION === $searchDirection) {
2023-06-21 12:34:58 +02:00
// destination can be
2025-01-03 09:15:52 +01:00
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value];
2023-06-21 12:34:58 +02:00
$collectorMethod = 'setDestinationAccounts';
if (true === $prohibited) {
$collectorMethod = 'excludeDestinationAccounts';
}
}
// either account could be:
2023-12-01 05:15:59 +01:00
if (SearchDirection::BOTH === $searchDirection) {
2025-01-03 09:15:52 +01:00
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value, AccountTypeEnum::REVENUE->value];
2023-06-21 12:34:58 +02:00
$collectorMethod = 'setAccounts';
if (true === $prohibited) {
$collectorMethod = 'excludeAccounts';
}
}
// string position (default): starts with:
$stringMethod = 'str_starts_with';
2023-06-21 12:34:58 +02:00
// string position: ends with:
2023-12-01 05:15:59 +01:00
if (StringPosition::ENDS === $stringPosition) {
2023-06-21 12:34:58 +02:00
$stringMethod = 'str_ends_with';
}
2023-12-01 05:15:59 +01:00
if (StringPosition::CONTAINS === $stringPosition) {
2023-06-21 12:34:58 +02:00
$stringMethod = 'str_contains';
}
2023-12-01 05:15:59 +01:00
if (StringPosition::IS === $stringPosition) {
2023-06-21 12:34:58 +02:00
$stringMethod = 'stringIsEqual';
}
// search for accounts:
$accounts = $this->accountRepository->searchAccountNr($value, $searchTypes, 1337);
2023-06-21 12:34:58 +02:00
if (0 === $accounts->count()) {
2023-10-29 06:33:43 +01:00
app('log')->debug('Found zero accounts, search for invalid account.');
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
return;
}
// if found, do filter
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Found %d accounts, will filter.', $accounts->count()));
$filtered = $accounts->filter(
2023-11-04 14:18:49 +01:00
static function (Account $account) use ($value, $stringMethod) {
2023-06-21 12:34:58 +02:00
// either IBAN or account number
2024-12-22 08:43:12 +01:00
$ibanMatch = $stringMethod(strtolower((string) $account->iban), strtolower($value));
2023-06-21 12:34:58 +02:00
$accountNrMatch = false;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
/** @var AccountMeta $meta */
foreach ($account->accountMeta as $meta) {
2025-05-04 13:50:20 +02:00
if ('account_number' === $meta->name && $stringMethod(strtolower((string) $meta->data), strtolower($value))) {
2023-06-21 12:34:58 +02:00
$accountNrMatch = true;
}
2023-05-29 13:56:55 +02:00
}
2022-03-27 16:03:50 +02:00
2023-06-21 12:34:58 +02:00
return $ibanMatch || $accountNrMatch;
}
);
2023-05-29 13:56:55 +02:00
2023-06-21 12:34:58 +02:00
if (0 === $filtered->count()) {
2023-10-29 06:33:43 +01:00
app('log')->debug('Left with zero, search for invalid account');
2023-06-21 12:34:58 +02:00
$this->collector->findNothing();
2023-05-29 13:56:55 +02:00
2023-06-21 12:34:58 +02:00
return;
}
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Left with %d, set as %s().', $filtered->count(), $collectorMethod));
2023-12-20 19:35:52 +01:00
$this->collector->{$collectorMethod}($filtered); // @phpstan-ignore-line
2023-06-21 12:34:58 +02:00
}
2023-05-29 13:56:55 +02:00
2023-06-21 12:34:58 +02:00
private function getCashAccount(): Account
{
return $this->accountRepository->getCashAccount();
}
private function findCurrency(string $value): ?TransactionCurrency
{
if (str_contains($value, '(') && str_contains($value, ')')) {
// bad method to split and get the currency code:
$parts = explode(' ', $value);
$value = trim($parts[count($parts) - 1], "() \t\n\r\0\x0B");
}
2023-10-28 18:08:43 +02:00
$result = $this->currencyRepository->findByCode($value);
2023-06-21 12:34:58 +02:00
if (null === $result) {
2025-05-27 17:06:15 +02:00
return $this->currencyRepository->findByName($value);
2023-06-21 12:34:58 +02:00
}
return $result;
}
/**
* @throws FireflyException
*/
2023-08-24 05:53:17 +02:00
private function parseDateRange(string $type, string $value): array
2023-06-21 12:34:58 +02:00
{
$parser = new ParseDateString();
if ($parser->isDateRange($value)) {
return $parser->parseRange($value);
}
2023-12-20 19:35:52 +01:00
2023-08-24 05:53:17 +02:00
try {
$parsedDate = $parser->parseDate($value);
2025-05-04 13:50:20 +02:00
} catch (FireflyException) {
2023-10-29 06:33:43 +01:00
app('log')->debug(sprintf('Could not parse date "%s", will return empty array.', $value));
2023-08-24 05:53:17 +02:00
$this->invalidOperators[] = [
'type' => $type,
2023-11-04 19:20:07 +01:00
'value' => $value,
2023-08-24 05:53:17 +02:00
];
2023-12-20 19:35:52 +01:00
2023-08-24 05:53:17 +02:00
return [];
}
2023-06-21 12:34:58 +02:00
return [
'exact' => $parsedDate,
];
}
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
private function setExactDateParams(array $range, bool $prohibited = false): void
{
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setExactParameters()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
app('log')->debug(sprintf('Set date_is_exact value "%s"', $value->format('Y-m-d')));
$this->collector->setRange($value, $value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_on', 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact_not':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
$this->collector->excludeRange($value, $value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'not_date_on', 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_exact YEAR value "%s"', $value));
$this->collector->yearIs($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_on_year', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_exact_not YEAR value "%s"', $value));
$this->collector->yearIsNot($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'not_date_on_year', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_exact MONTH value "%s"', $value));
$this->collector->monthIs($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_on_month', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_exact not MONTH value "%s"', $value));
$this->collector->monthIsNot($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'not_date_on_month', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_exact DAY value "%s"', $value));
$this->collector->dayIs($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_on_day', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set not date_is_exact DAY value "%s"', $value));
$this->collector->dayIsNot($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'not_date_on_day', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2023-05-29 13:56:55 +02:00
2023-06-21 12:34:58 +02:00
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
private function setDateBeforeParams(array $range, bool $prohibited = false): void
{
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setDateBeforeParams()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
$this->collector->setBefore($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_before', 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_before YEAR value "%s"', $value));
$this->collector->yearBefore($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_before_year', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_before MONTH value "%s"', $value));
$this->collector->monthBefore($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_before_month', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_before DAY value "%s"', $value));
$this->collector->dayBefore($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_before_day', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2023-05-29 13:56:55 +02:00
2023-06-21 12:34:58 +02:00
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
2023-11-04 11:31:14 +01:00
private function setDateAfterParams(array $range, bool $prohibited = false): void
2023-06-21 12:34:58 +02:00
{
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setDateAfterParams()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
$this->collector->setAfter($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_after', 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_after YEAR value "%s"', $value));
$this->collector->yearAfter($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_after_year', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_after MONTH value "%s"', $value));
$this->collector->monthAfter($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_after_month', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_after DAY value "%s"', $value));
$this->collector->dayAfter($value);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => 'date_after_day', 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2022-03-27 16:03:50 +02:00
2023-06-21 12:34:58 +02:00
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
private function setExactMetaDateParams(string $field, array $range, bool $prohibited = false): void
{
2023-10-29 06:33:43 +01:00
app('log')->debug('Now in setExactMetaDateParams()');
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setExactMetaDateParams()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
app('log')->debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));
$this->collector->setMetaDateRange($value, $value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact_not':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
app('log')->debug(sprintf('Set NOT %s_is_exact value "%s"', $field, $value->format('Y-m-d')));
$this->collector->excludeMetaDateRange($value, $value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('not_%s_on', $field), 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));
$this->collector->metaYearIs($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set NOT %s_is_exact YEAR value "%s"', $field, $value));
$this->collector->metaYearIsNot($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('not_%s_on_year', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));
$this->collector->metaMonthIs($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set NOT %s_is_exact MONTH value "%s"', $field, $value));
$this->collector->metaMonthIsNot($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('not_%s_on_month', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));
$this->collector->metaDayIs($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set NOT %s_is_exact DAY value "%s"', $field, $value));
$this->collector->metaDayIsNot($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('not_%s_on_day', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2022-03-27 16:03:50 +02:00
2023-06-21 12:34:58 +02:00
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
private function setMetaDateBeforeParams(string $field, array $range, bool $prohibited = false): void
{
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setMetaDateBeforeParams()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
$this->collector->setMetaBefore($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_before', $field), 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_before YEAR value "%s"', $field, $value));
$this->collector->metaYearBefore($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_before_year', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_before MONTH value "%s"', $field, $value));
$this->collector->metaMonthBefore($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_before_month', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_before DAY value "%s"', $field, $value));
$this->collector->metaDayBefore($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_before_day', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2022-03-27 16:03:50 +02:00
2023-06-21 12:34:58 +02:00
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
private function setMetaDateAfterParams(string $field, array $range, bool $prohibited = false): void
{
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setMetaDateAfterParams()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
$this->collector->setMetaAfter($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_after', $field), 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_after YEAR value "%s"', $field, $value));
$this->collector->metaYearAfter($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_after_year', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_after MONTH value "%s"', $field, $value));
$this->collector->metaMonthAfter($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_after_month', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_after DAY value "%s"', $field, $value));
$this->collector->metaDayAfter($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_after_day', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2022-03-29 14:59:58 +02:00
2023-06-21 12:34:58 +02:00
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
private function setExactObjectDateParams(string $field, array $range, bool $prohibited = false): void
{
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setExactObjectDateParams()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
app('log')->debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));
$this->collector->setObjectRange($value, clone $value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact_not':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
app('log')->debug(sprintf('Set NOT %s_is_exact value "%s"', $field, $value->format('Y-m-d')));
$this->collector->excludeObjectRange($value, clone $value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('not_%s_on', $field), 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));
$this->collector->objectYearIs($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set NOT %s_is_exact YEAR value "%s"', $field, $value));
$this->collector->objectYearIsNot($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('not_%s_on_year', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));
$this->collector->objectMonthIs($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set NOT %s_is_exact MONTH value "%s"', $field, $value));
$this->collector->objectMonthIsNot($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('not_%s_on_month', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));
$this->collector->objectDayIs($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day_not':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set NOT %s_is_exact DAY value "%s"', $field, $value));
$this->collector->objectDayIsNot($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('not_%s_on_day', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2022-03-29 14:59:58 +02:00
2023-06-21 12:34:58 +02:00
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
private function setObjectDateBeforeParams(string $field, array $range, bool $prohibited = false): void
{
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setObjectDateBeforeParams()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
$this->collector->setObjectBefore($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_before', $field), 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_before YEAR value "%s"', $value));
$this->collector->objectYearBefore($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_before_year', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_before MONTH value "%s"', $value));
$this->collector->objectMonthBefore($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_before_month', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_before DAY value "%s"', $value));
$this->collector->objectDayBefore($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_before_day', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2023-05-29 13:56:55 +02:00
2023-06-21 12:34:58 +02:00
/**
* @throws FireflyException
2023-12-20 19:35:52 +01:00
*
2025-01-03 15:53:10 +01:00
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
2023-06-21 12:34:58 +02:00
*/
private function setObjectDateAfterParams(string $field, array $range, bool $prohibited = false): void
{
/**
* @var string $key
* @var Carbon|string $value
*/
foreach ($range as $key => $value) {
$key = $prohibited ? sprintf('%s_not', $key) : $key;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
switch ($key) {
default:
throw new FireflyException(sprintf('Cannot handle key "%s" in setObjectDateAfterParams()', $key));
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'exact':
2023-11-28 05:31:26 +01:00
if ($value instanceof Carbon) {
$this->collector->setObjectAfter($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_after', $field), 'value' => $value->format('Y-m-d')]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'year':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_after YEAR value "%s"', $value));
$this->collector->objectYearAfter($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_after_year', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'month':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_after MONTH value "%s"', $value));
$this->collector->objectMonthAfter($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_after_month', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
case 'day':
2023-11-28 05:31:26 +01:00
if (is_string($value)) {
app('log')->debug(sprintf('Set date_is_after DAY value "%s"', $value));
$this->collector->objectDayAfter($value, $field);
2023-12-20 19:35:52 +01:00
$this->operators->push(['type' => sprintf('%s_after_day', $field), 'value' => $value]);
2023-11-28 05:31:26 +01:00
}
2023-12-20 19:35:52 +01:00
2023-06-21 12:34:58 +02:00
break;
}
}
}
2022-03-29 14:59:58 +02:00
2025-05-04 17:41:26 +02:00
private function handleNodeGroup(NodeGroup $node, bool $flipProhibitedFlag): void
{
$prohibited = $node->isProhibited($flipProhibitedFlag);
foreach ($node->getNodes() as $subNode) {
$this->handleSearchNode($subNode, $prohibited);
}
}
public function searchTime(): float
{
return microtime(true) - $this->startTime;
}
public function searchTransactions(): LengthAwarePaginator
{
$this->parseTagInstructions();
2025-01-03 00:13:51 +01:00
if (0 === count($this->getWords()) && 0 === count($this->getExcludedWords()) && 0 === count($this->getOperators())) {
return new LengthAwarePaginator([], 0, 5, 1);
}
return $this->collector->getPaginatedGroups();
}
2023-12-10 06:51:59 +01:00
private function parseTagInstructions(): void
{
app('log')->debug('Now in parseTagInstructions()');
// if exclude tags, remove excluded tags.
if (count($this->excludeTags) > 0) {
app('log')->debug(sprintf('%d exclude tag(s)', count($this->excludeTags)));
2023-12-20 19:35:52 +01:00
$collection = new Collection();
2023-12-10 06:51:59 +01:00
foreach ($this->excludeTags as $tagId) {
$tag = $this->tagRepository->find($tagId);
if (null !== $tag) {
app('log')->debug(sprintf('Exclude tag "%s"', $tag->tag));
$collection->push($tag);
}
}
app('log')->debug(sprintf('Selecting all tags except %d excluded tag(s).', $collection->count()));
$this->collector->setWithoutSpecificTags($collection);
}
// if include tags, include them:
if (count($this->includeTags) > 0) {
app('log')->debug(sprintf('%d include tag(s)', count($this->includeTags)));
2023-12-20 19:35:52 +01:00
$collection = new Collection();
2023-12-10 06:51:59 +01:00
foreach ($this->includeTags as $tagId) {
$tag = $this->tagRepository->find($tagId);
if (null !== $tag) {
app('log')->debug(sprintf('Include tag "%s"', $tag->tag));
$collection->push($tag);
}
}
$this->collector->setAllTags($collection);
2023-12-10 06:51:59 +01:00
}
2024-03-06 07:01:21 +01:00
// if include ANY tags, include them: (see #8632)
if (count($this->includeAnyTags) > 0) {
app('log')->debug(sprintf('%d include ANY tag(s)', count($this->includeAnyTags)));
$collection = new Collection();
foreach ($this->includeAnyTags as $tagId) {
$tag = $this->tagRepository->find($tagId);
if (null !== $tag) {
app('log')->debug(sprintf('Include ANY tag "%s"', $tag->tag));
$collection->push($tag);
}
}
$this->collector->setTags($collection);
}
2022-03-29 14:59:58 +02:00
}
2025-05-04 17:41:26 +02:00
public function getWords(): array
{
return $this->words;
}
public function getExcludedWords(): array
{
return $this->prohibitedWords;
}
public function setDate(Carbon $date): void
{
$this->date = $date;
}
public function setPage(int $page): void
{
$this->page = $page;
$this->collector->setPage($this->page);
}
public function setUser(User $user): void
{
$this->accountRepository->setUser($user);
$this->billRepository->setUser($user);
$this->categoryRepository->setUser($user);
$this->budgetRepository->setUser($user);
$this->tagRepository->setUser($user);
$this->collector = app(GroupCollectorInterface::class);
$this->collector->setUser($user);
$this->collector->withAccountInformation()->withCategoryInformation()->withBudgetInformation();
2024-12-22 08:43:12 +01:00
$this->setLimit((int) app('preferences')->getForUser($user, 'listPageSize', 50)->data);
}
public function setLimit(int $limit): void
{
$this->limit = $limit;
$this->collector->setLimit($this->limit);
}
2020-12-22 05:35:06 +01:00
}