hledgersdk

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 4 Imported by: 0

README

GoDoc

HLedger-Api SDK

Connects to the hldeger-web server at http://127.0.0.1:5000/

go get codeberg.org/lil5/hledger_sdk

Example

import (
   hledgersdk "codeberg.org/lil5/hledger_sdk"
)

hl := hledgersdk.New("http://127.0.0.1:5000")

res, err := hl.GetAccountNames() // ["assets","assets:bank", "expenses", "income"]
res, err := hl.GetAccountTransactions() // [AccountTransaction]
res, err := hl.GetAccounts() // [Account]
res, err := hl.GetCommodities() // ["€", "$", "h"]
res, err := hl.GetTransactions() // [Transaction]
res, err := hl.GetVersions() // "1.32.3"

// Add transaction to ledger
add := hledgersdk.AddTransactionArg{
   Comment: "ipsum doloremque",
   Date:    "2003-03-31",
   Postings: []hledgersdk.AddTransactionPostingArg{
      {
         AccountCredit: "income:work",
         AccountDebit:  "assets:bank",
         Commodity:     "$",
         DecimalPlaces: 0,
         Amount:        200,
      },
   },
}
err := hl.AddTransaction(add)
// 2003-03-31 ipsum doloremque
//     income:work                                         $-200
//     assets:bank                                          $200

// Add transaction to ledger
add := hledgersdk.AddTransactionMultiArg{
   Comment: "ipsum doloremque",
   Date:    "2003-03-31",
   Postings: []hledgersdk.AddTransactionPostingMultiArg{
      {
         Accounts: map[string]int {
            "income:work":         -200,
            "assets:bank":         180,
            "expenses:income_tax": 20,
         },
         Commodity:     "$",
         DecimalPlaces: 0,
      },
   },
}
err := hl.AddTransactionMulti(add)
// 2003-03-31 ipsum doloremque
//     income:work                                         $-200
//     assets:bank                                          $180
//     expenses:income_tax                                   $20

Test

make docker-start test

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Aname string `json:"aname"`
	// Adeclarationinfo any   `json:"adeclarationinfo"`
	// Aebalance        []any `json:"aebalance"`
	Aibalance []struct {
		Acommodity string `json:"acommodity"`
		// Aprice     any `json:"aprice"`
		Aquantity Quantity `json:"aquantity"`
	} `json:"aibalance"`
	Anumpostings int `json:"anumpostings"`
	// Aboring      bool          `json:"aboring"`
	Aparent string `json:"aparent_"`
}

type AccountNames

type AccountNames = []string

type AccountTransaction

type AccountTransaction struct {
	// the transaction, unmodified
	Transaction Transaction `json:"transaction"`
	// the transaction, as seen from the current account
	RelativeTransaction Transaction `json:"relative_transaction"`
	// is this a split (more than one posting to other accounts) ?
	Split bool `json:"split"`
	// a display string describing the other account(s), if any
	// parents are shortened!
	// AccountNameDisplay string `json:"account_name_display"`
	// the amount posted to the current account(s) (or total amount posted)
	PostedAmount []MixedAmount `json:"posted_amount"`
	// the register's running total or the current account(s)'s historical balance, after this transaction
	TotalAmount []MixedAmount `json:"total_amount"`
}

func (*AccountTransaction) UnmarshalJSON

func (r *AccountTransaction) UnmarshalJSON(p []byte) error

type AccountTransactions

type AccountTransactions = []AccountTransaction

List of related account

type Accounts

type Accounts = []Account

type AddTransaction

type AddTransaction struct {
	Tcode             string                  `json:"tcode"`
	Tcomment          string                  `json:"tcomment"`
	Tdate             string                  `json:"tdate"`
	Tdate2            any                     `json:"tdate2"`
	Tdescription      string                  `json:"tdescription"`
	Tindex            int                     `json:"tindex"`
	Tpostings         []AddTransactionPosting `json:"tpostings"`
	Tprecedingcomment string                  `json:"tprecedingcomment"`
	Tsourcepos        []SourceRepo            `json:"tsourcepos"`
	Tstatus           string                  `json:"tstatus"`
	Ttags             []any                   `json:"ttags"`
}

type AddTransactionArg

type AddTransactionArg struct {
	Comment  string
	Date     string
	Postings []AddTransactionPostingArg
}

type AddTransactionMultiArg added in v1.0.3

