Documentation ¶
Index ¶
- Constants
- func CleanUp[E Entities](fpath string) int
- func InitCypher(key string)
- func Load[E Entities, R Registry[E]](registry R, fpath string) (n int, err error)
- func Save[E Entities, R Registry[E]](registry R, fpath string) (n int, err error)
- type Account
- type AccountRegistry
- func (ar *AccountRegistry) Add(a Account) int
- func (ar *AccountRegistry) AddQueued(a Account)
- func (ar *AccountRegistry) Get(accID ID) *Account
- func (ar *AccountRegistry) List() map[ID]Account
- func (ar *AccountRegistry) Load() (int, error)
- func (ar *AccountRegistry) Save() (int, error)
- func (ar *AccountRegistry) SyncQueued() []Account
- type Balance
- type BalanceRegistry
- func (br *BalanceRegistry) Add(b Balance) int
- func (br *BalanceRegistry) AddQueued(b Balance)
- func (br *BalanceRegistry) List() []Balance
- func (br *BalanceRegistry) Load() (int, error)
- func (br *BalanceRegistry) Save() (int, error)
- func (br *BalanceRegistry) SyncQueued() (changes []Balance)
- func (br *BalanceRegistry) TransactionBalance(accID, trID ID) *Balance
- type Currency
- type CurrencyRegistry
- type Cypher
- type EncryptedString
- type Entities
- type ID
- type Ledger
- func (l *Ledger) AccountAmount(accID ID) float64
- func (l *Ledger) AccountBalance(accID ID) *Balance
- func (l *Ledger) AmountTransaction(t *Transaction) string
- func (l *Ledger) CreateAccount(n, t, d, c string, openedAt time.Time, initBalance float64) (*Account, error)
- func (l *Ledger) CreateBalance(accID, trID ID, value int64) *Balance
- func (l *Ledger) CreateInitialTransaction(accID ID, openedAt time.Time, v int64) *Transaction
- func (l *Ledger) CreateTransaction(src, dst ID, t time.Time, v float64, txt string) (*Transaction, error)
- func (l *Ledger) Save()
- func (l *Ledger) UpdateBalance(accID, trID ID, accType string, operType int, trTime time.Time, value int64) error
- type Registry
- type Tag
- type TagMap
- type TagMapRegistry
- func (tm *TagMapRegistry) Add(t TagMap) int
- func (tm *TagMapRegistry) AddQueued(t TagMap)
- func (tm *TagMapRegistry) Create(tagID, itemID ID)
- func (tm *TagMapRegistry) Items(tagID ID) (items []ID)
- func (tm *TagMapRegistry) Load() (int, error)
- func (tm *TagMapRegistry) Save() (int, error)
- func (tm *TagMapRegistry) SyncQueued() []TagMap
- func (tm *TagMapRegistry) Tags(itemID ID) (tags []ID)
- type TagRegistry
- func (tg *TagRegistry) Add(t Tag) int
- func (tg *TagRegistry) AddQueued(t Tag)
- func (tg *TagRegistry) Create(n string) *Tag
- func (tg *TagRegistry) GetById(tagID ID) *Tag
- func (tg *TagRegistry) GetByName(n string) *Tag
- func (tg *TagRegistry) List() map[ID]Tag
- func (tg *TagRegistry) Load() (int, error)
- func (tg *TagRegistry) Save() (int, error)
- func (tg *TagRegistry) SyncQueued() []Tag
- type Transaction
- type TransactionRegistry
- func (tr *TransactionRegistry) Add(t Transaction) int
- func (tr *TransactionRegistry) AddQueued(t Transaction)
- func (tr *TransactionRegistry) AllAfter(accID ID, trTime time.Time) (trs []Transaction)
- func (tr *TransactionRegistry) FirstBefore(accID ID, trTime time.Time) *Transaction
- func (tr *TransactionRegistry) Last(accID ID) *Transaction
- func (tr *TransactionRegistry) List() (transactions []Transaction)
- func (tr *TransactionRegistry) Load() (int, error)
- func (tr *TransactionRegistry) Save() (int, error)
- func (tr *TransactionRegistry) SyncQueued() []Transaction
Constants ¶
const ( Asset = "Asset" Liability = "Liability" Equity = "Equity" Income = "Income" Expense = "Expense" )
const ( Credit = iota Debit )
const ( ACCOUNTS_FILE = "miser.ar" TRANSACTIONS_FILE = "miser.tr" BALANCE_FILE = "miser.br" TAGS_FILE = "miser.tg" TAGS_MAPPING_FILE = "miser.tm" )
const ( Initial = "Initial" Unexpected = "Unexpected" // todo add analysis of transactions during the load and mark some transactions as: OverAverage = "OverAverage" Periodic = "Periodic" )
Special system tag names:
const ( Uncleared = iota // recorded but not yet reconciled; needs review Pending // tentatively reconciled (if needed, eg during a big reconciliation) Cleared // complete, reconciled as far as possible, and considered correct )
const Million = 1_000_000
const RANDOM_BYTES_LENGTH = 10
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Account ¶
type Account struct { ID ID Name, Type, Desc, Cur EncryptedString OpenedAt, ClosedAt time.Time Deleted bool }
type AccountRegistry ¶
func CreateAccountRegistry ¶
func CreateAccountRegistry() *AccountRegistry
func (*AccountRegistry) Add ¶
func (ar *AccountRegistry) Add(a Account) int
func (*AccountRegistry) AddQueued ¶
func (ar *AccountRegistry) AddQueued(a Account)
func (*AccountRegistry) Get ¶
func (ar *AccountRegistry) Get(accID ID) *Account
func (*AccountRegistry) List ¶
func (ar *AccountRegistry) List() map[ID]Account
func (*AccountRegistry) Load ¶
func (ar *AccountRegistry) Load() (int, error)
func (*AccountRegistry) Save ¶
func (ar *AccountRegistry) Save() (int, error)
func (*AccountRegistry) SyncQueued ¶
func (ar *AccountRegistry) SyncQueued() []Account
type Balance ¶
type Balance struct {
Account, Transaction ID // in fact the id of balance item is transaction id
Value int64
}
Balance is value object, it is immutable, do not try to change it, do create another one instead, the last version will be used (see Add method of BalanceRegistry).
type BalanceRegistry ¶
func CreateBalanceRegistry ¶
func CreateBalanceRegistry() *BalanceRegistry
func (*BalanceRegistry) Add ¶
func (br *BalanceRegistry) Add(b Balance) int
func (*BalanceRegistry) AddQueued ¶
func (br *BalanceRegistry) AddQueued(b Balance)
func (*BalanceRegistry) List ¶
func (br *BalanceRegistry) List() []Balance
func (*BalanceRegistry) Load ¶
func (br *BalanceRegistry) Load() (int, error)
func (*BalanceRegistry) Save ¶
func (br *BalanceRegistry) Save() (int, error)
func (*BalanceRegistry) SyncQueued ¶
func (br *BalanceRegistry) SyncQueued() (changes []Balance)
func (*BalanceRegistry) TransactionBalance ¶
func (br *BalanceRegistry) TransactionBalance(accID, trID ID) *Balance
Find a balance of given account transaction. Keep in mind: every transaction creates two different balances for source and destination accounts.
type CurrencyRegistry ¶
func CreateCurrencyRegistry ¶
func CreateCurrencyRegistry() *CurrencyRegistry
func (CurrencyRegistry) Get ¶
func (cr CurrencyRegistry) Get(code string) *Currency
type Cypher ¶
type Cypher struct {
// contains filtered or unexported fields
}
Cypher provides ecrypt and decrypt methods.
type EncryptedString ¶
type EncryptedString string
func (EncryptedString) MarshalJSON ¶
func (s EncryptedString) MarshalJSON() ([]byte, error)
func (*EncryptedString) UnmarshalJSON ¶
func (s *EncryptedString) UnmarshalJSON(b []byte) error
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
func CreateLedger ¶
func CreateLedger(ar *AccountRegistry, br *BalanceRegistry, tr *TransactionRegistry, cr *CurrencyRegistry, tg *TagRegistry, tm *TagMapRegistry) *Ledger
func (*Ledger) AccountBalance ¶
Account balance: balance at time of last transaction.
func (*Ledger) AmountTransaction ¶
func (l *Ledger) AmountTransaction(t *Transaction) string
func (*Ledger) CreateAccount ¶
func (*Ledger) CreateInitialTransaction ¶
func (*Ledger) CreateTransaction ¶
type Registry ¶
type Registry[E Entities] interface { *AccountRegistry | *TransactionRegistry | *BalanceRegistry | *TagRegistry | *TagMapRegistry Add(e E) int SyncQueued() []E }
type Tag ¶
type Tag struct { ID ID Name EncryptedString Deleted bool }
Tag ties name of a tag and its id, nothing more. For tagging object use TagMap.
type TagMap ¶
type TagMap struct {
Tag, Item ID
}
TagMap ties together a tag and some object: account, transaction etc.
type TagMapRegistry ¶
func CreateTagsMapRegistry ¶
func CreateTagsMapRegistry() *TagMapRegistry
func (*TagMapRegistry) Add ¶
func (tm *TagMapRegistry) Add(t TagMap) int
func (*TagMapRegistry) AddQueued ¶
func (tm *TagMapRegistry) AddQueued(t TagMap)
func (*TagMapRegistry) Create ¶
func (tm *TagMapRegistry) Create(tagID, itemID ID)
func (*TagMapRegistry) Items ¶
func (tm *TagMapRegistry) Items(tagID ID) (items []ID)
func (*TagMapRegistry) Load ¶
func (tm *TagMapRegistry) Load() (int, error)
func (*TagMapRegistry) Save ¶
func (tm *TagMapRegistry) Save() (int, error)
func (*TagMapRegistry) SyncQueued ¶
func (tm *TagMapRegistry) SyncQueued() []TagMap
func (*TagMapRegistry) Tags ¶
func (tm *TagMapRegistry) Tags(itemID ID) (tags []ID)
type TagRegistry ¶
func CreateTagRegistry ¶
func CreateTagRegistry() *TagRegistry
func (*TagRegistry) Add ¶
func (tg *TagRegistry) Add(t Tag) int
func (*TagRegistry) AddQueued ¶
func (tg *TagRegistry) AddQueued(t Tag)
func (*TagRegistry) Create ¶
func (tg *TagRegistry) Create(n string) *Tag
func (*TagRegistry) GetById ¶
func (tg *TagRegistry) GetById(tagID ID) *Tag
func (*TagRegistry) GetByName ¶
func (tg *TagRegistry) GetByName(n string) *Tag
func (*TagRegistry) Load ¶
func (tg *TagRegistry) Load() (int, error)
func (*TagRegistry) Save ¶
func (tg *TagRegistry) Save() (int, error)
func (*TagRegistry) SyncQueued ¶
func (tg *TagRegistry) SyncQueued() []Tag
type Transaction ¶
type Transaction struct {
ID, Source, Dest ID
Time time.Time
Text EncryptedString
Value int64 // in millionths
State int // one of: Uncleared, Pending, Cleared
Deleted bool
}
func (*Transaction) IsInitial ¶
func (t *Transaction) IsInitial() bool
type TransactionRegistry ¶
func CreateTransactionRegistry ¶
func CreateTransactionRegistry() *TransactionRegistry
func (*TransactionRegistry) Add ¶
func (tr *TransactionRegistry) Add(t Transaction) int
func (*TransactionRegistry) AddQueued ¶
func (tr *TransactionRegistry) AddQueued(t Transaction)
func (*TransactionRegistry) AllAfter ¶
func (tr *TransactionRegistry) AllAfter(accID ID, trTime time.Time) (trs []Transaction)
Find all transactions of account after given time.
func (*TransactionRegistry) FirstBefore ¶
func (tr *TransactionRegistry) FirstBefore(accID ID, trTime time.Time) *Transaction
Find a transaction of account before given time.
func (*TransactionRegistry) Last ¶
func (tr *TransactionRegistry) Last(accID ID) *Transaction
Find last transaction.
func (*TransactionRegistry) List ¶
func (tr *TransactionRegistry) List() (transactions []Transaction)
func (*TransactionRegistry) Load ¶
func (tr *TransactionRegistry) Load() (int, error)
func (*TransactionRegistry) Save ¶
func (tr *TransactionRegistry) Save() (int, error)
func (*TransactionRegistry) SyncQueued ¶
func (tr *TransactionRegistry) SyncQueued() []Transaction