From 5580313eebf7fc41ae61e217e8e5ae68b0a5d74e Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 30 Sep 2020 00:01:33 +0200 Subject: [PATCH] Setting countDaysForWhichTransactionsAreKept now on account and not on bank anymore as the count may differs from account type to account type (e.g. 540 days for checking accounts and 9999 days for credit card accounts) --- .../kotlin/net/dankito/banking/fints/FinTsClient.kt | 10 +++++----- .../net/dankito/banking/fints/model/AccountData.kt | 3 +++ .../kotlin/net/dankito/banking/fints/model/BankData.kt | 2 -- .../java/net/dankito/banking/persistence/model/Bank.kt | 5 ++--- .../dankito/banking/persistence/model/BankAccount.kt | 2 ++ .../banking/persistence/model/BankAccountEntity.kt | 1 + .../banking/persistence/model/BankDataEntity.kt | 2 +- .../kotlin/net/dankito/banking/ui/model/BankAccount.kt | 2 ++ .../net/dankito/banking/ui/model/IBankAccount.kt | 1 + .../kotlin/net/dankito/banking/ui/model/IBankData.kt | 3 --- .../dankito/banking/ui/presenter/BankingPresenter.kt | 2 +- .../BankingiOSApp.xcdatamodel/contents | 4 ++-- .../BankingiOSApp/persistence/Mapper.swift | 5 +++-- .../net/dankito/banking/mapper/fints4kModelMapper.kt | 2 +- 14 files changed, 24 insertions(+), 20 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt index c60aef8b..27fed746 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -409,7 +409,7 @@ open class FinTsClient( val successful = response.successful && (parameter.alsoRetrieveBalance == false || balance != null) val fromDate = parameter.fromDate - ?: dialogContext.bank.countDaysForWhichTransactionsAreKept?.let { Date(Date.today.millisSinceEpoch - it * OneDayMillis) } + ?: parameter.account.countDaysForWhichTransactionsAreKept?.let { Date(Date.today.millisSinceEpoch - it * OneDayMillis) } ?: bookedTransactions.map { it.valueDate }.sortedBy { it.millisSinceEpoch }.firstOrNull() val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, fromDate, parameter.toDate ?: Date.today) @@ -1011,10 +1011,6 @@ open class FinTsClient( } } - response.receivedSegments.filterIsInstance().firstOrNull()?.let { retrieveTransactionsParameters -> - bank.countDaysForWhichTransactionsAreKept = retrieveTransactionsParameters.countDaysForWhichTransactionsAreKept - } - response.getFirstSegmentById(InstituteSegmentId.SepaAccountInfo)?.let { sepaAccountInfo -> sepaAccountInfo.account.bic?.let { bank.bic = it // TODO: really set BIC on bank then? @@ -1066,6 +1062,10 @@ open class FinTsClient( mapAccountType(accountInfo), accountInfo.currency, accountHolderName, accountInfo.productName, accountInfo.accountLimit, accountInfo.allowedJobNames) + bank.supportedJobs.filterIsInstance().sortedByDescending { it.segmentVersion }.firstOrNull { newAccount.allowedJobNames.contains(it.jobName) }?.let { transactionsParameters -> + newAccount.countDaysForWhichTransactionsAreKept = transactionsParameters.countDaysForWhichTransactionsAreKept + } + bank.addAccount(newAccount) } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AccountData.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AccountData.kt index f48bffd9..1115aa16 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AccountData.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AccountData.kt @@ -29,6 +29,9 @@ open class AccountData( get() = FinTsClient.SupportedAccountTypes.contains(accountType) + open var countDaysForWhichTransactionsAreKept: Int? = null + + protected open val _supportedFeatures = mutableSetOf() open val supportedFeatures: Collection diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/BankData.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/BankData.kt index b50e406f..35e45253 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/BankData.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/BankData.kt @@ -42,8 +42,6 @@ open class BankData( */ open var countMaxJobsPerMessage: Int = 0, - open var countDaysForWhichTransactionsAreKept: Int? = null, - open var supportedHbciVersions: List = listOf(), open var supportedJobs: List = listOf() ) { diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/Bank.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/Bank.kt index 09212676..5d73ed43 100644 --- a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/Bank.kt +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/Bank.kt @@ -34,14 +34,13 @@ open class Bank( override var tanMedia: List = listOf(), - override var countDaysForWhichTransactionsAreKept: Int? = null, - - @PrimaryKey(autoGenerate = true) open var id: Long = BaseDao.IdNotSet, override var technicalId: String = id.toString(), + override var savePassword: Boolean = true, + override var userSetDisplayName: String? = null, override var displayIndex: Int = 0 ) : TypedBankData { diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/BankAccount.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/BankAccount.kt index 6bc47ef7..216527ae 100644 --- a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/BankAccount.kt +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/BankAccount.kt @@ -60,6 +60,8 @@ open class BankAccount( override var isAccountTypeSupportedByApplication: Boolean = true + override var countDaysForWhichTransactionsAreKept: Int? = null + override var userSetDisplayName: String? = null diff --git a/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/model/BankAccountEntity.kt b/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/model/BankAccountEntity.kt index 0d79351a..b8a2d0d6 100644 --- a/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/model/BankAccountEntity.kt +++ b/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/model/BankAccountEntity.kt @@ -33,6 +33,7 @@ open class BankAccountEntity( override var userSetDisplayName: String? = null, override var haveAllTransactionsBeenRetrieved: Boolean = false, override var isAccountTypeSupportedByApplication: Boolean = true, + override var countDaysForWhichTransactionsAreKept: Int? = null, override var displayIndex: Int = 0, override var hideAccount: Boolean = false, override var updateAccountAutomatically: Boolean = true, diff --git a/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/model/BankDataEntity.kt b/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/model/BankDataEntity.kt index 781ba18f..59306f17 100644 --- a/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/model/BankDataEntity.kt +++ b/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/model/BankDataEntity.kt @@ -23,8 +23,8 @@ open class BankDataEntity( override var supportedTanMethods: List = listOf(), override var selectedTanMethod: TanMethod? = null, override var tanMedia: List = listOf(), - override var countDaysForWhichTransactionsAreKept: Int? = null, override var technicalId: String = UUID.randomUUID().toString(), + override var savePassword: Boolean = true, override var userSetDisplayName: String? = null, override var displayIndex: Int = 0 ) : IBankData { diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/BankAccount.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/BankAccount.kt index 2efcc619..559b4e27 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/BankAccount.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/BankAccount.kt @@ -44,6 +44,8 @@ open class BankAccount @JvmOverloads constructor( override var isAccountTypeSupportedByApplication: Boolean = true + override var countDaysForWhichTransactionsAreKept: Int? = null + override var userSetDisplayName: String? = null diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/IBankAccount.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/IBankAccount.kt index 95096530..7dad6461 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/IBankAccount.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/IBankAccount.kt @@ -29,6 +29,7 @@ interface IBankAccount : OrderedDisplayable { var technicalId: String var haveAllTransactionsBeenRetrieved: Boolean var isAccountTypeSupportedByApplication: Boolean + var countDaysForWhichTransactionsAreKept: Int? var userSetDisplayName: String? /** diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/IBankData.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/IBankData.kt index 688f7a50..d36eb76b 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/IBankData.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/IBankData.kt @@ -57,9 +57,6 @@ interface IBankData, TAccountTransac get() = tanMedia.sortedByDescending { it.status == TanMediumStatus.Used } - var countDaysForWhichTransactionsAreKept: Int? - - val stringRepresentation: String get() = "$bankName $userName" 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 300ef6da..9994d2e0 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 @@ -400,7 +400,7 @@ open class BankingPresenter( } protected open fun didFetchAllTransactionsStoredOnBankServer(account: IBankAccount, fetchedTransactions: Collection): Boolean { - account.bank.countDaysForWhichTransactionsAreKept?.let { countDaysForWhichTransactionsAreKept -> + account.countDaysForWhichTransactionsAreKept?.let { countDaysForWhichTransactionsAreKept -> (account.retrievedTransactionsFromOn ?: getDateOfFirstRetrievedTransaction(account.bookedTransactions) ?: getDateOfFirstRetrievedTransaction(fetchedTransactions))?.let { retrievedTransactionsFromOn -> val dayOfFirstTransactionStoredOnBankServer = Date(Date.today.millisSinceEpoch - countDaysForWhichTransactionsAreKept * OneDayMillis) diff --git a/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents b/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents index d0f44c3d..c7d9fb81 100644 --- a/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents +++ b/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents @@ -47,6 +47,7 @@ + @@ -73,7 +74,6 @@ - @@ -107,7 +107,7 @@ - + diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift index 9ca0b6d6..1c6dafc9 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift @@ -37,7 +37,6 @@ class Mapper { mapped.customerName = bank.customerName mapped.userId = bank.userId mapped.iconUrl = bank.iconUrl - mapped.countDaysForWhichTransactionsAreKept = mapFromInt(bank.countDaysForWhichTransactionsAreKept) mapped.userSetDisplayName = bank.userSetDisplayName mapped.displayIndex = bank.displayIndex @@ -62,6 +61,7 @@ class Mapper { mapped.haveAllTransactionsBeenRetrieved = account.haveAllTransactionsBeenRetrieved mapped.isAccountTypeSupportedByApplication = account.isAccountTypeSupportedByApplication + mapped.countDaysForWhichTransactionsAreKept = mapToInt(account.countDaysForWhichTransactionsAreKept) mapped.userSetDisplayName = account.userSetDisplayName mapped.displayIndex = account.displayIndex @@ -92,7 +92,6 @@ class Mapper { mapped.balance = account.balance.decimal mapped.currency = account.currency mapped.type = map(account.type) - mapped.isAccountTypeSupportedByApplication = account.isAccountTypeSupportedByApplication mapped.productName = account.productName mapped.accountLimit = account.accountLimit mapped.retrievedTransactionsFromOn = account.retrievedTransactionsFromOn?.date @@ -103,6 +102,8 @@ class Mapper { mapped.supportsRealTimeTransfer = account.supportsRealTimeTransfer mapped.haveAllTransactionsBeenRetrieved = account.haveAllTransactionsBeenRetrieved + mapped.isAccountTypeSupportedByApplication = account.isAccountTypeSupportedByApplication + mapped.countDaysForWhichTransactionsAreKept = mapFromInt(account.countDaysForWhichTransactionsAreKept) mapped.userSetDisplayName = account.userSetDisplayName mapped.displayIndex = account.displayIndex diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt index 86aa7f2b..42690a19 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt @@ -77,7 +77,6 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { bank.bankName = fintsBank.bankName bank.bic = fintsBank.bic bank.customerName = fintsBank.customerName - bank.countDaysForWhichTransactionsAreKept = fintsBank.countDaysForWhichTransactionsAreKept bank.userId = fintsBank.userId bank.accounts = mapAccounts(bank, fintsBank.accounts) @@ -120,6 +119,7 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { account.currency = accountData.currency ?: "EUR" account.type = mapBankAccountType(accountData.accountType) account.isAccountTypeSupportedByApplication = accountData.isAccountTypeSupportedByApplication + account.countDaysForWhichTransactionsAreKept = accountData.countDaysForWhichTransactionsAreKept account.productName = accountData.productName account.accountLimit = accountData.accountLimit