ledger

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateFormat = "2006/01/02"
)

Variables

This section is empty.

Functions

func NewValidateError

func NewValidateError(firstFailure int, cause error) error

Types

type Error

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

func (Error) Error

func (e Error) Error() string

type Ledger

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

func New

func New(transactions []Transaction) (*Ledger, error)

func NewFromReader

func NewFromReader(reader io.Reader) (*Ledger, error)

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

func (l *Ledger) Balances() (start, end time.Time, balances map[string][]decimal.Decimal)

func (*Ledger) LastTransactionTime

func (l *Ledger) LastTransactionTime() time.Time

LastTransactionTime returns the last transactions Date field. Returns 0 if there are no transactions

func (*Ledger) String

func (l *Ledger) String() string

func (*Ledger) Validate

func (l *Ledger) Validate() error

func (*Ledger) WriteJSON added in v0.2.0

func (l *Ledger) WriteJSON(page, results int, w io.Writer)

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 NewPostingFromString(line string) (Posting, error)

func (Posting) FormatTable

func (p Posting) FormatTable(accountLen, amountLen int) string

func (Posting) ID

func (p Posting) ID() string

func (Posting) String

func (p Posting) String() string

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()

Jump to

Keyboard shortcuts

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