api

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LedgerVersion = Version{0, 1}

LedgerVersion is current ledger version

View Source
var Newline = fmt.Sprintln()
View Source
var Options struct {
	Dbname     string
	Journals   []string
	Currentdt  string
	Begindt    *time.Time
	Enddt      *time.Time
	Finyear    int
	Period     string
	Nosubtotal bool
	Subtotal   bool
	Cleared    bool
	Uncleared  bool
	Pending    bool
	Dcformat   bool
	Strict     bool
	Pedantic   bool
	Checkpayee bool
	Stitch     bool
	Nopl       bool
	Onlypl     bool
	Detailed   bool
	Bypayee    bool
	Daily      bool
	Weekly     bool
	Monthly    bool
	Quarterly  bool
	Yearly     bool
	Dow        bool
	Verbose    bool
	Outfd      *os.File
	Loglevel   string
}
View Source
var YFilterExpr parsec.Parser

Functions

func Crc64

func Crc64(data []byte) uint64

func FilterPeriod

func FilterPeriod(date time.Time, nobegin bool) bool

func GetStacktrace

func GetStacktrace(skip int, stack []byte) string

func HasString

func HasString(xs []string, y string) bool

func MakeFilterexpr

func MakeFilterexpr(args []string) string

func Maxints

func Maxints(numbers ...int) int

Maxints return the max value amont numbers.

func Parsecsv

func Parsecsv(input string) []string

Parsecsv parses the input string for comma separated string values and return parsed strings.

func RedFn

func RedFn(s string) string

func Repeatstr

func Repeatstr(str string, n int) string

Repeatstr to repeat the string `string` n times and return the same.

func StringSet

func StringSet(xs []string) []string

func ValidateDate

func ValidateDate(tm time.Time, year, month, date, hour, min, sec int) bool

func YellowFn

func YellowFn(s string) string

Types

type Accounter

type Accounter interface {
	// Name of the account.
	Name() string

	// Notes return list of notes declared on this account.
	Notes() []string

	// Balance amount, for commodity specified by `obj`, after all postings
	// from all transactions are applied on to this account. Note that each
	// accounts can exchange with any number of commodities.
	// `obj` can either be an instance implementing Commoditiser or it can be
	// string calling out the commodity name.
	Balance(obj interface{}) Commoditiser

	// Balances return the list of all commodities' balance amounts after all
	// postings form all transactions are applied on to this account.
	Balances() []Commoditiser

	// HasPosting return true if this account has ever participated in a
	// transaction posting.
	HasPosting() bool

	// IsIncome return true of account is declared as income account
	IsIncome() bool

	// IsExpense return true if account is declared as expense account
	IsExpense() bool

	// Directive return the account details as directive declaration.
	Directive() string

	Formatter
}

Accounter encapsulates an account.

type Commoditiser

type Commoditiser interface {
	// Name of the commodity, like: $, INR, Gold, Oil etc...
	Name() string

	// Notes return list of notes declared on this commodity.
	Notes() []string

	// Amount as in quantity, not necessarily as value.
	Amount() float64

	// Currency is true if commodity is of type bool.
	Currency() bool

	// ApplyAmount commodities
	ApplyAmount(other Commoditiser) error

	// BalanceEqual is equality between two commodity, which implies equality
	// in Name(), Amount() and Currency().
	BalanceEqual(Commoditiser) (bool, error)

	// IsCredit commodity is positive.
	IsCredit() bool

	// IsDebit commodity is negative.
	IsDebit() bool

	// MakeSimilar create a new instance of commodity simlar to this commodity
	MakeSimilar(amount float64) Commoditiser

	// Directive return the commodity details as directive declaration.
	Directive() string

	Clone(db Datastorer) Commoditiser

	String() string
}

Commoditiser encapsulates a commodity.

type Datastorer

