hledger-lib-1.3: Core data types, parsers and functionality for the hledger accounting tools

Safe Haskell | None
Language | Haskell2010

Hledger.Data.Journal

Contents

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

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

- addMarketPrice :: MarketPrice -> Journal -> Journal
- addModifierTransaction :: ModifierTransaction -> Journal -> Journal
- addPeriodicTransaction :: PeriodicTransaction -> Journal -> Journal
- addTransaction :: Transaction -> Journal -> Journal
- journalApplyAliases :: [AccountAlias] -> Journal -> Journal
- journalBalanceTransactions :: Bool -> Journal -> Either String Journal
- journalApplyCommodityStyles :: Journal -> Journal
- commodityStylesFromAmounts :: [Amount] -> Map CommoditySymbol AmountStyle
- journalConvertAmountsToCost :: Journal -> Journal
- journalFinalise :: ClockTime -> FilePath -> Text -> Bool -> ParsedJournal -> Either String Journal
- filterJournalTransactions :: Query -> Journal -> Journal
- filterJournalPostings :: Query -> Journal -> Journal
- filterJournalAmounts :: Query -> Journal -> Journal
- filterTransactionAmounts :: Query -> Transaction -> Transaction
- filterTransactionPostings :: Query -> Transaction -> Transaction
- filterPostingAmount :: Query -> Posting -> Posting
- journalAccountNames :: Journal -> [AccountName]
- journalAccountNamesUsed :: Journal -> [AccountName]
- journalAmounts :: Journal -> [Amount]
- overJournalAmounts :: (Amount -> Amount) -> Journal -> Journal
- traverseJournalAmounts :: Applicative f => (Amount -> f Amount) -> Journal -> f Journal
- journalDateSpan :: Bool -> Journal -> DateSpan
- journalDescriptions :: Journal -> [Text]
- journalFilePath :: Journal -> FilePath
- journalFilePaths :: Journal -> [FilePath]
- journalTransactionAt :: Journal -> Integer -> Maybe Transaction
- journalNextTransaction :: Journal -> Transaction -> Maybe Transaction
- journalPrevTransaction :: Journal -> Transaction -> Maybe Transaction
- 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
- canonicalStyleFrom :: [AmountStyle] -> AmountStyle
- matchpats :: [String] -> String -> Bool
- nulljournal :: Journal
- journalCheckBalanceAssertions :: Journal -> Either String Journal
- journalNumberAndTieTransactions :: Journal -> Journal
- journalUntieTransactions :: Transaction -> Transaction
- samplejournal :: Journal
- tests_Hledger_Data_Journal :: Test

# Parsing helpers

addMarketPrice :: MarketPrice -> Journal -> Journal #

addModifierTransaction :: ModifierTransaction -> Journal -> Journal #

addPeriodicTransaction :: PeriodicTransaction -> Journal -> Journal #

addTransaction :: Transaction -> Journal -> Journal #

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

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

journalBalanceTransactions :: Bool -> Journal -> Either String Journal #

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 applying canonical commodity styles, since balancing depends on display precision. Reports only the first error encountered.

journalApplyCommodityStyles :: Journal -> Journal #

Choose and apply a consistent display format to the posting amounts in each commodity. Each commodity's format is specified by a commodity format directive, or otherwise inferred from posting amounts as in hledger < 0.28.

commodityStylesFromAmounts :: [Amount] -> Map CommoditySymbol AmountStyle #

Given a list of amounts in parse order, build a map from their commodity names to standard commodity display formats.

journalConvertAmountsToCost :: Journal -> Journal #

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

journalFinalise :: ClockTime -> FilePath -> Text -> Bool -> ParsedJournal -> Either String Journal #

Do post-parse processing on a parsed journal to make it ready for use. Reverse parsed data to normal order, canonicalise amount formats, check/ensure that transactions are balanced, and maybe check balance assertions.

# Filtering

filterJournalTransactions :: Query -> Journal -> Journal #

Keep only transactions matching the query expression.

filterJournalPostings :: Query -> Journal -> Journal #

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

filterJournalAmounts :: Query -> Journal -> Journal #

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

filterTransactionAmounts :: Query -> Transaction -> Transaction #

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

filterTransactionPostings :: Query -> Transaction -> Transaction #

filterPostingAmount :: Query -> Posting -> Posting #

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

# Querying

journalAccountNames :: Journal -> [AccountName] #

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

journalAccountNamesUsed :: Journal -> [AccountName] #

Unique account names posted to in this journal.

journalAmounts :: Journal -> [Amount] #

Get an ordered list of the amounts in this journal which will influence amount style canonicalisation. These are:

- amounts in market price directives (in parse order)
- amounts in postings (in parse order)

Amounts in default commodity directives also influence canonicalisation, but earlier, as amounts are parsed. Amounts in posting prices are not used for canonicalisation.

overJournalAmounts :: (Amount -> Amount) -> Journal -> Journal #

Maps over all of the amounts in the journal

traverseJournalAmounts :: Applicative f => (Amount -> f Amount) -> Journal -> f Journal #

Traverses over all ofthe amounts in the journal, in the order indicated by `journalAmounts`.

journalDateSpan :: Bool -> Journal -> DateSpan #

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 -> [Text] #

Unique transaction descriptions used in this journal.

journalFilePath :: Journal -> FilePath #

journalFilePaths :: Journal -> [FilePath] #

journalTransactionAt :: Journal -> Integer -> Maybe Transaction #

Get the transaction with this index (its 1-based position in the input stream), if any.

journalNextTransaction :: Journal -> Transaction -> Maybe Transaction #

Get the transaction that appeared immediately after this one in the input stream, if any.

journalPrevTransaction :: Journal -> Transaction -> Maybe Transaction #

Get the transaction that appeared immediately before this one in the input stream, if any.

journalPostings :: Journal -> [Posting] #

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

# Standard account types

journalBalanceSheetAccountQuery :: Journal -> Query #

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 #

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 #

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 #

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

journalAssetAccountQuery :: Journal -> Query #

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

journalLiabilityAccountQuery :: Journal -> Query #

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 #

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

journalCashAccountQuery :: Journal -> Query #

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

canonicalStyleFrom :: [AmountStyle] -> AmountStyle #

Given an ordered list of amount styles, choose a canonical style. That is: the style of the first, and the maximum precision of all.

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

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.

nulljournal :: Journal #

journalCheckBalanceAssertions :: Journal -> Either String Journal #

Check any balance assertions in the journal and return an error message if any of them fail.

journalNumberAndTieTransactions :: Journal -> Journal #

journalUntieTransactions :: Transaction -> Transaction #

Untie all transaction-posting knots in this journal, so that eg recursiveSize and GHCI's :sprint can work on it.

# Tests

samplejournal :: Journal #

tests_Hledger_Data_Journal :: Test #

# Orphan instances

Show Journal # |
Methods showsPrec :: Int -> Journal -> ShowS # show :: Journal -> String # showList :: [Journal] -> ShowS #
Monoid Journal # |
Methods mempty :: Journal # mappend :: Journal -> Journal -> Journal # mconcat :: [Journal] -> Journal #