chore: replace int amount_cents for string storage and decimal pkg
This commit is contained in:
parent
13774eec7d
commit
c8a1eb5b7a
45 changed files with 706 additions and 587 deletions
|
|
@ -13,6 +13,7 @@ import (
|
|||
"git.juancwu.dev/juancwu/budgit/internal/ui/components/label"
|
||||
"git.juancwu.dev/juancwu/budgit/internal/ui/components/pagination"
|
||||
"git.juancwu.dev/juancwu/budgit/internal/ui/components/selectbox"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func frequencyLabel(f model.Frequency) string {
|
||||
|
|
@ -32,7 +33,7 @@ func frequencyLabel(f model.Frequency) string {
|
|||
}
|
||||
}
|
||||
|
||||
templ BalanceSummaryCard(spaceID string, totalBalance int, availableBalance int, oob bool) {
|
||||
templ BalanceSummaryCard(spaceID string, totalBalance decimal.Decimal, availableBalance decimal.Decimal, oob bool) {
|
||||
<div
|
||||
id="accounts-balance-summary"
|
||||
class="border rounded-lg p-4 bg-card text-card-foreground"
|
||||
|
|
@ -44,20 +45,20 @@ templ BalanceSummaryCard(spaceID string, totalBalance int, availableBalance int,
|
|||
<div class="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<p class="text-sm text-muted-foreground">Total Balance</p>
|
||||
<p class={ "text-xl font-bold", templ.KV("text-destructive", totalBalance < 0) }>
|
||||
{ fmt.Sprintf("$%.2f", float64(totalBalance)/100.0) }
|
||||
<p class={ "text-xl font-bold", templ.KV("text-destructive", totalBalance.LessThan(decimal.Zero)) }>
|
||||
{ model.FormatMoney(totalBalance) }
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-muted-foreground">Allocated</p>
|
||||
<p class="text-xl font-bold">
|
||||
{ fmt.Sprintf("$%.2f", float64(totalBalance-availableBalance)/100.0) }
|
||||
{ model.FormatMoney(totalBalance.Sub(availableBalance)) }
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-muted-foreground">Available</p>
|
||||
<p class={ "text-xl font-bold", templ.KV("text-destructive", availableBalance < 0) }>
|
||||
{ fmt.Sprintf("$%.2f", float64(availableBalance)/100.0) }
|
||||
<p class={ "text-xl font-bold", templ.KV("text-destructive", availableBalance.LessThan(decimal.Zero)) }>
|
||||
{ model.FormatMoney(availableBalance) }
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -79,8 +80,8 @@ templ AccountCard(spaceID string, acct *model.MoneyAccountWithBalance, oob ...bo
|
|||
<div class="flex justify-between items-start mb-3">
|
||||
<div>
|
||||
<h3 class="font-semibold text-lg">{ acct.Name }</h3>
|
||||
<p class={ "text-2xl font-bold", templ.KV("text-destructive", acct.BalanceCents < 0) }>
|
||||
{ fmt.Sprintf("$%.2f", float64(acct.BalanceCents)/100.0) }
|
||||
<p class={ "text-2xl font-bold", templ.KV("text-destructive", acct.Balance.LessThan(decimal.Zero)) }>
|
||||
{ model.FormatMoney(acct.Balance) }
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-1">
|
||||
|
|
@ -356,7 +357,7 @@ templ RecurringDepositItem(spaceID string, rd *model.RecurringDepositWithAccount
|
|||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-bold text-green-600 whitespace-nowrap">
|
||||
+{ fmt.Sprintf("$%.2f", float64(rd.AmountCents)/100.0) }
|
||||
+{ model.FormatMoney(rd.Amount) }
|
||||
</span>
|
||||
// Toggle
|
||||
@button.Button(button.Props{
|
||||
|
|
@ -636,11 +637,11 @@ templ TransferHistoryItem(spaceID string, t *model.AccountTransferWithAccount) {
|
|||
<div class="flex items-center gap-2">
|
||||
if t.Direction == model.TransferDirectionDeposit {
|
||||
<span class="font-bold text-green-600 whitespace-nowrap">
|
||||
+{ fmt.Sprintf("$%.2f", float64(t.AmountCents)/100.0) }
|
||||
+{ model.FormatMoney(t.Amount) }
|
||||
</span>
|
||||
} else {
|
||||
<span class="font-bold text-destructive whitespace-nowrap">
|
||||
-{ fmt.Sprintf("$%.2f", float64(t.AmountCents)/100.0) }
|
||||
-{ model.FormatMoney(t.Amount) }
|
||||
</span>
|
||||
}
|
||||
@button.Button(button.Props{
|
||||
|
|
@ -696,7 +697,7 @@ templ EditRecurringDepositForm(spaceID string, rd *model.RecurringDepositWithAcc
|
|||
Name: "amount",
|
||||
ID: "edit-rd-amount-" + rd.ID,
|
||||
Type: "number",
|
||||
Value: fmt.Sprintf("%.2f", float64(rd.AmountCents)/100.0),
|
||||
Value: model.FormatDecimal(rd.Amount),
|
||||
Attributes: templ.Attributes{"step": "0.01", "required": "true", "min": "0.01"},
|
||||
})
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue