diff --git a/app/Support/Search/Modifier.php b/app/Support/Search/Modifier.php index b4e3cd5fd8..a79744097a 100644 --- a/app/Support/Search/Modifier.php +++ b/app/Support/Search/Modifier.php @@ -67,6 +67,10 @@ class Modifier $res = Modifier::category($transaction, $modifier['value']); Log::debug(sprintf('Category is %s? %s', $modifier['value'], var_export($res, true))); break; + case 'budget': + $res = Modifier::budget($transaction, $modifier['value']); + Log::debug(sprintf('Budget is %s? %s', $modifier['value'], var_export($res, true))); + break; } @@ -88,6 +92,26 @@ class Modifier } + /** + * @param Transaction $transaction + * @param string $search + * + * @return bool + */ + private static function budget(Transaction $transaction, string $search): bool + { + $journalBudget = ''; + if (!is_null($transaction->transaction_journal_budget_name)) { + $journalBudget = Steam::decrypt(intval($transaction->transaction_journal_budget_encrypted), $transaction->transaction_journal_budget_name); + } + $transactionBudget = ''; + if (!is_null($transaction->transaction_budget_name)) { + $journalBudget = Steam::decrypt(intval($transaction->transaction_budget_encrypted), $transaction->transaction_budget_name); + } + + return self::stringCompare($journalBudget, $search) || self::stringCompare($transactionBudget, $search); + } + /** * @param Transaction $transaction * @param string $search diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index 0a0e80f566..add2d3fc7d 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -193,8 +193,10 @@ class Search implements SearchInterface /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); $collector->setUser($this->user); - $collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page) - ->withOpposingAccount()->withCategoryInformation(); + $collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page); + if($this->hasModifiers()) { + $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation(); + } $set = $collector->getPaginatedJournals()->getCollection(); $words = $this->words;