54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
type BudgetPeriod string
|
|
|
|
const (
|
|
BudgetPeriodWeekly BudgetPeriod = "weekly"
|
|
BudgetPeriodMonthly BudgetPeriod = "monthly"
|
|
BudgetPeriodYearly BudgetPeriod = "yearly"
|
|
)
|
|
|
|
type BudgetStatus string
|
|
|
|
const (
|
|
BudgetStatusOnTrack BudgetStatus = "on_track"
|
|
BudgetStatusWarning BudgetStatus = "warning"
|
|
BudgetStatusOver BudgetStatus = "over"
|
|
)
|
|
|
|
type Budget struct {
|
|
ID string `db:"id"`
|
|
SpaceID string `db:"space_id"`
|
|
Amount decimal.Decimal `db:"amount"`
|
|
AmountCents int `db:"amount_cents"` // deprecated: kept for SELECT * compatibility
|
|
Period BudgetPeriod `db:"period"`
|
|
StartDate time.Time `db:"start_date"`
|
|
EndDate *time.Time `db:"end_date"`
|
|
IsActive bool `db:"is_active"`
|
|
CreatedBy string `db:"created_by"`
|
|
CreatedAt time.Time `db:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at"`
|
|
}
|
|
|
|
type BudgetWithSpent struct {
|
|
Budget
|
|
Tags []*Tag
|
|
Spent decimal.Decimal
|
|
Percentage float64
|
|
Status BudgetStatus
|
|
}
|
|
|
|
func (b *BudgetWithSpent) TagNames() string {
|
|
names := make([]string, len(b.Tags))
|
|
for i, t := range b.Tags {
|
|
names[i] = t.Name
|
|
}
|
|
return strings.Join(names, ", ")
|
|
}
|