ledger

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Ledger provides the functionality of generating hledger journals.

Index

Constants

View Source
const HLedgerDateFormat = "2006-01-02"

HLedgerDateFormat defines the default date format as required by hledger.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	Mode     string
	Element  string
	DoManual bool
	Errors   []error
}

Comment reassembles a comment which can be generated based on the state of this struct.

func NewComment

func NewComment(mode, element string) Comment

NewComment returns a new Comment.

func NewManualComment

func NewManualComment(mode, element string) Comment

NewManualComment returns a new Comment with the request to the user to manually correct the given journal entry.

func (Comment) String

func (c Comment) String() string

String returns generates the comment for the journal based on the state of the struct.

type Entry

type Entry struct {
	TransactionType util.TransactionType
	Date            time.Time
	Status          EntryStatus
	Code            string
	Description     string
	Comment         Comment
	Account1        string
	Account2        string
	Amount          util.Money
}

Entry is a single journal entry.

func EntriesForExpense

func EntriesForExpense(s schema.Schema, exp schema.Expense) []Entry

EntriesForExpense returns the journal entries for a given schema.Expense. Depending on the nature of the expense the appropriate function will be called.

func EntriesForInvoicing

func EntriesForInvoicing(s schema.Schema, inv schema.Invoice) []Entry

EntriesForInvoicing returns the journal entries for invoicing of the given schema.Invoice.

func EntriesForTransaction

func EntriesForTransaction(s schema.Schema, trn schema.Transaction) []Entry

EntriesForTransaction returns the journal entries for a given schema.Transaction.

func SettlementEntriesForExpense

func SettlementEntriesForExpense(s schema.Schema, trn schema.Transaction, exp schema.Expense) []Entry

SettlementEntriesForExpense takes the related schema.Transaction and schema.Expense and returns the settlement entries.

func SettlementEntriesForInvoice

func SettlementEntriesForInvoice(s schema.Schema, trn schema.Transaction, inv schema.Invoice) []Entry

SettlementEntriesForInvoice returns the entries for the settlement (aka receiving the money from the customer) of the related invoice.

func (Entry) Transaction

func (e Entry) Transaction() string

Transaction renders the hledger transaction for the given entry.

type EntryStatus

type EntryStatus int

EntryStatus reassembles the three states a transaction can have in hledger. This information isn't necessary but is here implemented for future usage.

const (
	UnmarkedStatus EntryStatus = iota
	PendingStatus
	ClearedStatus
)

func (EntryStatus) TrnEle

func (s EntryStatus) TrnEle() string

TrnEle renders the representation of the state in a hledger journal.

type Journal

type Journal struct {
	Aliases [][]string
	Entries []Entry
}

Journal is a data structure which can be converted into a hledger journal.

On Aliases

Some standard chart of accounts uses multiple root accounts for the same account type. An example is Switzerland where "Personalaufwand" and "Betriebsfremder Aufwand" are both root accounts. In hledger both of them have to be children of the "expense" account. To accomplish this the use of aliases is possible. Alias declaration for the given example:

aliases := [][]string{
	[]string{"Personalaufwand", "expenses"},
	[]string{"Betriebsfremder Aufwand", "expenses"}}

func JournalFromAcc

func JournalFromAcc(s schema.Schema, year int) Journal

JournalFromAcc takes an schema.Schema project and converts it into an Journal. This is mainly used to export the Journal afterwards into a hledger journal. Optionally the year can be filtered, if the given year parameter is > 0, only events happened in this year will be converted into transactions.

TODO: Es brauch ein separates acc für alle Jahre und eins für d

func NewJournal

func NewJournal(aliases [][]string) Journal

NewJournalConfig returns a new Journal with the given aliases.

func (*Journal) AddEntries

func (j *Journal) AddEntries(entries []Entry)

AddEntries adds new entries to the journal.

func (Journal) HLedger

func (j Journal) HLedger() string

HLedger retruns the hledger styled journal as a string.

func (Journal) HLedgerHeader

func (j Journal) HLedgerHeader() string

HLedgerHeader generates the header of the hledger journal as a string.

func (Journal) Len

func (j Journal) Len() int

Len returns the number of journal entries. Used for sorting.

func (Journal) Less

func (j Journal) Less(i, k int) bool

Less states whether the entry at index i is less as the entry at index k. Used for sorting.

func (Journal) SaveHLedgerFile

func (j Journal) SaveHLedgerFile(path string)

SaveHLedgerFile saves the given Journal as a hledger journal at the given path.

func (Journal) Swap

func (j Journal) Swap(i, k int)

Swap swaps to journal entries at the given indexes. Used for sorting.

Jump to

Keyboard shortcuts

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