journal

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

AccountTypes is an array with the ordered accont types.

Functions

func CompareAccountTypes added in v0.0.16

func CompareAccountTypes(t1, t2 AccountType) compare.Order

func CompareAccounts added in v0.1.1

func CompareAccounts(a1, a2 *Account) compare.Order

func CompareCommodities added in v0.0.16

func CompareCommodities(c1, c2 *Commodity) compare.Order

func CompareDays added in v0.1.1

func CompareDays(d *Day, d2 *Day) compare.Order

Less establishes an ordering on Day.

func ComparePostings added in v0.1.1

func ComparePostings(p, p2 *Posting) compare.Order

Less determines an order on postings.

func CompareTransactions added in v0.1.1

func CompareTransactions(t *Transaction, t2 *Transaction) compare.Order

Less defines an order on transactions.

func CompareWeighted added in v0.0.16

func CompareWeighted(jctx Context, w map[*Account]float64) compare.Compare[*Account]

func FilterAccount added in v0.1.1

func FilterAccount(r []*regexp.Regexp) filter.Filter[Key]

func FilterCommodity added in v0.1.1

func FilterCommodity(rx []*regexp.Regexp) filter.Filter[Key]

func FilterDates added in v0.1.1

func FilterDates(f filter.Filter[time.Time]) filter.Filter[Key]

func FilterOther added in v0.1.1

func FilterOther(r []*regexp.Regexp) filter.Filter[Key]

func MapCommodity added in v0.0.16

func MapCommodity(t bool) func(*Commodity) *Commodity

func NoOp added in v0.1.1

func NoOp[T any](_ T) error

func RemapAccount added in v0.1.1

func RemapAccount(jctx Context, rs regex.Regexes) mapper.Mapper[*Account]

func ShortenAccount added in v0.1.1

func ShortenAccount(jctx Context, m AccountMapping) mapper.Mapper[*Account]

Types

type Account added in v0.0.14

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

Account represents an account which can be used in bookings.

func (Account) IsAL added in v0.0.14

func (a Account) IsAL() bool

IsAL returns whether this account is an asset or liability account.

func (Account) IsIE added in v0.1.1

func (a Account) IsIE() bool

IsIE returns whether this account is an income or expense account.

func (Account) Level added in v0.0.14

func (a Account) Level() int

Level returns the name of this account.

func (Account) Name added in v0.0.14

func (a Account) Name() string

Name returns the name of this account.

func (Account) Segment added in v0.0.14

func (a Account) Segment() string

Segment returns the name of this account.

func (*Account) Split added in v0.0.14

func (a *Account) Split() []string

Split returns the account name split into segments.

func (Account) String added in v0.0.14

func (a Account) String() string

func (Account) Type added in v0.0.14

func (a Account) Type() AccountType

Type returns the account type.

type AccountMapping added in v0.1.1

type AccountMapping []Rule

AccountMapping is a set of mapping rules.

func (AccountMapping) String added in v0.1.1

func (m AccountMapping) String() string

type AccountType added in v0.0.14

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.14

func (t AccountType) String() string

type Accounts added in v0.0.14

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

Accounts is a thread-safe collection of accounts.

func NewAccounts added in v0.0.14

func NewAccounts() *Accounts

NewAccounts creates a new thread-safe collection of accounts.

func (*Accounts) Ancestors added in v0.0.16

func (as *Accounts) Ancestors(a *Account) []*Account

Ancestors returns the chain of ancestors of a, including a.

func (*Accounts) Children added in v0.0.16

func (as *Accounts) Children(a *Account) []*Account

Children returns the children of this account.

func (*Accounts) Get added in v0.0.14

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

Get returns an account.

func (*Accounts) NthParent added in v0.1.1

func (as *Accounts) NthParent(a *Account, n int) *Account

func (*Accounts) Parent added in v0.0.16

func (as *Accounts) Parent(a *Account) *Account

Parent returns the parent of this account.

func (*Accounts) SwapType added in v0.1.1

func (as *Accounts) SwapType(a *Account) *Account

type Accrual added in v0.1.1

type Accrual struct {
	Range
	Interval date.Interval
	Period   date.Period
	Account  *Account
}

Accrual represents an accrual.

func (Accrual) Expand added in v0.1.1

func (a Accrual) Expand(t *Transaction) []*Transaction

Expand expands an accrual transaction.

type Amounts added in v0.1.1

type Amounts map[Key]decimal.Decimal

Amounts keeps track of amounts by account and commodity.

func (Amounts) Add added in v0.1.1

func (am Amounts) Add(k Key, d decimal.Decimal)

func (Amounts) Amount added in v0.1.1

func (am Amounts) Amount(k Key) decimal.Decimal

Amount returns the amount for the given key.

func (Amounts) Clone added in v0.1.1

func (am Amounts) Clone() Amounts

Clone clones these amounts.

func (Amounts) Commodities added in v0.1.1

func (am Amounts) Commodities() set.Set[*Commodity]

func (Amounts) CommoditiesSorted added in v0.1.1

func (am Amounts) CommoditiesSorted() []*Commodity

func (Amounts) Dates added in v0.1.1

func (am Amounts) Dates() set.Set[time.Time]

func (Amounts) DatesSorted added in v0.1.1

func (am Amounts) DatesSorted() []time.Time

func (Amounts) Index added in v0.1.1

func (am Amounts) Index(cmp compare.Compare[Key]) []Key

func (Amounts) Minus added in v0.1.1

func (am Amounts) Minus(a Amounts) Amounts

Minus mutably subtracts.

func (Amounts) Plus added in v0.1.1

func (am Amounts) Plus(a Amounts) Amounts

Plus mutably adds.

func (Amounts) SumBy added in v0.1.1

func (am Amounts) SumBy(f func(k Key) bool, m func(k Key) Key) Amounts

func (Amounts) SumIntoBy added in v0.1.1

func (am Amounts) SumIntoBy(as Amounts, f func(k Key) bool, m func(k Key) Key)

func (Amounts) SumOver added in v0.1.1

func (am Amounts) SumOver(f func(k Key) bool) decimal.Decimal

type Assertion added in v0.1.1

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

Assertion represents a balance assertion.

type Close added in v0.1.1

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

Close represents a close command.

type Collection added in v0.1.1

type Collection interface {
	Insert(k Key, v decimal.Decimal)
}

type Commodities added in v0.0.14

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

Commodities is a thread-safe collection of commodities.

func NewCommodities added in v0.0.14

func NewCommodities() *Commodities

NewCommodities creates a new thread-safe collection of commodities.

func (*Commodities) Get added in v0.0.14

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

Get creates a new commodity.

func (*Commodities) TagCurrency added in v0.0.14

func (cs *Commodities) TagCurrency(name string) error

TagCurrency tags the commodity as a currency.

type Commodity added in v0.0.14

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

Commodity represents a currency or security.

func (Commodity) Name added in v0.1.1

func (c Commodity) Name() string

type Context added in v0.0.14

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.14

func NewContext() Context

NewContext creates a new, empty context.

func (Context) Account added in v0.0.14

func (ctx Context) Account(name string) *Account

Account returns a commodity or panics.

func (Context) Accounts added in v0.0.14

func (ctx Context) Accounts() *Accounts

Accounts returns the accounts.

func (Context) Commodities added in v0.0.14

func (ctx Context) Commodities() *Commodities

Commodities returns the commodities.

func (Context) Commodity added in v0.0.14

func (ctx Context) Commodity(name string) *Commodity

Commodity returns a commodity or panics.

func (Context) GetAccount added in v0.0.14

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

GetAccount returns an account.

func (Context) GetCommodity added in v0.0.14

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

GetCommodity returns a commodity.

func (Context) TBDAccount added in v0.0.14

func (ctx Context) TBDAccount() *Account

TBDAccount returns the TBD account.

func (Context) ValuationAccount added in v0.0.14

func (ctx Context) ValuationAccount() *Account

ValuationAccount returns the account for automatic valuation bookings.

func (Context) ValuationAccountFor added in v0.0.14

func (ctx Context) ValuationAccountFor(a *Account) *Account

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

type Currency added in v0.1.1

type Currency struct {
	Range
	Date time.Time
	*Commodity
}

Currency declares that a commodity is a currency.

type Day added in v0.1.1

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

	Normalized NormalizedPrices

	Performance *Performance
}

Day groups all commands for a given date.

type DayFn added in v0.1.1

type DayFn = func(*Day) error

