Documentation
¶
Index ¶
- func Migrate(db *gorm.DB) error
- func TransactionsSum(db *gorm.DB, incoming, outgoing Transaction) decimal.Decimal
- type Account
- type AccountCreate
- type AggregatedTransaction
- type Allocation
- type AllocationCreate
- type Budget
- func (b Budget) Available(db *gorm.DB, month time.Time) (decimal.Decimal, error)
- func (b Budget) Budgeted(db *gorm.DB, month time.Time) (decimal.Decimal, error)
- func (b Budget) Income(db *gorm.DB, t time.Time) (decimal.Decimal, error)
- func (b Budget) Overspent(db *gorm.DB, month time.Time) (decimal.Decimal, error)
- func (b Budget) TotalBudgeted(db *gorm.DB, month time.Time) (decimal.Decimal, error)
- func (b Budget) TotalIncome(db *gorm.DB, month time.Time) (decimal.Decimal, error)
- func (b Budget) WithCalculations(db *gorm.DB) Budget
- type BudgetCreate
- type BudgetMonth
- type Category
- type CategoryCreate
- type CategoryEnvelopes
- type DefaultModel
- type Envelope
- type EnvelopeCreate
- type EnvelopeMonth
- type EnvelopeMonthAllocation
- type EnvelopeMonthConfig
- type EnvelopeMonthLinks
- type Month
- type MonthConfig
- type MonthConfigCreate
- type OverspendMode
- type Timestamps
- type Transaction
- type TransactionCreate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TransactionsSum ¶
func TransactionsSum(db *gorm.DB, 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 {
DefaultModel
AccountCreate
Budget Budget `json:"-"`
Balance decimal.Decimal `json:"balance" gorm:"-" example:"2735.17"`
ReconciledBalance decimal.Decimal `json:"reconciledBalance" gorm:"-" example:"2539.57"`
}
Account represents an asset account, e.g. a bank account.
func (*Account) BeforeSave ¶
BeforeSave sets OnBudget to false when External is true.
func (Account) SumReconciledTransactions ¶
Transactions returns all transactions for this account.
func (Account) Transactions ¶
func (a Account) Transactions(db *gorm.DB) []Transaction
Transactions returns all transactions for this account.
type AccountCreate ¶
type AccountCreate struct {
Name string `json:"name" example:"Cash" default:""`
Note string `json:"note" example:"Money in my wallet" default:""`
BudgetID uuid.UUID `json:"budgetId" example:"550dc009-cea6-4c12-b2a5-03446eb7b7cf"`
OnBudget bool `json:"onBudget" example:"true" default:"false"` // Always false when external: true
External bool `json:"external" example:"false" default:"false"`
InitialBalance decimal.Decimal `json:"initialBalance" example:"173.12" default:"0"`
Hidden bool `json:"hidden" example:"true" default:"false"`
}
type AggregatedTransaction ¶ added in v1.13.1
type Allocation ¶
type Allocation struct {
DefaultModel
AllocationCreate
Envelope Envelope `json:"-"`
}
Allocation represents the allocation of money to an Envelope for a specific month.
type AllocationCreate ¶
type AllocationCreate struct {
Month time.Time `json:"month" gorm:"uniqueIndex:allocation_month_envelope" example:"2021-12-01T00:00:00.000000Z"` // Only year and month of this timestamp are used, everything else is ignored. This will always be set to 00:00 UTC on the first of the specified month
Amount decimal.Decimal `` // The maximum value is "999999999999.99999999", swagger unfortunately rounds this.
/* 132-byte string literal not displayed */
EnvelopeID uuid.UUID `json:"envelopeId" gorm:"uniqueIndex:allocation_month_envelope" example:"a0909e84-e8f9-4cb6-82a5-025dff105ff2"`
}
type Budget ¶
type Budget struct {
DefaultModel
BudgetCreate
Balance decimal.Decimal `json:"balance" gorm:"-" example:"3423.42"`
}
Budget represents a budget
A budget is the highest level of organization in Envelope Zero, all other resources reference it directly or transitively.
func (Budget) Available ¶ added in v0.47.0
Available calculates the amount that is available to be budgeted in the specified monht.
func (Budget) Budgeted ¶ added in v1.1.0
Budgeted calculates the sum that has been budgeted for a specific month.
func (Budget) TotalBudgeted ¶ added in v0.45.0
TotalBudgeted calculates the total sum that has been budgeted before a specific month.
func (Budget) TotalIncome ¶ added in v0.44.0
TotalIncome calculates the total income over all time.
type BudgetCreate ¶
type BudgetMonth ¶
type BudgetMonth struct {
ID uuid.UUID `json:"id" example:"1e777d24-3f5b-4c43-8000-04f65f895578"` // The ID of the Budget
Name string `json:"name" example:"Groceries"` // The name of the Budget
Month time.Time `json:"month" example:"2006-05-01T00:00:00.000000Z"` // This is always set to 00:00 UTC on the first of the month.
Budgeted decimal.Decimal `json:"budgeted" example:"2100"`
Income decimal.Decimal `json:"income" example:"2317.34"`
Available decimal.Decimal `json:"available" example:"217.34"`
Envelopes []EnvelopeMonth `json:"envelopes"`
}
type Category ¶
type Category struct {
DefaultModel
CategoryCreate
Budget Budget `json:"-"`
}
Category represents a category of envelopes.
type CategoryCreate ¶
type CategoryCreate struct {
Name string `json:"name" gorm:"uniqueIndex:category_budget_name" example:"Saving" default:""`
BudgetID uuid.UUID `json:"budgetId" gorm:"uniqueIndex:category_budget_name" example:"52d967d3-33f4-4b04-9ba7-772e5ab9d0ce"`
Note string `json:"note" example:"All envelopes for long-term saving" default:""`
Hidden bool `json:"hidden" example:"true" default:"false"`
}
type CategoryEnvelopes ¶ added in v1.1.0
type CategoryEnvelopes struct {
ID uuid.UUID `json:"id" example:"dafd9a74-6aeb-46b9-9f5a-cfca624fea85"`
Name string `json:"name" example:"Rainy Day Funds" default:""`
Envelopes []EnvelopeMonth `json:"envelopes"`
}
type DefaultModel ¶ added in v1.9.0
type DefaultModel struct {
ID uuid.UUID `json:"id" example:"65392deb-5e92-4268-b114-297faad6cdce"`
Timestamps
}
DefaultModel is the base model for most models in Envelope Zero. As EnvelopeMonth uses the Envelope ID and the Month as primary key, we the timestamps are managed in the Timestamps struct.
func (*DefaultModel) AfterFind ¶ added in v1.9.0
func (m *DefaultModel) 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 (*DefaultModel) BeforeCreate ¶ added in v1.9.0
func (m *DefaultModel) BeforeCreate(tx *gorm.DB) (err error)
BeforeCreate is set to generate a UUID for the resource.
type Envelope ¶
type Envelope struct {
DefaultModel
EnvelopeCreate
Category Category `json:"-"`
}
Envelope represents an envelope in your budget.
func (Envelope) Balance ¶ added in v0.47.1
Balance calculates the balance of an Envelope in a specific month.
type EnvelopeCreate ¶
type EnvelopeCreate struct {
Name string `json:"name" gorm:"uniqueIndex:envelope_category_name" example:"Groceries" default:""`
CategoryID uuid.UUID `json:"categoryId" gorm:"uniqueIndex:envelope_category_name" example:"878c831f-af99-4a71-b3ca-80deb7d793c1"`
Note string `json:"note" example:"For stuff bought at supermarkets and drugstores" default:""`
Hidden bool `json:"hidden" example:"true" default:"false"`
}
type EnvelopeMonth ¶
type EnvelopeMonth struct {
ID uuid.UUID `json:"id" example:"10b9705d-3356-459e-9d5a-28d42a6c4547"` // The ID of the Envelope
Name string `json:"name" example:"Groceries"` // The name of the Envelope
Month time.Time `json:"month" example:"1969-06-01T00:00:00.000000Z" hidden:"deprecated"` // This is always set to 00:00 UTC on the first of the month. **This field is deprecated and will be removed in v2**
Spent decimal.Decimal `json:"spent" example:"73.12"`
Balance decimal.Decimal `json:"balance" example:"12.32"`
Allocation decimal.Decimal `json:"allocation" example:"85.44"`
Links EnvelopeMonthLinks `json:"links"`
}
EnvelopeMonth contains data about an Envelope for a specific month.
type EnvelopeMonthAllocation ¶ added in v1.13.1
type EnvelopeMonthConfig ¶ added in v1.13.1
type EnvelopeMonthConfig struct {
Month time.Time
OverspendMode OverspendMode
}
type EnvelopeMonthLinks ¶ added in v1.3.0
type EnvelopeMonthLinks struct {
Allocation string `json:"allocation" example:"https://example.com/api/v1/allocations/772d6956-ecba-485b-8a27-46a506c5a2a3"` // This is an empty string when no allocation exists
}
type Month ¶ added in v1.1.0
type Month struct {
ID uuid.UUID `json:"id" example:"1e777d24-3f5b-4c43-8000-04f65f895578"` // The ID of the Budget
Name string `json:"name" example:"Zero budget"` // The name of the Budget
Month time.Time `json:"month" example:"2006-05-01T00:00:00.000000Z"` // This is always set to 00:00 UTC on the first of the month.
Budgeted decimal.Decimal `json:"budgeted" example:"2100"` // The sum of all allocations for the month
Income decimal.Decimal `json:"income" example:"2317.34"` // The total income for the month (sum of all incoming transactions without an Envelope)
Available decimal.Decimal `json:"available" example:"217.34"` // The amount available to budget
Balance decimal.Decimal `json:"balance" example:"5231.37"` // The sum of all envelope balances
Spent decimal.Decimal `json:"spent" example:"133.70"` // The amount of money spent in this month
Categories []CategoryEnvelopes `json:"categories"` // A list of envelope month calculations grouped by category
}
type MonthConfig ¶ added in v1.9.0
type MonthConfig struct {
Timestamps // To include the gorm timestamps
EnvelopeID uuid.UUID `json:"envelopeId" gorm:"primaryKey" example:"10b9705d-3356-459e-9d5a-28d42a6c4547" `
Month time.Time `json:"month" gorm:"primaryKey" example:"1969-06-01T00:00:00.000000Z"` // This is always set to 00:00 UTC on the first of the month.
MonthConfigCreate
}
type MonthConfigCreate ¶ added in v1.9.0
type MonthConfigCreate struct {
OverspendMode OverspendMode `json:"overspendMode" example:"AFFECT_ENVELOPE" default:"AFFECT_AVAILABLE"`
}
type OverspendMode ¶ added in v1.9.0
type OverspendMode string
swagger:enum OverspendMode
const ( AffectAvailable OverspendMode = "AFFECT_AVAILABLE" AffectEnvelope OverspendMode = "AFFECT_ENVELOPE" )
type Timestamps ¶ added in v1.9.0
type Timestamps struct {
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" gorm:"index" example:"2022-04-22T21:01:05.058161Z" swaggertype:"primitive,string"`
}
Timestamps only contains the timestamps that gorm sets automatically to enable other primary keys than ID.
type Transaction ¶
type Transaction struct {
DefaultModel
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" example:"1815-12-10T18:43:00.271152Z"`
Amount decimal.Decimal `` // The maximum value is "999999999999.99999999", swagger unfortunately rounds this.
/* 132-byte string literal not displayed */
Note string `json:"note" example:"Lunch" default:""`
BudgetID uuid.UUID `json:"budgetId" example:"55eecbd8-7c46-4b06-ada9-f287802fb05e"`
SourceAccountID uuid.UUID `` /* 155-byte string literal not displayed */
DestinationAccountID uuid.UUID `json:"destinationAccountId" example:"8e16b456-a719-48ce-9fec-e115cfa7cbcc"`
EnvelopeID *uuid.UUID `json:"envelopeId" example:"2649c965-7999-4873-ae16-89d5d5fa972e"`
Reconciled bool `json:"reconciled" example:"true" default:"false"`
}