The context for internal accounting artifacts: journals and postings.
Applications should normally publish business events (Logistiki.process/1)
rather than calling these functions directly. The functions here are exposed
for tests, migration, support tools, and controlled administrative
operations.
Summary
Functions
Administrative helper to build a draft journal directly from attrs (for tests, migration, and support tools). Not the normal application-facing API.
Fetches a journal by id.
Fetches a journal by id, raising if not found.
Lists journals, optionally filtered, with postings preloaded.
Lists postings for journal, ordered by sequence.
Posts a draft journal and its postings.
Reverses a posted journal by creating a new posted reversal journal that
exactly negates the original postings, and marks the original reversed.
Functions
Administrative helper to build a draft journal directly from attrs (for tests, migration, and support tools). Not the normal application-facing API.
Fetches a journal by id.
Arguments
id—integer()— the journal primary key.
Returns
{:ok, %Journal{}}— the journal with postings preloaded.{:error, :not_found}— no journal with that id.
Examples
iex> {:ok, journal} = Logistiki.Accounting.get_journal(1)
iex> journal.status
"posted"
iex> {:error, :not_found} = Logistiki.Accounting.get_journal(999)
Fetches a journal by id, raising if not found.
Arguments
id—integer()— the journal primary key.
Returns
%Journal{}— the journal with postings preloaded. RaisesEcto.NoResultsErrorif not found.
Examples
iex> journal = Logistiki.Accounting.get_journal!(1)
iex> journal.status
"posted"
iex> journal.postings
[%Posting{...}, %Posting{...}]
Lists journals, optionally filtered, with postings preloaded.
Arguments
opts—keyword()of options::status—String.t— e.g."posted","draft","reversed":event_id—String.t— filter by originating event id
Returns
[Journal.t()]— ordered byinserted_atdescending, with:postingspreloaded. Empty list if none match.
Examples
iex> Logistiki.Accounting.list_journals(status: "posted")
[%Journal{status: "posted", postings: [%Posting{...}, ...]}, ...]
iex> Logistiki.Accounting.list_journals(event_id: "evt_001")
[%Journal{event_id: "evt_001", ...}]
Lists postings for journal, ordered by sequence.
Arguments
journal—%Journal{}— the journal whose postings to list.
Returns
[Posting.t()]— ordered bysequenceascending.
Examples
iex> Logistiki.Accounting.list_postings(journal)
[%Posting{sequence: 1, ...}, %Posting{sequence: 2, ...}]
Posts a draft journal and its postings.
Validates the full invariant set, resolves virtual_account_id for each
posting from its account_code, then inserts the journal (status posted)
and its postings in a single transaction.
Returns {:ok, posted_journal} or {:error, %Logistiki.Error{}}.
Reverses a posted journal by creating a new posted reversal journal that
exactly negates the original postings, and marks the original reversed.
Returns {:ok, reversal_journal} or {:error, %Logistiki.Error{}}.