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

Safe Haskell | None
Language | Haskell2010

Hledger.Data.Journal

Contents

- Parsing helpers
- Filtering
- Querying
- Standard account types
- Misc
- Tests

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

- addHistoricalPrice :: HistoricalPrice -> Journal -> Journal
- addModifierTransaction :: ModifierTransaction -> Journal -> Journal
- addPeriodicTransaction :: PeriodicTransaction -> Journal -> Journal
- addTimeLogEntry :: TimeLogEntry -> Journal -> Journal
- addTransaction :: Transaction -> Journal -> Journal
- journalApplyAliases :: [AccountAlias] -> Journal -> Journal
- journalBalanceTransactions :: Journal -> Either String Journal
- journalCanonicaliseAmounts :: Journal -> Journal
- journalConvertAmountsToCost :: Journal -> Journal
- journalFinalise :: ClockTime -> LocalTime -> FilePath -> String -> JournalContext -> Bool -> Journal -> Either String Journal
- filterJournalTransactions :: Query -> Journal -> Journal
- filterJournalPostings :: Query -> Journal -> Journal
- filterJournalAmounts :: Query -> Journal -> Journal
- filterTransactionAmounts :: Query -> Transaction -> Transaction
- filterPostingAmount :: Query -> Posting -> Posting
- journalAccountNames :: Journal -> [AccountName]
- journalAccountNamesUsed :: Journal -> [AccountName]
- journalAmounts :: Journal -> [Amount]
- journalDateSpan :: Bool -> Journal -> DateSpan
- journalDescriptions :: Journal -> [String]
- journalFilePath :: Journal -> FilePath
- journalFilePaths :: Journal -> [FilePath]
- journalPostings :: Journal -> [Posting]
- journalBalanceSheetAccountQuery :: Journal -> Query
- journalProfitAndLossAccountQuery :: Journal -> Query
- journalIncomeAccountQuery :: Journal -> Query
- journalExpenseAccountQuery :: Journal -> Query
- journalAssetAccountQuery :: Journal -> Query
- journalLiabilityAccountQuery :: Journal -> Query
- journalEquityAccountQuery :: Journal -> Query
- journalCashAccountQuery :: Journal -> Query
- canonicalStyles :: [Amount] -> Map Commodity AmountStyle
- matchpats :: [String] -> String -> Bool
- nullctx :: JournalContext
- nulljournal :: Journal
- samplejournal :: Journal
- tests_Hledger_Data_Journal :: Test

# Parsing helpers

addHistoricalPrice :: HistoricalPrice -> Journal -> Journal Source

addModifierTransaction :: ModifierTransaction -> Journal -> Journal Source

addPeriodicTransaction :: PeriodicTransaction -> Journal -> Journal Source

addTimeLogEntry :: TimeLogEntry -> Journal -> Journal Source

addTransaction :: Transaction -> Journal -> Journal Source

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.

journalFilePath :: Journal -> FilePath Source

journalFilePaths :: Journal -> [FilePath] Source

journalPostings :: Journal -> [Posting] Source

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

# Standard account types

journalBalanceSheetAccountQuery :: Journal -> Query Source

A query for Asset, Liability & Equity accounts in this journal. Cf http://en.wikipedia.org/wiki/Chart_of_accounts#Balance_Sheet_Accounts.

journalProfitAndLossAccountQuery :: Journal -> Query Source

A query for Profit & Loss accounts in this journal. Cf http://en.wikipedia.org/wiki/Chart_of_accounts#Profit_.26_Loss_accounts.

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.

nullctx :: JournalContext Source

nulljournal :: Journal Source

# Tests

samplejournal :: Journal Source

tests_Hledger_Data_Journal :: Test Source