From 1e5c83c3698c92cee64ba2efd1ef14a2546abf0a Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 5 Sep 2024 22:04:05 +0200 Subject: [PATCH] Renamed haveAllTransactionsBeenRetrieved to haveAllRetainedTransactionsBeenRetrieved and made it evaluating countDaysForWhichTransactionsAreKeptOnBankServer and retrievedTransactionsFrom instead of being set to a fixed value --- .../banking/client/model/BankAccount.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccount.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccount.kt index 5f1bcf1a..da0a32e2 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccount.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccount.kt @@ -1,7 +1,6 @@ package net.codinux.banking.client.model -import kotlinx.datetime.Instant -import kotlinx.datetime.LocalDate +import kotlinx.datetime.* import net.codinux.banking.client.model.config.JsonIgnore import net.codinux.banking.client.model.config.NoArgConstructor @@ -22,12 +21,10 @@ open class BankAccount( val isAccountTypeSupportedByApplication: Boolean = false, val features: Set = emptySet(), + val countDaysForWhichTransactionsAreKeptOnBankServer: Int? = null, open var lastTransactionsRetrievalTime: Instant? = null, var retrievedTransactionsFrom: LocalDate? = null, - var haveAllTransactionsBeenRetrieved: Boolean = false, - val countDaysForWhichTransactionsAreKept: Int? = null, - open val bookedTransactions: MutableList = mutableListOf(), open val unbookedTransactions: MutableList = mutableListOf(), @@ -44,5 +41,21 @@ open class BankAccount( fun supportsAnyFeature(vararg features: BankAccountFeatures): Boolean = features.any { this.features.contains(it) } + /** + * Determines if all transactions that are retained on bank server have been fetched. + * + * Does this by comparing [countDaysForWhichTransactionsAreKeptOnBankServer] to [retrievedTransactionsFrom]. + */ + open val haveAllRetainedTransactionsBeenRetrieved: Boolean by lazy { + val fromDay = retrievedTransactionsFrom + if (fromDay == null) { + false + } else { + // if countDaysForWhichTransactionsAreKeptOnBankServer is not set, we cannot know for how long bank server keeps transactions. We then assume for 90 days + val storageDays = countDaysForWhichTransactionsAreKeptOnBankServer ?: 90 + fromDay < Clock.System.now().toLocalDateTime(TimeZone.of("Europe/Berlin")).date.minus(storageDays, DateTimeUnit.DAY) + } + } + override fun toString() = "$type $identifier $productName (IBAN: $iban)" } \ No newline at end of file