ledger

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

AccountTypes is an array with the ordered accont types.

Functions

This section is empty.

Types

type Account added in v0.0.13

type Account struct {
	// contains filtered or unexported fields
}

Account represents an account which can be used in bookings.

func (Account) Split added in v0.0.13

func (a Account) Split() []string

Split returns the account name split into segments.

func (Account) String added in v0.0.13

func (a Account) String() string

func (Account) Type added in v0.0.13

func (a Account) Type() AccountType

Type returns the account type.

func (Account) WriteTo added in v0.0.13

func (a Account) WriteTo(w io.Writer) (int64, error)

WriteTo writes the account to the writer.

type AccountType added in v0.0.13

type AccountType int

AccountType is the type of an account.

const (
	// ASSETS represents an asset account.
	ASSETS AccountType = iota
	// LIABILITIES represents a liability account.
	LIABILITIES
	// EQUITY represents an equity account.
	EQUITY
	// INCOME represents an income account.
	INCOME
	// EXPENSES represents an expenses account.
	EXPENSES
)

func (AccountType) String added in v0.0.13

func (t AccountType) String() string

type Accounts added in v0.0.13

type Accounts struct {
	// contains filtered or unexported fields
}

Accounts is a thread-safe collection of accounts.

func NewAccounts added in v0.0.13

func NewAccounts() *Accounts

NewAccounts creates a new thread-safe collection of accounts.

func (*Accounts) Get added in v0.0.13

func (a *Accounts) Get(name string) (*Account, error)

Get returns an account.

type Accrual added in v0.0.7

type Accrual struct {
	Range
	Period      date.Period
	T0, T1      time.Time
	Account     *Account
	Transaction Transaction
}

Accrual represents an accrual.

func (Accrual) Expand added in v0.0.7

func (a Accrual) Expand() []Transaction

Expand expands an accrual transaction.

type Assertion added in v0.0.7

type Assertion struct {
	Range
	Date      time.Time
	Account   *Account
	Amount    decimal.Decimal
	Commodity *Commodity
}

Assertion represents a balance assertion.

type Builder

type Builder struct {
	Context Context
	// contains filtered or unexported fields
}

Builder maps dates to days

func NewBuilder

func NewBuilder(ctx Context, f Filter) *Builder

NewBuilder creates a new builder.

func (*Builder) AddAccrual added in v0.0.13

func (b *Builder) AddAccrual(t Accrual)

AddAccrual adds an accrual directive.

func (*Builder) AddAssertion

func (b *Builder) AddAssertion(a Assertion)

AddAssertion adds an assertion directive.

func (*Builder) AddClosing

func (b *Builder) AddClosing(close Close)

AddClosing adds a close directive.

func (*Builder) AddOpening

func (b *Builder) AddOpening(o Open)

AddOpening adds an open directive.

func (*Builder) AddPrice

func (b *Builder) AddPrice(p Price)

AddPrice adds a price directive.

func (*Builder) AddTransaction

func (b *Builder) AddTransaction(t Transaction)

AddTransaction adds a transaction directive.

func (*Builder) AddValue

func (b *Builder) AddValue(a Value)

AddValue adds an value directive.

func (*Builder) Build

func (b *Builder) Build() Ledger

Build creates a new

type Close added in v0.0.7

type Close struct {
	Range
	Date    time.Time
	Account *Account
}

Close represents a close command.

type Commodities added in v0.0.13

type Commodities struct {
	// contains filtered or unexported fields
}

Commodities is a thread-safe collection of commodities.

func NewCommodities added in v0.0.13

func NewCommodities() *Commodities

NewCommodities creates a new thread-safe collection of commodities.

func (*Commodities) Get added in v0.0.13

func (c *Commodities) Get(name string) (*Commodity, error)

Get creates a new commodity.

type Commodity added in v0.0.13

type Commodity struct {
	// contains filtered or unexported fields
}

Commodity represents a currency or security.

func (Commodity) MarshalJSON added in v0.0.13

func (c Commodity) MarshalJSON() ([]byte, error)

MarshalJSON marshals a commodity to JSON.

func (Commodity) String added in v0.0.13

func (c Commodity) String() string

type Context added in v0.0.13

type Context struct {
	// contains filtered or unexported fields
}

Context has context for this ledger, namely a collection of referenced accounts and

func NewContext added in v0.0.13

func NewContext() Context

NewContext creates a new, empty context.

func (Context) EquityAccount added in v0.0.13

func (c Context) EquityAccount() *Account

EquityAccount is the equity account used for trades

func (Context) GetAccount added in v0.0.13

func (c Context) GetAccount(name string) (*Account, error)

GetAccount returns an account.

func (Context) GetCommodity added in v0.0.13

func (c Context) GetCommodity(name string) (*Commodity, error)

