From d01074e0700138f4c7c02c5237786935c04d5507 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 16 Sep 2020 03:33:35 +0200 Subject: [PATCH] Added to fallbacks to find bank name from BIC or IBAN --- .../banking/ui/presenter/BankingPresenter.kt | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index b336e46a..2f6bf770 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -533,14 +533,35 @@ open class BankingPresenter constructor( open fun findRemitteesForName(name: String): List { return remitteeSearcher.findRemittees(name).map { remittee -> - remittee.bic?.let { bic -> - remittee.bankName = bankFinder.findBankByBic(bic)?.name - } + remittee.bankName = tryToFindBankName(remittee) remittee } } + protected open fun tryToFindBankName(remittee: Remittee): String? { + remittee.bic?.let { bic -> + bankFinder.findBankByBic(bic)?.name?.let { + return it + } + + if (bic.length == 8) { + bankFinder.findBankByBic(bic + "XXX")?.name?.let { + return it + } + } + } + + remittee.iban?.let { iban -> + if (iban.length > 12) { + val bankCode = iban.substring(4, 12) + return bankFinder.findBankByBankCode(bankCode).firstOrNull()?.name + } + } + + return null + } + open fun searchSelectedAccountTransactions(query: String): List { return searchAccountTransactions(query, selectedBankAccountsAccountTransactions)