Documentation
¶
Index ¶
- Variables
- func ConnectDatabase() error
- func TransactionsSum(incoming, outgoing Transaction) decimal.Decimal
- type Account
- type AccountCreate
- type Allocation
- type AllocationCreate
- type Budget
- type BudgetCreate
- type BudgetMonth
- type Category
- type CategoryCreate
- type Envelope
- type EnvelopeCreate
- type EnvelopeMonth
- type Model
- type Transaction
- type TransactionCreate
Constants ¶
This section is empty.
Variables ¶
var DB *gorm.DB
DB is the database used by the backend.
Functions ¶
func ConnectDatabase ¶ added in v0.1.0
func ConnectDatabase() error
ConnectDatabase connects to the database DB.
func TransactionsSum ¶ added in v0.11.0
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 ¶ added in v0.1.0
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 ¶ added in v0.5.0
BeforeSave sets OnBudget to false when External is true.
func (Account) SumReconciledTransactions ¶ added in v0.7.0
Transactions returns all transactions for this account.
func (Account) Transactions ¶ added in v0.1.0
func (a Account) Transactions() []Transaction
Transactions returns all transactions for this account.
func (Account) WithCalculations ¶ added in v0.7.0
type AccountCreate ¶ added in v0.14.0
type Allocation ¶ added in v0.1.0
type Allocation struct { Model AllocationCreate Envelope Envelope `json:"-"` }
Allocation represents the allocation of money to an Envelope for a specific month.
type AllocationCreate ¶ added in v0.14.0
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 uint64 `json:"envelopeId,omitempty"` }
type Budget ¶
type Budget struct { Model BudgetCreate }
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 ¶ added in v0.14.0
type BudgetMonth ¶ added in v0.13.0
type BudgetMonth struct { ID uint64 `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 ¶ added in v0.1.0
type Category struct { Model CategoryCreate Budget Budget `json:"-"` }
Category represents a category of envelopes.
type CategoryCreate ¶ added in v0.14.0
type Envelope ¶ added in v0.1.0
type Envelope struct { Model EnvelopeCreate Category Category `json:"-"` }
Envelope represents an envelope in your budget.
type EnvelopeCreate ¶ added in v0.14.0
type EnvelopeMonth ¶ added in v0.13.0
type EnvelopeMonth struct { ID uint64 `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 ¶ added in v0.1.0
type Model struct { ID uint64 `json:"id" example:"42" format:"uint64"` 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.
type Transaction ¶ added in v0.1.0
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 RawTransactions ¶ added in v0.11.0
func RawTransactions(query string) ([]Transaction, error)
RawTransactions returns a list of transactions for a raw SQL query.
func (*Transaction) AfterFind ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (t *Transaction) BeforeSave(tx *gorm.DB) (err error)
BeforeSave sets the timezone for the Date for UTC.
type TransactionCreate ¶ added in v0.14.0
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 uint64 `json:"budgetId,omitempty"` SourceAccountID uint64 `json:"sourceAccountId,omitempty"` DestinationAccountID uint64 `json:"destinationAccountId,omitempty"` EnvelopeID uint64 `json:"envelopeId,omitempty"` Reconciled bool `json:"reconciled"` }