hledger-lib-0.26: Core data types, parsers and utilities for the hledger accounting tool.

Safe HaskellNone
LanguageHaskell2010

Hledger.Data.Journal

Contents

Description

A Journal is a set of transactions, plus optional related data. This is hledger's primary data object. It is usually parsed from a journal file or other data format (see Hledger.Read).

Synopsis

Parsing helpers

journalApplyAliases :: [AccountAlias] -> Journal -> Journal Source

Apply additional account aliases (eg from the command-line) to all postings in a journal.

journalBalanceTransactions :: Journal -> Either String Journal Source

Fill in any missing amounts and check that all journal transactions balance, or return an error message. This is done after parsing all amounts and working out the canonical commodities, since balancing depends on display precision. Reports only the first error encountered.

journalCanonicaliseAmounts :: Journal -> Journal Source

Convert all the journal's posting amounts (not price amounts) to their canonical display settings. Ie, all amounts in a given commodity will use (a) the display settings of the first, and (b) the greatest precision, of the posting amounts in that commodity.

journalConvertAmountsToCost :: Journal -> Journal Source

Convert all this journal's amounts to cost by applying their prices, if any.

journalFinalise :: ClockTime -> LocalTime -> FilePath -> String -> JournalContext -> Bool -> Journal -> Either String Journal Source

Do post-parse processing on a journal to make it ready for use: check all transactions balance, canonicalise amount formats, close any open timelog entries, maybe check balance assertions and so on.

Filtering

filterJournalTransactions :: Query -> Journal -> Journal Source

Keep only transactions matching the query expression.

filterJournalPostings :: Query -> Journal -> Journal Source

Keep only postings matching the query expression. This can leave unbalanced transactions.

filterJournalAmounts :: Query -> Journal -> Journal Source

Within each posting's amount, keep only the parts matching the query. This can leave unbalanced transactions.

filterTransactionAmounts :: Query -> Transaction -> Transaction Source

Filter out all parts of this transaction's amounts which do not match the query. This can leave the transaction unbalanced.

filterPostingAmount :: Query -> Posting -> Posting Source

Filter out all parts of this posting's amount which do not match the query.

Querying

journalAccountNames :: Journal -> [AccountName] Source

Unique account names in this journal, including parent accounts containing no postings.

journalAccountNamesUsed :: Journal -> [AccountName] Source

Unique account names posted to in this journal.

journalAmounts :: Journal -> [Amount] Source

Get all this journal's component amounts, roughly in the order parsed.

journalDateSpan :: Bool -> Journal -> DateSpan Source

The fully specified date span enclosing the dates (primary or secondary) of all this journal's transactions and postings, or DateSpan Nothing Nothing if there are none.

journalDescriptions :: Journal -> [String] Source

Unique transaction descriptions used in this journal.

journalPostings :: Journal -> [Posting] Source

All postings from this journal's transactions, in order.

Standard account types

journalIncomeAccountQuery :: Journal -> Query Source

A query for Income (Revenue) accounts in this journal. This is currently hard-coded to the case-insensitive regex ^(income|revenue)s?(:|$).

journalExpenseAccountQuery :: Journal -> Query Source

A query for Expense accounts in this journal. This is currently hard-coded to the case-insensitive regex ^expenses?(:|$).

journalAssetAccountQuery :: Journal -> Query Source

A query for Asset accounts in this journal. This is currently hard-coded to the case-insensitive regex ^assets?(:|$).

journalLiabilityAccountQuery :: Journal -> Query Source

A query for Liability accounts in this journal. This is currently hard-coded to the case-insensitive regex ^(debts?|liabilit(y|ies))(:|$).

journalEquityAccountQuery :: Journal -> Query Source

A query for Equity accounts in this journal. This is currently hard-coded to the case-insensitive regex ^equity(:|$).

journalCashAccountQuery :: Journal -> Query Source

A query for Cash (-equivalent) accounts in this journal (ie, accounts which appear on the cashflow statement.) This is currently hard-coded to be all the Asset accounts except for those containing the case-insensitive regex (receivable|A/R).

Misc

canonicalStyles :: [Amount] -> Map Commodity AmountStyle Source

Given a list of amounts in parse order, build a map from commodities to canonical display styles for amounts in that commodity.

matchpats :: [String] -> String -> Bool Source

Check if a set of hledger account/description filter patterns matches the given account name or entry description. Patterns are case-insensitive regular expressions. Prefixed with not:, they become anti-patterns.

Tests