Added conversion to BigDecimal directly to Amount
This commit is contained in:
parent
b99522fda9
commit
e973ce256b
|
@ -1,5 +1,7 @@
|
|||
package net.dankito.banking.fints.model
|
||||
|
||||
import net.dankito.utils.multiplatform.BigDecimal
|
||||
|
||||
|
||||
open class Amount(
|
||||
val string: String
|
||||
|
@ -13,6 +15,10 @@ open class Amount(
|
|||
internal constructor() : this("") // for object deserializers
|
||||
|
||||
|
||||
open val bigDecimal: BigDecimal
|
||||
get() = BigDecimal(this.string.replace(',', '.'))
|
||||
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is Amount) return false
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.dankito.banking.fints.model
|
||||
|
||||
import net.dankito.utils.multiplatform.BigDecimal
|
||||
|
||||
|
||||
open class Money(
|
||||
val amount: Amount,
|
||||
|
@ -12,6 +14,10 @@ open class Money(
|
|||
internal constructor() : this(Amount.Zero, "") // for object deserializers
|
||||
|
||||
|
||||
|
||||
open val bigDecimal: BigDecimal
|
||||
get() = amount.bigDecimal
|
||||
|
||||
open val displayString: String
|
||||
get() = "$amount $currency"
|
||||
|
||||
|
|
|
@ -11,12 +11,4 @@ fun BigDecimal.toAmount(): Amount {
|
|||
|
||||
fun BigDecimal.toMoney(): Money {
|
||||
return Money(this.toAmount(), "EUR")
|
||||
}
|
||||
|
||||
fun Amount.toBigDecimal(): BigDecimal {
|
||||
return BigDecimal(this.string.replace(',', '.'))
|
||||
}
|
||||
|
||||
fun Money.toBigDecimal(): BigDecimal {
|
||||
return this.amount.toBigDecimal()
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package net.dankito.banking.mapper
|
||||
|
||||
import net.dankito.banking.extensions.toBigDecimal
|
||||
import net.dankito.banking.ui.model.*
|
||||
import net.dankito.banking.ui.model.responses.AddAccountResponse
|
||||
import net.dankito.banking.ui.model.responses.BankingClientResponse
|
||||
|
@ -54,7 +53,7 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) {
|
|||
return RetrievedAccountData(
|
||||
account,
|
||||
retrievedData.successfullyRetrievedData,
|
||||
retrievedData.balance?.toBigDecimal(),
|
||||
retrievedData.balance?.bigDecimal,
|
||||
mapTransactions(account, retrievedData.bookedTransactions),
|
||||
listOf(), // TODO: map unbooked transactions
|
||||
retrievedData.retrievedTransactionsFrom,
|
||||
|
@ -198,7 +197,7 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) {
|
|||
open fun mapTransaction(account: TypedBankAccount, transaction: net.dankito.banking.fints.model.AccountTransaction): IAccountTransaction {
|
||||
return modelCreator.createTransaction(
|
||||
account,
|
||||
transaction.amount.toBigDecimal(),
|
||||
transaction.amount.bigDecimal,
|
||||
transaction.amount.currency.code,
|
||||
transaction.unparsedUsage,
|
||||
transaction.bookingDate,
|
||||
|
@ -209,8 +208,8 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) {
|
|||
transaction.valueDate,
|
||||
transaction.statementNumber,
|
||||
transaction.sequenceNumber,
|
||||
transaction.openingBalance?.toBigDecimal(),
|
||||
transaction.closingBalance?.toBigDecimal(),
|
||||
transaction.openingBalance?.bigDecimal,
|
||||
transaction.closingBalance?.bigDecimal,
|
||||
|
||||
transaction.endToEndReference,
|
||||
transaction.customerReference,
|
||||
|
|
Loading…
Reference in New Issue