diff --git a/internal/handler/space.go b/internal/handler/space.go index d1abaa8..c030c65 100644 --- a/internal/handler/space.go +++ b/internal/handler/space.go @@ -1535,6 +1535,13 @@ func (h *spaceHandler) SpaceCreateTransferPage(w http.ResponseWriter, r *http.Re return } + allocSummary, err := h.allocationService.SummaryForAccount(accountID) + if err != nil { + slog.Error("failed to load allocation summary", "error", err, "account_id", accountID) + ui.RenderError(w, r, "Failed to load page", http.StatusInternalServerError) + return + } + ui.Render(w, r, pages.SpaceCreateTransferPage(pages.SpaceCreateTransferPageProps{ SpaceID: spaceID, SpaceName: space.Name, @@ -1544,6 +1551,9 @@ func (h *spaceHandler) SpaceCreateTransferPage(w http.ResponseWriter, r *http.Re SpaceID: spaceID, SourceAccountID: accountID, DestAccounts: dests, + SourceAvailable: allocSummary.Available.StringFixedBank(2), + SourceAllocated: allocSummary.Allocated.StringFixedBank(2), + SourceOverflow: allocSummary.Overflow, Date: time.Now().Format("2006-01-02"), }, })) @@ -1583,6 +1593,14 @@ func (h *spaceHandler) HandleCreateTransfer(w http.ResponseWriter, r *http.Reque Description: descriptionInput, } + if allocSummary, err := h.allocationService.SummaryForAccount(accountID); err != nil { + slog.Error("failed to load allocation summary", "error", err, "account_id", accountID) + } else { + formProps.SourceAvailable = allocSummary.Available.StringFixedBank(2) + formProps.SourceAllocated = allocSummary.Allocated.StringFixedBank(2) + formProps.SourceOverflow = allocSummary.Overflow + } + hasErr := false if titleInput == "" { formProps.TitleErr = "Title is required." diff --git a/internal/ui/forms/create_transfer.templ b/internal/ui/forms/create_transfer.templ index 35f56d1..321be79 100644 --- a/internal/ui/forms/create_transfer.templ +++ b/internal/ui/forms/create_transfer.templ @@ -7,6 +7,7 @@ import "git.juancwu.dev/juancwu/budgit/internal/ui/components/card" import "git.juancwu.dev/juancwu/budgit/internal/ui/components/form" import "git.juancwu.dev/juancwu/budgit/internal/ui/components/input" import "git.juancwu.dev/juancwu/budgit/internal/ui/components/textarea" +import "git.juancwu.dev/juancwu/budgit/internal/ui/utils" type CreateTransferProps struct { SpaceID string @@ -16,6 +17,12 @@ type CreateTransferProps struct { // can transfer to. Excludes the source account. DestAccounts []*model.Account + // SourceAvailable / SourceAllocated are the source account's unallocated + // and allocated cash, formatted as plain decimal strings (e.g. "1234.50"). + SourceAvailable string + SourceAllocated string + SourceOverflow bool + Title string Amount string DestAccountID string @@ -33,6 +40,25 @@ templ CreateTransfer(props CreateTransferProps) {
@card.Card(card.Props{Class: "rounded-sm"}) { @card.Content(card.ContentProps{Class: "p-4 space-y-4"}) { + if props.SourceAvailable != "" { + {{ + availClasses := []string{"text-2xl font-bold"} + if props.SourceOverflow { + availClasses = append(availClasses, "text-red-600 dark:text-red-400") + } + availFormatted, _ := utils.FormatDecimalWithThousands(props.SourceAvailable) + allocFormatted, _ := utils.FormatDecimalWithThousands(props.SourceAllocated) + }} +
+
+

Available

+

${ availFormatted }

+
+

+ Allocated: ${ allocFormatted } +

+
+ } if props.GeneralErr != "" { @form.Message(form.MessageProps{Variant: form.MessageVariantError}) { { props.GeneralErr }