Added lastTransactionRetrievalTime to BankAccount, removed retrievedTransactionsTo for it

This commit is contained in:
dankito 2024-09-03 01:05:04 +02:00
parent e36c27c0e0
commit 09c2080481
4 changed files with 21 additions and 5 deletions

View File

@ -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)

View File

@ -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<GetAccountTransactionsResponse>): CustomerAccount {
open fun map(bank: BankData, retrievedTransactionsResponses: List<GetAccountTransactionsResponse>, 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<MessageLogEntry>?): List<MessageLogEntry> {
return messageLogs.filterNotNull().flatten()
}
open fun mergeMessageLog(vararg responses: FinTsClientResponse?): List<MessageLogEntry> {
return responses.filterNotNull().flatMap { it.messageLog }
}

View File

@ -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<AccountTransaction>,
open var unbookedTransactions: Collection<Any>,
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)
}
}

View File

@ -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<AccountTransaction> = listOf()