View Source Bookk.ChartOfAccounts behaviour (bookk v0.1.3)

A Chart of Accounts (abbrv.: CoA) is a mapping of all the accounts and all the ledgers that can exist in your system. But instead of hard-coding them, you define patterns for accounts and ledgers supported by your application using functions and pattern matching.

For example, if your application allows ledgers to have an account for exampenses from paying salary to an employee, you could define a function with a signature the like the one below:

def account({:salary, {:employee, employee_id}})

And if your application, following the previous example, allows for every employee to have their own ledger, you could define a function with a signature like the one below:

def ledger({:employee, employee_id})

Summary

Callbacks

This function maps all possible patterns of accounts that your application supports. It's recomended to use pattern matching and let it crash in the event of a mismatch.

This function maps all possible patterns of ledger names your application supports. It's recomended to use pattern matching and let it crash in the event of a mismatch.

Callbacks

@callback account(term()) :: Bookk.AccountHead.t()

This function maps all possible patterns of accounts that your application supports. It's recomended to use pattern matching and let it crash in the event of a mismatch.

Examples

def account(:cash), do: %Bookk.AccountHead{...}
def account(:deposits), do: %Bookk.AccountHead{...}
def account({:payables, {:user, id}}), do: %Bookk.AccountHead{...}
def account({:receivables, {:user, id}}), do: %Bookk.AccountHead{...}
@callback ledger(term()) :: String.t()

This function maps all possible patterns of ledger names your application supports. It's recomended to use pattern matching and let it crash in the event of a mismatch.

Example

def ledger(:acme), do: "acme"
def ledger({:user, <<id::binary-size(36)>>}), do: "user(#{id})"