func Balance added in v0.1.1

func Balance(jctx Context, v *Commodity) DayFn

Balance balances the journal.

func CloseAccounts added in v0.1.1

func CloseAccounts(j *Journal, enable bool, ds []time.Time) DayFn

Balance balances the journal.

func ComputePrices added in v0.1.1

func ComputePrices(v *Commodity) DayFn

ComputePrices updates prices.

func Query added in v0.1.1

func Query(f filter.Filter[Key], m mapper.Mapper[Key], v *Commodity, c Collection) DayFn

func Sort added in v0.1.1

func Sort() DayFn

Sort sorts the directives in this day.

type Directive added in v0.1.1

type Directive interface {
	Position() Range
}

Directive is an element in a journal with a position.

type Error added in v0.1.1

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

Error is a processing error, with a reference to a directive with a source location.

func (Error) Error added in v0.1.1

func (be Error) Error() string

type Include added in v0.1.1

type Include struct {
	Range
	Path string
}

Include represents an include directive.

type Journal

type Journal struct {
	Context Context
	Days    map[time.Time]*Day
	// contains filtered or unexported fields
}

Journal represents an unprocessed

func FromPath added in v0.1.1

func FromPath(ctx context.Context, jctx Context, path string) (*Journal, error)

func New added in v0.1.1

func New(ctx Context) *Journal

New creates a new Journal.

func (*Journal) AddAssertion added in v0.1.1

func (j *Journal) AddAssertion(a *Assertion)

AddAssertion adds an Assertion directive.

func (*Journal) AddClose added in v0.1.1

func (j *Journal) AddClose(c *Close)

AddClose adds an Close directive.

func (*Journal) AddOpen added in v0.1.1

func (j *Journal) AddOpen(o *Open)

AddOpen adds an Open directive.

func (*Journal) AddPrice added in v0.1.1

func (j *Journal) AddPrice(p *Price)

AddPrice adds an Price directive.

func (*Journal) AddTransaction added in v0.1.1

func (j *Journal) AddTransaction(t *Transaction)

AddTransaction adds an Transaction directive.

func (*Journal) AddValue added in v0.1.1

func (j *Journal) AddValue(v *Value)

AddValue adds an Value directive.

func (*Journal) Day added in v0.1.1

func (j *Journal) Day(d time.Time) *Day

Day returns the Day for the given date.

func (*Journal) Max added in v0.1.1

func (j *Journal) Max() time.Time

func (*Journal) Min added in v0.1.1

func (j *Journal) Min() time.Time

func (*Journal) Period added in v0.1.1

func (j *Journal) Period() date.Period

func (*Journal) Process added in v0.1.1

func (j *Journal) Process(fs ...func(*Day) error) (*Ledger, error)

func (*Journal) ToLedger added in v0.1.1

func (j *Journal) ToLedger() *Ledger

type Key added in v0.1.1

type Key struct {
	Date           time.Time
	Account, Other *Account
	Commodity      *Commodity
	Valuation      *Commodity
	Description    string
}

Key represents a position.

func AccountCommodityKey added in v0.1.1

func AccountCommodityKey(a *Account, c *Commodity) Key

func AccountKey added in v0.1.1

func AccountKey(a *Account) Key

func CommodityKey added in v0.1.1

func CommodityKey(c *Commodity) Key

func DateCommodityKey added in v0.1.1

func DateCommodityKey(d time.Time, c *Commodity) Key

func DateKey added in v0.1.1

func DateKey(d time.Time) Key

type KeyMapper added in v0.1.1

type KeyMapper struct {
	Date                 mapper.Mapper[time.Time]
	Account, Other       mapper.Mapper[*Account]
	Commodity, Valuation mapper.Mapper[*Commodity]
	Description          mapper.Mapper[string]
}

func (KeyMapper) Build added in v0.1.1

func (km KeyMapper) Build() mapper.Mapper[Key]

type Ledger added in v0.1.1

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

Ledger is an ordered and processed list of Days.

type Lot added in v0.1.1

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

Lot represents a lot.

type NormalizedPrices added in v0.0.14

type NormalizedPrices map[*Commodity]decimal.Decimal

NormalizedPrices is a map representing the price of commodities in some base commodity.

func NewNormalizedPrices added in v0.1.1

