accounting

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AccountMgr is the account manager instance used in all rest endpoint
	AccountMgr acccore.AccountManager

	// JournalMgr is the journal manager instance used in all rest endpoint
	JournalMgr acccore.JournalManager

	// TransactionMgr is the transaction manager instance used in all rest endpoint
	TransactionMgr acccore.TransactionManager

	// ExchangeMgr is the exchange manager instance used in all rest endpoint
	ExchangeMgr acccore.ExchangeManager

	// UniqueIDGenerator is the UniqueIDGenerator instance used in all rest endpoint
	UniqueIDGenerator acccore.UniqueIDGenerator

	// ErrRestPathInvalid base error used to indicate if a URL path is not valid
	ErrRestPathInvalid = errors.New("invalid path error")

	// RestTimeFormat data format for all time.Time typed json string.
	RestTimeFormat = "2006-01-02T15:04:05"
)

Functions

func CalculateExchange

func CalculateExchange(w http.ResponseWriter, r *http.Request)

CalculateExchange calculates the exchange betwee two currencies

func CalculateExchangeRate

func CalculateExchangeRate(w http.ResponseWriter, r *http.Request)

CalculateExchangeRate calculates the exchange rate

func CreateAccount

func CreateAccount(w http.ResponseWriter, r *http.Request)

CreateAccount creates an account

func CreateJournal

func CreateJournal(w http.ResponseWriter, r *http.Request)

CreateJournal creates a journal

func CreateReversalJournal

func CreateReversalJournal(w http.ResponseWriter, r *http.Request)

CreateReversalJournal creates a reversal journal response

func DrawAccount

func DrawAccount(w http.ResponseWriter, r *http.Request)

DrawAccount draws the account activity

func DrawJournal

func DrawJournal(w http.ResponseWriter, r *http.Request)

DrawJournal draws the journal activity for easier debugging

func FindAccount

func FindAccount(w http.ResponseWriter, r *http.Request)

FindAccount searches for a given account id

func GetAccount

func GetAccount(w http.ResponseWriter, r *http.Request)

GetAccount is the controller to handle retrieval of single account

func GetCommonDenominator

func GetCommonDenominator(w http.ResponseWriter, r *http.Request)

GetCommonDenominator returns the current common denominator

func GetCurrency

func GetCurrency(w http.ResponseWriter, r *http.Request)

GetCurrency gets the currency details

func GetJournal

func GetJournal(w http.ResponseWriter, r *http.Request)

GetJournal fetches a journal from journal ID

func GetTransaction

func GetTransaction(w http.ResponseWriter, r *http.Request)

GetTransaction retrieves a transaction from its ID

func ListCurrencies

func ListCurrencies(w http.ResponseWriter, r *http.Request)

ListCurrencies lists all the currency

func ListJournal

func ListJournal(w http.ResponseWriter, r *http.Request)

ListJournal lists the journal given

func ListTransactionByAccount

func ListTransactionByAccount(w http.ResponseWriter, r *http.Request)

ListTransactionByAccount lists transactions given an account

func NewMySQLAccountManager

func NewMySQLAccountManager(repo connector.DBRepository) acccore.AccountManager

NewMySQLAccountManager returns new sql account manager

func NewMySQLExchangeManager

func NewMySQLExchangeManager(repo connector.DBRepository) acccore.ExchangeManager

NewMySQLExchangeManager new sqlexcnage amanager

func NewMySQLJournalManager

func NewMySQLJournalManager(repo connector.DBRepository) acccore.JournalManager

NewMySQLJournalManager returns the sql journal manager

func NewMySQLTransactionManager

func NewMySQLTransactionManager(repo connector.DBRepository) acccore.TransactionManager

NewMySQLTransactionManager returns new SQL Transaction Manager

func SetCommonDenominator

func SetCommonDenominator(w http.ResponseWriter, r *http.Request)

SetCommonDenominator sets the common denominator

func SetCurrency

func SetCurrency(w http.ResponseWriter, r *http.Request)

SetCurrency sets the currency details

Types

type AccountEntity

type AccountEntity struct {
	AccountNo   string `json:"account_number"`
	Name        string `json:"name"`
	Description string `json:"description"`
	COA         string `json:"coa"`
	Currency    string `json:"currency"`
	Alignment   string `json:"alignment"`
	Balance     int64  `json:"balance"`
}

AccountEntity is the structure of response body that contains an account

type AccountItemsResponseBody

type AccountItemsResponseBody struct {
	AccountNumber string `json:"account_number"`
	Name          string `json:"name"`
	Description   string `json:"description"`
	COA           string `json:"coa"`
	Currency      string `json:"currency"`
	Alignment     string `json:"alignment"`
	Balance       int64  `json:"balance"`
}

