feat: pay bills

This commit is contained in:
juancwu 2026-04-22 15:49:00 +00:00
commit 8c681282ef
15 changed files with 607 additions and 65 deletions

View file

@ -11,14 +11,15 @@ import (
)
type App struct {
Cfg *config.Config
DB *sqlx.DB
UserService *service.UserService
AuthService *service.AuthService
EmailService *service.EmailService
SpaceService *service.SpaceService
AccountService *service.AccountService
InviteService *service.InviteService
Cfg *config.Config
DB *sqlx.DB
UserService *service.UserService
AuthService *service.AuthService
EmailService *service.EmailService
SpaceService *service.SpaceService
AccountService *service.AccountService
TransactionService *service.TransactionService
InviteService *service.InviteService
}
func New(cfg *config.Config) (*App, error) {
@ -39,12 +40,15 @@ func New(cfg *config.Config) (*App, error) {
tokenRepository := repository.NewTokenRepository(database)
spaceRepository := repository.NewSpaceRepository(database)
accountRepository := repository.NewAccountRepository(database)
transactionRepository := repository.NewTransactionRepository(database)
categoryRepository := repository.NewCategoryRepository(database)
invitationRepository := repository.NewInvitationRepository(database)
// Services
userService := service.NewUserService(userRepository)
spaceService := service.NewSpaceService(spaceRepository)
accountService := service.NewAccountService(accountRepository)
transactionService := service.NewTransactionService(transactionRepository, categoryRepository, accountService)
emailService := service.NewEmailService(
emailClient,
cfg.MailerEmailFrom,
@ -66,14 +70,15 @@ func New(cfg *config.Config) (*App, error) {
inviteService := service.NewInviteService(invitationRepository, spaceRepository, userRepository, emailService)
return &App{
Cfg: cfg,
DB: database,
UserService: userService,
AuthService: authService,
EmailService: emailService,
SpaceService: spaceService,
AccountService: accountService,
InviteService: inviteService,
Cfg: cfg,
DB: database,
UserService: userService,
AuthService: authService,
EmailService: emailService,
SpaceService: spaceService,
AccountService: accountService,
TransactionService: transactionService,
InviteService: inviteService,
}, nil
}

View file

@ -8,13 +8,13 @@ import (
)
const (
UserKey string = "user"
UserKey string = "user"
URLPathKey string = "url_path"
ConfigKey string = "config"
CSRFTokenKey string = "csrf_token"
AppVersionKey string = "app_version"
SidebarCollapsedKey string = "sidebar_collapsed"
URLPathKey string = "url_path"
ConfigKey string = "config"
CSRFTokenKey string = "csrf_token"
AppVersionKey string = "app_version"
SidebarCollapsedKey string = "sidebar_collapsed"
)
func User(ctx context.Context) *model.User {
@ -26,7 +26,6 @@ func WithUser(ctx context.Context, user *model.User) context.Context {
return context.WithValue(ctx, UserKey, user)
}
func URLPath(ctx context.Context) string {
path, _ := ctx.Value(URLPathKey).(string)
return path

View file

@ -0,0 +1,11 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE transactions ADD COLUMN title TEXT NOT NULL DEFAULT '';
ALTER TABLE transactions ADD COLUMN occurred_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE transactions DROP COLUMN occurred_at;
ALTER TABLE transactions DROP COLUMN title;
-- +goose StatementEnd

View file

@ -0,0 +1,22 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE related_transactions (
transaction_one_id TEXT NOT NULL REFERENCES transactions(id) ON DELETE CASCADE,
transaction_two_id TEXT NOT NULL REFERENCES transactions(id) ON DELETE CASCADE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (transaction_one_id, transaction_two_id),
UNIQUE (transaction_one_id),
UNIQUE (transaction_two_id),
CHECK (transaction_one_id < transaction_two_id)
);
ALTER TABLE transactions DROP COLUMN related_transaction_id;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE transactions ADD COLUMN related_transaction_id TEXT REFERENCES transactions(id) ON DELETE SET NULL;
DROP TABLE related_transactions;
-- +goose StatementEnd

View file

@ -4,9 +4,11 @@ import (
"log/slog"
"net/http"
"strings"
"time"
"git.juancwu.dev/juancwu/budgit/internal/ctxkeys"
"git.juancwu.dev/juancwu/budgit/internal/model"
"git.juancwu.dev/juancwu/budgit/internal/routeurl"
"git.juancwu.dev/juancwu/budgit/internal/service"
"git.juancwu.dev/juancwu/budgit/internal/ui"
"git.juancwu.dev/juancwu/budgit/internal/ui/blocks"
@ -16,12 +18,21 @@ import (
)
type spaceHandler struct {
spaceService *service.SpaceService
accountService *service.AccountService
spaceService *service.SpaceService
accountService *service.AccountService
transactionService *service.TransactionService
}
func NewSpaceHandler(spaceService *service.SpaceService, accountService *service.AccountService) *spaceHandler {
return &spaceHandler{spaceService: spaceService, accountService: accountService}
func NewSpaceHandler(
spaceService *service.SpaceService,
accountService *service.AccountService,
transactionService *service.TransactionService,
) *spaceHandler {
return &spaceHandler{
spaceService: spaceService,
accountService: accountService,
transactionService: transactionService,
}
}
func (h *spaceHandler) SpacesPage(w http.ResponseWriter, r *http.Request) {
@ -164,12 +175,154 @@ func (h *spaceHandler) SpaceAccountPage(w http.ResponseWriter, r *http.Request)
spaceID := r.PathValue("spaceID")
accountID := r.PathValue("accountID")
account, err := h.accountService.GetAccount(accountID)
if err != nil {
slog.Error("failed to load account", "error", err, "account_id", accountID)
ui.Render(w, r, pages.NotFound())
return
}
if account.SpaceID != spaceID {
ui.Render(w, r, pages.NotFound())
return
}
ui.Render(w, r, pages.SpaceAccountPage(pages.SpaceAccountPageProps{
SpaceID: spaceID,
AccountID: accountID,
AccountName: "Money Account",
AccountDescription: "Vault Infinite Priority",
AccountNumber: "4492",
AccountBalance: decimal.NewFromFloat(32093.11),
SpaceID: spaceID,
AccountID: accountID,
AccountName: account.Name,
AccountBalance: account.Balance,
}))
}
func (h *spaceHandler) SpaceCreateBillPage(w http.ResponseWriter, r *http.Request) {
spaceID := r.PathValue("spaceID")
accountID := r.PathValue("accountID")
account, err := h.accountService.GetAccount(accountID)
if err != nil {
slog.Error("failed to load account", "error", err, "account_id", accountID)
ui.Render(w, r, pages.NotFound())
return
}
if account.SpaceID != spaceID {
ui.Render(w, r, pages.NotFound())
return
}
categories, err := h.transactionService.ListCategories()
if err != nil {
slog.Error("failed to load categories", "error", err)
ui.RenderError(w, r, "Failed to load categories", http.StatusInternalServerError)
return
}
ui.Render(w, r, pages.SpaceCreateBillPage(pages.SpaceCreateBillPageProps{
SpaceID: spaceID,
AccountID: accountID,
AccountName: account.Name,
Form: forms.CreateBillProps{
SpaceID: spaceID,
AccountID: accountID,
Categories: categories,
Date: time.Now().Format("2006-01-02"),
},
}))
}
func (h *spaceHandler) HandleCreateBill(w http.ResponseWriter, r *http.Request) {
spaceID := r.PathValue("spaceID")
accountID := r.PathValue("accountID")
titleInput := strings.TrimSpace(r.FormValue("title"))
amountInput := strings.TrimSpace(r.FormValue("amount"))
dateInput := strings.TrimSpace(r.FormValue("date"))
descriptionInput := strings.TrimSpace(r.FormValue("description"))
categoryInput := strings.TrimSpace(r.FormValue("category"))
categories, err := h.transactionService.ListCategories()
if err != nil {
slog.Error("failed to load categories", "error", err)
ui.RenderError(w, r, "Failed to load categories", http.StatusInternalServerError)
return
}
formProps := forms.CreateBillProps{
SpaceID: spaceID,
AccountID: accountID,
Categories: categories,
Title: titleInput,
Amount: amountInput,
Date: dateInput,
Description: descriptionInput,
CategoryID: categoryInput,
}
hasErr := false
if titleInput == "" {
formProps.TitleErr = "Title is required."
hasErr = true
}
var amount decimal.Decimal
if amountInput == "" {
formProps.AmountErr = "Amount is required."
hasErr = true
} else {
amt, err := decimal.NewFromString(amountInput)
if err != nil {
formProps.AmountErr = "Enter a valid amount (e.g. 12.34)."
hasErr = true
} else if !amt.IsPositive() {
formProps.AmountErr = "Amount must be greater than zero."
hasErr = true
} else if amt.Exponent() < -2 {
formProps.AmountErr = "Amount can have at most 2 decimal places."
hasErr = true
} else {
amount = amt
}
}
var occurredAt time.Time
if dateInput == "" {
formProps.DateErr = "Date is required."
hasErr = true
} else {
parsed, err := time.Parse("2006-01-02", dateInput)
if err != nil {
formProps.DateErr = "Enter a valid date."
hasErr = true
} else {
occurredAt = parsed
}
}
if hasErr {
ui.Render(w, r, forms.CreateBill(formProps))
return
}
_, err = h.transactionService.PayBill(service.PayBillInput{
AccountID: accountID,
Title: titleInput,
Amount: amount,
OccurredAt: occurredAt,
Description: descriptionInput,
CategoryID: categoryInput,
})
if err != nil {
slog.Error("failed to create bill", "error", err, "account_id", accountID)
formProps.GeneralErr = "Something went wrong. Please try again."
ui.Render(w, r, forms.CreateBill(formProps))
return
}
redirectTo := routeurl.URL(
"page.app.spaces.space.accounts.account.overview",
"spaceID", spaceID,
"accountID", accountID,
)
w.Header().Set("HX-Redirect", redirectTo)
w.WriteHeader(http.StatusOK)
}

View file

@ -23,14 +23,15 @@ const (
)
type Transaction struct {
ID string `db:"id"`
Value decimal.Decimal `db:"value"`
Type TransactionType `db:"type"`
AccountID string `db:"account_id"`
Description *string `db:"description"`
RelatedTransactionID *string `db:"related_transaction_id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
ID string `db:"id"`
Value decimal.Decimal `db:"value"`
Type TransactionType `db:"type"`
AccountID string `db:"account_id"`
Title string `db:"title"`
Description *string `db:"description"`
OccurredAt time.Time `db:"occurred_at"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type Tag struct {

View file

@ -0,0 +1,27 @@
package repository
import (
"git.juancwu.dev/juancwu/budgit/internal/model"
"github.com/jmoiron/sqlx"
)
type CategoryRepository interface {
All() ([]*model.Category, error)
}
type categoryRepository struct {
db *sqlx.DB
}
func NewCategoryRepository(db *sqlx.DB) CategoryRepository {
return &categoryRepository{db: db}
}
func (r *categoryRepository) All() ([]*model.Category, error) {
var categories []*model.Category
query := `SELECT * FROM categories ORDER BY name ASC;`
if err := r.db.Select(&categories, query); err != nil {
return nil, err
}
return categories, nil
}

View file

@ -0,0 +1,53 @@
package repository
import (
"time"
"git.juancwu.dev/juancwu/budgit/internal/model"
"github.com/jmoiron/sqlx"
"github.com/shopspring/decimal"
)
type TransactionRepository interface {
CreateBillAtomic(t *model.Transaction, newBalance decimal.Decimal, categoryID *string) error
}
type transactionRepository struct {
db *sqlx.DB
}
func NewTransactionRepository(db *sqlx.DB) TransactionRepository {
return &transactionRepository{db: db}
}
func (r *transactionRepository) CreateBillAtomic(t *model.Transaction, newBalance decimal.Decimal, categoryID *string) error {
return WithTx(r.db, func(tx *sqlx.Tx) error {
insertTxn := `
INSERT INTO transactions
(id, value, type, account_id, title, description, occurred_at, created_at, updated_at)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9);
`
if _, err := tx.Exec(
insertTxn,
t.ID, t.Value, t.Type, t.AccountID, t.Title, t.Description,
t.OccurredAt, t.CreatedAt, t.UpdatedAt,
); err != nil {
return err
}
updateBalance := `UPDATE accounts SET balance = $1, updated_at = $2 WHERE id = $3;`
if _, err := tx.Exec(updateBalance, newBalance, time.Now(), t.AccountID); err != nil {
return err
}
if categoryID != nil && *categoryID != "" {
linkCategory := `INSERT INTO transaction_categories (category_id, transaction_id) VALUES ($1, $2);`
if _, err := tx.Exec(linkCategory, *categoryID, t.ID); err != nil {
return err
}
}
return nil
})
}

View file

@ -19,7 +19,7 @@ func SetupRoutes(a *app.App) http.Handler {
authH := handler.NewAuthHandler(a.AuthService, a.InviteService, a.SpaceService)
homeH := handler.NewHomeHandler()
settingsH := handler.NewSettingsHandler(a.AuthService, a.UserService)
spaceH := handler.NewSpaceHandler(a.SpaceService, a.AccountService)
spaceH := handler.NewSpaceHandler(a.SpaceService, a.AccountService, a.TransactionService)
redirectH := handler.NewRedirectHandler()
r := router.New()
@ -95,6 +95,8 @@ func SetupRoutes(a *app.App) http.Handler {
g.SubGroup("/accounts/{accountID}", func(g *router.Group) {
g.Get("/overview", spaceH.SpaceAccountPage).Name("page.app.spaces.space.accounts.account.overview")
g.Get("/bills/create", spaceH.SpaceCreateBillPage).Name("page.app.spaces.space.accounts.account.bills.create")
g.Post("/bills/create", spaceH.HandleCreateBill).Name("action.app.spaces.space.accounts.account.bills.create")
})
})
})

View file

@ -0,0 +1,98 @@
package service
import (
"fmt"
"strings"
"time"
"git.juancwu.dev/juancwu/budgit/internal/model"
"git.juancwu.dev/juancwu/budgit/internal/repository"
"github.com/google/uuid"
"github.com/shopspring/decimal"
)
type TransactionService struct {
transactionRepo repository.TransactionRepository
categoryRepo repository.CategoryRepository
accountService *AccountService
}
func NewTransactionService(
transactionRepo repository.TransactionRepository,
categoryRepo repository.CategoryRepository,
accountService *AccountService,
) *TransactionService {
return &TransactionService{
transactionRepo: transactionRepo,
categoryRepo: categoryRepo,
accountService: accountService,
}
}
type PayBillInput struct {
AccountID string
Title string
Amount decimal.Decimal
OccurredAt time.Time
Description string
CategoryID string
}
func (s *TransactionService) PayBill(input PayBillInput) (*model.Transaction, error) {
title := strings.TrimSpace(input.Title)
if title == "" {
return nil, fmt.Errorf("title is required")
}
if input.AccountID == "" {
return nil, fmt.Errorf("account id is required")
}
if !input.Amount.IsPositive() {
return nil, fmt.Errorf("amount must be greater than zero")
}
if input.OccurredAt.IsZero() {
return nil, fmt.Errorf("date is required")
}
account, err := s.accountService.GetAccount(input.AccountID)
if err != nil {
return nil, fmt.Errorf("failed to load account: %w", err)
}
newBalance := account.Balance.Sub(input.Amount)
now := time.Now()
var description *string
if d := strings.TrimSpace(input.Description); d != "" {
description = &d
}
var categoryID *string
if c := strings.TrimSpace(input.CategoryID); c != "" {
categoryID = &c
}
txn := &model.Transaction{
ID: uuid.NewString(),
Value: input.Amount,
Type: model.TransactionTypeWithdrawal,
AccountID: input.AccountID,
Title: title,
Description: description,
OccurredAt: input.OccurredAt,
CreatedAt: now,
UpdatedAt: now,
}
if err := s.transactionRepo.CreateBillAtomic(txn, newBalance, categoryID); err != nil {
return nil, fmt.Errorf("failed to create bill transaction: %w", err)
}
return txn, nil
}
func (s *TransactionService) ListCategories() ([]*model.Category, error) {
categories, err := s.categoryRepo.All()
if err != nil {
return nil, fmt.Errorf("failed to list categories: %w", err)
}
return categories, nil
}

View file

@ -1415,9 +1415,9 @@ var internalSvgData = map[string]string{
<path d="M7 6v12" />`,
"chevron-last": `<path d="m7 18 6-6-6-6" />
<path d="M17 6v12" />`,
"chevron-left": `<path d="m15 18-6-6 6-6" />`,
"chevron-left": `<path d="m15 18-6-6 6-6" />`,
"chevron-right": `<path d="m9 18 6-6-6-6" />`,
"chevron-up": `<path d="m18 15-6-6-6 6" />`,
"chevron-up": `<path d="m18 15-6-6-6 6" />`,
"chevrons-down": `<path d="m7 6 5 5 5-5" />
<path d="m7 13 5 5 5-5" />`,
"chevrons-down-up": `<path d="m7 20 5-5 5 5" />
@ -2619,9 +2619,9 @@ var internalSvgData = map[string]string{
<path d="m2 2 20 20" />
<path d="M4 22V4" />
<path d="M7.656 2H8c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10.347" />`,
"flag-triangle-left": `<path d="M18 22V2.8a.8.8 0 0 0-1.17-.71L5.45 7.78a.8.8 0 0 0 0 1.44L18 15.5" />`,
"flag-triangle-left": `<path d="M18 22V2.8a.8.8 0 0 0-1.17-.71L5.45 7.78a.8.8 0 0 0 0 1.44L18 15.5" />`,
"flag-triangle-right": `<path d="M6 22V2.8a.8.8 0 0 1 1.17-.71l11.38 5.69a.8.8 0 0 1 0 1.44L6 15.5" />`,
"flame": `<path d="M12 3q1 4 4 6.5t3 5.5a1 1 0 0 1-14 0 5 5 0 0 1 1-3 1 1 0 0 0 5 0c0-2-1.5-3-1.5-5q0-2 2.5-4" />`,
"flame": `<path d="M12 3q1 4 4 6.5t3 5.5a1 1 0 0 1-14 0 5 5 0 0 1 1-3 1 1 0 0 0 5 0c0-2-1.5-3-1.5-5q0-2 2.5-4" />`,
"flame-kindling": `<path d="M12 2c1 3 2.5 3.5 3.5 4.5A5 5 0 0 1 17 10a5 5 0 1 1-10 0c0-.3 0-.6.1-.9a2 2 0 1 0 3.3-2C8 4.5 11 2 12 2Z" />
<path d="m5 22 14-4" />
<path d="m5 18 14 4" />`,
@ -4189,7 +4189,7 @@ var internalSvgData = map[string]string{
<path d="m9 9 12-2" />
<circle cx="6" cy="18" r="3" />
<circle cx="18" cy="16" r="3" />`,
"navigation": `<polygon points="3 11 22 2 13 21 11 13 3 11" />`,
"navigation": `<polygon points="3 11 22 2 13 21 11 13 3 11" />`,
"navigation-2": `<polygon points="12 2 19 21 12 17 5 21 12 2" />`,
"navigation-2-off": `<path d="M9.31 9.31 5 21l7-4 7 4-1.17-3.17" />
<path d="M14.53 8.88 12 2l-1.17 3.17" />
@ -4768,9 +4768,9 @@ var internalSvgData = map[string]string{
<path d="M12 12h.01" />
<path d="M17 12h.01" />
<path d="M7 12h.01" />`,
"rectangle-goggles": `<path d="M20 6a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-4a2 2 0 0 1-1.6-.8l-1.6-2.13a1 1 0 0 0-1.6 0L9.6 17.2A2 2 0 0 1 8 18H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z" />`,
"rectangle-goggles": `<path d="M20 6a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-4a2 2 0 0 1-1.6-.8l-1.6-2.13a1 1 0 0 0-1.6 0L9.6 17.2A2 2 0 0 1 8 18H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z" />`,
"rectangle-horizontal": `<rect width="20" height="12" x="2" y="6" rx="2" />`,
"rectangle-vertical": `<rect width="12" height="20" x="6" y="2" rx="2" />`,
"rectangle-vertical": `<rect width="12" height="20" x="6" y="2" rx="2" />`,
"recycle": `<path d="M7 19H4.815a1.83 1.83 0 0 1-1.57-.881 1.785 1.785 0 0 1-.004-1.784L7.196 9.5" />
<path d="M11 19h8.203a1.83 1.83 0 0 0 1.556-.89 1.784 1.784 0 0 0 0-1.775l-1.226-2.12" />
<path d="m14 16-3 3 3 3" />
@ -5723,7 +5723,7 @@ var internalSvgData = map[string]string{
<path d="M22 14v2" />
<path d="M22 20a2 2 0 0 1-2 2" />`,
"squares-unite": `<path d="M4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v3a1 1 0 0 0 1 1h3a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2v-3a1 1 0 0 0-1-1z" />`,
"squircle": `<path d="M12 3c7.2 0 9 1.8 9 9s-1.8 9-9 9-9-1.8-9-9 1.8-9 9-9" />`,
"squircle": `<path d="M12 3c7.2 0 9 1.8 9 9s-1.8 9-9 9-9-1.8-9-9 1.8-9 9-9" />`,
"squircle-dashed": `<path d="M13.77 3.043a34 34 0 0 0-3.54 0" />
<path d="M13.771 20.956a33 33 0 0 1-3.541.001" />
<path d="M20.18 17.74c-.51 1.15-1.29 1.93-2.439 2.44" />
@ -5739,7 +5739,7 @@ var internalSvgData = map[string]string{
"stamp": `<path d="M14 13V8.5C14 7 15 7 15 5a3 3 0 0 0-6 0c0 2 1 2 1 3.5V13" />
<path d="M20 15.5a2.5 2.5 0 0 0-2.5-2.5h-11A2.5 2.5 0 0 0 4 15.5V17a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1z" />
<path d="M5 22h14" />`,
"star": `<path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z" />`,
"star": `<path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z" />`,
"star-half": `<path d="M12 18.338a2.1 2.1 0 0 0-.987.244L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.12 2.12 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.12 2.12 0 0 0 1.597-1.16l2.309-4.679A.53.53 0 0 1 12 2" />`,
"star-off": `<path d="m10.344 4.688 1.181-2.393a.53.53 0 0 1 .95 0l2.31 4.679a2.12 2.12 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.237 3.152" />
<path d="m17.945 17.945.43 2.505a.53.53 0 0 1-.771.56l-4.618-2.428a2.12 2.12 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.12 2.12 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a8 8 0 0 0 .4-.099" />
@ -6280,7 +6280,7 @@ var internalSvgData = map[string]string{
"tv-minimal-play": `<path d="M15.033 9.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56V7.648a.645.645 0 0 1 .967-.56z" />
<path d="M7 21h10" />
<rect width="20" height="14" x="2" y="3" rx="2" />`,
"twitch": `<path d="M21 2H3v16h5v4l4-4h5l4-4V2zm-10 9V7m5 4V7" />`,
"twitch": `<path d="M21 2H3v16h5v4l4-4h5l4-4V2zm-10 9V7m5 4V7" />`,
"twitter": `<path d="M22 4s-.7 2.1-2 3.4c1.6 10-9.4 17.3-18 11.6 2.2.1 4.4-.6 6-2C3 15.5.5 9.6 3 5c2.2 2.6 5.6 4.1 9 4-.9-4.2 4-6.6 7-3.8 1.1 0 3-1.2 3-1.2z" />`,
"type": `<path d="M12 4v16" />
<path d="M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2" />

View file

@ -1,6 +1,7 @@
// templui component icon - version: v1.9.5 installed by templui v1.9.5
// 📚 Documentation: https://templui.io/docs/components/icon
package icon
// This file is auto generated
// Using Lucide icons version 0.576.0
var AArrowDown = Icon("a-arrow-down")

View file

@ -0,0 +1,155 @@
package forms
import "git.juancwu.dev/juancwu/budgit/internal/model"
import "git.juancwu.dev/juancwu/budgit/internal/routeurl"
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/button"
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"
type CreateBillProps struct {
SpaceID string
AccountID string
Categories []*model.Category
Title string
Amount string
Date string
Description string
CategoryID string
TitleErr string
AmountErr string
DateErr string
GeneralErr string
}
templ CreateBill(props CreateBillProps) {
<form hx-post={ routeurl.URL("action.app.spaces.space.accounts.account.bills.create", "spaceID", props.SpaceID, "accountID", props.AccountID) }>
@card.Card(card.Props{Class: "rounded-sm"}) {
@card.Content(card.ContentProps{Class: "p-4 space-y-4"}) {
if props.GeneralErr != "" {
@form.Message(form.MessageProps{Variant: form.MessageVariantError}) {
{ props.GeneralErr }
}
}
@form.Item() {
@form.Label(form.LabelProps{For: "title"}) {
Title
}
@input.Input(input.Props{
ID: "title",
Name: "title",
Type: input.TypeText,
Placeholder: "e.g. Hydro bill",
Class: "rounded-sm",
Value: props.Title,
HasError: props.TitleErr != "",
Required: true,
Attributes: templ.Attributes{
"autocomplete": "off",
"autofocus": "",
},
})
if props.TitleErr != "" {
@form.Message(form.MessageProps{Variant: form.MessageVariantError}) {
{ props.TitleErr }
}
}
}
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
@form.Item() {
@form.Label(form.LabelProps{For: "amount"}) {
Amount
}
@input.Input(input.Props{
ID: "amount",
Name: "amount",
Type: input.TypeNumber,
Placeholder: "0.00",
Class: "rounded-sm",
Value: props.Amount,
HasError: props.AmountErr != "",
Required: true,
Attributes: templ.Attributes{
"step": "0.01",
"min": "0",
"inputmode": "decimal",
"autocomplete": "off",
},
})
if props.AmountErr != "" {
@form.Message(form.MessageProps{Variant: form.MessageVariantError}) {
{ props.AmountErr }
}
}
}
@form.Item() {
@form.Label(form.LabelProps{For: "date"}) {
Date
}
@input.Input(input.Props{
ID: "date",
Name: "date",
Type: input.TypeDate,
Class: "rounded-sm",
Value: props.Date,
HasError: props.DateErr != "",
Required: true,
})
if props.DateErr != "" {
@form.Message(form.MessageProps{Variant: form.MessageVariantError}) {
{ props.DateErr }
}
}
}
</div>
@form.Item() {
@form.Label(form.LabelProps{For: "category"}) {
Category
}
<select
id="category"
name="category"
class="flex h-9 w-full items-center rounded-sm border border-input bg-transparent px-3 py-1 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
>
<option value="" selected?={ props.CategoryID == "" }>Uncategorized</option>
for _, c := range props.Categories {
<option value={ c.ID } selected?={ props.CategoryID == c.ID }>{ c.Name }</option>
}
</select>
@form.Description() {
Optional. Helps with budget reporting.
}
}
@form.Item() {
@form.Label(form.LabelProps{For: "description"}) {
Description
}
@textarea.Textarea(textarea.Props{
ID: "description",
Name: "description",
Placeholder: "Anything extra worth remembering",
Rows: 3,
Value: props.Description,
})
@form.Description() {
Optional.
}
}
}
@card.Footer(card.FooterProps{Class: "flex justify-end gap-2"}) {
@button.Button(button.Props{
Variant: button.VariantGhost,
Href: routeurl.URL("page.app.spaces.space.accounts.account.overview", "spaceID", props.SpaceID, "accountID", props.AccountID),
}) {
Cancel
}
@button.Button(button.Props{Type: button.TypeSubmit}) {
Pay Bill
}
}
}
</form>
}

View file

@ -1,6 +1,7 @@
package pages
import "github.com/shopspring/decimal"
import "git.juancwu.dev/juancwu/budgit/internal/routeurl"
import "git.juancwu.dev/juancwu/budgit/internal/ui/layouts"
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/card"
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/button"
@ -8,12 +9,10 @@ import "git.juancwu.dev/juancwu/budgit/internal/ui/components/icon"
import "git.juancwu.dev/juancwu/budgit/internal/ui/utils"
type SpaceAccountPageProps struct {
SpaceID string
AccountID string
AccountName string
AccountDescription string
AccountNumber string
AccountBalance decimal.Decimal
SpaceID string
AccountID string
AccountName string
AccountBalance decimal.Decimal
}
templ SpaceAccountPage(props SpaceAccountPageProps) {
@ -35,16 +34,10 @@ templ SpaceAccountPage(props SpaceAccountPageProps) {
@card.Title() {
{ props.AccountName }
}
@card.Description(card.DescriptionProps{Class: "text-sm"}) {
{ props.AccountDescription }
}
}
@card.Content() {
<h1 class={ utils.TwMerge(balanceTextClasses...) }>${ utils.FormatDecimalWithThousands(props.AccountBalance.StringFixedBank(2)) }</h1>
<p class="text-sm text-muted-foreground">Available Balance</p>
<p class="mt-8 text-sm text-muted-foreground">
Account <span>•••• { props.AccountNumber }</span>
</p>
}
}
@card.Card(card.Props{Class: "rounded-sm col-span-full md:col-span-4"}) {
@ -57,6 +50,7 @@ templ SpaceAccountPage(props SpaceAccountPageProps) {
@button.Button(button.Props{
Class: "w-full flex gap-2 md:gap-4 items-center",
Variant: button.VariantDefault,
Href: routeurl.URL("page.app.spaces.space.accounts.account.bills.create", "spaceID", props.SpaceID, "accountID", props.AccountID),
}) {
Pay Bills
@icon.HandCoins()

View file

@ -1,4 +1,25 @@
package pages
templ SpaceCreateBill() {
import "git.juancwu.dev/juancwu/budgit/internal/ui/forms"
import "git.juancwu.dev/juancwu/budgit/internal/ui/layouts"
type SpaceCreateBillPageProps struct {
SpaceID string
AccountID string
AccountName string
Form forms.CreateBillProps
}
templ SpaceCreateBillPage(props SpaceCreateBillPageProps) {
@layouts.App("Pay Bills", spaceOverviewSidebarContent(), spaceSpecificSidebarContent(props.SpaceID)) {
<div class="container max-w-3xl px-6 py-8 mx-auto space-y-8">
<div>
<h1 class="text-3xl font-bold">Pay Bills</h1>
<p class="text-muted-foreground mt-2">
Record a bill paid from { props.AccountName }.
</p>
</div>
@forms.CreateBill(props.Form)
</div>
}
}