func NewNormalizedPrices() NormalizedPrices

func (NormalizedPrices) Valuate added in v0.0.14

Valuate valuates the given amount.

type Open added in v0.1.1

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

Open represents an open command.

type Parser added in v0.1.1

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

Parser parses a journal

func ParserFromPath added in v0.1.1

func ParserFromPath(ctx Context, path string) (*Parser, func() error, error)

ParserFromPath creates a new parser for the given file.

func (*Parser) Next added in v0.1.1

func (p *Parser) Next() (Directive, error)

Next returns the Next directive

type Performance added in v0.1.1

type Performance struct {
	V0, V1, Inflow, Outflow, InternalInflow, InternalOutflow map[*Commodity]float64
	PortfolioInflow, PortfolioOutflow                        float64
}

Performance holds aggregate information used to compute portfolio performance.

type Posting added in v0.1.1

type Posting struct {
	Amount, Value  decimal.Decimal
	Account, Other *Account
	Commodity      *Commodity
	Targets        []*Commodity
	Lot            *Lot
}

Posting represents a posting.

type PostingBuilder added in v0.1.1

type PostingBuilder struct {
	Amount, Value decimal.Decimal
	Credit, Debit *Account
	Commodity     *Commodity
	Targets       []*Commodity
	Lot           *Lot
}

func (PostingBuilder) Build added in v0.1.1

func (pb PostingBuilder) Build() []*Posting

type PostingBuilders added in v0.1.1

type PostingBuilders []PostingBuilder

func (PostingBuilders) Build added in v0.1.1

func (pbs PostingBuilders) Build() []*Posting

type Price added in v0.1.1

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

Price represents a price command.

type Prices added in v0.0.14

type Prices map[*Commodity]NormalizedPrices

Prices stores the price for a commodity to a target commodity Outer map: target commodity Inner map: commodity value: price in (target commodity / commodity)

func (Prices) Insert added in v0.0.14

func (p Prices) Insert(commodity *Commodity, price decimal.Decimal, target *Commodity)

Insert inserts a new price.

func (Prices) Normalize added in v0.0.14

func (pr Prices) Normalize(t *Commodity) NormalizedPrices

Normalize creates a normalized price map for the given commodity.

type Printer added in v0.1.1

type Printer struct {
	Padding int
}

Printer prints directives.

func NewPrinter added in v0.1.1

func NewPrinter() *Printer

New creates a new Printer.

func (*Printer) Initialize added in v0.1.1

func (p *Printer) Initialize(directive []Directive)

Initialize initializes the padding of this printer.

func (Printer) PrintDirective added in v0.1.1

func (p Printer) PrintDirective(w io.Writer, directive Directive) (n int, err error)

PrintDirective prints a directive to the given Writer.

func (*Printer) PrintLedger added in v0.1.1

func (p *Printer) PrintLedger(w io.Writer, l *Ledger) (int, error)

PrintLedger prints a Ledger.

type Range added in v0.1.1

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

Range describes a range of locations in a file.

func (Range) Position added in v0.1.1

func (r Range) Position() Range

Position returns the Range itself.

type RecursiveParser added in v0.1.1

type RecursiveParser struct {
	File    string
	Context Context
	// contains filtered or unexported fields
}

RecursiveParser parses a file hierarchy recursively.

func (*RecursiveParser) Parse added in v0.1.1

func (rp *RecursiveParser) Parse(ctx context.Context) <-chan any

Parse parses the journal at the path, and branches out for include files

type Rule added in v0.0.14

type Rule struct {
	Level int
	Regex *regexp.Regexp
}

Rule is a rule to shorten accounts which match the given regex.

func (Rule) String added in v0.0.14

func (r Rule) String() string

type Tag added in v0.1.1

type Tag string

Tag represents a tag for a transaction or booking.

type Transaction added in v0.1.1

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

Transaction represents a transaction.

func (Transaction) Position added in v0.1.1

func (t Transaction) Position() Range

Position returns the source location.

type TransactionBuilder added in v0.1.1

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

TransactionBuilder builds transactions.

func (TransactionBuilder) Build added in v0.1.1

func (tb TransactionBuilder) Build() *Transaction

Build builds a transactions.

type Value added in v0.1.1

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

Value represents a value directive.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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