From 3033b0fa7f147d794d840928c79150e726a7cfbb Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 11 Jan 2023 18:02:24 +0100 Subject: [PATCH] Fix https://github.com/firefly-iii/firefly-iii/issues/6834 --- .../Internal/Support/JournalServiceTrait.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/Services/Internal/Support/JournalServiceTrait.php b/app/Services/Internal/Support/JournalServiceTrait.php index ba96fffa78..55ba7ef582 100644 --- a/app/Services/Internal/Support/JournalServiceTrait.php +++ b/app/Services/Internal/Support/JournalServiceTrait.php @@ -75,11 +75,23 @@ trait JournalServiceTrait Log::debug('Now searching by ID'); $result = $this->findAccountById($data, $expectedTypes[$transactionType]); Log::debug('If nothing is found, searching by IBAN'); - $result = $this->findAccountByIban($result, $data, $expectedTypes[$transactionType]); + $result = $this->findAccountByIban($result, $data, $expectedTypes[$transactionType]); + $ibanResult = $result; + // if result is NULL but IBAN is set, any result of the search by NAME can't overrule + // this account. In such a case, the name search must be retried with a new name. + Log::debug('If nothing is found, searching by number'); - $result = $this->findAccountByNumber($result, $data, $expectedTypes[$transactionType]); + $result = $this->findAccountByNumber($result, $data, $expectedTypes[$transactionType]); + $numberResult = $result; Log::debug('If nothing is found, searching by name'); $result = $this->findAccountByName($result, $data, $expectedTypes[$transactionType]); + + if (null !== $result && null === $numberResult && null === $ibanResult && null !== $data['iban']) { + $data['name'] = sprintf('%s (%s)', $data['name'], $data['iban']); + Log::debug(sprintf('Search again using the new name, "%s".', $data['name'])); + $result = $this->findAccountByName(null, $data, $expectedTypes[$transactionType]); + } + Log::debug('If nothing is found, create it.'); $result = $this->createAccount($result, $data, $expectedTypes[$transactionType][0]); Log::debug('If cant be created, return cash account.');