diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/TransactionsList.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/TransactionsList.kt index 971fbf8..af5e5da 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/TransactionsList.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/TransactionsList.kt @@ -13,6 +13,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight @@ -20,10 +21,14 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import kotlinx.datetime.LocalDate import net.codinux.banking.client.model.AccountTransaction +import net.codinux.banking.client.model.Amount +import net.codinux.banking.ui.extensions.toBigDecimal import net.codinux.banking.ui.service.Colors import net.codinux.banking.ui.service.DI import org.jetbrains.compose.ui.tooling.preview.Preview +private val formatUtil = DI.formatUtil + @Composable fun TransactionsList(transactions: List) { val groupedByMonth by remember(transactions) { @@ -60,6 +65,22 @@ fun TransactionsList(transactions: List) { } } } + + Column(Modifier.fillMaxWidth().padding(top = 10.dp), horizontalAlignment = Alignment.End) { + Text( + // TODO: find a better solution + text = formatUtil.formatAmount(Amount(monthTransactions.map { it.amount.toBigDecimal() }.filter { it > 0 }.sum().toString()), "EUR"), + color = formatUtil.getColorForAmount(Amount.Zero) + ) + } + + Column(Modifier.fillMaxWidth().padding(top = 2.dp), horizontalAlignment = Alignment.End) { + Text( + // TODO: find a better solution + text = formatUtil.formatAmount(Amount(monthTransactions.map { it.amount.toBigDecimal() }.filter { it < 0 }.sum().toString()), "EUR"), + color = formatUtil.getColorForAmount(Amount("-1")) + ) + } } } } 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 new file mode 100644 index 0000000..1b6446b --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/extensions/AmountExtensions.kt @@ -0,0 +1,5 @@ +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/FormatUtil.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt index 3e0ec19..335d6f2 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 @@ -34,7 +34,8 @@ class FormatUtil { val parts = amount.amount.split('.') val decimalPart = if (parts.size == 2) parts[1] else "00" - return "${parts[0]},${decimalPart.padEnd(2, '0')} ${formatCurrency(currency)}" + // TODO: add thousands separator + return "${parts[0]},${decimalPart.padEnd(2, '0').substring(0, 2)} ${formatCurrency(currency)}" } fun formatCurrency(currency: String): String = when (currency) {