Documentation
¶
Index ¶
- Constants
- func NewValidateError(firstFailure int, cause error) error
- type Error
- type Ledger
- func (l *Ledger) AddTransactions(txns []Transaction) error
- func (l *Ledger) Balances() (start, end *time.Time, balances map[string][]decimal.Decimal)
- func (l *Ledger) FirstTransactionTime() time.Time
- func (l *Ledger) LastTransactionTime() time.Time
- func (l *Ledger) OpeningBalances() (opening Transaction, found bool)
- func (l *Ledger) Query(search string, page, results int) QueryResult
- func (l *Ledger) String() string
- func (l *Ledger) UpdateAccount(oldAccount, newAccount string) error
- func (l *Ledger) UpdateOpeningBalance(opening Transaction) error
- func (l *Ledger) UpdateTransaction(id string, transaction Transaction) error
- func (l *Ledger) Validate() error
- type Posting
- type QueryResult
- type Transaction
- type Transactions
Constants ¶
const (
DateFormat = "2006/01/02"
)
const (
// OpeningBalanceID is an ID used only for the ledger's opening balances transaction (in an equity: posting)
OpeningBalanceID = "Opening-Balance"
)
Variables ¶
This section is empty.
Functions ¶
func NewValidateError ¶
Types ¶
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
Ledger tracks transactions from multiple institutions. Include error checking and validation for all ledger changes. Serializes into a "plain-text accounting" ledger file.
func New ¶
func New(transactions []Transaction) (*Ledger, error)
New creates a ledger with the given transactions. Must not contain any duplicate IDs
func NewFromReader ¶
NewFromReader creates a ledger from the given "plain-text accounting" ledger-encoded reader
func (*Ledger) AddTransactions ¶
func (l *Ledger) AddTransactions(txns []Transaction) error
AddTransactions attempts to add the provided transactions. Returns an error if the ledger fails validation (i.e. fail balance assertions). In the event of an error, attempts to add all valid transactions up to the error.
func (*Ledger) Balances ¶ added in v0.2.0
Balances returns a cumulative balance sheet for all accounts over the given time period. Current interval is monthly.
func (*Ledger) FirstTransactionTime ¶ added in v0.4.0
FirstTransactionTime returns the last transactions Date field. Returns 0 if there are no transactions
func (*Ledger) LastTransactionTime ¶
LastTransactionTime returns the last transactions Date field. Returns 0 if there are no transactions
func (*Ledger) OpeningBalances ¶ added in v0.4.0
func (l *Ledger) OpeningBalances() (opening Transaction, found bool)
OpeningBalances attempts to find the opening balances transaction and return it Note: only checks the first transaction in the ledger
func (*Ledger) Query ¶ added in v0.3.0
func (l *Ledger) Query(search string, page, results int) QueryResult
func (*Ledger) UpdateAccount ¶ added in v0.3.0
UpdateAccount changes all transactions' accounts matching oldAccount to newAccount
func (*Ledger) UpdateOpeningBalance ¶ added in v0.4.0
func (l *Ledger) UpdateOpeningBalance(opening Transaction) error
UpdateOpeningBalance inserts or updates an account's opening balance for this ledger. The opening balance must be the first transaction in the ledger, if the ledger is non-empty.
func (*Ledger) UpdateTransaction ¶ added in v0.3.0
func (l *Ledger) UpdateTransaction(id string, transaction Transaction) error
UpdateTransaction replaces a transaction where ID is 'id' with 'transaction' The new transaction must be valid
type Posting ¶
type Posting struct {
Account string
Amount decimal.Decimal
Balance *decimal.Decimal `json:",omitempty"`
Comment string `json:",omitempty"`
Currency string
Tags map[string]string `json:",omitempty"`
}
func NewPostingFromString ¶
func (Posting) FormatTable ¶
func (Posting) IsOpeningBalance ¶ added in v0.4.0
IsOpeningBalance returns true if this matches an "opening balance" posting, false otherwise
type QueryResult ¶ added in v0.3.0
type QueryResult struct {
Count int
Page int
Results int
Transactions
}
type Transaction ¶
type Transaction struct {
Comment string `json:",omitempty"`
Date time.Time
Payee string
Postings []Posting
Tags map[string]string `json:",omitempty"`
}
Transaction is a strict(er) representation of a ledger transaction. The extra restrictions are used to verify correctness more easily.
func (Transaction) Balanced ¶
func (t Transaction) Balanced() bool
func (Transaction) ID ¶
func (t Transaction) ID() string
func (Transaction) String ¶
func (t Transaction) String() string
func (Transaction) Validate ¶
func (t Transaction) Validate() error
type Transactions ¶
type Transactions []Transaction
func (Transactions) Sort ¶
func (txns Transactions) Sort()