Zerobook. Transaction
(zerobook v0.1.0)
Copy Markdown
A transaction: a set of Zerobook.Entry lines that must balance to zero
per currency (double-entry accounting).
Transactions are immutable, carry a UTC timestamp, an optional external
reference (e.g. your own order/payment id — uniqueness is enforced by the
ledger, not here), and an optional human description.
Summary
Functions
Validates the transaction and returns {:ok, tx} or
{:error, {:unbalanced, currency, total}}.
Creates a transaction, validating that entries balance to zero in every currency.
Returns :ok when the transaction balances (sums to zero in every
currency), otherwise {:error, reason} with the offending balances.
Types
@type t() :: %Zerobook.Transaction{ description: String.t() | nil, entries: [Zerobook.Entry.t()], id: String.t(), reference: String.t() | nil, timestamp: DateTime.t() }
Functions
Validates the transaction and returns {:ok, tx} or
{:error, {:unbalanced, currency, total}}.
Creates a transaction, validating that entries balance to zero in every currency.
Examples
iex> tx = Zerobook.Transaction.new("txn_1", [
...> Zerobook.Entry.new("1000.cash", 1_000, "BRL"),
...> Zerobook.Entry.new("2000.revenue", -1_000, "BRL")
...> ])
iex> tx.id
"txn_1"
Returns :ok when the transaction balances (sums to zero in every
currency), otherwise {:error, reason} with the offending balances.