AccountItemsResponseBody response for account items

type AccountResponseBody

type AccountResponseBody struct {
	AccountNumber string `json:"account_number"`
	Name          string `json:"name"`
	Description   string `json:"description"`
	COA           string `json:"coa"`
	Currency      string `json:"currency"`
	Alignment     string `json:"alignment"`
	Creator       string `json:"creator"`
}

AccountResponseBody with the account details

type CreateJournalRequest

type CreateJournalRequest struct {
	Description  string                `json:"description"`
	Creator      string                `json:"creator"`
	Transactions []*TransactionRequest `json:"transactions"`
}

CreateJournalRequest is the create journal request paylaod

type CreateReversalRequest

type CreateReversalRequest struct {
	Description string `json:"description"`
	JournalID   string `json:"journal_id"`
	Creator     string `json:"creator"`
}

CreateReversalRequest is the create reversal request payload

type CurrencyRet

type CurrencyRet struct {
	Code     string  `json:"code"`
	Name     string  `json:"name"`
	Exchange float64 `json:"exchange"`
}

CurrencyRet is the currency respose

type JournalDetail

type JournalDetail struct {
	JournalID       string `json:"journal_id"`
	JournalingTime  string `json:"journaling_time"`
	Description     string `json:"description"`
	Reversal        bool   `json:"reversal"`
	ReversedJournal string `json:"reversed_journal"`
	Amount          int64  `json:"amount"`
	Transactions    []*TransactionListItem
	CreateTime      string `json:"create_time"`
	CreateBy        string `json:"create_by"`
}

JournalDetail is the journal detail struct

type MySQLAccountManager

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

MySQLAccountManager implementation of AccountManager using Account table in MySQL

func (*MySQLAccountManager) FindAccounts

func (am *MySQLAccountManager) FindAccounts(ctx context.Context, nameLike string, request acccore.PageRequest) (acccore.PageResult, []acccore.Account, error)

FindAccounts returns list of accounts that have their name contains a substring of specified parameter. this search should be case insensitive.

func (*MySQLAccountManager) GetAccountByID

func (am *MySQLAccountManager) GetAccountByID(ctx context.Context, id string) (acccore.Account, error)

GetAccountByID retrieve an account information by specifying the ID/number

func (*MySQLAccountManager) IsAccountIDExist

func (am *MySQLAccountManager) IsAccountIDExist(ctx context.Context, id string) (bool, error)

IsAccountIDExist will check if an account ID/number is exist in the database.

func (*MySQLAccountManager) ListAccountByCOA

func (am *MySQLAccountManager) ListAccountByCOA(ctx context.Context, coa string, request acccore.PageRequest) (acccore.PageResult, []acccore.Account, error)

ListAccountByCOA returns list of accounts that have the same COA number. This function uses pagination

func (*MySQLAccountManager) ListAccounts

ListAccounts list all account in the database. This function uses pagination

func (*MySQLAccountManager) NewAccount

func (am *MySQLAccountManager) NewAccount(ctx context.Context) acccore.Account

NewAccount will create a new blank un-persisted account.

func (*MySQLAccountManager) PersistAccount

func (am *MySQLAccountManager) PersistAccount(ctx context.Context, AccountToPersist acccore.Account) error

PersistAccount will save the account into database. will throw error if the account already persisted

func (*MySQLAccountManager) UpdateAccount

func (am *MySQLAccountManager) UpdateAccount(ctx context.Context, AccountToUpdate acccore.Account) error

UpdateAccount will update the account database to reflect to the provided account information. This update account function will fail if the account ID/number is not existing in the database.

type MySQLExchangeManager

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

MySQLExchangeManager is the manager struct

func (*MySQLExchangeManager) CalculateExchange

func (am *MySQLExchangeManager) CalculateExchange(ctx context.Context, fromCurrency, toCurrency string, amount int64) (int64, error)

CalculateExchange gets the currency exchange value for the amount of fromCurrency into toCurrency. If any of the currency is not exist, an error should be returned. if from and to currency is equal, the returned amount must be equal to the amount in the argument.

func (*MySQLExchangeManager) CalculateExchangeRate

func (am *MySQLExchangeManager) CalculateExchangeRate(ctx context.Context, fromCurrency, toCurrency string) (*big.Float, error)

CalculateExchangeRate Get the currency exchange rate for exchanging between the two currency. if any of the currency is not exist, an error should be returned. if from and to currency is equal, this must return 1.0

func (*MySQLExchangeManager) CreateCurrency

func (am *MySQLExchangeManager) CreateCurrency(ctx context.Context, code, name string, exchange *big.Float, author string) (acccore.Currency, error)

