From 963c3b2a6873cc081d216454a5ad3685d2602c16 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 23 Jun 2020 20:18:59 +0200 Subject: [PATCH] Fix #3391 --- .../Extensions/CollectorProperties.php | 2 ++ .../Collector/Extensions/MetaCollection.php | 32 +++++++++++++++++++ app/Helpers/Collector/GroupCollector.php | 2 +- .../Collector/GroupCollectorInterface.php | 18 +++++++++++ app/Support/Search/Search.php | 6 ++++ config/firefly.php | 3 +- resources/lang/en_US/firefly.php | 2 ++ 7 files changed, 63 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Collector/Extensions/CollectorProperties.php b/app/Helpers/Collector/Extensions/CollectorProperties.php index fd55907012..2c0e0463eb 100644 --- a/app/Helpers/Collector/Extensions/CollectorProperties.php +++ b/app/Helpers/Collector/Extensions/CollectorProperties.php @@ -58,4 +58,6 @@ trait CollectorProperties private $total; /** @var User The user object. */ private $user; + + private bool $hasJoinedMetaTables; } diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php index ea0bea686f..5680226951 100644 --- a/app/Helpers/Collector/Extensions/MetaCollection.php +++ b/app/Helpers/Collector/Extensions/MetaCollection.php @@ -310,4 +310,36 @@ trait MetaCollection } + /** + * @inheritDoc + */ + public function setExternalId(string $externalId): GroupCollectorInterface + { + if (false === $this->hasJoinedMetaTables) { + $this->hasJoinedMetaTables = true; + $this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id'); + } + $this->query->where('journal_meta.name', '=', 'external_id'); + $this->query->where('journal_meta.data', 'LIKE', sprintf('%%%s%%', $externalId)); + + return $this; + } + + /** + * @inheritDoc + */ + public function setInternalReference(string $internalReference): GroupCollectorInterface + { + if (false === $this->hasJoinedMetaTables) { + $this->hasJoinedMetaTables = true; + $this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id'); + } + + $this->query->where('journal_meta.name', '=', 'internal_reference'); + $this->query->where('journal_meta.data', 'LIKE', sprintf('%%%s%%', $internalReference)); + + return $this; + } + + } diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index b3bfbf4e75..73901525ef 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -65,6 +65,7 @@ class GroupCollector implements GroupCollectorInterface $this->hasNotesInformation = false; $this->hasJoinedTagTables = false; $this->hasJoinedAttTables = false; + $this->hasJoinedMetaTables = false; $this->integerFields = [ 'transaction_group_id', 'user_id', @@ -687,5 +688,4 @@ class GroupCollector implements GroupCollectorInterface ->orderBy('transaction_journals.description', 'DESC') ->orderBy('source.amount', 'DESC'); } - } diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php index 17a4e4f0ca..0d5d8e4e8d 100644 --- a/app/Helpers/Collector/GroupCollectorInterface.php +++ b/app/Helpers/Collector/GroupCollectorInterface.php @@ -426,4 +426,22 @@ interface GroupCollectorInterface */ public function withoutCategory(): GroupCollectorInterface; + /** + * Look for specific external ID's. + * + * @param string $externalId + * + * @return GroupCollectorInterface + */ + public function setExternalId(string $externalId): GroupCollectorInterface; + + /** + * Look for specific external ID's. + * + * @param string $externalId + * + * @return GroupCollectorInterface + */ + public function setInternalReference(string $externalId): GroupCollectorInterface; + } diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index 1a3f7a3371..5e28ef2d6a 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -298,6 +298,12 @@ class Search implements SearchInterface $updatedAt = new Carbon($modifier['value']); $collector->setUpdatedAt($updatedAt); break; + case 'external_id': + $collector->setExternalId($modifier['value']); + break; + case 'internal_reference': + $collector->setInternalReference($modifier['value']); + break; } } $collector->setAccounts($totalAccounts); diff --git a/config/firefly.php b/config/firefly.php index b265566943..5fe3c1b17a 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -574,7 +574,8 @@ return [ 'default_locale' => envNonEmpty('DEFAULT_LOCALE', 'equal'), 'search_modifiers' => ['amount_is', 'amount', 'amount_max', 'amount_min', 'amount_less', 'amount_more', 'source', 'destination', 'category', 'budget', 'bill', 'type', 'date', 'date_before', 'date_after', 'on', 'before', 'after', 'from', 'to', 'tag', 'created_on', - 'updated_on',], + 'updated_on', 'external_id', 'internal_reference',], + // TODO notes has_attachments 'cer_providers' => [ diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 1fb1b3eacf..ff44ccbf6b 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -278,6 +278,8 @@ return [ 'search_modifier_after' => 'Transaction date is after :value', 'search_modifier_created_on' => 'Transaction was created on :value', 'search_modifier_updated_on' => 'Transaction was last updated on :value', + 'search_modifier_external_id' => 'External ID is ":value"', + 'search_modifier_internal_reference' => 'Internal reference is ":value"', 'modifiers_applies_are' => 'The following modifiers are applied to the search as well:', 'general_search_error' => 'An error occurred while searching. Please check the log files for more information.', 'search_box' => 'Search',