diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/RouterAndroid.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/RouterAndroid.kt index acb4fc28..61dc1953 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/RouterAndroid.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/RouterAndroid.kt @@ -4,15 +4,12 @@ import net.dankito.banking.ui.android.util.CurrentActivityTracker import net.dankito.banking.ui.IRouter import net.dankito.banking.ui.android.dialogs.* import net.dankito.banking.ui.model.Customer -import net.dankito.banking.ui.model.BankAccount import net.dankito.banking.ui.model.parameters.TransferMoneyData import net.dankito.banking.ui.model.tan.EnterTanGeneratorAtcResult import net.dankito.banking.ui.model.tan.EnterTanResult import net.dankito.banking.ui.model.tan.TanChallenge import net.dankito.banking.ui.model.tan.TanGeneratorTanMedium import net.dankito.banking.ui.presenter.BankingPresenter -import java.util.concurrent.CountDownLatch -import java.util.concurrent.atomic.AtomicReference open class RouterAndroid(protected val activityTracker: CurrentActivityTracker) : IRouter { @@ -43,9 +40,9 @@ open class RouterAndroid(protected val activityTracker: CurrentActivityTracker) } } - override fun showTransferMoneyDialog(presenter: BankingPresenter, preselectedBankAccount: BankAccount?, preselectedValues: TransferMoneyData?) { + override fun showTransferMoneyDialog(presenter: BankingPresenter, preselectedValues: TransferMoneyData?) { activityTracker.currentOrNextActivity { activity -> - TransferMoneyDialog().show(activity, preselectedBankAccount, preselectedValues) + TransferMoneyDialog().show(activity, preselectedValues) } } diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt index 301035a7..33b688bb 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt @@ -50,8 +50,6 @@ open class TransferMoneyDialog : DialogFragment() { } - protected var preselectedBankAccount: BankAccount? = null - protected lateinit var bankAccount: BankAccount protected var preselectedValues: TransferMoneyData? = null @@ -84,12 +82,11 @@ open class TransferMoneyDialog : DialogFragment() { } - open fun show(activity: AppCompatActivity, preselectedBankAccount: BankAccount?, fullscreen: Boolean = false) { - show(activity, preselectedBankAccount, null, fullscreen) + open fun show(activity: AppCompatActivity, fullscreen: Boolean = false) { + show(activity, null, fullscreen) } - open fun show(activity: AppCompatActivity, preselectedBankAccount: BankAccount?, preselectedValues: TransferMoneyData?, fullscreen: Boolean = false) { - this.preselectedBankAccount = preselectedBankAccount + open fun show(activity: AppCompatActivity, preselectedValues: TransferMoneyData?, fullscreen: Boolean = false) { this.preselectedValues = preselectedValues val style = if(fullscreen) R.style.FullscreenDialogWithStatusBar else R.style.FloatingDialog @@ -111,7 +108,7 @@ open class TransferMoneyDialog : DialogFragment() { setPreselectedValues(rootView) val allBankAccountsSupportingTransferringMoney = presenter.bankAccountsSupportingTransferringMoney - bankAccount = preselectedBankAccount ?: allBankAccountsSupportingTransferringMoney.first() + bankAccount = preselectedValues?.account ?: allBankAccountsSupportingTransferringMoney.first() if (allBankAccountsSupportingTransferringMoney.size > 1) { rootView.lytSelectBankAccount.visibility = View.VISIBLE @@ -122,7 +119,7 @@ open class TransferMoneyDialog : DialogFragment() { this.bankAccount = selectedBankAccount setInstantPaymentControlsVisibility(rootView) } - preselectedBankAccount?.let { rootView.spnBankAccounts.setSelection(adapter.getItems().indexOf(it)) } + preselectedValues?.account?.let { rootView.spnBankAccounts.setSelection(adapter.getItems().indexOf(it)) } } initRemitteeAutocompletion(rootView.edtxtRemitteeName) @@ -249,6 +246,7 @@ open class TransferMoneyDialog : DialogFragment() { protected open fun transferMoney() { getEnteredAmount()?.let { amount -> // should only come at this stage when a valid amount has been entered val data = TransferMoneyData( + bankAccount, inputValidator.convertToAllowedSepaCharacters(edtxtRemitteeName.text.toString()), edtxtRemitteeIban.text.toString().replace(" ", ""), remitteeBic?.replace(" ", "") ?: "", // should always be != null at this point @@ -257,7 +255,7 @@ open class TransferMoneyDialog : DialogFragment() { chkbxInstantPayment.isChecked ) - presenter.transferMoneyAsync(bankAccount, data) { + presenter.transferMoneyAsync(data) { context?.asActivity()?.runOnUiThread { handleTransferMoneyResultOnUiThread(data, it) } diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt index debfe603..444ce94e 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt @@ -174,7 +174,7 @@ class HomeFragment : Fragment() { private fun showTransferMoneyDialog() { transactionAdapter.selectedTransaction?.let { selectedTransaction -> - presenter.showTransferMoneyDialog(selectedTransaction.bankAccount, mapPreselectedValues(selectedTransaction)) + presenter.showTransferMoneyDialog(mapPreselectedValues(selectedTransaction)) } } diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/RouterJavaFx.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/RouterJavaFx.kt index 9276823e..e29d5ef6 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/RouterJavaFx.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/RouterJavaFx.kt @@ -5,7 +5,6 @@ import net.dankito.banking.ui.javafx.dialogs.AddAccountDialog import net.dankito.banking.ui.javafx.dialogs.cashtransfer.TransferMoneyDialog import net.dankito.banking.ui.javafx.dialogs.tan.EnterTanDialog import net.dankito.banking.ui.model.Customer -import net.dankito.banking.ui.model.BankAccount import net.dankito.banking.ui.model.parameters.TransferMoneyData import net.dankito.banking.ui.model.tan.EnterTanGeneratorAtcResult import net.dankito.banking.ui.model.tan.EnterTanResult @@ -15,8 +14,6 @@ import net.dankito.banking.ui.presenter.BankingPresenter import tornadofx.FX import tornadofx.FX.Companion.messages import tornadofx.get -import java.util.concurrent.CountDownLatch -import java.util.concurrent.atomic.AtomicReference open class RouterJavaFx : IRouter { @@ -37,8 +34,8 @@ open class RouterJavaFx : IRouter { callback(EnterTanGeneratorAtcResult.userDidNotEnterAtc()) // TODO: implement EnterAtcDialog } - override fun showTransferMoneyDialog(presenter: BankingPresenter, preselectedBankAccount: BankAccount?, preselectedValues: TransferMoneyData?) { - TransferMoneyDialog(presenter, preselectedBankAccount, preselectedValues).show(messages["transfer.money.dialog.title"]) + override fun showTransferMoneyDialog(presenter: BankingPresenter, preselectedValues: TransferMoneyData?) { + TransferMoneyDialog(presenter, preselectedValues).show(messages["transfer.money.dialog.title"]) } override fun showSendMessageLogDialog(presenter: BankingPresenter) { diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt index bdc4009c..9445b0f6 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt @@ -107,7 +107,7 @@ open class AccountTransactionsView(private val presenter: BankingPresenter) : Vi } protected open fun showTransferMoneyDialog(transaction: AccountTransaction) { - presenter.showTransferMoneyDialog(transaction.bankAccount, TransferMoneyData.fromAccountTransaction(transaction)) + presenter.showTransferMoneyDialog(TransferMoneyData.fromAccountTransaction(transaction)) } diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/TransferMoneyDialog.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/TransferMoneyDialog.kt index 8397d0d1..906d81c7 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/TransferMoneyDialog.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/TransferMoneyDialog.kt @@ -33,7 +33,6 @@ import tornadofx.* open class TransferMoneyDialog @JvmOverloads constructor( protected val presenter: BankingPresenter, - preselectedBankAccount: BankAccount? = null, preselectedValues: TransferMoneyData? = null ) : Window() { @@ -50,7 +49,7 @@ open class TransferMoneyDialog @JvmOverloads constructor( protected val bankAccountsSupportingTransferringMoney = FXCollections.observableArrayList(presenter.bankAccounts.filter { it.supportsTransferringMoney }) - protected val selectedBankAccount = SimpleObjectProperty(preselectedBankAccount ?: bankAccountsSupportingTransferringMoney.firstOrNull()) + protected val selectedBankAccount = SimpleObjectProperty(preselectedValues?.account ?: bankAccountsSupportingTransferringMoney.firstOrNull()) protected val showBankAccounts = SimpleBooleanProperty(bankAccountsSupportingTransferringMoney.size > 1) @@ -350,6 +349,7 @@ open class TransferMoneyDialog @JvmOverloads constructor( val bankAccount = selectedBankAccount.value val data = TransferMoneyData( + bankAccount, inputValidator.convertToAllowedSepaCharacters(remitteeName.value), remitteeIban.value.replace(" ", ""), remitteeBic.value.replace(" ", ""), @@ -358,7 +358,7 @@ open class TransferMoneyDialog @JvmOverloads constructor( instantPayment.value ) - presenter.transferMoneyAsync(bankAccount, data) { + presenter.transferMoneyAsync(data) { runLater { handleTransferMoneyResultOnUiThread(bankAccount, data, it) } diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt index 027b354e..2fb1f078 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt @@ -22,7 +22,7 @@ interface IBankingClient { callback: (GetTransactionsResponse) -> Unit ) - fun transferMoneyAsync(data: TransferMoneyData, bankAccount: BankAccount, callback: (BankingClientResponse) -> Unit) + fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) fun restoreData() diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IRouter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IRouter.kt index b17e849a..202b6d19 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IRouter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IRouter.kt @@ -18,7 +18,7 @@ interface IRouter { fun getAtcFromUserFromNonUiThread(tanMedium: TanGeneratorTanMedium, callback: (EnterTanGeneratorAtcResult) -> Unit) - fun showTransferMoneyDialog(presenter: BankingPresenter, preselectedBankAccount: BankAccount?, preselectedValues: TransferMoneyData?) + fun showTransferMoneyDialog(presenter: BankingPresenter, preselectedValues: TransferMoneyData?) fun showSendMessageLogDialog(presenter: BankingPresenter) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/parameters/TransferMoneyData.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/parameters/TransferMoneyData.kt index 9280cc35..33dd3241 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/parameters/TransferMoneyData.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/parameters/TransferMoneyData.kt @@ -2,9 +2,11 @@ package net.dankito.banking.ui.model.parameters import net.dankito.utils.multiplatform.BigDecimal import net.dankito.banking.ui.model.AccountTransaction +import net.dankito.banking.ui.model.BankAccount open class TransferMoneyData( + val account: BankAccount, val creditorName: String, val creditorIban: String, val creditorBic: String, @@ -17,6 +19,7 @@ open class TransferMoneyData( fun fromAccountTransaction(transaction: AccountTransaction): TransferMoneyData { return TransferMoneyData( + transaction.bankAccount, transaction.otherPartyName ?: "", transaction.otherPartyAccountId ?: "", transaction.otherPartyBankCode ?: "", 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 ce61a764..76710273 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 @@ -410,11 +410,13 @@ open class BankingPresenter( } - open fun transferMoneyAsync(bankAccount: BankAccount, data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) { - getBankingClientForAccount(bankAccount.customer)?.let { client -> - client.transferMoneyAsync(data, bankAccount) { response -> + open fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) { + val account = data.account + + getBankingClientForAccount(account.customer)?.let { client -> + client.transferMoneyAsync(data) { response -> if (response.isSuccessful) { - updateBankAccountTransactionsAsync(bankAccount, true) { } + updateBankAccountTransactionsAsync(account, true) { } } callback(response) @@ -435,11 +437,12 @@ open class BankingPresenter( val invoiceData = invoiceDataExtractor.extractInvoiceData(extractedText) if (invoiceData.potentialTotalAmount != null || invoiceData.potentialIban != null) { // if at least an amount or IBAN could get extracted - val transferMoneyData = TransferMoneyData("", + val transferMoneyData = TransferMoneyData( + bankAccounts.first(), "", invoiceData.potentialIban ?: "", invoiceData.potentialBic ?: "", invoiceData.potentialTotalAmount ?: BigDecimal.Zero, "") - showTransferMoneyDialog(null, transferMoneyData) + showTransferMoneyDialog(transferMoneyData) } else { return ExtractTransferMoneyDataFromPdfResult( @@ -541,8 +544,8 @@ open class BankingPresenter( router.showAddAccountDialog(this) } - open fun showTransferMoneyDialog(preselectedBankAccount: BankAccount? = null, preselectedValues: TransferMoneyData? = null) { - router.showTransferMoneyDialog(this, preselectedBankAccount, preselectedValues) + open fun showTransferMoneyDialog(preselectedValues: TransferMoneyData? = null) { + router.showTransferMoneyDialog(this, preselectedValues) } open fun showSendMessageLogDialog() { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftUiRouter.swift b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftUiRouter.swift index 1d725a92..887a3d7b 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftUiRouter.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftUiRouter.swift @@ -23,7 +23,7 @@ class SwiftUiRouter : IRouter { callback(EnterTanGeneratorAtcResult.Companion().userDidNotEnterAtc()) } - func showTransferMoneyDialog(presenter: BankingPresenter, preselectedBankAccount: BankAccount?, preselectedValues: TransferMoneyData?) { + func showTransferMoneyDialog(presenter: BankingPresenter, preselectedValues: TransferMoneyData?) { } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift index 969a2274..13a20898 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift @@ -369,9 +369,9 @@ struct TransferMoneyDialog: View { private func transferMoney() { if let amount = inputValidator.convertAmountString(enteredAmountString: self.amount) { - let data = TransferMoneyData(creditorName: remitteeName, creditorIban: remitteeIban, creditorBic: remitteeBic, amount: amount, usage: usage, instantPayment: instantPayment) + let data = TransferMoneyData(account: account!, creditorName: remitteeName, creditorIban: remitteeIban, creditorBic: remitteeBic, amount: amount, usage: usage, instantPayment: instantPayment) - presenter.transferMoneyAsync(bankAccount: account!, data: data) { response in + presenter.transferMoneyAsync(data: data) { response in self.handleTransferMoneyResponse(data, response) } } diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt index 7c371826..2069ef68 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt @@ -108,8 +108,8 @@ open class fints4kBankingClient( } - override fun transferMoneyAsync(data: TransferMoneyData, bankAccount: BankAccount, callback: (BankingClientResponse) -> Unit) { - findAccountForBankAccount(bankAccount) { account, errorMessage -> + override fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) { + findAccountForBankAccount(data.account) { account, errorMessage -> if (account == null) { callback(BankingClientResponse(false, errorMessage)) } diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt index 29d872f7..352ed8ba 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt @@ -226,24 +226,24 @@ open class hbci4jBankingClient( } - override fun transferMoneyAsync(data: TransferMoneyData, bankAccount: BankAccount, callback: (BankingClientResponse) -> Unit) { + override fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) { asyncRunner.runAsync { - callback(transferMoney(data, bankAccount)) + callback(transferMoney(data)) } } - open fun transferMoney(data: TransferMoneyData, bankAccount: BankAccount): BankingClientResponse { + open fun transferMoney(data: TransferMoneyData): BankingClientResponse { val connection = connect() connection.handle?.let { handle -> try { - createTransferCashJob(handle, data, bankAccount) + createTransferCashJob(handle, data) val status = handle.execute() return BankingClientResponse(status.isOK, status.toString()) } catch(e: Exception) { - log.error("Could not transfer cash for account $bankAccount" , e) + log.error("Could not transfer cash for account ${data.account}" , e) return BankingClientResponse(false, e.getInnerExceptionMessage()) } finally { @@ -254,11 +254,11 @@ open class hbci4jBankingClient( return BankingClientResponse(false, connection.error.getInnerExceptionMessage() ?: "Could not connect") } - protected open fun createTransferCashJob(handle: HBCIHandler, data: TransferMoneyData, bankAccount: BankAccount) { + protected open fun createTransferCashJob(handle: HBCIHandler, data: TransferMoneyData) { // TODO: implement instant payment val transferCashJob = handle.newJob("UebSEPA") - val source = mapper.mapToKonto(bankAccount) + val source = mapper.mapToKonto(data.account) val destination = mapper.mapToKonto(data) val amount = Value(data.amount, "EUR")