dblentry

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

View Source
const (
	// PostUncleared notion for a posting.
	PostUncleared = "uncleared"
	// PostCleared notion for a posting.
	PostCleared = "cleared"
	// PostPending notion for a posting.
	PostPending = "pending"
)

Variables

This section is empty.

Functions

func AccountLcp

func AccountLcp(ss []string) string

AccountLcp return longest common prefix for account names.

func FitAccountname

func FitAccountname(name string, maxwidth int) string

FitAccountname for formatting.

func FitPayee

func FitPayee(payee string, maxwidth int) string

FitPayee for formatting.

func JoinAccounts

func JoinAccounts(segments []string) string

JoinAccounts from segments.

func SplitAccount

func SplitAccount(name string) []string

SplitAccount into segments.

func Vector2scalar

func Vector2scalar(nodes []parsec.ParsecNode) parsec.ParsecNode

Vector2scalar convert vector of arity ONE to scalar.

func Ydate

func Ydate(year int) parsec.Parser

Ydate return a parser-combinator that can parse date/time string.

Types

type Account

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

Account implements api.Accounter{} interface.

func NewAccount

func NewAccount(name string) *Account

NewAccount create a new instance of Account{}.

func (*Account) Balance

func (acc *Account) Balance(obj interface{}) (balance api.Commoditiser)

func (*Account) Balanced

func (acc *Account) Balanced() bool

func (*Account) Balances

func (acc *Account) Balances() []api.Commoditiser

func (*Account) Clone

func (acc *Account) Clone(ndb *Datastore) *Account

func (*Account) Credit

func (acc *Account) Credit(obj interface{}) (balance api.Commoditiser)

func (*Account) Credits

func (acc *Account) Credits() []api.Commoditiser

func (*Account) Debit

func (acc *Account) Debit(obj interface{}) (balance api.Commoditiser)

func (*Account) Debits

func (acc *Account) Debits() []api.Commoditiser

func (*Account) Directive

func (acc *Account) Directive() string

func (*Account) Firstpass

func (acc *Account) Firstpass(
	db *Datastore, trans *Transaction, p *Posting) error

func (*Account) FmtBalances

func (acc *Account) FmtBalances(
	db api.Datastorer, trans api.Transactor, p api.Poster,
	_ api.Accounter) [][]string

func (*Account) FmtDCBalances

func (acc *Account) FmtDCBalances(
	db api.Datastorer, trans api.Transactor, p api.Poster,
	_ api.Accounter) [][]string

func (*Account) FmtEquity

func (acc *Account) FmtEquity(
	db api.Datastorer, trans api.Transactor, p api.Poster,
	_ api.Accounter) [][]string

func (*Account) FmtPassbook

func (acc *Account) FmtPassbook(
	db api.Datastorer, trans api.Transactor, p api.Poster,
	_ api.Accounter) [][]string

func (*Account) FmtRegister

func (acc *Account) FmtRegister(
	db api.Datastorer, trans api.Transactor, p api.Poster,
	_ api.Accounter) [][]string

func (*Account) HasPosting

func (acc *Account) HasPosting() bool

func (*Account) IsExpense

func (acc *Account) IsExpense() bool

func (*Account) IsIncome

func (acc *Account) IsIncome() bool

func (*Account) Name

func (acc *Account) Name() string

func (*Account) Notes

func (acc *Account) Notes() []string

func (*Account) Secondpass

func (acc *Account) Secondpass(
	db *Datastore, trans *Transaction, p *Posting) error

func (*Account) String

func (acc *Account) String() string

func (*Account) Yledger

func (acc *Account) Yledger(db *Datastore) parsec.Parser

Yledger return a parser-combinator that can parse an account name.

func (*Account) Ypostaccn

func (acc *Account) Ypostaccn(db *Datastore) parsec.Parser

Ypostaccn return a parser-combinator that parses an account name in the context of a posting.

type Comment

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

Comment type

func NewComment

func NewComment() *Comment

NewComment create comment type.

func (*Comment) Firstpass

func (cmt *Comment) Firstpass(db *Datastore) error

func (*Comment) Secondpass

func (cmt *Comment) Secondpass(db *Datastore) error

func (*Comment) Yledger

func (cmt *Comment) Yledger(db *Datastore) parsec.Parser

Yledger return a parser-combinator that can parse a comment string.

type Commodity

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

Commodity that can be exchanged between accounts.

func NewCommodity

func NewCommodity(name string) *Commodity

NewCommodity return an new commodity instance.

func (*Commodity) Amount

func (comm *Commodity) Amount() float64

func (*Commodity) ApplyAmount

func (comm *Commodity) ApplyAmount(other api.Commoditiser) error

