Will update IBAN in existing account if necessary and/or possible.

This commit is contained in:
James Cole
2023-02-18 06:37:05 +01:00
parent 38b88dce44
commit e0577bddc5
4 changed files with 66 additions and 13 deletions

View File

@@ -54,7 +54,6 @@ trait JournalServiceTrait
* @param array $data
*
* @return Account|null
* @throws FireflyException
*/
protected function getAccount(string $transactionType, string $direction, array $data): ?Account
@@ -78,10 +77,11 @@ trait JournalServiceTrait
$result = $this->findAccountByNumber($result, $data, $expectedTypes[$transactionType]);
$numberResult = $result;
$result = $this->findAccountByName($result, $data, $expectedTypes[$transactionType]);
$nameResult =$result;
// if result is NULL but IBAN is set, any result of the search by NAME can't overrule
// if $result (find by name) 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.
if (null !== $result && null === $numberResult && null === $ibanResult && '' !== (string) $data['iban']) {
if (null !== $nameResult && null === $numberResult && null === $ibanResult && '' !== (string)$data['iban'] && '' !== (string) $nameResult->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]);
@@ -101,11 +101,15 @@ trait JournalServiceTrait
$result = $this->createAccount(null, $tempData, $expectedTypes[$transactionType][0]);
}
}
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.');
return $this->getCashAccount($result, $data, $expectedTypes[$transactionType]);
if (null === $result) {
Log::debug('If nothing is found, create it.');
$result = $this->createAccount($result, $data, $expectedTypes[$transactionType][0]);
}
if (null === $result) {
Log::debug('If cant be created, return cash account.');
$result = $this->getCashAccount($result, $data, $expectedTypes[$transactionType]);
}
return $result;
}
/**
@@ -329,7 +333,6 @@ trait JournalServiceTrait
*
* @return string
* @throws FireflyException
*/
protected function getAmount(string $amount): string
{
@@ -348,7 +351,6 @@ trait JournalServiceTrait
* @param string|null $amount
*
* @return string|null
*/
protected function getForeignAmount(?string $amount): ?string
{