models

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: AGPL-3.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransactionsSum

func TransactionsSum(incoming, outgoing Transaction) decimal.Decimal

TransactionSums returns the sum of all transactions matching two Transaction structs

The incoming Transactions fields is used to add the amount of all matching transactions to the overall sum The outgoing Transactions fields is used to subtract the amount of all matching transactions from the overall sum.

Types

type Account

type Account struct {
	Model
	AccountCreate
	Budget            Budget          `json:"-"`
	Balance           decimal.Decimal `json:"balance" gorm:"-"`
	ReconciledBalance decimal.Decimal `json:"reconciledBalance" gorm:"-"`
}

Account represents an asset account, e.g. a bank account.

func (*Account) BeforeSave

func (a *Account) BeforeSave(tx *gorm.DB) (err error)

BeforeSave sets OnBudget to false when External is true.

func (Account) SumReconciledTransactions

func (a Account) SumReconciledTransactions() decimal.Decimal

Transactions returns all transactions for this account.

func (Account) Transactions

func (a Account) Transactions() []Transaction

Transactions returns all transactions for this account.

func (Account) WithCalculations

func (a Account) WithCalculations() Account

type AccountCreate

type AccountCreate struct {
	Name     string    `json:"name,omitempty" example:"Checking"`
	Note     string    `json:"note,omitempty" example:"My bank account"`
	BudgetID uuid.UUID `json:"budgetId" example:"550dc009-cea6-4c12-b2a5-03446eb7b7cf"`
	OnBudget bool      `json:"onBudget" example:"false"` // Always false when external: true
	External bool      `json:"external" example:"true"`
}

type Allocation

type Allocation struct {
	Model
	AllocationCreate
	Envelope Envelope `json:"-"`
}

Allocation represents the allocation of money to an Envelope for a specific month.

type AllocationCreate

type AllocationCreate struct {
	Month      uint8           `json:"month" gorm:"uniqueIndex:year_month;check:month_valid,month >= 1 AND month <= 12"`
	Year       uint            `json:"year" gorm:"uniqueIndex:year_month"`
	Amount     decimal.Decimal `json:"amount" gorm:"type:DECIMAL(20,8)"`
	EnvelopeID uuid.UUID       `json:"envelopeId,omitempty"`
}

type Budget

type Budget struct {
	Model
	BudgetCreate
	Balance decimal.Decimal `json:"balance" gorm:"-"`
}

Budget represents a budget

A budget is the highest level of organization in Envelope Zero, all other resources reference it directly or transitively.

type BudgetCreate

type BudgetCreate struct {
	Name     string `json:"name,omitempty" example:"My First Budget"`
	Note     string `json:"note,omitempty" example:"A description so I remember what this was for"`
	Currency string `json:"currency,omitempty" example:"€"`
}

type BudgetMonth

type BudgetMonth struct {
	ID        uuid.UUID       `json:"id" example:"23"`
	Name      string          `json:"name" example:"A test envelope"`
	Month     time.Time       `json:"month" example:"2006-05-04T15:02:01.000000Z"`
	Envelopes []EnvelopeMonth `json:"envelopes,omitempty"`
}

type Category

type Category struct {
	Model
	CategoryCreate
	Budget Budget `json:"-"`
}

Category represents a category of envelopes.

type CategoryCreate

type CategoryCreate struct {
	Name     string    `json:"name,omitempty"`
	BudgetID uuid.UUID `json:"budgetId"`
	Note     string    `json:"note,omitempty"`
}

type Envelope

type Envelope struct {
	Model
	EnvelopeCreate
	Category Category `json:"-"`
}

Envelope represents an envelope in your budget.

func (Envelope) Month

func (e Envelope) Month(t time.Time) EnvelopeMonth

Month calculates the month specific values for an envelope and returns an EnvelopeMonth for them.

func (Envelope) Spent

func (e Envelope) Spent(t time.Time) decimal.Decimal

Spent returns the amount spent for the month the time.Time instance is in.

type EnvelopeCreate

type EnvelopeCreate struct {
	Name       string    `json:"name,omitempty"`
	CategoryID uuid.UUID `json:"categoryId"`
	Note       string    `json:"note,omitempty"`
}

type EnvelopeMonth

type EnvelopeMonth struct {
	ID         uuid.UUID       `json:"id"`
	Name       string          `json:"name"`
	Month      time.Time       `json:"month"`
	Spent      decimal.Decimal `json:"spent"`
	Balance    decimal.Decimal `json:"balance"`
	Allocation decimal.Decimal `json:"allocation"`
}

EnvelopeMonth contains data about an Envelope for a specific month.

type Model

type Model struct {
	ID        uuid.UUID       `json:"id" example:"65392deb-5e92-4268-b114-297faad6cdce"`
	CreatedAt time.Time       `json:"createdAt" example:"2022-04-02T19:28:44.491514Z"`
	UpdatedAt time.Time       `json:"updatedAt" example:"2022-04-17T20:14:01.048145Z"`
	DeletedAt *gorm.DeletedAt `json:"deletedAt,omitempty" gorm:"index"`
}

Model is the base model for all other models in Envelope Zero.

func (*Model) AfterFind

func (m *Model) AfterFind(tx *gorm.DB) (err error)

AfterFind updates the timestamps to use UTC as timezone, not +0000. Yes, this is different.

We already store them in UTC, but somehow reading them from the database returns them as +0000.

func (*Model) BeforeCreate

func (m *Model) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate is set to generate a UUID for the resource.

type Transaction

type Transaction struct {
	Model
	TransactionCreate
	Budget             Budget   `json:"-"`
	SourceAccount      Account  `json:"-"`
	DestinationAccount Account  `json:"-"`
	Envelope           Envelope `json:"-"`
}

Transaction represents a transaction between two accounts.

func (*Transaction) AfterFind

func (t *Transaction) AfterFind(tx *gorm.DB) (err error)

AfterFind updates the timestamps to use UTC as timezone, not +0000. Yes, this is different.

We already store them in UTC, but somehow reading them from the database returns them as +0000.

func (*Transaction) BeforeSave

func (t *Transaction) BeforeSave(tx *gorm.DB) (err error)

BeforeSave sets the timezone for the Date for UTC.

type TransactionCreate

type TransactionCreate struct {
	Date                 time.Time       `json:"date,omitempty"`
	Amount               decimal.Decimal `json:"amount" gorm:"type:DECIMAL(20,8)"`
	Note                 string          `json:"note,omitempty"`
	BudgetID             uuid.UUID       `json:"budgetId,omitempty"`
	SourceAccountID      uuid.UUID       `json:"sourceAccountId,omitempty"`
	DestinationAccountID uuid.UUID       `json:"destinationAccountId,omitempty"`
	EnvelopeID           uuid.UUID       `json:"envelopeId,omitempty"`
	Reconciled           bool            `json:"reconciled"`
}

Jump to

Keyboard shortcuts

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