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 0dce6277..a1668772 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 @@ -354,18 +354,20 @@ open class BankingPresenter( protected open fun didFetchAllTransactionsStoredOnBankServer(account: IBankAccount, fetchedTransactions: Collection): Boolean { account.customer.countDaysForWhichTransactionsAreKept?.let { countDaysForWhichTransactionsAreKept -> - val firstAccountTransactions = if (account.bookedTransactions.isNotEmpty()) account.bookedTransactions else fetchedTransactions - - firstAccountTransactions.map { it.valueDate }.minBy { it.millisSinceEpoch }?.let { dateOfFirstRetrievedTransaction -> + (account.retrievedTransactionsFromOn ?: getDateOfFirstRetrievedTransaction(account.bookedTransactions) ?: getDateOfFirstRetrievedTransaction(fetchedTransactions))?.let { retrievedTransactionsFromOn -> val dayOfFirstTransactionStoredOnBankServer = Date(Date.today.millisSinceEpoch - countDaysForWhichTransactionsAreKept * OneDayMillis) - return dateOfFirstRetrievedTransaction.isBeforeOrEquals(dayOfFirstTransactionStoredOnBankServer) + return retrievedTransactionsFromOn.isBeforeOrEquals(dayOfFirstTransactionStoredOnBankServer) } } return false } + protected open fun getDateOfFirstRetrievedTransaction(transactions: Collection): Date? { + return transactions.map { it.valueDate }.minBy { it.millisSinceEpoch } + } + protected open fun receivedAccountsTransactionChunk(bankAccount: TypedBankAccount, accountTransactionsChunk: List) { if (accountTransactionsChunk.isNotEmpty()) { asyncRunner.runAsync { // don't block retrieving next chunk by blocked saving to db / json