ledger

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionStockUnits added in v0.10.0

func ActionStockUnits(ledgerName string, stockTransaction StockTransaction) error

ActionStockUnits adds stock purchase/redeem related transactions to the database

func AddAccount

func AddAccount(ledger string, account Account) error

AddAccount adds the given account to the database

func AddCategory

func AddCategory(ledger string, category Category) error

AddCategory adds the given category to the database

func AddLedger

func AddLedger()

func AddStock added in v0.10.0

func AddStock(ledger string, stock Stock) error

AddAccount adds the given account to the database

func AddTransaction

func AddTransaction(ledgerName string, transaction Transaction) error

AddTransaction adds a transaction to the database

func DeleteTransaction added in v0.5.0

func DeleteTransaction(ledgerName string, transactionID int) error

DeleteTransaction deletes a transaction from the database and updates the account balance

func FormatAccounts

func FormatAccounts(accounts []*Account, prefix string) []string

FormatAccounts takes a slice of Account struct and returns a slice of string with account names prefixed with appropriate spaces to give it a nested list look

func FormatCategories

func FormatCategories(categories []*Category, prefix string) []string

FormatCategories takes a slice of Category struct and returns a slice of string with category names prefixed with appropriate spaces to give it a nested list look

func GetAccountBalance added in v0.13.0

func GetAccountBalance(accounts []*Account, accountName string) float64

getAccountBalance calculates the total balance for a given account accumulates balances from all child accounts if its a placeholder account

func GetAccountID added in v0.7.0

func GetAccountID(accountName string, accounts []*Account) int

GetAccountID returns the account id of the given account

func GetAccountType added in v0.9.0

func GetAccountType(accountName string, accounts []*Account) string

GetAccountType returns the account type of the given account

func GetCategoryID added in v0.7.0

func GetCategoryID(categoryName string, categories []*Category) int

GetCategoryID returns the category id of the given category name

func GetCategoryType added in v0.9.0

func GetCategoryType(categoryName string, categories []*Category) string

GetCategoryType returns the category type of the given category name

func GetChildAccountIDs added in v0.3.0

func GetChildAccountIDs(accountID int, accounts []*Account) []int

GetChildAccountIDs returns a slice of IDs of all the child accounts for the given account

func GetChildCategoryIDs

func GetChildCategoryIDs(categoryID int, categories []*Category) []int

GetChildCategoryIDs returns a slice of IDs of all the child categories for the given category

func GetCurrencyForLedger

func GetCurrencyForLedger(ledgerName string) string

func GetLedgersList

func GetLedgersList() ([]string, error)

func GetStockCodesList added in v0.10.0

func GetStockCodesList(stocks []*Stock) []string

GetStockCodesList returns a slice of string with stock codes

func GetStockID added in v0.10.0

func GetStockID(stockName string, stocks []*Stock) int

GetStockID returns the stock id of the given stock

func GetStockNamesList added in v0.10.0

func GetStockNamesList(stocks []*Stock) []string

GetStockNamesList returns a slice of string with stock names

func GetStockType added in v0.10.0

func GetStockType(stockName string, stocks []*Stock) string

GetStockType returns the stock type of the given stock

func GoldStocksFound added in v0.10.2

func GoldStocksFound(stocks []*Stock) bool

func IsPlaceHolderAccount added in v0.9.0

func IsPlaceHolderAccount(accountName string, accounts []*Account) bool

IsPlaceHolderAccount returns true if the given account is a placeholder account, false otherwise

func IsPlaceHolderCategory added in v0.7.1

func IsPlaceHolderCategory(categoryID int, categories []*Category) bool

IsPlaceHolderCategory returns true if the given category is a placeholder category, false otherwise

func IsValidLedger

func IsValidLedger(ledgerName string) bool

func ToggleStockStatus added in v0.10.0

func ToggleStockStatus(ledgerName string, stockID int, currStatus string) error

func TransferFunds

func TransferFunds(fromLedger string, toLedger string, transactions []Transaction) error

TransferFunds adds transfer transactions contained in a slice of Transaction struct to database

func UpdateGoldPrice added in v0.10.2

func UpdateGoldPrice(ledgerName string) error

func UpdateNAVs added in v0.10.0

func UpdateNAVs(ledgerName string, stockCodesList []string) error

Types

type Account

type Account struct {
	ID             int
	Name           string
	Type           string
	OpeningBalance float64
	Balance        float64
	Placeholder    int
	ParentID       int
	Children       []*Account
}

An Account is a representation of a record from the accounts table

func FetchAccounts

func FetchAccounts(ledger string, accountType string, placeholder bool) ([]*Account, error)

