diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt index 941d990f..87a8cac6 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt @@ -2,6 +2,7 @@ package net.codinux.banking.fints import kotlinx.coroutines.delay import kotlinx.datetime.LocalDate +import kotlinx.datetime.LocalDateTime import net.codinux.log.logger import net.codinux.banking.fints.messages.MessageBuilder import net.codinux.banking.fints.messages.MessageBuilderResult @@ -19,6 +20,7 @@ import net.codinux.banking.fints.tan.FlickerCodeDecoder import net.codinux.banking.fints.tan.TanImageDecoder import net.codinux.banking.fints.util.TanMethodSelector import net.codinux.banking.fints.extensions.minusDays +import net.codinux.banking.fints.extensions.nowAtEuropeBerlin import net.codinux.banking.fints.extensions.todayAtEuropeBerlin import net.codinux.banking.fints.extensions.todayAtSystemDefaultTimeZone import kotlin.math.max @@ -230,6 +232,8 @@ open class FinTsJobExecutor( } } + val startTime = LocalDateTime.nowAtEuropeBerlin() + val response = getAndHandleResponseForMessage(context, message) closeDialog(context) @@ -239,7 +243,7 @@ open class FinTsJobExecutor( val fromDate = parameter.fromDate ?: parameter.account.countDaysForWhichTransactionsAreKept?.let { LocalDate.todayAtSystemDefaultTimeZone().minusDays(it) } ?: bookedTransactions.minByOrNull { it.valueDate }?.valueDate - val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, fromDate, parameter.toDate ?: LocalDate.todayAtEuropeBerlin(), response.internalError) + val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, startTime, fromDate, parameter.toDate ?: LocalDate.todayAtEuropeBerlin(), response.internalError) return GetAccountTransactionsResponse(context, response, retrievedData, if (parameter.maxCountEntries != null) parameter.isSettingMaxCountEntriesAllowedByBank else null) diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/mapper/FinTsModelMapper.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/mapper/FinTsModelMapper.kt index 7f2857c4..0f68d259 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/mapper/FinTsModelMapper.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/mapper/FinTsModelMapper.kt @@ -1,6 +1,7 @@ package net.codinux.banking.fints.mapper import kotlinx.datetime.LocalDate +import kotlinx.datetime.atTime import net.dankito.banking.client.model.* import net.dankito.banking.client.model.AccountTransaction import net.dankito.banking.client.model.parameter.FinTsClientParameter @@ -70,7 +71,7 @@ open class FinTsModelMapper { } } - open fun map(bank: BankData, retrievedTransactionsResponses: List): CustomerAccount { + open fun map(bank: BankData, retrievedTransactionsResponses: List, retrieveTransactionsTo: LocalDate? = null): CustomerAccount { val customerAccount = map(bank) val retrievedData = retrievedTransactionsResponses.mapNotNull { it.retrievedData } @@ -78,7 +79,10 @@ open class FinTsModelMapper { retrievedData.firstOrNull { it.account.accountIdentifier == bankAccount.identifier }?.let { accountTransactionsResponse -> bankAccount.balance = accountTransactionsResponse.balance ?: Money.Zero bankAccount.retrievedTransactionsFrom = accountTransactionsResponse.retrievedTransactionsFrom - bankAccount.retrievedTransactionsTo = accountTransactionsResponse.retrievedTransactionsTo + val retrievalTime = if (retrieveTransactionsTo == null) accountTransactionsResponse.retrievalTime else retrieveTransactionsTo.atTime(0, 0) + if (bankAccount.lastTransactionRetrievalTime == null || bankAccount.lastTransactionRetrievalTime!! <= retrievalTime) { // if retrieveTransactionsTo is set it may is older than current account's lastTransactionRetrievalTime + bankAccount.lastTransactionRetrievalTime = retrievalTime + } bankAccount.bookedTransactions = map(accountTransactionsResponse) } } @@ -157,6 +161,10 @@ open class FinTsModelMapper { else errorMessages.joinToString("\r\n") } + open fun mergeMessageLog(vararg messageLogs: List?): List { + return messageLogs.filterNotNull().flatten() + } + open fun mergeMessageLog(vararg responses: FinTsClientResponse?): List { return responses.filterNotNull().flatMap { it.messageLog } } diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/RetrievedAccountData.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/RetrievedAccountData.kt index b29a6da1..3e41191f 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/RetrievedAccountData.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/RetrievedAccountData.kt @@ -1,6 +1,8 @@ package net.codinux.banking.fints.model import kotlinx.datetime.LocalDate +import kotlinx.datetime.LocalDateTime +import net.codinux.banking.fints.extensions.nowAtEuropeBerlin open class RetrievedAccountData( @@ -9,6 +11,7 @@ open class RetrievedAccountData( open val balance: Money?, open var bookedTransactions: Collection, open var unbookedTransactions: Collection, + open val retrievalTime: LocalDateTime, open val retrievedTransactionsFrom: LocalDate?, open val retrievedTransactionsTo: LocalDate?, open val errorMessage: String? = null @@ -17,7 +20,7 @@ open class RetrievedAccountData( companion object { fun unsuccessful(account: AccountData): RetrievedAccountData { - return RetrievedAccountData(account, false, null, listOf(), listOf(), null, null) + return RetrievedAccountData(account, false, null, listOf(), listOf(), LocalDateTime.nowAtEuropeBerlin(), null, null) } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/BankAccount.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/BankAccount.kt index daedd8fc..3ae85831 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/BankAccount.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/BankAccount.kt @@ -1,6 +1,7 @@ package net.dankito.banking.client.model import kotlinx.datetime.LocalDate +import kotlinx.datetime.LocalDateTime import kotlinx.serialization.Serializable import net.codinux.banking.fints.model.Currency import net.codinux.banking.fints.model.Money @@ -35,7 +36,7 @@ open class BankAccount( open var retrievedTransactionsFrom: LocalDate? = null - open var retrievedTransactionsTo: LocalDate? = null + open var lastTransactionRetrievalTime: LocalDateTime? = null open var bookedTransactions: List = listOf()