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 396f2b9..cab70a6 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt @@ -328,13 +328,15 @@ open class SqliteBankingRepository( ) - @JvmName("mapAmount") - @JsName("mapAmount") + @JvmName("mapAmountNullable") + @JsName("mapAmountNullable") private fun mapAmount(amount: Amount?): String? = amount?.let { mapAmount(it) } - private fun mapAmount(amount: Amount): String = amount.amount + private fun mapAmount(amount: Amount): String = amount.toString() + @JvmName("mapToAmountNullable") + @JsName("mapToAmountNullable") private fun mapToAmount(serializedAmount: String?): Amount? = serializedAmount?.let { mapToAmount(it) } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/HoldingListItem.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/HoldingListItem.kt index 6f5e2a5..e370a77 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/HoldingListItem.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/HoldingListItem.kt @@ -59,7 +59,7 @@ fun HoldingListItem(holding: Holding, isOddItem: Boolean = false, isNotLastItem: if (performance != null) { Text( text = formatUtil.formatPercentage(performance), - color = formatUtil.getColorForAmount(Amount(performance.toDouble()), showColoredAmounts) + color = formatUtil.getColorForAmount(Amount(performance.toString()), showColoredAmounts) ) } } 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 f15607c..7063984 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 recipientName by remember { mutableStateOf(data.recipientName ?: "") } var recipientAccountIdentifier by remember { mutableStateOf(data.recipientAccountIdentifier ?: "") } - var amount by remember { mutableStateOf(data.amount?.amount ?: "") } + var amount by remember { mutableStateOf(data.amount.toString()) } var paymentReference by remember { mutableStateOf(data.reference ?: "") } val accountSupportsInstantTransfer by remember(senderAccount) { derivedStateOf { senderAccount.supportsInstantTransfer } } var instantTransfer by remember { mutableStateOf(false) } @@ -202,10 +202,10 @@ fun TransferMoneyDialog( minTextLengthForSearch = 0, modifier = Modifier.weight(1f).focusRequester(amountFocus), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal, imeAction = ImeAction.Next), - getItemTitle = { suggestion -> suggestion.amount.amount }, + getItemTitle = { suggestion -> suggestion.amount.toString() }, onEnteredTextChanged = { amount = it }, onSelectedItemChanged = { - amount = it?.amount?.amount ?: "" + amount = it?.amount.toString() if (it != null) { paymentReference = it.reference } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/extensions/AmountExtensions.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/extensions/AmountExtensions.kt deleted file mode 100644 index 1b6446b..0000000 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/extensions/AmountExtensions.kt +++ /dev/null @@ -1,5 +0,0 @@ -package net.codinux.banking.ui.extensions - -import net.codinux.banking.client.model.Amount - -fun Amount.toBigDecimal(): Double = this.amount.toDouble() \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankDataImporterAndExporter.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankDataImporterAndExporter.kt index 1737dd5..4f0cc7c 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankDataImporterAndExporter.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankDataImporterAndExporter.kt @@ -32,9 +32,9 @@ class BankDataImporterAndExporter { private fun formatAmount(amount: Amount, decimalSeparator: Char): String = if (decimalSeparator == '.') { - amount.amount + amount.toString() } else { - amount.amount.replace('.', decimalSeparator) + amount.toString().replace('.', decimalSeparator) } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/CalculatorService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/CalculatorService.kt index f9a3522..8ad541b 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/CalculatorService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/CalculatorService.kt @@ -1,32 +1,26 @@ package net.codinux.banking.ui.service -import net.codinux.banking.client.model.Amount -import net.codinux.banking.client.model.User +import net.codinux.banking.client.model.* import net.codinux.banking.dataaccess.entities.UserEntity -import net.codinux.banking.ui.extensions.toBigDecimal import net.codinux.banking.ui.model.AccountTransactionViewModel import net.codinux.banking.ui.model.AccountTransactionsFilter class CalculatorService { fun sumTransactions(transactions: Collection): Amount = - // TODO: find a better solution - Amount(transactions.sumOf { it.amount.toBigDecimal() }.toString()) + transactions.map { it.amount }.sum() fun calculateBalanceOfUser(user: User): Amount = sumAmounts(user.accounts.map { it.balance }) fun sumAmounts(amounts: Collection): Amount = - // TODO: find a better solution - Amount(amounts.sumOf { it.toBigDecimal() }.toString()) + amounts.sum() fun sumIncome(transactions: Collection): Amount = - // TODO: find a better solution - Amount(transactions.map { it.amount.toBigDecimal() }.filter { it > 0 }.sum().toString()) + sumAmounts(transactions.map { it.amount }.filterNot { it.isNegative }) fun sumExpenses(transactions: Collection): Amount = - // TODO: find a better solution - Amount(transactions.map { it.amount.toBigDecimal() }.filter { it < 0 }.sum().toString()) + sumAmounts(transactions.map { it.amount }.filter { it.isNegative }) fun calculateBalanceOfDisplayedTransactions(transactions: Collection, users: Collection, filter: AccountTransactionsFilter): Amount { if (filter.noFiltersApplied) { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt index 944b377..aad120a 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt @@ -56,7 +56,7 @@ class FormatUtil { fun formatAmount(amount: Amount, currency: String): String { - return "${formatToTwoDecimalPlaces(amount.amount)} ${formatCurrency(currency)}" + return "${formatToTwoDecimalPlaces(amount.toString())} ${formatCurrency(currency)}" } fun formatCurrency(currency: String): String = when (currency) { @@ -66,7 +66,7 @@ class FormatUtil { fun getColorForAmount(amount: Amount, showColoredAmounts: Boolean = true): Color = when { showColoredAmounts == false -> Color.Unspecified - amount.amount.startsWith("-") -> Colors.Red600 + amount.toString().startsWith("-") -> Colors.Red600 else -> Colors.Green600 } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/RecipientFinder.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/RecipientFinder.kt index e156830..c491f1f 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/RecipientFinder.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/RecipientFinder.kt @@ -45,7 +45,7 @@ class RecipientFinder(private val bankFinder: BankFinder) { transactionsByIban = transactions.filter { it.otherPartyAccountId != null }.groupBy { it.otherPartyAccountId!! } .mapValues { it.value.map { - PaymentDataSuggestion(it.reference ?: "", Amount(it.amount.amount.replace("-", "")), it.currency, it.valueDate) + PaymentDataSuggestion(it.reference ?: "", Amount(it.amount.toString().replace("-", "")), it.currency, it.valueDate) }.toSet().sortedByDescending { it.valueDate } } }