budget

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidID        = errors.New("invalid budget ID")
	ErrInvalidUserID    = errors.New("invalid user ID")
	ErrEmptyName        = errors.New("budget name cannot be empty")
	ErrInvalidAmount    = errors.New("budget amount must be greater than zero")
	ErrInvalidCurrency  = errors.New("invalid currency code")
	ErrInvalidPeriod    = errors.New("invalid budget period")
	ErrInvalidDateRange = errors.New("start date must be before end date")
)

Domain errors for Budget operations.

Functions

This section is empty.

Types

type Budget

type Budget struct {
	ID          uuid.UUID   `json:"id"`
	UserID      uuid.UUID   `json:"user_id"`
	Name        string      `json:"name"`
	Amount      float64     `json:"amount"` // Amount in major currency units
	Currency    string      `json:"currency"`
	Period      Period      `json:"period"`
	StartDate   time.Time   `json:"start_date"`
	EndDate     time.Time   `json:"end_date"`
	CategoryIDs []uuid.UUID `json:"category_ids,omitempty"` // Specific categories this budget applies to; empty means general
	CreatedAt   time.Time   `json:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at"`
}

Budget represents a financial constraint or plan set by a user for a specific duration.

func NewBudget

func NewBudget(userID uuid.UUID, name string, amount float64, currency string, period Period, start, end time.Time, categories []uuid.UUID) (*Budget, error)

NewBudget creates a new Budget entity with validation and default timestamps.

func (*Budget) IsActive

func (b *Budget) IsActive(t time.Time) bool

IsActive checks if the budget is currently active based on the provided time.

func (*Budget) PercentUsed

func (b *Budget) PercentUsed(spent float64) float64

PercentUsed calculates the percentage of the budget that has been utilized.

func (*Budget) Remaining

func (b *Budget) Remaining(spent float64) float64

Remaining calculates the remaining budget given the spent amount.

func (*Budget) Update

func (b *Budget) Update(name string, amount float64, currency string, period Period, start, end time.Time, categories []uuid.UUID) error

Update modifies the budget details and updates the timestamp.

type Period

type Period string

Period defines the recurrence or time span type of a budget.

const (
	PeriodWeekly  Period = "WEEKLY"
	PeriodMonthly Period = "MONTHLY"
	PeriodYearly  Period = "YEARLY"
	PeriodCustom  Period = "CUSTOM"
)

func (Period) IsValid

func (p Period) IsValid() bool

IsValid checks if the period is a known type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL