From 89b700b740ace5e22506099c4310aff4e93ea371 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 6 Sep 2024 01:29:38 +0200 Subject: [PATCH] Added recipient account id and bank id to ShowTransferMoneyDialogData --- .../banking/dataaccess/BankingRepository.kt | 2 + .../dataaccess/InMemoryBankingRepository.kt | 3 + .../dataaccess/SqliteBankingRepository.kt | 112 ++++++++---------- .../transactions/TransactionListItem.kt | 23 ++-- .../banking/ui/dialogs/TransferMoneyDialog.kt | 2 +- .../ui/model/ShowTransferMoneyDialogData.kt | 3 +- .../banking/ui/service/BankingService.kt | 2 + .../codinux/banking/ui/AccountTransaction.sq | 6 +- 8 files changed, 79 insertions(+), 74 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/BankingRepository.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/BankingRepository.kt index 8c05670..2287612 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/BankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/BankingRepository.kt @@ -22,4 +22,6 @@ interface BankingRepository { fun getAllTransactionsOfUserAccount(userAccount: UserAccountEntity): List + fun getTransactionById(transactionId: Long): AccountTransactionEntity? + } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt index 976b89c..be672e0 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt @@ -40,6 +40,9 @@ class InMemoryBankingRepository( override fun getAllTransactionsOfUserAccount(userAccount: UserAccountEntity): List = getAllAccountTransactions().filter { it.userAccountId == userAccount.id } + override fun getTransactionById(transactionId: Long): AccountTransactionEntity? = + getAllAccountTransactions().firstOrNull { it.id == transactionId } + private fun map(account: UserAccount) = UserAccountEntity( nextId++, diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt index 29b4186..d89f39e 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt @@ -107,75 +107,16 @@ open class SqliteBankingRepository( }.executeAsList() override fun getAllAccountTransactions(): List { - return accountTransactionQueries.selectAllTransactions { id, userAccountId, bankAccountId, amount, currency, reference, bookingDate, valueDate, otherPartyName, otherPartyBankCode, otherPartyAccountId, bookingText, userSetDisplayName, category, notes, information, statementNumber, sequenceNumber, openingBalance, closingBalance, endToEndReference, customerReference, mandateReference, creditorIdentifier, originatorsIdentificationCode, compensationAmount, originalAmount, sepaReference, deviantOriginator, deviantRecipient, referenceWithNoSpecialType, primaNotaNumber, textKeySupplement, currencyType, bookingKey, referenceForTheAccountOwner, referenceOfTheAccountServicingInstitution, supplementaryDetails, transactionReferenceNumber, relatedReferenceNumber -> - AccountTransactionEntity( - id, - userAccountId, bankAccountId, - - Amount(amount), currency, reference, - mapToDate(bookingDate), mapToDate(valueDate), - otherPartyName, otherPartyBankCode, otherPartyAccountId, - bookingText, - - userSetDisplayName, category, notes, - - information, - statementNumber?.toInt(), sequenceNumber?.toInt(), - - mapToAmount(openingBalance), mapToAmount(closingBalance), - - endToEndReference, customerReference, mandateReference, - creditorIdentifier, originatorsIdentificationCode, - compensationAmount, originalAmount, - sepaReference, - deviantOriginator, deviantRecipient, - referenceWithNoSpecialType, primaNotaNumber, - textKeySupplement, - - currencyType, bookingKey, - referenceForTheAccountOwner, referenceOfTheAccountServicingInstitution, - supplementaryDetails, - - transactionReferenceNumber, relatedReferenceNumber - ) - }.executeAsList() + return accountTransactionQueries.selectAllTransactions(::mapTransaction).executeAsList() } override fun getAllTransactionsOfUserAccount(userAccount: UserAccountEntity): List { - return accountTransactionQueries.selectAllTransactionsOfUserAccount(userAccount.id) { id, userAccountId, bankAccountId, amount, currency, reference, bookingDate, valueDate, otherPartyName, otherPartyBankCode, otherPartyAccountId, bookingText, userSetDisplayName, category, notes, information, statementNumber, sequenceNumber, openingBalance, closingBalance, endToEndReference, customerReference, mandateReference, creditorIdentifier, originatorsIdentificationCode, compensationAmount, originalAmount, sepaReference, deviantOriginator, deviantRecipient, referenceWithNoSpecialType, primaNotaNumber, textKeySupplement, currencyType, bookingKey, referenceForTheAccountOwner, referenceOfTheAccountServicingInstitution, supplementaryDetails, transactionReferenceNumber, relatedReferenceNumber -> - AccountTransactionEntity( - id, - userAccountId, bankAccountId, - - Amount(amount), currency, reference, - mapToDate(bookingDate), mapToDate(valueDate), - otherPartyName, otherPartyBankCode, otherPartyAccountId, - bookingText, - - userSetDisplayName, category, notes, - - information, - statementNumber?.toInt(), sequenceNumber?.toInt(), - - mapToAmount(openingBalance), mapToAmount(closingBalance), - - endToEndReference, customerReference, mandateReference, - creditorIdentifier, originatorsIdentificationCode, - compensationAmount, originalAmount, - sepaReference, - deviantOriginator, deviantRecipient, - referenceWithNoSpecialType, primaNotaNumber, - textKeySupplement, - - currencyType, bookingKey, - referenceForTheAccountOwner, referenceOfTheAccountServicingInstitution, - supplementaryDetails, - - transactionReferenceNumber, relatedReferenceNumber - ) - }.executeAsList() + return accountTransactionQueries.selectAllTransactionsOfUserAccount(userAccount.id, ::mapTransaction).executeAsList() } + override fun getTransactionById(transactionId: Long): AccountTransactionEntity? = + accountTransactionQueries.getTransactionWithId(transactionId, ::mapTransaction).executeAsOneOrNull() + override suspend fun persistTransactions(bankAccount: BankAccountEntity, transactions: List): List { return accountTransactionQueries.transactionWithResult { @@ -225,6 +166,49 @@ open class SqliteBankingRepository( userAccountQueries.getLastInsertedId().executeAsOne() + private fun mapTransaction( + id: Long, userAccountId: Long, bankAccountId: Long, + amount: String, currency: String, reference: String, bookingDate: String, valueDate: String, + otherPartyName: String?, otherPartyBankCode: String?, otherPartyAccountId: String?, bookingText: String?, + userSetDisplayName: String?, category: String?, notes: String?, + information: String?, statementNumber: Long?, sequenceNumber: Long?, + openingBalance: String?, closingBalance: String?, + endToEndReference: String?, customerReference: String?, mandateReference: String?, creditorIdentifier: String?, originatorsIdentificationCode: String?, + compensationAmount: String?, originalAmount: String?, sepaReference: String?, deviantOriginator: String?, deviantRecipient: String?, referenceWithNoSpecialType: String?, + primaNotaNumber: String?, textKeySupplement: String?, currencyType: String?, bookingKey: String?, referenceForTheAccountOwner: String?, referenceOfTheAccountServicingInstitution: String?, + supplementaryDetails: String?, transactionReferenceNumber: String?, relatedReferenceNumber: String?): AccountTransactionEntity = + AccountTransactionEntity( + id, + userAccountId, bankAccountId, + + Amount(amount), currency, reference, + mapToDate(bookingDate), mapToDate(valueDate), + otherPartyName, otherPartyBankCode, otherPartyAccountId, + bookingText, + + userSetDisplayName, category, notes, + + information, + statementNumber?.toInt(), sequenceNumber?.toInt(), + + mapToAmount(openingBalance), mapToAmount(closingBalance), + + endToEndReference, customerReference, mandateReference, + creditorIdentifier, originatorsIdentificationCode, + compensationAmount, originalAmount, + sepaReference, + deviantOriginator, deviantRecipient, + referenceWithNoSpecialType, primaNotaNumber, + textKeySupplement, + + currencyType, bookingKey, + referenceForTheAccountOwner, referenceOfTheAccountServicingInstitution, + supplementaryDetails, + + transactionReferenceNumber, relatedReferenceNumber + ) + + @JvmName("mapAmount") @JsName("mapAmount") private fun mapAmount(amount: Amount?): String? = diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionListItem.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionListItem.kt index 42ed632..0f11cee 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionListItem.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionListItem.kt @@ -12,6 +12,7 @@ import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.dp +import kotlinx.coroutines.launch import net.codinux.banking.client.model.UserAccount import net.codinux.banking.ui.composables.BankIcon import net.codinux.banking.ui.config.Colors @@ -37,16 +38,24 @@ fun TransactionListItem(userAccount: UserAccount?, transaction: AccountTransacti var showMenuAt by remember { mutableStateOf(null) } + val coroutineScope = rememberCoroutineScope() + fun newMoneyTransferToOtherParty(withSameData: Boolean) { showMenuAt = null - DI.uiState.showTransferMoneyDialogData.value = ShowTransferMoneyDialogData( - DI.uiState.userAccounts.value.firstNotNullOf { it.accounts.firstOrNull { it.id == transaction.bankAccountId } }, - transaction.otherPartyName, - if (withSameData) transaction.amount else null, - if (withSameData) transaction.reference else null - ) + coroutineScope.launch { + val transactionEntity = DI.bankingService.getTransaction(transaction.id) + + DI.uiState.showTransferMoneyDialogData.value = ShowTransferMoneyDialogData( + DI.uiState.userAccounts.value.firstNotNullOf { it.accounts.firstOrNull { it.id == transaction.bankAccountId } }, + transaction.otherPartyName, + transactionEntity?.otherPartyBankCode, + transactionEntity?.otherPartyAccountId, + if (withSameData) transaction.amount else null, + if (withSameData) transaction.reference else null + ) + } } @@ -103,7 +112,7 @@ fun TransactionListItem(userAccount: UserAccount?, transaction: AccountTransacti ) } - DropdownMenu(showMenuAt != null, { showMenuAt = null }, Modifier.widthIn(min = 350.dp), + DropdownMenu(showMenuAt != null, { showMenuAt = null }, Modifier.widthIn(min = 375.dp), offset = showMenuAt ?: DpOffset.Zero, ) { DropdownMenuItem({ newMoneyTransferToOtherParty(false) }) { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt index edcfe01..a8d4ef0 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt @@ -56,7 +56,7 @@ fun TransferMoneyDialog( var senderAccount by remember { mutableStateOf(data.senderAccount ?: accountsSupportingTransferringMoney.first()) } var recipientName by remember { mutableStateOf(data.recipientName ?: "") } - var recipientAccountIdentifier by remember { mutableStateOf("") } + var recipientAccountIdentifier by remember { mutableStateOf(data.recipientAccountIdentifier ?: "") } var amount by remember { mutableStateOf(data.amount?.amount ?: "") } var paymentReference by remember { mutableStateOf(data.reference ?: "") } val accountSupportsInstantTransfer by remember(senderAccount) { derivedStateOf { senderAccount.supportsAnyFeature(BankAccountFeatures.InstantPayment) } } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/ShowTransferMoneyDialogData.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/ShowTransferMoneyDialogData.kt index 6cf74ed..4da1afc 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/ShowTransferMoneyDialogData.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/ShowTransferMoneyDialogData.kt @@ -6,7 +6,8 @@ import net.codinux.banking.dataaccess.entities.BankAccountEntity data class ShowTransferMoneyDialogData( val senderAccount: BankAccountEntity? = null, val recipientName: String? = null, - // TODO: add recipient account identifier + val recipientBankCode: String? = null, + val recipientAccountIdentifier: String? = null, val amount: Amount? = null, val reference: String? = null ) \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt index f9c698c..4424994 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt @@ -65,6 +65,8 @@ class BankingService( fun getAllAccountTransactionsAsViewModel() = bankingRepository.getAllAccountTransactionsAsViewModel() + fun getTransaction(transactionId: Long) = bankingRepository.getTransactionById(transactionId) + suspend fun findBanks(query: String): List = bankFinder.findBankByNameBankCodeOrCity(query, 25) diff --git a/composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/AccountTransaction.sq b/composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/AccountTransaction.sq index 4479a87..be7881a 100644 --- a/composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/AccountTransaction.sq +++ b/composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/AccountTransaction.sq @@ -124,4 +124,8 @@ FROM AccountTransaction; selectAllTransactionsOfUserAccount: SELECT AccountTransaction.* -FROM AccountTransaction WHERE userAccountId = ?; \ No newline at end of file +FROM AccountTransaction WHERE userAccountId = ?; + +getTransactionWithId: +SELECT AccountTransaction.* +FROM AccountTransaction WHERE id = ?; \ No newline at end of file