From 1bc8a93ba4fc0d6a61838fb1c548c20438e053d4 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 22 Sep 2020 04:01:25 +0200 Subject: [PATCH] Fixed checking if all transactions have been fetched by using retrievedTransactionsFromOn (as first retrieved transaction may not is on the first day of the fetched period( --- .../dankito/banking/ui/presenter/BankingPresenter.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 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