FetchAccounts fetches account records for the given ledger from the database and returns a slice of Account struct.

If placeholder is true, only records where placeholder is set to 1 is fetched.

If accountType is set to either asset or liability, only those records are fetched.

type Category

type Category struct {
	ID          int
	Name        string
	Type        string
	Placeholder int
	ParentID    int
	Children    []*Category
}

A Category is a representation of a record from the categories table

func FetchCategories

func FetchCategories(ledger string, categoryType string, placeholder bool) ([]*Category, error)

FetchCategories fetches category records for the given ledger from the database and returns a slice of Category struct.

If placeholder is true, only records where placeholder is set to 1 is fetched.

If categoryType is set to either income or expense, only those records are fetched.

type InvestmentStatus added in v0.12.0

type InvestmentStatus struct {
	MFInvested     float64
	MFValue        float64
	GoldInvested   float64
	GoldValue      float64
	OthersInvested float64
	OthersValue    float64
}

type Ledger

type Ledger struct {
	Name     string
	Currency string
}

func FetchLedgers

func FetchLedgers() ([]*Ledger, error)

type SplitTransaction

type SplitTransaction struct {
	ID             int
	Date           time.Time
	Notes          string
	Credit         float64
	Debit          float64
	AccountID      int
	Account        string
	CategoryID     int
	Category       *string
	CurrencySymbol string
	ParentID       int
}

A SplitTransaction is a representation of a record from the split_transactions table

func GetSplitsForTransaction

func GetSplitsForTransaction(ledgerName string, transactionID int) ([]SplitTransaction, error)

GetSplitsForTransaction fetches all split transactions for a given transaction id and returns them as a slice of SplitTransaction

type StatsData

type StatsData struct {
	Period string
	Amount float64
}

A StatsData represents a period and an amount of money

func FetchCategoryStatsData

func FetchCategoryStatsData(ledgerName string, category string, period string, count int) ([]*StatsData, error)

FetchCategoryStatsData returns a slice of StatsData struct for the given period for the given category for the given count.

Period can be either "monthly" or "yearly"

func FetchIncomeExpenseStatsData

func FetchIncomeExpenseStatsData(ledgerName string, incomeOrExpense string, period string, count int) ([]*StatsData, error)

FetchIncomeExpenseStatsData returns a slice of StatsData of either income or expense for the given period for given count

type Stock added in v0.10.0

type Stock struct {
	ID       int
	Name     string
	Type     string
	Code     string
	Plan     string
	Status   string
	Units    float64
	Nav      float64
	NavDate  string
	Invested float64
}

A stock is a representation of a record from the stocks table

func FetchStocks added in v0.10.0

func FetchStocks(ledger string, stockStatus string) ([]*Stock, error)

FetchStocks fetches stock records for the given ledger from the database and returns a slice of Stock struct.

type StockTransaction added in v0.10.0

type StockTransaction struct {
	TransactionType string
	StockID         int
	StockName       string
	Date            time.Time
	Units           float64
	Nav             float64
	Amount          float64
	BankAccountID   int
	BankName        *string
}

func GetTransactionsForStock added in v0.10.0

func GetTransactionsForStock(ledgerName string, stockID int) ([]StockTransaction, error)

GetTransactionsForStock fetches transactions for the given stock from the database and returns them as a slice of StockTransaction struct

type Transaction

type Transaction struct {
	ID             int
	Date           time.Time
	Notes          string
	Credit         float64
	Debit          float64
	AccountID      int
	Account        string
	CategoryID     int
	Category       *string
	CurrencySymbol string
	IsSplit        int
	Splits         []SplitTransaction
}

A Transaction is a representation of a record from the transactions table

func GetTransaction added in v0.5.0

func GetTransaction(ledgerName string, transactionID int) (Transaction, error)

GetTransaction returns a transaction matching given transaction id in a Transaction struct

func GetTransactionsForAccount

func GetTransactionsForAccount(ledgerName string, accountName string, limit int) ([]Transaction, error)

GetTransactionsForAccount fetches transactions for the given account from the database and returns them as a slice of Transaction struct

func GetTransactionsForCategory

func GetTransactionsForCategory(ledgerName string, category string, limit int) ([]Transaction, error)

GetTransactionsForCategory fetches transactions for the given category from the database and returns them as a slice of Transaction struct

func GetTransactionsForKeywords added in v0.4.0

func GetTransactionsForKeywords(ledgerName string, keywords string) ([]Transaction, error)

GetTransactionsForKeywords fetches transactions matching the keywords and returns them as a slice of Transaction struct

Jump to

Keyboard shortcuts

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