func (*Commodity) BalanceEqual

func (comm *Commodity) BalanceEqual(other api.Commoditiser) (bool, error)

func (*Commodity) Clone

func (comm *Commodity) Clone(ndb api.Datastorer) api.Commoditiser

func (*Commodity) Currency

func (comm *Commodity) Currency() bool

func (*Commodity) Directive

func (comm *Commodity) Directive() string

func (*Commodity) Firstpass

func (comm *Commodity) Firstpass(
	db *Datastore, trans *Transaction, p *Posting) error

func (*Commodity) IsCredit

func (comm *Commodity) IsCredit() bool

func (*Commodity) IsDebit

func (comm *Commodity) IsDebit() bool

func (*Commodity) MakeSimilar

func (comm *Commodity) MakeSimilar(amount float64) api.Commoditiser

func (*Commodity) Name

func (comm *Commodity) Name() string

func (*Commodity) Notes

func (comm *Commodity) Notes() []string

func (*Commodity) Secondpass

func (comm *Commodity) Secondpass(
	db *Datastore, trans *Transaction, p *Posting) error

func (*Commodity) String

func (comm *Commodity) String() string

func (*Commodity) Ybalprice

func (comm *Commodity) Ybalprice(db *Datastore) parsec.Parser

Ybalprice return a parser-combinator that can parse a commodity in balance-price format, like: =<comm>

func (*Commodity) Ycommodityname

func (comm *Commodity) Ycommodityname(db *Datastore) parsec.Parser

Ycommodityname parse commodity, non-currency name, as simple token or as double-quoted token.

func (*Commodity) Ycostprice

func (comm *Commodity) Ycostprice(db *Datastore) parsec.Parser

Ycostprice return a parser-combinator that can parse a commodity in costprice format, like: @ <comm>

func (*Commodity) Ycurrencyname

func (comm *Commodity) Ycurrencyname(db *Datastore) parsec.Parser

Ycurrencyname parse commodity as currency as simple token or as double-quoted token.

func (*Commodity) Yledger

func (comm *Commodity) Yledger(db *Datastore) parsec.Parser

Yledger return a parser-combinator that can parse a commodity amount/name.

func (*Commodity) Ylotprice

func (comm *Commodity) Ylotprice(db *Datastore) parsec.Parser

Ylotprice return a parser-combinator that can parse a commodity in lotprice format, like: {...}

func (*Commodity) Yname

func (comm *Commodity) Yname(db *Datastore) parsec.Parser

Yname return a parser-combinator that can parse a commodity name.

type DB

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

DB impelements array based sorted key-value entries.

func NewDB

func NewDB(name string) *DB

NewDB create a new DB.

func (*DB) Clone

func (db *DB) Clone() *DB

func (*DB) Insert

func (db *DB) Insert(k time.Time, v interface{}) error

Insert a KV entry into DB.

func (*DB) Len

func (db *DB) Len() int

func (*DB) Less

func (db *DB) Less(i, j int) bool

func (*DB) Range

func (db *DB) Range(
	low, high *time.Time, incl string,
	entries []api.TimeEntry) []api.TimeEntry

Range over DB entries, from low to high with specified include option.

func (*DB) Swap

func (db *DB) Swap(i, j int)

type Datastore

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

Datastore managing accounts, commodities, transactions and posting and every thing else that are related.

func NewDatastore

func NewDatastore(name string, reporter api.Reporter) *Datastore

NewDatastore return a new datastore.

func (*Datastore) Accountnames

func (db *Datastore) Accountnames() []string

func (*Datastore) Addjournal

func (db *Datastore) Addjournal(journalfile string, data []byte)

func (*Datastore) AggregateTotal

func (db *Datastore) AggregateTotal(trans api.Transactor, p api.Poster) error

func (*Datastore) Applytill

func (db *Datastore) Applytill(till time.Time)

func (*Datastore) Balance

func (db *Datastore) Balance(obj interface{}) (balance api.Commoditiser)

func (*Datastore) Balances

func (db *Datastore) Balances() []api.Commoditiser

func (*Datastore) Clone

func (db *Datastore) Clone(nreporter api.Reporter) api.Datastorer

func (*Datastore) Commoditynames

func (db *Datastore) Commoditynames() []string

func (*Datastore) Credit

func (db *Datastore) Credit(obj interface{}) (balance api.Commoditiser)

func (*Datastore) Credits

func (db *Datastore) Credits() []api.Commoditiser

func (*Datastore) CurrentJournal

func (db *Datastore) CurrentJournal() string

func (*Datastore) Debit

func (db *Datastore) Debit(obj interface{}) (balance api.Commoditiser)

func (*Datastore) Debits

func (db *Datastore) Debits() []api.Commoditiser

func (*Datastore) Firstpass

func (db *Datastore) Firstpass(obj interface{}) (err error)

func (*Datastore) Firstpassok

func (db *Datastore) Firstpassok()

Firstpassok to track parsephase

func (*Datastore) FmtBalances

func (db *Datastore) FmtBalances(
	_ api.Datastorer, trans api.Transactor, p api.Poster,
	acc api.Accounter) [][]string

func (*Datastore) FmtDCBalances

func (db *Datastore) FmtDCBalances(
	_ api.Datastorer, trans api.Transactor, p api.Poster,
	acc api.Accounter) [][]string

func (*Datastore) FmtEquity

func (db *Datastore) FmtEquity(
	_ api.Datastorer, trans api.Transactor, _ api.Poster,
	_ api.Accounter) [][]string

func (*Datastore) FmtPassbook

func (db *Datastore) FmtPassbook(
	_ api.Datastorer, trans api.Transactor, _ api.Poster,
	_ api.Accounter) [][]string

func (*Datastore) FmtRegister

func (db *Datastore) FmtRegister(
	_ api.Datastorer, trans api.Transactor, p api.Poster,
	acc api.Accounter) [][]string

func (*Datastore) GetAccount

func (db *Datastore) GetAccount(name string) api.Accounter

func (*Datastore) GetCommodity

func (db *Datastore) GetCommodity(name string) api.Commoditiser

func (*Datastore) Hasjournal

func (db *Datastore) Hasjournal(data []byte) bool

func (*Datastore) IsAccountDeclared

func (db *Datastore) IsAccountDeclared(name string) bool

func (*Datastore) IsCommodityDeclared

func (db *Datastore) IsCommodityDeclared(name string) bool

func (*Datastore) IsPayeeDeclared

func (db *Datastore) IsPayeeDeclared(name string) bool

func (*Datastore) PrintAccounts

func (db *Datastore) PrintAccounts()

PrintAccounts is a debug api for application.

func (*Datastore) Secondpass

func (db *Datastore) Secondpass() error

func (*Datastore) Secondpassok

func (db *Datastore) Secondpassok()

Secondpassok to track parsephase

type Directive

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

Directive can handle all directives in ledger journal.

func NewDirective

func NewDirective() *Directive

NewDirective create a new Directive instance, one instance to be created for handling each directive in the journal file.

func (*Directive) Firstpass

func (d *Directive) Firstpass(db *Datastore) error

func (*Directive) Includefile

func (d *Directive) Includefile() string

func (*Directive) Secondpass

func (d *Directive) Secondpass(db *Datastore) error

func (*Directive) Type

func (d *Directive) Type() string

func (*Directive) Yledger

func (d *Directive) Yledger(db *Datastore) parsec.Parser

Yledger return a parser-combinator that can parse directives.

func (*Directive) Yledgerblock

func (d *Directive) Yledgerblock(db *Datastore, block []string) (int, error)

Yledgerblock return a parser-combinator that can parse sub directives under account directive.

type DoubleEntry

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

func NewDoubleEntry

func NewDoubleEntry(name string) *DoubleEntry

func (*DoubleEntry) AddBalance

func (de *DoubleEntry) AddBalance(commodity api.Commoditiser) error

func (*DoubleEntry) Balance

func (de *DoubleEntry) Balance(obj interface{}) (comm api.Commoditiser)

func (*DoubleEntry) Balances

func (de *DoubleEntry) Balances() []api.Commoditiser

func (*DoubleEntry) Clone

func (de *DoubleEntry) Clone() *DoubleEntry

func (*DoubleEntry) Credit

func (de *DoubleEntry) Credit(obj interface{}) (comm api.Commoditiser)

func (*DoubleEntry) Credits

func (de *DoubleEntry) Credits() []api.Commoditiser

func (*DoubleEntry) Debit

func (de *DoubleEntry) Debit(obj interface{}) (comm api.Commoditiser)

func (*DoubleEntry) Debits

func (de *DoubleEntry) Debits() []api.Commoditiser

func (*DoubleEntry) IsBalanced

func (de *DoubleEntry) IsBalanced() bool

type KV

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

KV entry within DB.

func (KV) Key

func (kv KV) Key() time.Time

func (KV) Value

func (kv KV) Value() interface{}

type ParsePhase

type ParsePhase int

ParsePhase state to be tracked at datastore.

const (
	// DBSTART is parsing started.
	DBSTART ParsePhase = iota + 1
	// DBFIRSTPASS is all Firstpass() calls are completed.
	DBFIRSTPASS
	// DBSECONDPASS is all Secondpass() calls are completed.
	DBSECONDPASS
)

