By default transactions don't get sorted anymore. Is not required in all cases

This commit is contained in:
dankito 2021-11-06 01:59:15 +01:00
parent 2cc5408857
commit babc74179a
4 changed files with 21 additions and 6 deletions

View File

@ -139,7 +139,7 @@ open class SettingsDialog : SettingsDialogBase() {
val config = FileChooserDialogConfig(initialDirectory = initialDirectory, suggestedFilenameForSaveFileDialog = suggestedFilename)
FileChooserDialog().showSaveFileInFullscreenDialog(activity, permissionsService, config) { _, selectedFile ->
selectedFile?.let {
val transactions = presenter.allTransactions.map { mapTransaction(it) }
val transactions = presenter.allTransactionsSorted.map { mapTransaction(it) }
CsvAccountTransactionsExporter().export(selectedFile, transactions)

View File

@ -133,7 +133,7 @@ open class MainMenuBar(protected val presenter: BankingPresenter) : View() {
destinationFile = File(destinationFile.absolutePath + ".csv")
}
val transactions = presenter.allTransactions.map { mapTransaction(it) }
val transactions = presenter.allTransactionsSorted.map { mapTransaction(it) }
CsvAccountTransactionsExporter().export(destinationFile, transactions)
}

View File

@ -48,8 +48,6 @@ import io.ktor.http.cio.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import net.dankito.banking.ui.model.issues.CreateTicketRequestDto
import net.dankito.banking.ui.model.issues.IssueDescriptionFormat
open class BankingPresenter(
@ -796,11 +794,14 @@ open class BankingPresenter(
open fun searchAccountTransactions(query: String, transactions: List<IAccountTransaction>): List<IAccountTransaction> {
val queryLowercase = query.trim().toLowerCase()
// get transactions sorted by date
val transactionsSorted = transactions.toSet().sortedByDate()
if (queryLowercase.isEmpty()) {
return transactions
return transactionsSorted
}
return transactions.filter {
return transactionsSorted.filter {
it.otherPartyName?.toLowerCase()?.contains(queryLowercase) == true
|| it.reference.toLowerCase().contains(queryLowercase)
|| it.bookingText?.toLowerCase()?.contains(queryLowercase) == true
@ -989,6 +990,9 @@ open class BankingPresenter(
open val allTransactions: List<IAccountTransaction>
get() = getTransactionsForAccounts(allAccounts)
open val allTransactionsSorted: List<IAccountTransaction>
get() = getTransactionsForAccountsSorted(allAccounts)
open val balanceOfAllAccounts: BigDecimal
get() = getBalanceForBanks(allBanks)
@ -1042,6 +1046,11 @@ open class BankingPresenter(
protected open fun getTransactionsForAccounts(accounts: Collection<TypedBankAccount>): List<IAccountTransaction> {
return accounts.flatMap { it.bookedTransactions }.sortedByDescending { it.valueDate.millisSinceEpoch } // TODO: someday add unbooked transactions
}
protected open fun getTransactionsForAccountsSorted(accounts: Collection<TypedBankAccount>): List<IAccountTransaction> {
return getTransactionsForAccounts(accounts).sortedByDate()
}
open fun currencyIsoCodeOfAccounts(accounts: List<TypedBankAccount>): String {
// TODO: this is of course not right, it assumes that all accounts have the same currency. But we don't support e.g. calculating the balance of accounts with different currencies anyway
// at start up list with selectedAccounts is empty

View File

@ -1,5 +1,6 @@
package net.dankito.banking.util
import net.dankito.banking.ui.model.IAccountTransaction
import net.dankito.banking.ui.model.OrderedDisplayable
@ -38,3 +39,8 @@ fun <T : OrderedDisplayable> List<T>.sortedByDisplayIndex(): List<T> {
fun <T : OrderedDisplayable> Collection<T>.sortedByDisplayIndex(): Collection<T> {
return this.sortedBy { it.displayIndex }
}
fun <T : IAccountTransaction> Iterable<T>.sortedByDate(): List<T> {
return this.sortedByDescending { it.valueDate.millisSinceEpoch }
}