ledger

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 AddTransaction

func AddTransaction(ledgerName string, transaction Transaction) error

AddTransaction adds a transaction to the database

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 GetChildCategoryIDs added in v0.1.1

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 IsPlaceholderAccount

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

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

func IsValidLedger

func IsValidLedger(ledgerName string) bool

func TransferFunds

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

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

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.

func PromptForNewAccount

func PromptForNewAccount(ledger string) Account

PromptForNewAccount gathers new account details from the user and returns an Account struct which can then be added to the database

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.

func PromptForNewCategory

func PromptForNewCategory(ledger string) Category

PromptForNewCategory gathers new category details from the user and returns an Category struct which can then be added to the database

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 added in v0.1.1

type StatsData struct {
	Period string
	Amount float64
}

A StatsData represents a period and an amount of money

func FetchCategoryStatsData added in v0.1.1

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 added in v0.1.1

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 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 GetTransactionsForAccount added in v0.1.1

func GetTransactionsForAccount(ledgerName string, account 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 PromptForNewTransaction

func PromptForNewTransaction(ledgerName string, transactionType string) Transaction

PromptForNewTransaction gathers details of new transaction from user into A Transaction struct, which can then be added to the database.

transactionType is either income or expense

func PromptForNewTransfer

func PromptForNewTransfer(ledgerName string) (string, []Transaction)

PromptForNewTransfer gathers details of a new transfer from user into a slice of Transaction struct, which can then be added to the database

Jump to

Keyboard shortcuts

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