type Payee

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

func NewPayee

func NewPayee(name string) *Payee

type Posting

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

Posting instance for every single posting within a transaction.

func NewPosting

func NewPosting(trans *Transaction) *Posting

NewPosting create a new posting instance.

func (*Posting) Account

func (p *Posting) Account() api.Accounter

func (*Posting) Balanceprice

func (p *Posting) Balanceprice() api.Commoditiser

func (*Posting) Clone

func (p *Posting) Clone(ndb *Datastore, ntrans *Transaction) *Posting

func (*Posting) Commodity

func (p *Posting) Commodity() api.Commoditiser

func (*Posting) Costprice

func (p *Posting) Costprice() api.Commoditiser

func (*Posting) Firstpass

func (p *Posting) Firstpass(db *Datastore, trans *Transaction) error

func (*Posting) FmtBalances

func (p *Posting) FmtBalances(
	db api.Datastorer, trans api.Transactor, _ api.Poster,
	_ api.Accounter) [][]string

func (*Posting) FmtEquity

func (p *Posting) FmtEquity(
	db api.Datastorer, trans api.Transactor, _ api.Poster,
	_ api.Accounter) [][]string

func (*Posting) FmtPassbook

func (p *Posting) FmtPassbook(
	db api.Datastorer, trans api.Transactor, _ api.Poster,
	_ api.Accounter) [][]string

func (*Posting) FmtRegister

func (p *Posting) FmtRegister(
	db api.Datastorer, trans api.Transactor, _ api.Poster,
	_ api.Accounter) [][]string

func (*Posting) IsCredit

func (p *Posting) IsCredit() bool

func (*Posting) IsDebit

func (p *Posting) IsDebit() bool

func (*Posting) Lotprice

func (p *Posting) Lotprice() api.Commoditiser

func (*Posting) Payee

func (p *Posting) Payee() string

func (*Posting) Secondpass

func (p *Posting) Secondpass(db *Datastore, trans *Transaction) error

func (*Posting) Yledger

func (p *Posting) Yledger(db *Datastore) parsec.Parser

Yledger return parser-combinator that can parse a posting line within a transaction.

type Price

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

Price equivalence between commodities, TBD...

func NewPrice

func NewPrice() *Price

NewPrice return a new Price instance.

func (*Price) Clone

func (price *Price) Clone(ndb *Datastore) *Price

func (*Price) Firstpass

func (price *Price) Firstpass(db *Datastore) error

func (*Price) Secondpass

func (price *Price) Secondpass(db *Datastore) error

func (*Price) Yledger

func (price *Price) Yledger(db *Datastore) parsec.Parser

Yledger return a parser-combinator that can parse a price directive.

type Tags

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

Tags from journal within a posting and/or a transactions.

func NewTag

func NewTag() *Tags

NewTag create a new Tags instance.

func (*Tags) Yledger

func (tag *Tags) Yledger(db *Datastore) parsec.Parser

Yledger return a parser-combinator that can parse a tag specification.

type Transaction

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

Transaction instance for every transaction in the journal file.

func NewTransaction

func NewTransaction(journalfile string) *Transaction

NewTransaction create a new transaction object.

func (*Transaction) Addlines

func (trans *Transaction) Addlines(lines ...string)

func (*Transaction) Clone

func (trans *Transaction) Clone(ndb *Datastore) *Transaction

func (*Transaction) Crc64

func (trans *Transaction) Crc64() uint64

func (*Transaction) Date

func (trans *Transaction) Date() time.Time

func (*Transaction) Firstpass

func (trans *Transaction) Firstpass(db *Datastore) error

func (*Transaction) GetPostings

func (trans *Transaction) GetPostings() []api.Poster

func (*Transaction) Journalfile

func (trans *Transaction) Journalfile() string

func (*Transaction) Lineno

func (trans *Transaction) Lineno() int

Lineno get lineno in journal file for this transaction.

func (*Transaction) Payee

func (trans *Transaction) Payee() string

func (*Transaction) Printlines

func (trans *Transaction) Printlines() []string

func (*Transaction) Secondpass

func (trans *Transaction) Secondpass(db *Datastore) error

func (*Transaction) SetLineno

func (trans *Transaction) SetLineno(lineno int)

SetLineno in journal file for this transaction.

func (*Transaction) Yledger

func (trans *Transaction) Yledger(db *Datastore) parsec.Parser

Yledger return a parser-combinator that can parse first line of a transaction.

func (*Transaction) Yledgerblock

func (trans *Transaction) Yledgerblock(
	db *Datastore, block []string) (int, error)

Yledgerblock return a parser combinaty that can parse all the posting within the transaction.

Jump to

Keyboard shortcuts

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