CreateCurrency set the specified value as denominator value for that speciffic Currency. This function should return error if the Currency specified is not exist.

func (*MySQLExchangeManager) GetCurrency

func (am *MySQLExchangeManager) GetCurrency(ctx context.Context, code string) (acccore.Currency, error)

GetCurrency retrieve currency data indicated by the code argument

func (*MySQLExchangeManager) GetDenom

func (am *MySQLExchangeManager) GetDenom(ctx context.Context) *big.Float

GetDenom get the current common denominator used in the exchange

func (*MySQLExchangeManager) IsCurrencyExist

func (am *MySQLExchangeManager) IsCurrencyExist(ctx context.Context, currency string) (bool, error)

IsCurrencyExist will check in the exchange system for a currency existence non-existent currency means that the currency is not supported. error should be thrown if only there's an underlying error such as db error.

func (*MySQLExchangeManager) ListCurrencies

func (am *MySQLExchangeManager) ListCurrencies(ctx context.Context) ([]acccore.Currency, error)

ListCurrencies will list all currencies.

func (*MySQLExchangeManager) SetDenom

func (am *MySQLExchangeManager) SetDenom(ctx context.Context, denom *big.Float)

SetDenom set the current common denominator value into the specified value

func (*MySQLExchangeManager) UpdateCurrency

func (am *MySQLExchangeManager) UpdateCurrency(ctx context.Context, code string, currency acccore.Currency, author string) error

UpdateCurrency updates the currency data Error should be returned if the specified Currency is not exist.

type MySQLJournalManager

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

MySQLJournalManager implementation of JournalManager using Journal table in MySQL

func (*MySQLJournalManager) CancelJournal

func (jm *MySQLJournalManager) CancelJournal(ctx context.Context, journalToCancel acccore.Journal) error

CancelJournal Cancel a journal Only non committed journal can be committed. use this if the implementation database do not support 2 phased commit. if your database do not support 2 phased commit, you should do all roll back in the PersistJournal function and this function should simply return nil.

func (*MySQLJournalManager) CommitJournal

func (jm *MySQLJournalManager) CommitJournal(ctx context.Context, journalToCommit acccore.Journal) error

CommitJournal will commit the journal into the system Only non committed journal can be committed. use this if the implementation database do not support 2 phased commit. if your database support 2 phased commit, you should do all commit in the PersistJournal function and this function should simply return nil.

func (*MySQLJournalManager) GetJournalByID

func (jm *MySQLJournalManager) GetJournalByID(ctx context.Context, journalID string) (acccore.Journal, error)

GetJournalByID retrieved a Journal information identified by its ID. the provided ID must be exactly the same, not uses the LIKE select expression.

func (*MySQLJournalManager) IsJournalIDExist

func (jm *MySQLJournalManager) IsJournalIDExist(ctx context.Context, journalID string) (bool, error)

IsJournalIDExist will check if a journal ID/number exist in the database.

func (*MySQLJournalManager) IsJournalIDReversed

func (jm *MySQLJournalManager) IsJournalIDReversed(ctx context.Context, journalID string) (bool, error)

IsJournalIDReversed check if the journal with specified ID has been reversed

func (*MySQLJournalManager) ListJournals

func (jm *MySQLJournalManager) ListJournals(ctx context.Context, from time.Time, until time.Time, request acccore.PageRequest) (acccore.PageResult, []acccore.Journal, error)

ListJournals retrieve list of journals with transaction date between the `from` and `until` time range inclusive. This function uses pagination.

func (*MySQLJournalManager) NewJournal

func (jm *MySQLJournalManager) NewJournal(ctx context.Context) acccore.Journal

NewJournal will create new blank un-persisted journal

func (*MySQLJournalManager) PersistJournal

func (jm *MySQLJournalManager) PersistJournal(ctx context.Context, journalToPersist acccore.Journal) error

PersistJournal will record a journal entry into database. It requires list of transactions for which each of the transaction MUST BE :

1.NOT BE PERSISTED. (the journal accountNumber is not exist in DB yet)
2.Pointing or owned by a PERSISTED Account
3.Each of this account must belong to the same Currency
4.Balanced. The total sum of DEBIT and total sum of CREDIT is equal.
5.No duplicate transaction that belongs to the same Account.

If your database support 2 phased commit, you can make all balance changes in accounts and transactions. If your db do not support this, you can implement your own 2 phase commits mechanism on the CommitJournal and CancelJournal

func (*MySQLJournalManager) RenderJournal

func (jm *MySQLJournalManager) RenderJournal(ctx context.Context, journal acccore.Journal) string

