A posting is a single debit or credit leg of a journal.
Amounts are always positive; the debit_credit field encodes direction.
Postings only target leaf virtual accounts. Once a journal is posted, its
postings are immutable.
Fields
id—integer()— primary keyjournal_id—integer()— FK tojournalsvirtual_account_id—integer() | nil— FK tovirtual_accountsaccount_code—String.t()— denormalized for audit readability (e.g."ASSETS:CASH:USD:NOSTRO")debit_credit—String.t()—"debit"or"credit"amount—Decimal.t()— always positive (e.g.Decimal.new("1000.00"))currency—String.t()— e.g."USD"memo—String.t() | nilsequence—integer()— ordering within the journal (1-based)metadata—map()— includes the symbolicrole(e.g.%{"role" => "cash_account"})inserted_at/updated_at—DateTime.t()
Rules
- amount is positive; direction encodes sign
debit_creditisdebitorcredit- the posting account must be a leaf, active, posting-allowed account
- the journal must balance per currency
- postings are immutable once the journal is posted
account_codeis denormalized for audit readability butvirtual_account_idremains canonical
Example
%Logistiki.Accounting.Posting{
id: 1,
journal_id: 1,
virtual_account_id: 10,
account_code: "ASSETS:CASH:USD:NOSTRO",
debit_credit: "debit",
amount: Decimal.new("1000.00"),
currency: "USD",
sequence: 1,
metadata: %{"role" => "cash_account"}
}
Summary
Functions
True for a credit posting.
True for a debit posting.
Returns the list of allowed posting directions as atoms.
Returns the signed amount: positive for debit, negative for credit.
Types
@type t() :: %Logistiki.Accounting.Posting{ __meta__: term(), account_code: String.t() | nil, amount: Decimal.t() | nil, currency: String.t() | nil, debit_credit: String.t() | nil, id: integer() | nil, inserted_at: DateTime.t() | nil, journal: term(), journal_id: integer() | nil, memo: String.t() | nil, metadata: map() | nil, sequence: integer() | nil, updated_at: DateTime.t() | nil, virtual_account: term(), virtual_account_id: integer() | nil }
The Posting struct type — a single debit or credit leg of a journal.
Fields
id—integer() | nil— primary key (e.g.1)journal_id—integer() | nil— FK tojournals(e.g.1)virtual_account_id—integer() | nil— FK tovirtual_accounts(e.g.10)account_code—String.t() | nil— denormalized (e.g."ASSETS:CASH:USD:NOSTRO")debit_credit—String.t() | nil—"debit"or"credit"amount—Decimal.t() | nil— always positive (e.g.Decimal.new("1000.00"))currency—String.t() | nil— e.g."USD"memo—String.t() | nil— optional memosequence—integer() | nil— ordering within the journalmetadata—map() | nil— includes the symbolic roleinserted_at—DateTime.t() | nilupdated_at—DateTime.t() | nil
Example
%Logistiki.Accounting.Posting{
id: 1, journal_id: 1, virtual_account_id: 10,
account_code: "ASSETS:CASH:USD:NOSTRO", debit_credit: "debit",
amount: Decimal.new("1000.00"), currency: "USD", sequence: 1
}
Functions
True for a credit posting.
Arguments
posting—%__MODULE__{}or any term.
Returns
boolean()—truewhendebit_credit == "credit".
Examples
iex> Logistiki.Accounting.Posting.credit?(%Logistiki.Accounting.Posting{debit_credit: "credit"})
true
True for a debit posting.
Arguments
posting—%__MODULE__{}or any term.
Returns
boolean()—truewhendebit_credit == "debit".
Examples
iex> Logistiki.Accounting.Posting.debit?(%Logistiki.Accounting.Posting{debit_credit: "debit"})
true
iex> Logistiki.Accounting.Posting.debit?(%Logistiki.Accounting.Posting{debit_credit: "credit"})
false
@spec directions() :: [atom(), ...]
Returns the list of allowed posting directions as atoms.
Returns
[atom()]—[:debit, :credit]
Examples
iex> Logistiki.Accounting.Posting.directions()
[:debit, :credit]
Returns the signed amount: positive for debit, negative for credit.
Arguments
posting—%__MODULE__{}.
Returns
Decimal.t()—amountfor debit,-amountfor credit.
Examples
iex> Logistiki.Accounting.Posting.signed_amount(%Logistiki.Accounting.Posting{amount: Decimal.new("100"), debit_credit: "debit"})
Decimal.new("100")
iex> Logistiki.Accounting.Posting.signed_amount(%Logistiki.Accounting.Posting{amount: Decimal.new("100"), debit_credit: "credit"})
Decimal.new("-100")