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