type AddTransactionMultiArg struct {
	Comment  string
	Date     string
	Postings []AddTransactionPostingMultiArg
}

type AddTransactionPosting

type AddTransactionPosting struct {
	Paccount          string                        `json:"paccount"`
	Pamount           []AddTransactionPostingAmount `json:"pamount"`
	Pbalanceassertion any                           `json:"pbalanceassertion"`
	Pcomment          string                        `json:"pcomment"`
	Pdate             any                           `json:"pdate"`
	Pdate2            any                           `json:"pdate2"`
	Poriginal         any                           `json:"poriginal"`
	Pstatus           string                        `json:"pstatus"`
	Ptags             []any                         `json:"ptags"`
	Ptransaction      string                        `json:"ptransaction_"`
	Ptype             string                        `json:"ptype"`
}

type AddTransactionPostingAmount

type AddTransactionPostingAmount struct {
	Acommodity string   `json:"acommodity"`
	Aprice     any      `json:"aprice"`
	Aquantity  Quantity `json:"aquantity"`
	Astyle     Style    `json:"astyle"`
}

type AddTransactionPostingArg

type AddTransactionPostingArg struct {
	AccountCredit string
	AccountDebit  string
	Commodity     string
	DecimalPlaces int
	Amount        int
}

type AddTransactionPostingMultiArg added in v1.0.3

type AddTransactionPostingMultiArg struct {
	Accounts      map[string]int64
	Commodity     string
	DecimalPlaces int
}

type Commodities

type Commodities = []string

type HLedgerSdk

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

func New

func New(baseURL string) *HLedgerSdk

func (*HLedgerSdk) AddTransaction

func (s *HLedgerSdk) AddTransaction(add AddTransactionArg) error

func (*HLedgerSdk) AddTransactionMulti added in v1.0.3

func (s *HLedgerSdk) AddTransactionMulti(add AddTransactionMultiArg) error

func (*HLedgerSdk) GetAccountNames

func (s *HLedgerSdk) GetAccountNames() (*AccountNames, error)

func (*HLedgerSdk) GetAccountTransactions

func (s *HLedgerSdk) GetAccountTransactions(name string) (*AccountTransactions, error)

func (*HLedgerSdk) GetAccounts

func (s *HLedgerSdk) GetAccounts() (*Accounts, error)

func (*HLedgerSdk) GetCommodities

func (s *HLedgerSdk) GetCommodities() (*Commodities, error)

func (*HLedgerSdk) GetTransactions

func (s *HLedgerSdk) GetTransactions() (*Transactions, error)

func (*HLedgerSdk) GetVersion

func (s *HLedgerSdk) GetVersion() (*string, error)

type MixedAmount

type MixedAmount struct {
	Acommodity string `json:"acommodity"`
	// Aprice     any `json:"aprice"`
	Aquantity Quantity `json:"aquantity"`
}

type Posting

type Posting struct {
	Paccount string `json:"paccount"`
	Pamount  []struct {
		Acommodity string `json:"acommodity"`
		// Aprice     any `json:"aprice"`
		Aquantity Quantity `json:"aquantity"`
	} `json:"pamount"`
}

type Quantity

type Quantity struct {
	DecimalMantissa int `json:"decimalMantissa"`
	DecimalPlaces   int `json:"decimalPlaces"`
	FloatingPoint   int `json:"floatingPoint"`
}

type SourceRepo

type SourceRepo struct {
	SourceColumn int    `json:"sourceColumn"`
	SourceLine   int    `json:"sourceLine"`
	SourceName   string `json:"sourceName"`
}

type Style

type Style struct {
	Ascommodityside   string `json:"ascommodityside"`
	Ascommodityspaced bool   `json:"ascommodityspaced"`
	Asdecimalmark     string `json:"asdecimalmark"`
	Asdigitgroups     any    `json:"asdigitgroups"`
	Asprecision       int    `json:"asprecision"`
	Asrounding        string `json:"asrounding"`
}

type Transaction

type Transaction struct {
	// Tcode        string      `json:"tcode"`
	// Tcomment     string      `json:"tcomment"`
	Tdate string `json:"tdate"`
	// Tdate2       any `json:"tdate2"`
	Tdescription string `json:"tdescription"`
	// Tindex       int         `json:"tindex"`
	Tpostings []Posting `json:"tpostings"`
}

type Transactions

type Transactions = []Transaction

Jump to

Keyboard shortcuts

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