Added BankAccount to TransferMoneyData
This commit is contained in:
parent
2324d7ceda
commit
92456604bb
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ class HomeFragment : Fragment() {
|
|||
|
||||
private fun showTransferMoneyDialog() {
|
||||
transactionAdapter.selectedTransaction?.let { selectedTransaction ->
|
||||
presenter.showTransferMoneyDialog(selectedTransaction.bankAccount, mapPreselectedValues(selectedTransaction))
|
||||
presenter.showTransferMoneyDialog(mapPreselectedValues(selectedTransaction))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<BankAccount>(preselectedBankAccount ?: bankAccountsSupportingTransferringMoney.firstOrNull())
|
||||
protected val selectedBankAccount = SimpleObjectProperty<BankAccount>(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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 ?: "",
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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?) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in New Issue