GetCommodity returns a commodity.

func (Context) RetainedEarningsAccount added in v0.0.13

func (c Context) RetainedEarningsAccount() *Account

RetainedEarningsAccount returns the account for automatic valuation bookings.

func (Context) TBDAccount added in v0.0.13

func (c Context) TBDAccount() *Account

TBDAccount returns the TBD account.

func (Context) ValuationAccount added in v0.0.13

func (c Context) ValuationAccount() *Account

ValuationAccount returns the account for automatic valuation bookings.

func (Context) ValuationAccountFor added in v0.0.13

func (c Context) ValuationAccountFor(a *Account) (*Account, error)

ValuationAccountFor returns the valuation account which corresponds to the given Asset or Liability account.

type Day added in v0.0.7

type Day struct {
	Date         time.Time
	Prices       []Price
	Assertions   []Assertion
	Values       []Value
	Openings     []Open
	Transactions []Transaction
	Closings     []Close
}

Day groups all commands for a given date.

type Directive added in v0.0.8

type Directive interface {
	Position() Range
}

Directive is an element in a journal with a position.

type Filter added in v0.0.8

type Filter struct {
	AccountsFilter, CommoditiesFilter *regexp.Regexp
}

Filter represents a filter creating a

func (Filter) MatchAccount added in v0.0.11

func (b Filter) MatchAccount(a *Account) bool

MatchAccount returns whether this filterthe given Account.

func (Filter) MatchCommodity added in v0.0.11

func (b Filter) MatchCommodity(c *Commodity) bool

MatchCommodity returns whether this filter matches the given Commodity.

type Finalizer added in v0.0.13

type Finalizer interface {
	Finalize() error
}

Finalizer gets called after all days have been processed.

type Include added in v0.0.7

type Include struct {
	Range
	Date time.Time
	Path string
}

Include represents an include directive.

type Initializer added in v0.0.13

type Initializer interface {
	Initialize(l Ledger) error
}

Initializer gets called before processing.

type Ledger

type Ledger struct {
	Days    []*Day
	Context Context
}

Ledger is a

func FromDirectives added in v0.0.8

func FromDirectives(ctx Context, filter Filter, results <-chan interface{}) (Ledger, error)

FromDirectives reads directives from the given channel and builds a Ledger if successful.

func (Ledger) Dates added in v0.0.13

func (l Ledger) Dates(from, to *time.Time, period date.Period) []time.Time

Dates returns a series of dates.

func (Ledger) MaxDate

func (l Ledger) MaxDate() (time.Time, bool)

MaxDate returns the maximum date for the given

func (Ledger) MinDate

func (l Ledger) MinDate() (time.Time, bool)

MinDate returns the minimum date for this ledger, as the first date on which an account is opened (ignoring prices, for example).

type Lot added in v0.0.7

type Lot struct {
	Date      time.Time
	Label     string
	Price     float64
	Commodity *Commodity
}

Lot represents a lot.

type Open added in v0.0.7

type Open struct {
	Range
	Date    time.Time
	Account *Account
}

Open represents an open command.

type Posting added in v0.0.7

type Posting struct {
	Amount, Value decimal.Decimal
	Credit, Debit *Account
	Commodity     *Commodity
	Lot           *Lot
}

Posting represents a posting.

func NewPosting added in v0.0.7

func NewPosting(crAccount, drAccount *Account, commodity *Commodity, amt decimal.Decimal) Posting

NewPosting creates a new posting from the given parameters. If amount is negative, it will be inverted and the accounts reversed.

type Price added in v0.0.7

type Price struct {
	Range
	Date      time.Time
	Commodity *Commodity
	Target    *Commodity
	Price     decimal.Decimal
}

Price represents a price command.

type Process added in v0.0.13

type Process interface {
	Process(d *Day) error
}

Process processes the balance and the ledger day.

type Processor added in v0.0.13

type Processor struct {
	Steps []Process
}

Processor processes a ledger.

func (Processor) Process added in v0.0.13

func (b Processor) Process(l Ledger) error

Process processes a ledger.

type Range added in v0.0.13

type Range struct {
	Path       string
	Start, End scanner.Location
}

Range describes a range of locations in a file.

func (Range) Position added in v0.0.13

func (r Range) Position() Range

Position returns the Range itself.

type Tag added in v0.0.7

type Tag string

Tag represents a tag for a transaction or booking.

type Transaction added in v0.0.7

type Transaction struct {
	Range
	Date        time.Time
	Description string
	Tags        []Tag
	Postings    []Posting
}

Transaction represents a transaction.

type Value added in v0.0.7

type Value struct {
	Range
	Date      time.Time
	Account   *Account
	Amount    decimal.Decimal
	Commodity *Commodity
}

Value represents a value directive.

Jump to

Keyboard shortcuts

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