RenderJournal Render this journal into string for easy inspection

type MySQLTransactionManager

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

MySQLTransactionManager implementation of TransactionManager using Transaction table in MySQL

func (*MySQLTransactionManager) GetTransactionByID

func (am *MySQLTransactionManager) GetTransactionByID(ctx context.Context, id string) (acccore.Transaction, error)

GetTransactionByID will retrieve one single transaction that identified by some ID

func (*MySQLTransactionManager) IsTransactionIDExist

func (am *MySQLTransactionManager) IsTransactionIDExist(ctx context.Context, id string) (bool, error)

IsTransactionIDExist will check if an Transaction ID/number is exist in the database.

func (*MySQLTransactionManager) ListTransactionsOnAccount

func (am *MySQLTransactionManager) ListTransactionsOnAccount(ctx context.Context, from time.Time, until time.Time, account acccore.Account, request acccore.PageRequest) (acccore.PageResult, []acccore.Transaction, error)

ListTransactionsOnAccount retrieves list of transactions that belongs to this account that transaction happens between the `from` and `until` time range. This function uses pagination

func (*MySQLTransactionManager) NewTransaction

func (am *MySQLTransactionManager) NewTransaction(ctx context.Context) acccore.Transaction

NewTransaction will create new blank un-persisted Transaction

func (*MySQLTransactionManager) RenderTransactionsOnAccount

func (am *MySQLTransactionManager) RenderTransactionsOnAccount(ctx context.Context, from time.Time, until time.Time, account acccore.Account, request acccore.PageRequest) (string, error)

RenderTransactionsOnAccount Render list of transaction been down on an account in a time span

type NewAccountEntity

type NewAccountEntity struct {
	AccountNo   string `json:"account_number"`
	Name        string `json:"name"`
	Description string `json:"description"`
	COA         string `json:"coa"`
	Currency    string `json:"currency"`
	Alignment   string `json:"alignment"`
	Creator     string `json:"creator"`
}

NewAccountEntity is the structure of request body for creating new Account

type PageResultBody

type PageResultBody struct {
	RequestPage  int  `json:"request_page"`
	RequestSize  int  `json:"request_size"`
	TotalEntries int  `json:"total_entries"`
	TotalPages   int  `json:"total_pages"`
	Page         int  `json:"page"`
	PageSize     int  `json:"page_size"`
	NextPage     int  `json:"next_page"`
	PreviousPage int  `json:"previous_page"`
	LastPage     int  `json:"last_page"`
	FirstPage    int  `json:"first_page"`
	IsFirst      bool `json:"is_first"`
	IsLast       bool `json:"is_last"`
	HavePrevious bool `json:"have_previous"`
	HaveNext     bool `json:"have_next"`
	Offset       int  `json:"offset"`
}

PageResultBody is the pagination payload

func FromAccorePageResult

func FromAccorePageResult(pr acccore.PageResult) *PageResultBody

FromAccorePageResult returns the pagination detail

type PaginatedJournalsResponse

type PaginatedJournalsResponse struct {
	Journals   []acccore.Journal  `json:"journals"`
	Pagination acccore.PageResult `json:"pagination"`
}

PaginatedJournalsResponse is the journal response paginated

type PaginatedResponse

type PaginatedResponse struct {
	Items      interface{}
	Pagination acccore.PageResult
}

PaginatedResponse is the structure of stuff that requires pagination

type SetCurrencyBody

type SetCurrencyBody struct {
	Name     string  `json:"name"`
	Exchange float64 `json:"exchange"`
	Author   string  `json:"author"`
}

SetCurrencyBody is the set currency request payload

type TransactionListItem

type TransactionListItem struct {
	TransactionID   string `json:"transaction_id"`
	TransactionTime string `json:"transaction_time"`
	AccountNumber   string `json:"account_number"`
	JournalID       string `json:"journal_id"`
	Description     string `json:"description"`
	TransactionType string `json:"transaction_type"`
	Amount          int64  `json:"amount"`
	AccountBalance  int64  `json:"account_balance"`
	CreateTime      string `json:"create_time"`
	CreateBy        string `json:"create_by"`
}

TransactionListItem is the transaction detail

type TransactionListResponse

type TransactionListResponse struct {
	Transactions []*TransactionListItem `json:"transactions"`
	Pagination   acccore.PageResult     `json:"pagination"`
}

TransactionListResponse is the structure response

type TransactionRequest

type TransactionRequest struct {
	AccountNumber string `json:"account_number"`
	Description   string `json:"description"`
	Alignment     string `json:"alignment"`
	Amount        int64  `json:"amount"`
}

TransactionRequest is the create transaction request payload

Jump to

Keyboard shortcuts

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