From 0a5908e4d8859b3eeae386477792b797af9ddd68 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Mon, 24 Jan 2022 20:20:03 -0700 Subject: [PATCH 1/2] Attempt to add external_url filtering support --- .../Collector/Extensions/MetaCollection.php | 30 +++++++++++++++++++ .../Collector/GroupCollectorInterface.php | 14 +++++++++ app/Support/Search/OperatorQuerySearch.php | 9 ++++++ config/firefly.php | 2 ++ public/v1/js/ff/rules/create-edit.js | 2 ++ resources/lang/en_US/firefly.php | 2 ++ 6 files changed, 59 insertions(+) diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php index 746657ac98..193cb8ef63 100644 --- a/app/Helpers/Collector/Extensions/MetaCollection.php +++ b/app/Helpers/Collector/Extensions/MetaCollection.php @@ -212,6 +212,36 @@ trait MetaCollection return $this; } + /** + * @inheritDoc + */ + public function withoutExternalUrl(): 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_url'); + $this->query->whereNull('journal_meta.data'); + + return $this; + } + + /** + * @inheritDoc + */ + public function withExternalUrl(): 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_url'); + $this->query->whereNotNull('journal_meta.data'); + + return $this; + } + /** * @inheritDoc */ diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php index ccbee0145e..5216a59242 100644 --- a/app/Helpers/Collector/GroupCollectorInterface.php +++ b/app/Helpers/Collector/GroupCollectorInterface.php @@ -305,6 +305,20 @@ interface GroupCollectorInterface */ public function setExternalId(string $externalId): GroupCollectorInterface; + /** + * Transactions without an external URL + * + * @return GroupCollectorInterface + */ + public function withoutExternalUrl(): GroupCollectorInterface; + + /** + * Transactions with an external URL + * + * @return GroupCollectorInterface + */ + public function withExternalUrl(): GroupCollectorInterface; + /** * Limit results to a specific foreign currency. * diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index e89927ee62..269b43928f 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -627,6 +627,15 @@ class OperatorQuerySearch implements SearchInterface $this->collector->setUpdatedAt($updatedAt); break; // + // external URL + // + case 'no_external_url': + $this->collector->withoutExternalUrl(); + break; + case 'any_external_url': + $this->collector->withExternalUrl(); + break; + // // other fields // case 'external_id': diff --git a/config/firefly.php b/config/firefly.php index 5b2189b007..fa75e3621b 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -518,6 +518,8 @@ return [ 'notes_are' => ['alias' => false, 'needs_context' => true,], 'no_notes' => ['alias' => false, 'needs_context' => false,], 'any_notes' => ['alias' => false, 'needs_context' => false,], + 'no_external_url' => ['alias' => false, 'needs_context' => false,], + 'any_external_url' => ['alias' => false, 'needs_context' => false,], // one exact (or array of) journals: 'id' => ['alias' => false, 'trigger_class' => null, 'needs_context' => true,], diff --git a/public/v1/js/ff/rules/create-edit.js b/public/v1/js/ff/rules/create-edit.js index 2f2eb43140..656746a822 100644 --- a/public/v1/js/ff/rules/create-edit.js +++ b/public/v1/js/ff/rules/create-edit.js @@ -348,6 +348,8 @@ function updateTriggerInput(selectList) { case 'source_is_cash': case 'destination_is_cash': case 'account_is_cash': + case 'no_external_url': + case 'any_external_url': console.log('Select list value is ' + selectList.val() + ', so input needs to be disabled.'); inputResult.prop('disabled', true); inputResult.typeahead('destroy'); diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index f5fa8f107e..403ea38144 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -562,6 +562,8 @@ return [ 'rule_trigger_internal_reference' => 'Internal reference is ":trigger_value"', 'rule_trigger_journal_id_choice' => 'Transaction journal ID is..', 'rule_trigger_journal_id' => 'Transaction journal ID is ":trigger_value"', + 'rule_trigger_no_external_url' => 'Transaction has no external URL', + 'rule_trigger_any_external_url' => 'Transaction has an external URL', // actions 'rule_action_delete_transaction_choice' => 'DELETE transaction (!)', From ecda8eebf27a2e3cfe404e3678f1e21354a39f48 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Mon, 24 Jan 2022 23:03:33 -0700 Subject: [PATCH 2/2] Fix withoutExternalUrl query and add search modifiers Co-authored-by: JC5 --- app/Helpers/Collector/Extensions/MetaCollection.php | 8 ++++++-- resources/lang/en_US/firefly.php | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php index 193cb8ef63..11e0c90b59 100644 --- a/app/Helpers/Collector/Extensions/MetaCollection.php +++ b/app/Helpers/Collector/Extensions/MetaCollection.php @@ -221,8 +221,12 @@ trait MetaCollection $this->hasJoinedMetaTables = true; $this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id'); } - $this->query->where('journal_meta.name', '=', 'external_url'); - $this->query->whereNull('journal_meta.data'); + $this->query->where(function(Builder $q1) { + $q1->where(function(Builder $q2) { + $q2->where('journal_meta.name', '=', 'external_url'); + $q2->whereNull('journal_meta.data'); + })->orWhereNull('journal_meta.name'); + }); return $this; } diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 403ea38144..7b7250c6fc 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -291,6 +291,8 @@ return [ '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_no_external_url' => 'The transaction has no external URL', + 'search_modifier_any_external_url' => 'The transaction must have a (any) external URL', 'search_modifier_internal_reference' => 'Internal reference is ":value"', 'search_modifier_description_starts' => 'Description is ":value"', 'search_modifier_description_ends' => 'Description ends with ":value"',