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




Generate several common kinds of report from a journal, as "*Report" - simple intermediate data structures intended to be easily rendered as text, html, json, csv etc. by hledger commands, hamlet templates, javascript, or whatever. This is under Hledger.Cli since it depends on the command-line options, should move to hledger-lib later.



dateSpanFromOpts :: Day -> ReportOpts -> DateSpanSource

Figure out the date span we should report on, based on any beginendperiod options provided. A period option will cause begin and end options to be ignored.

intervalFromOpts :: ReportOpts -> IntervalSource

Figure out the reporting interval, if any, specified by the options. --period overrides --daily overrides --weekly overrides --monthly etc.

clearedValueFromOpts :: ReportOpts -> Maybe BoolSource

Get a maybe boolean representing the last cleared/uncleared option if any.

whichDateFromOpts :: ReportOpts -> WhichDateSource

Detect which date we will report on, based on --effective.

journalSelectingDateFromOpts :: ReportOpts -> Journal -> JournalSource

Convert this journal's transactions' primary date to either the actual or effective date, as per options.

journalSelectingAmountFromOpts :: ReportOpts -> Journal -> JournalSource

Convert this journal's postings' amounts to the cost basis amounts if specified by options.

optsToFilterSpec :: ReportOpts -> Day -> FilterSpecSource

Convert application options to the library's generic filter specification.

Entries report

type EntriesReport = [EntriesReportItem]Source

A journal entries report is a list of whole transactions as originally entered in the journal (mostly). Used by eg hledger's print command and hledger-web's journal entries view.

entriesReport :: ReportOpts -> FilterSpec -> Journal -> EntriesReportSource

Select transactions for an entries report.

Postings report

type PostingsReport = (String, [PostingsReportItem])Source

A postings report is a list of postings with a running total, a label for the total field, and a little extra transaction info to help with rendering.

postingsReport :: ReportOpts -> FilterSpec -> Journal -> PostingsReportSource

Select postings from the journal and add running balance and other information to make a postings report. Used by eg hledger's register command.

mkpostingsReportItem :: Bool -> Posting -> MixedAmount -> PostingsReportItemSource

Generate one postings report line item, from a flag indicating whether to include transaction info, a posting, and the current running balance.

Transactions report

type TransactionsReport = (String, [TransactionsReportItem])Source

A transactions report includes a list of transactions (posting-filtered and unfiltered variants), a running balance, and some other information helpful for rendering a register view (a flag indicating multiple other accounts and a display string describing them) with or without a notion of current account(s).

triDate :: (Transaction, t, t1, t2, t3, t4) -> DaySource

triBalance :: (t, t1, t2, t3, t4, MixedAmount) -> [Char]Source

journalTransactionsReport :: ReportOpts -> Journal -> Matcher -> TransactionsReportSource

Select transactions from the whole journal for a transactions report, with no "current" account. The end result is similar to postingsReport except it uses matchers and transaction-based report items and the items are most recent first. Used by eg hledger-web's journal view.

accountTransactionsReport :: ReportOpts -> Journal -> Matcher -> Matcher -> TransactionsReportSource

Select transactions within one or more "current" accounts, and make a transactions report relative to those account(s). This means:

  1. it shows transactions from the point of view of the current account(s). The transaction amount is the amount posted to the current account(s). The other accounts' names are provided.
  2. With no transaction filtering in effect other than a start date, it shows the accurate historical running balance for the current account(s). Otherwise it shows a running total starting at 0.

Currently, reporting intervals are not supported, and report items are most recent first. Used by eg hledger-web's account register view.

Accounts report

type AccountsReport = ([AccountsReportItem], MixedAmount)Source

An accounts report is a list of account names (full and short variants) with their balances, appropriate indentation for rendering as a hierarchy, and grand total.

accountsReport :: ReportOpts -> FilterSpec -> Journal -> AccountsReportSource

Select accounts, and get their balances at the end of the selected period, and misc. display information, for an accounts report. Used by eg hledger's balance command.

accountsReport2 :: ReportOpts -> Matcher -> Journal -> AccountsReportSource

Select accounts, and get their balances at the end of the selected period, and misc. display information, for an accounts report. Like accountsReport but uses the new matchers. Used by eg hledger-web's accounts sidebar.

isInteresting :: ReportOpts -> Ledger -> AccountName -> BoolSource

Is the named account considered interesting for this ledger's accounts report, following the eliding style of ledger's balance command ?