From 5e3f9f9bce8d86969c7a36c989333d2d7f4d0bff Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 29 Dec 2022 15:42:26 +0100 Subject: [PATCH] Expand search with external ID searches. --- .../Collector/Extensions/MetaCollection.php | 32 +++++++++++++++++++ .../Collector/GroupCollectorInterface.php | 16 +++++++++- app/Support/Search/OperatorQuerySearch.php | 8 +++++ config/search.php | 3 ++ resources/lang/en_US/firefly.php | 6 +++- 5 files changed, 63 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php index b1f0dce85e..0af16d95a1 100644 --- a/app/Helpers/Collector/Extensions/MetaCollection.php +++ b/app/Helpers/Collector/Extensions/MetaCollection.php @@ -930,6 +930,18 @@ trait MetaCollection return $this; } + /** + * @inheritDoc + */ + public function withExternalId(): GroupCollectorInterface + { + $this->joinMetaDataTables(); + $this->query->where('journal_meta.name', '=', 'external_id'); + $this->query->whereNotNull('journal_meta.data'); + + return $this; + } + /** * Limit results to a transactions without a bill. * @@ -988,6 +1000,26 @@ trait MetaCollection return $this; } + /** + * @inheritDoc + */ + public function withoutExternalId(): GroupCollectorInterface + { + $this->joinMetaDataTables(); + // TODO not sure if this will work properly. + $this->query->where(function (Builder $q1) { + $q1->where(function (Builder $q2) { + $q2->where('journal_meta.name', '=', 'external_id'); + $q2->whereNull('journal_meta.data'); + })->orWhere(function (Builder $q3) { + $q3->where('journal_meta.name', '!=', 'external_id'); + })->orWhere(function (Builder $q4) { + $q4->whereNull('journal_meta.name'); + }); + }); + + return $this; + } /** * @return GroupCollectorInterface diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php index 40704ea139..65b9dfd07c 100644 --- a/app/Helpers/Collector/GroupCollectorInterface.php +++ b/app/Helpers/Collector/GroupCollectorInterface.php @@ -1306,12 +1306,19 @@ interface GroupCollectorInterface public function withCategoryInformation(): GroupCollectorInterface; /** - * Transactions with an external URL + * Transactions with any external URL * * @return GroupCollectorInterface */ public function withExternalUrl(): GroupCollectorInterface; + /** + * Transactions with any external ID + * + * @return GroupCollectorInterface + */ + public function withExternalId(): GroupCollectorInterface; + /** * Transaction must have meta date field X. * @@ -1362,6 +1369,13 @@ interface GroupCollectorInterface */ public function withoutExternalUrl(): GroupCollectorInterface; + /** + * Transactions without an external ID + * + * @return GroupCollectorInterface + */ + public function withoutExternalId(): GroupCollectorInterface; + /** * @return GroupCollectorInterface */ diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index 434666f143..d512848bd2 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -1169,6 +1169,14 @@ class OperatorQuerySearch implements SearchInterface case 'any_external_url': $this->collector->withExternalUrl(); break; + case '-any_external_id': + case 'no_external_id': + $this->collector->withoutExternalId(); + break; + case '-no_external_id': + case 'any_external_id': + $this->collector->withExternalId(); + break; case 'external_url_is': $this->collector->setExternalUrl($value); diff --git a/config/search.php b/config/search.php index 730554e150..6e065e4f07 100644 --- a/config/search.php +++ b/config/search.php @@ -232,5 +232,8 @@ return [ 'attachment_notes_end' => ['alias' => true, 'alias_for' => 'attachment_notes_ends', 'needs_context' => true], 'exists' => ['alias' => false, 'needs_context' => false,], 'sepa_ct_is' => ['alias' => false, 'needs_context' => true], + 'no_external_id' => ['alias' => false, 'needs_context' => false], + 'any_external_id' => ['alias' => false, 'needs_context' => false], + ], ]; diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index a70cf9637d..a7b277b324 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -335,9 +335,13 @@ return [ 'search_modifier_external_id_is' => 'External ID is ":value"', 'search_modifier_not_external_id_is' => 'External ID is not ":value"', 'search_modifier_no_external_url' => 'The transaction has no external URL', + 'search_modifier_no_external_id' => 'The transaction has no external ID', 'search_modifier_not_any_external_url' => 'The transaction has no external URL', + 'search_modifier_not_any_external_id' => 'The transaction has no external ID', 'search_modifier_any_external_url' => 'The transaction must have a (any) external URL', + 'search_modifier_any_external_id' => 'The transaction must have a (any) external ID', 'search_modifier_not_no_external_url' => 'The transaction must have a (any) external URL', + 'search_modifier_not_no_external_id' => 'The transaction must have a (any) external ID', 'search_modifier_internal_reference_is' => 'Internal reference is ":value"', 'search_modifier_not_internal_reference_is' => 'Internal reference is not ":value"', 'search_modifier_description_starts' => 'Description starts with ":value"', @@ -1490,7 +1494,7 @@ return [ 'title_transfer' => 'Transfers', 'title_transfers' => 'Transfers', 'submission_options' => 'Submission options', - 'apply_rules_checkbox' => 'Apply rules', + 'apply_rules_checkbox' => 'Apply rules', 'fire_webhooks_checkbox' => 'Fire webhooks', // convert stuff: