Documentation
¶
Index ¶
- func AccountNameToList(name string) []string
- func ProduceEntries(fs afero.Fs, filename string, entryChan chan<- Entry) error
- func ReadJournalEntries(fs afero.Fs, filename string, handlers []EntryHandler) error
- func SplitComment(line string) (data, comment string)
- func ValidateAccount(account *parser.Account, ledger *Ledger) (*parser.Account, error)
- type Account
- type Directive
- type DirectiveHeader
- type Entry
- type EntryHandler
- type Ledger
- func (l *Ledger) AddAccount(pa *parser.Account, autoCreate bool) error
- func (l *Ledger) AddCommodity(c *parser.Commodity) error
- func (l *Ledger) AddDocument(doc *parser.Document, filename string, autoCreate bool) error
- func (l *Ledger) AddTransaction(t *parser.Transaction, autoCreate bool) error
- func (l *Ledger) CheckAccountName(name string, autoCreate bool) (bool, error)
- func (l *Ledger) CheckCommoditySymbol(symbol string, autoCreate bool) (bool, error)
- func (l *Ledger) LinkAccountsTransactions()
- func (l *Ledger) MermaidSummary() string
- func (l *Ledger) SetDefaultCommodity() error
- type Movement
- type RawArgument
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccountNameToList ¶
func ProduceEntries ¶
ProduceEntries reads a journal file and sends entries through the provided channel. It skips empty lines and adds comments to the entry. It handles comments both for whole lines and for directives and argumentss. The caller is responsible for closing the provided channel.
func ReadJournalEntries ¶
func ReadJournalEntries(fs afero.Fs, filename string, handlers []EntryHandler) error
ReadJournalEntries reads entries from a journal file and processes them using the provided handlers
func SplitComment ¶
Types ¶
type Account ¶
func (*Account) BalanceLatest ¶
func (*Account) LinkMovement ¶
func (*Account) SortMovements ¶
func (a *Account) SortMovements()
type DirectiveHeader ¶
type DirectiveHeader struct {
ValueDate time.Time
KnowledgeDate *time.Time // nil if not present
Name string
ExtraParams string
Comment string
}
This just descibes the data in the directive line which is common to all directives The entry part has all the extra arguments
func NewDirectiveHeader ¶
func NewDirectiveHeader(line string) (directive DirectiveHeader, err error)
Take a full line
func (DirectiveHeader) GetComment ¶
func (dd DirectiveHeader) GetComment() string
func (DirectiveHeader) GetExtraParams ¶
func (dd DirectiveHeader) GetExtraParams() string
func (DirectiveHeader) GetKnowledgeDate ¶
func (dd DirectiveHeader) GetKnowledgeDate() *time.Time
func (DirectiveHeader) GetName ¶
func (dd DirectiveHeader) GetName() string
func (DirectiveHeader) GetValueDate ¶
func (dd DirectiveHeader) GetValueDate() time.Time
func (DirectiveHeader) String ¶
func (d DirectiveHeader) String() string
Convert a simple directive to the first lines of the plain text Unit tested in commodity_test
type Entry ¶
type Entry struct {
Lines []string // Original lines for backwards compatibility
Comments []string
ThisDirective DirectiveHeader
Arguments []RawArgument
}
Entry represents a parsed journal entry
func (*Entry) HasDirective ¶
type EntryHandler ¶
type EntryHandler interface {
// HandleEntry attempts to process an entry. Returns true if the entry
// was successfully handled, false if the entry was not recognized
HandleEntry(Entry) bool
}
EntryHandler defines the interface for processing journal entries
type Ledger ¶
type Ledger struct {
// Raw data
Commodities []*parser.Commodity
Accounts []*Account
Transactions []*parser.Transaction
// Helper data Names are case insensitive
CommoditiesMap map[string]*parser.Commodity
AccountsMap map[string]*Account
DefaultCommodity *parser.Commodity
}
A Ledger is a working list of all entries. Whereas the document is a list of all the entries in a raw form
func NewLedgerFrom ¶
Given a directory read all the .luca files and return a Ledger
func NewLedgerFromFs ¶
NewLedgerFromFs creates a new ledger from files in the given directory using the provided filesystem
func (*Ledger) AddDocument ¶
Assume that all entires are now in the document so if in mutiple files they need to be merged or added in sequence Commodities --> Accounts --> Transactions
func (*Ledger) AddTransaction ¶
func (l *Ledger) AddTransaction(t *parser.Transaction, autoCreate bool) error
func (*Ledger) CheckAccountName ¶
func (*Ledger) CheckCommoditySymbol ¶
CheckCommodity used when adding an account. This can auto create the commodity if it doesn't exist It is assumed that by this point that all the commodities have been added that have been specified. and supplies default values if meaningful in which case it returns true
func (*Ledger) LinkAccountsTransactions ¶
func (l *Ledger) LinkAccountsTransactions()
func (*Ledger) MermaidSummary ¶
func (*Ledger) SetDefaultCommodity ¶
SetDefaultCommodity checks for a single default commodity and sets it
type RawArgument ¶
Argument represents a parsed argument line from an entry
func NewRawArgument ¶
func NewRawArgument(line string) (argument RawArgument, err error)