Displaying income and expenses of each month
This commit is contained in:
parent
fedbb3a544
commit
a7731091be
|
@ -13,6 +13,7 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
@ -20,10 +21,14 @@ import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import net.codinux.banking.client.model.AccountTransaction
|
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.Colors
|
||||||
import net.codinux.banking.ui.service.DI
|
import net.codinux.banking.ui.service.DI
|
||||||
import org.jetbrains.compose.ui.tooling.preview.Preview
|
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||||
|
|
||||||
|
private val formatUtil = DI.formatUtil
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TransactionsList(transactions: List<AccountTransaction>) {
|
fun TransactionsList(transactions: List<AccountTransaction>) {
|
||||||
val groupedByMonth by remember(transactions) {
|
val groupedByMonth by remember(transactions) {
|
||||||
|
@ -60,6 +65,22 @@ fun TransactionsList(transactions: List<AccountTransaction>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"))
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package net.codinux.banking.ui.extensions
|
||||||
|
|
||||||
|
import net.codinux.banking.client.model.Amount
|
||||||
|
|
||||||
|
fun Amount.toBigDecimal(): Double = this.amount.toDouble()
|
|
@ -34,7 +34,8 @@ class FormatUtil {
|
||||||
val parts = amount.amount.split('.')
|
val parts = amount.amount.split('.')
|
||||||
val decimalPart = if (parts.size == 2) parts[1] else "00"
|
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) {
|
fun formatCurrency(currency: String): String = when (currency) {
|
||||||
|
|
Loading…
Reference in New Issue