type Datastorer interface {
	// GetAccount() to get the singleton object, if a singleton is not already
	// created for `name`, GetAccount() will create a new singleton object for
	// that name, and return the same.
	GetAccount(name string) Accounter

	// GetCommodity() returns the commodity object by name or creates an new
	// one. Note that this commodity object serves as the blue print for
	// commodity instansiation.
	GetCommodity(name string) Commoditiser

	// Accountnames return list of all account names.
	Accountnames() []string

	// Commoditynames return list of all commodity names.
	Commoditynames() []string

	// Balance amount, for commodity specified by `obj`, after all transactions
	// are tallied between the accounts. Note that each accounts can exchange
	// with any number of commodities.
	// `obj` can either be an instance implementing Commoditiser or it can be
	// string calling out the commodity name.
	Balance(obj interface{}) Commoditiser

	// Balances return the list of all commodities' balance amounts after all
	// transactions are tallied between the accounts.
	Balances() []Commoditiser

	// Firstpass to parse journal file.
	Firstpass(obj interface{}) error

	// Secondpass to apply journal entries.
	Secondpass() error

	// Firstpassok means firstpass completed on the datastore.
	Firstpassok()

	// Secondpassok means secondpass completed on the datastore.
	Secondpassok()

	// Clone this instance and all its nested reference.
	Clone(Reporter) Datastorer

	// AggregateTotal containing ledger for each posting.
	AggregateTotal(Transactor, Poster) error

	// IsCommodityDeclared return true if commodity is pre-declared
	IsCommodityDeclared(name string) bool

	// IsAccountDeclared return true if account is pre-declared
	IsAccountDeclared(name string) bool

	// IsPayeeDeclared return true if payee is pre-declared
	IsPayeeDeclared(name string) bool

	Formatter
}

Datastorer maintains the state of all accounts. Accounts are maintained as singleton objects.

type Filterexpr

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

func (*Filterexpr) Match

func (fe *Filterexpr) Match(name string) bool

func (*Filterexpr) String

func (fe *Filterexpr) String() string

type Formatter

type Formatter interface {
	// FmtBalances used for `balance` reporting.
	FmtBalances(Datastorer, Transactor, Poster, Accounter) [][]string

	// FmtDCBalances used for `balance` reporting, in debit-credit format.
	FmtDCBalances(Datastorer, Transactor, Poster, Accounter) [][]string

	// FmtRegister used for `register` reporting.
	FmtRegister(Datastorer, Transactor, Poster, Accounter) [][]string

	// FmtEquity used for `equity` reporting.
	FmtEquity(Datastorer, Transactor, Poster, Accounter) [][]string

	// FmtPassbook used for `passbook` reporting.
	FmtPassbook(Datastorer, Transactor, Poster, Accounter) [][]string
}

Formatter implements are uniform tabularized {row,column} formatting across all types under dblentry package.

type Poster

type Poster interface {
	// Commodity posted as credit or debit.
	Commodity() Commoditiser

	// Lotprice return the lot-price of this posting's commodity.
	Lotprice() Commoditiser

	// Costprice return the cost-price of this posting's commodity.
	Costprice() Commoditiser

	// Balanceprice return the balance-price of this posting's account.
	Balanceprice() Commoditiser

	// Payee for this posting, if unspecified in the posting, shall return the
	// transaction's payee.
	Payee() string

	// IsCredit takes the amount from the account, giver.
	IsCredit() bool

	// IsDebit accumulates the amount to the account, taker.
	IsDebit() bool

	// Account to which the commodity should be posted.
	Account() Accounter
}

Poster encapsulates a single posting within a transaction.

type Reporter

type Reporter interface {
	Firstpass(Datastorer, Transactor, Poster) error

	Transaction(Datastorer, Transactor) error

	Posting(Datastorer, Transactor, Poster) error

	BubblePosting(Datastorer, Transactor, Poster, Accounter) error

	Render(args []string, db Datastorer)

	Startjournal(journalfile string, included bool)

	Clone() Reporter
}

Reporter encapsulates callbacks that can be used by report generating plugins.

type Store

type Store interface {
	// Insert a new {key,value} pair
	Insert(k time.Time, v interface{}) error

	// Range over {key,value} pairs, entries can be used for returning the
	// results.
	Range(low, high *time.Time, incl string, entries []TimeEntry) []TimeEntry

	// Make an immutable copy of store.
	Clone()
}

Store maintains an index of key,vlue pairs, key being time.Time and value as interface.

type TimeEntry

type TimeEntry interface {
	// Key return the key part.
	Key() time.Time

	// Value return the value part.
	Value() interface{}
}

TimeEntry captures a single key,value pair, key being time.Time and value as interface.

type Transactor

type Transactor interface {
	// Date of transaction.
	Date() time.Time

	// Payee is the person or organization that receives money, a person or
	// organization that is paid money.
	Payee() string

	// GetPostings return list of all postings under this transaction.
	GetPostings() []Poster

	// Crc64 return a hash value that can uniquely identify the transaction.
	Crc64() uint64

	// Journalfile in which this transaction is defined.
	Journalfile() string

	// Printlines return the original lines from which transaction was parsed.
	Printlines() []string
}

Transactor encapsulates a single transaction between one or more creditors and one or more debtors.

type Version

type Version [2]byte

Version type with {major-byte, minor-byte}.

func (Version) String

func (ver Version) String() string

Jump to

Keyboard shortcuts

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