Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- addTransactionModifier :: TransactionModifier -> Journal -> Journal
- addPeriodicTransaction :: PeriodicTransaction -> Journal -> Journal
- addTransaction :: Transaction -> Journal -> Journal
- journalBalanceTransactions :: Bool -> Journal -> Either String Journal
- journalApplyCommodityStyles :: Journal -> Journal
- commodityStylesFromAmounts :: [Amount] -> Map CommoditySymbol AmountStyle
- journalCommodityStyles :: Journal -> Map CommoditySymbol AmountStyle
- journalConvertAmountsToCost :: Journal -> Journal
- journalReverse :: Journal -> Journal
- journalSetLastReadTime :: ClockTime -> Journal -> Journal
- journalPivot :: Text -> Journal -> 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
- journalAccountNamesUsed :: Journal -> [AccountName]
- journalAccountNamesImplied :: Journal -> [AccountName]
- journalAccountNamesDeclared :: Journal -> [AccountName]
- journalAccountNamesDeclaredOrUsed :: Journal -> [AccountName]
- journalAccountNamesDeclaredOrImplied :: Journal -> [AccountName]
- journalAccountNames :: 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
- journalRevenueAccountQuery :: 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_Journal :: Test ()
Parsing helpers
addMarketPrice :: MarketPrice -> Journal -> Journal Source #
addTransaction :: Transaction -> Journal -> Journal Source #
journalBalanceTransactions :: Bool -> 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 applying canonical commodity styles, since balancing depends on display precision. Reports only the first error encountered.
journalApplyCommodityStyles :: Journal -> Journal Source #
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 Source #
Given a list of amounts in parse order, build a map from their commodity names to standard commodity display formats.
journalCommodityStyles :: Journal -> Map CommoditySymbol AmountStyle Source #
Get all the amount styles defined in this journal, either declared by a commodity directive or inferred from amounts, as a map from symbol to style. Styles declared by commodity directives take precedence, and these also are guaranteed to know their decimal point character.
journalConvertAmountsToCost :: Journal -> Journal Source #
Convert all this journal's amounts to cost by applying their prices, if any.
journalReverse :: Journal -> Journal Source #
Reverse parsed data to normal order. This is used for post-parse processing, since data is added to the head of the list during parsing.
journalSetLastReadTime :: ClockTime -> Journal -> Journal Source #
Set this journal's last read time, ie when its files were last read.
journalPivot :: Text -> Journal -> Journal Source #
Apply the pivot transformation to all postings in a journal, replacing their account name by their value for the given field or tag.
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
journalAccountNamesUsed :: Journal -> [AccountName] Source #
Sorted unique account names posted to by this journal's transactions.
journalAccountNamesImplied :: Journal -> [AccountName] Source #
Sorted unique account names implied by this journal's transactions - accounts posted to and all their implied parent accounts.
journalAccountNamesDeclared :: Journal -> [AccountName] Source #
Sorted unique account names declared by account directives in this journal.
journalAccountNamesDeclaredOrUsed :: Journal -> [AccountName] Source #
Sorted unique account names declared by account directives or posted to by transactions in this journal.
journalAccountNamesDeclaredOrImplied :: Journal -> [AccountName] Source #
Sorted unique account names declared by account directives, or posted to or implied as parents by transactions in this journal.
journalAccountNames :: Journal -> [AccountName] Source #
Convenience/compatibility alias for journalAccountNamesDeclaredOrImplied.
journalAmounts :: Journal -> [Amount] Source #
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 Source #
Maps over all of the amounts in the journal
traverseJournalAmounts :: Applicative f => (Amount -> f Amount) -> Journal -> f Journal Source #
Traverses over all ofthe amounts in the journal, in the order
indicated by journalAmounts
.
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 -> [Text] Source #
Unique transaction descriptions used in this journal.
journalFilePath :: Journal -> FilePath Source #
journalFilePaths :: Journal -> [FilePath] Source #
journalTransactionAt :: Journal -> Integer -> Maybe Transaction Source #
Get the transaction with this index (its 1-based position in the input stream), if any.
journalNextTransaction :: Journal -> Transaction -> Maybe Transaction Source #
Get the transaction that appeared immediately after this one in the input stream, if any.
journalPrevTransaction :: Journal -> Transaction -> Maybe Transaction Source #
Get the transaction that appeared immediately before this one in the input stream, if any.
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.
journalRevenueAccountQuery :: Journal -> Query Source #
A query for accounts in this journal which have been
declared as Revenue by account directives, or otherwise for
accounts with names matched by the case-insensitive regular expression
^(income|revenue)s?(:|$)
.
journalExpenseAccountQuery :: Journal -> Query Source #
A query for accounts in this journal which have been
declared as Expense by account directives, or otherwise for
accounts with names matched by the case-insensitive regular expression
^(income|revenue)s?(:|$)
.
journalAssetAccountQuery :: Journal -> Query Source #
A query for accounts in this journal which have been
declared as Asset by account directives, or otherwise for
accounts with names matched by the case-insensitive regular expression
^assets?(:|$)
.
journalLiabilityAccountQuery :: Journal -> Query Source #
A query for accounts in this journal which have been
declared as Liability by account directives, or otherwise for
accounts with names matched by the case-insensitive regular expression
^(debts?|liabilit(y|ies))(:|$)
.
journalEquityAccountQuery :: Journal -> Query Source #
A query for accounts in this journal which have been
declared as Equity by account directives, or otherwise for
accounts with names matched by the case-insensitive regular expression
^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 with names
containing the case-insensitive regular expression (receivable|:A/R|:fixed)
.
Misc
canonicalStyleFrom :: [AmountStyle] -> AmountStyle Source #
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 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.
journalCheckBalanceAssertions :: Journal -> Either String Journal Source #
Check any balance assertions in the journal and return an error message if any of them fail.
journalUntieTransactions :: Transaction -> Transaction Source #
Untie all transaction-posting knots in this journal, so that eg recursiveSize and GHCI's :sprint can work on it.
Tests
tests_Journal :: Test () Source #