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
|
|
@ -3,6 +3,7 @@ package pages
|
|||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"github.com/shopspring/decimal"
|
||||
"git.juancwu.dev/juancwu/budgit/internal/model"
|
||||
"git.juancwu.dev/juancwu/budgit/internal/ui/components/button"
|
||||
"git.juancwu.dev/juancwu/budgit/internal/ui/components/card"
|
||||
|
|
@ -185,8 +186,8 @@ templ LoansListContent(spaceID string, loans []*model.LoanWithPaymentSummary, cu
|
|||
|
||||
templ LoanCard(spaceID string, loan *model.LoanWithPaymentSummary) {
|
||||
{{ progressPct := 0 }}
|
||||
if loan.OriginalAmountCents > 0 {
|
||||
{{ progressPct = (loan.TotalPaidCents * 100) / loan.OriginalAmountCents }}
|
||||
if !loan.OriginalAmount.IsZero() {
|
||||
{{ progressPct = int(loan.TotalPaid.Div(loan.OriginalAmount).Mul(decimal.NewFromInt(100)).IntPart()) }}
|
||||
if progressPct > 100 {
|
||||
{{ progressPct = 100 }}
|
||||
}
|
||||
|
|
@ -205,7 +206,7 @@ templ LoanCard(spaceID string, loan *model.LoanWithPaymentSummary) {
|
|||
}
|
||||
</div>
|
||||
@card.Description() {
|
||||
{ fmt.Sprintf("$%.2f", float64(loan.OriginalAmountCents)/100.0) }
|
||||
{ model.FormatMoney(loan.OriginalAmount) }
|
||||
if loan.InterestRateBps > 0 {
|
||||
{ fmt.Sprintf(" @ %.2f%%", float64(loan.InterestRateBps)/100.0) }
|
||||
}
|
||||
|
|
@ -218,9 +219,9 @@ templ LoanCard(spaceID string, loan *model.LoanWithPaymentSummary) {
|
|||
Class: "h-2",
|
||||
})
|
||||
<div class="flex justify-between text-sm text-muted-foreground mt-2">
|
||||
<span>Paid: { fmt.Sprintf("$%.2f", float64(loan.TotalPaidCents)/100.0) }</span>
|
||||
if loan.RemainingCents > 0 {
|
||||
<span>Left: { fmt.Sprintf("$%.2f", float64(loan.RemainingCents)/100.0) }</span>
|
||||
<span>Paid: { model.FormatMoney(loan.TotalPaid) }</span>
|
||||
if loan.Remaining.GreaterThan(decimal.Zero) {
|
||||
<span>Left: { model.FormatMoney(loan.Remaining) }</span>
|
||||
} else {
|
||||
<span class="text-green-600">Fully paid</span>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue