Skip to content

Firefly III: a personal finances manager

Fix https://github.com/firefly-iii/firefly-iii/issues/6834

James Cole3033b0fa7f14
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.');