Logistiki.Ledger (logistiki v0.1.0)

Copy Markdown View Source

The context for ledger backends.

The runtime calls the configured backend (see config :logistiki, :ledger_backend) to execute journals, reverse them, and compute projections. Backends implement Logistiki.Ledger.Behaviour.

Summary

Functions

Returns the configured ledger backend module.

Returns the list of available backends.

Computes a balance through the configured backend.

Executes a journal through the configured backend.

Sets the ledger backend at runtime (mainly for tests).

Reverses a journal through the configured backend.

Computes a statement through the configured backend.

Computes a trial balance through the configured backend.

Functions

backend()

(since 0.1.0)
@spec backend() :: module()

Returns the configured ledger backend module.

Returns

Examples

iex> Logistiki.Ledger.backend()
Logistiki.Ledger.Simulation

backends()

(since 0.1.0)
@spec backends() :: [module(), ...]

Returns the list of available backends.

Returns

  • [module()][Logistiki.Ledger.Simulation, Logistiki.Ledger.Beancount].

Examples

iex> Logistiki.Ledger.backends()
[Logistiki.Ledger.Simulation, Logistiki.Ledger.Beancount]

balance(account, opts \\ [])

(since 0.1.0)

Computes a balance through the configured backend.

Arguments

  • accountVirtualAccount.t() | String.t() | integer() — account struct, code, or id.

  • optskeyword() — e.g. [currency: "USD"].

Returns

  • {:ok, [Logistiki.Projections.Balance.t()]} — balances per currency.

Examples

iex> {:ok, [balance]} = Logistiki.Ledger.balance("ASSETS:CASH:USD:NOSTRO")
iex> balance.net
Decimal.new("1000.00")

execute_journal(journal, opts \\ [])

(since 0.1.0)
@spec execute_journal(
  Logistiki.Accounting.Journal.t(),
  keyword()
) :: {:ok, Logistiki.Ledger.Result.t()} | {:error, term()}

Executes a journal through the configured backend.

Arguments

  • journalJournal.t() — the draft journal with postings attached.
  • optskeyword() — backend-specific options (e.g. [currency: "USD"]).

Returns

  • {:ok, Logistiki.Ledger.Result.t()} — the backend result.
  • {:error, term()} — execution failed.

Examples

iex> {:ok, result} = Logistiki.Ledger.execute_journal(journal)
iex> result.status
:ok

put_backend(module)

(since 0.1.0)
@spec put_backend(module()) :: :ok

Sets the ledger backend at runtime (mainly for tests).

Arguments

Examples

iex> Logistiki.Ledger.put_backend(Logistiki.Ledger.Beancount)
:ok

reverse_journal(journal, attrs \\ %{}, opts \\ [])

(since 0.1.0)
@spec reverse_journal(Logistiki.Accounting.Journal.t(), map(), keyword()) ::
  {:ok, Logistiki.Ledger.Result.t()} | {:error, term()}

Reverses a journal through the configured backend.

Arguments

  • journalJournal.t() — the posted journal to reverse.
  • attrsmap() — reversal attributes (e.g. %{reason: "mistaken fee"}).
  • optskeyword() — backend-specific options.

Returns

  • {:ok, Logistiki.Ledger.Result.t()} — the reversal result.
  • {:error, term()} — reversal failed.

Examples

iex> {:ok, result} = Logistiki.Ledger.reverse_journal(journal, %{reason: "mistaken fee"})
iex> result.status
:ok

statement(account, opts \\ [])

(since 0.1.0)

Computes a statement through the configured backend.

Arguments

  • accountVirtualAccount.t() | String.t() | integer().

  • optskeyword() — e.g. [currency: "USD"].

Returns

  • {:ok, [Logistiki.Projections.StatementLine.t()]} — ordered lines.

Examples

iex> {:ok, lines} = Logistiki.Ledger.statement("LIABILITIES:CLIENT_DEPOSITS:USD:ACME:OPERATING")
iex> hd(lines).running_balance
Decimal.new("-1000.00")

trial_balance(opts \\ [])

(since 0.1.0)
@spec trial_balance(keyword()) :: {:ok, Logistiki.Projections.TrialBalance.t()}

Computes a trial balance through the configured backend.

Arguments

  • optskeyword() — e.g. [currency: "USD"].

Returns

  • {:ok, Logistiki.Projections.TrialBalance.t()} — with lines, currencies, balanced.

Examples

iex> {:ok, tb} = Logistiki.Ledger.trial_balance()
iex> tb.balanced
true