bean

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package bean contains all beancount logic Including parsing, validating, calculating etc

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintAccBalances

func PrintAccBalances(accBalances AccBal)

PrintAccBalances pretty prints account balances by currency

Types

type AccBal

type AccBal = map[AccountName]CcyAmount

AccBal is a map of Account -> CcyBal

type Account

type Account struct {
	Name AccountName
}

Account is for now simply a string

func (Account) String

func (a Account) String() string

type AccountEvent

type AccountEvent struct {
	Date    time.Time
	Open    bool
	Account Account
	Ccy     Ccy
}

AccountEvent is opening/closing accounts

func (AccountEvent) String

func (ae AccountEvent) String() string

type AccountName

type AccountName string

AccountName is of the form Assets:Bob:Investing:Etc

type AccountTimeLine

type AccountTimeLine = map[AccountName][]AccountEvent

AccountTimeLine is a map of account events, sorted ascending by date well it should be...

func NewAccountTimeLine

func NewAccountTimeLine(aes []AccountEvent) (AccountTimeLine, error)

NewAccountTimeLine maps the AccountEvents by AccountName

type Amount

type Amount struct {
	Number apd.Decimal
	Ccy    Ccy
}

Amount is a number with a currency

func MustNewAmount

func MustNewAmount(num string, ccy string) Amount

MustNewAmount creates an Amount and panics! on underlying errors

func NewAmount

func NewAmount(num string, ccy string) (Amount, error)

NewAmount creates an Amount

func (Amount) Add

func (a Amount) Add(other Amount) (Amount, error)

Add adds other to the amount

func (Amount) Eq

func (a Amount) Eq(other Amount) bool

Eq returns true if the Amounts have same Number and Ccy

func (Amount) MustAdd

func (a Amount) MustAdd(other Amount) Amount

MustAdd adds other to the Amount

func (Amount) Neg

func (a Amount) Neg() Amount

Neg returns the negated Amount

func (Amount) String

func (a Amount) String() string

type Balance

type Balance struct {
	Date    time.Time
	Account Account
	Amount  Amount
}

Balance statement

func (Balance) String

func (b Balance) String() string

type Ccy

type Ccy string

Ccy is a currency like USD or GOOG or WHATEVER

type CcyAmount

type CcyAmount = map[Ccy]Amount

CcyAmount is a map of Ccy -> number

func MustNewCcyAmount

func MustNewCcyAmount(bals map[string]string) CcyAmount

MustNewCcyAmount converts a regular string map to a CcyAmount

func NewCcyAmount

func NewCcyAmount(bals map[string]string) (CcyAmount, error)

NewCcyAmount converts a string map to a CcyAmount

type Directive

type Directive struct {
	Lines []Line
}

Directive is one or more lines that go together

func (Directive) LineNum

func (d Directive) LineNum() int

LineNum returns the soruce file number of the _first line_ of this line

func (Directive) String

func (d Directive) String() string

type Ledger

type Ledger struct {
	AccountEvents   []AccountEvent
	AccountTimeLine AccountTimeLine
	Balances        []Balance
	Transactions    []Transaction
	Postings        []Posting
	Prices          []Price
	Pads            []Pad
}

Ledger is the full view of the beancount file

func NewLedger

func NewLedger(dbg bool) *Ledger

NewLedger parses the supplied file and creates a ledger ready for calculations

func (*Ledger) GetBalances

func (l *Ledger) GetBalances(date time.Time) (AccBal, error)

GetBalances returns the final balance of all accounts, separately for each currency

func (*Ledger) Load

func (l *Ledger) Load(rc io.ReadCloser) (*Ledger, error)

Load a beancount file/string into the Ledger

type Line

type Line struct {
	Blank  bool
	Tokens []Token
}

A Line from the beancount file

func (Line) LineNum

func (l Line) LineNum() int

LineNum returns the source file line number of this Line

func (Line) String

func (l Line) String() string

type Pad

type Pad struct {
	Date    time.Time
	PadTo   Account
	PadFrom Account
}

Pad is a pad directive

func (Pad) String

func (p Pad) String() string

type Posting

type Posting struct {
	Account     Account
	Amount      *Amount      // to allow nil
	Transaction *Transaction // nil until exctractPostings is run
}

Posting is an individual leg of a transaction

func (Posting) String

func (p Posting) String() string

type Price

type Price struct {
	Date   time.Time
	Ccy    Ccy
	Amount Amount
}

Price contains an exchange rate between commodities

func (Price) String

func (p Price) String() string

type Token

type Token struct {
	LineNum int
	Indent  bool
	Quote   bool
	Comment bool
	EOL     bool
	Text    string
}

Token is raw token from input file with a bunch of flags quotes are removed, newlines inside quotes are maintained

type Transaction

type Transaction struct {
	Date      time.Time
	Type      string
	Payee     string
	Narration string
	Postings  []Posting
}

Transaction must have at least two postings

func (Transaction) String

func (t Transaction) String() string

Jump to

Keyboard shortcuts

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