hledger-lib-1.41: A library providing the core functionality of hledger

Safe Haskell | None
Language | Haskell2010

Hledger.Reports.MultiBalanceReport

Contents

- Helper functions

Description

Multi-column balance reports, used by the balance command.

Synopsis

- type MultiBalanceReport = PeriodicReport DisplayName MixedAmount
- type MultiBalanceReportRow = PeriodicReportRow DisplayName MixedAmount
- multiBalanceReport :: ReportSpec -> Journal -> MultiBalanceReport
- multiBalanceReportWith :: ReportSpec -> Journal -> PriceOracle -> Set AccountName -> MultiBalanceReport
- compoundBalanceReport :: ReportSpec -> Journal -> [CBCSubreportSpec a] -> CompoundPeriodicReport a MixedAmount
- compoundBalanceReportWith :: ReportSpec -> Journal -> PriceOracle -> [CBCSubreportSpec a] -> CompoundPeriodicReport a MixedAmount
- sortRows :: ReportOpts -> Journal -> [MultiBalanceReportRow] -> [MultiBalanceReportRow]
- sortRowsLike :: [AccountName] -> [PeriodicReportRow DisplayName b] -> [PeriodicReportRow DisplayName b]
- makeReportQuery :: ReportSpec -> DateSpan -> ReportSpec
- getPostingsByColumn :: ReportSpec -> Journal -> PriceOracle -> [DateSpan] -> [(DateSpan, [Posting])]
- getPostings :: ReportSpec -> Journal -> PriceOracle -> [Posting]
- startingPostings :: ReportSpec -> Journal -> PriceOracle -> DateSpan -> [Posting]
- generateMultiBalanceReport :: ReportSpec -> Journal -> PriceOracle -> Set AccountName -> [(DateSpan, [Posting])] -> HashMap AccountName Account -> MultiBalanceReport
- tests_MultiBalanceReport :: TestTree

# Documentation

type MultiBalanceReport = PeriodicReport DisplayName MixedAmount #

A multi balance report is a kind of periodic report, where the amounts correspond to balance changes or ending balances in a given period. It has:

1. a list of each column's period (date span)
2. a list of rows, each containing:

- the full account name, display name, and display depth
- A list of amounts, one for each column.
- the total of the row's amounts for a periodic report
- the average of the row's amounts

1. the column totals, and the overall grand total (or zero for cumulative/historical reports) and grand average.

type MultiBalanceReportRow = PeriodicReportRow DisplayName MixedAmount #

multiBalanceReport :: ReportSpec -> Journal -> MultiBalanceReport #

Generate a multicolumn balance report for the matched accounts, showing the change of balance, accumulated balance, or historical balance in each of the specified periods. If the normalbalance_ option is set, it adjusts the sorting and sign of amounts (see ReportOpts and CompoundBalanceCommand). hledger's most powerful and useful report, used by the balance command (in multiperiod mode) and (via compoundBalanceReport) by the bscfis commands.

multiBalanceReportWith :: ReportSpec -> Journal -> PriceOracle -> Set AccountName -> MultiBalanceReport #

A helper for multiBalanceReport. This one takes some extra arguments, a `PriceOracle` to be used for looking up market prices, and a set of `AccountName`s which should not be elided. Commands which run multiple reports (bs etc.) can generate the price oracle just once for efficiency, passing it to each report by calling this function directly.

compoundBalanceReport :: ReportSpec -> Journal -> [CBCSubreportSpec a] -> CompoundPeriodicReport a MixedAmount #

Generate a compound balance report from a list of CBCSubreportSpec. This shares postings between the subreports.

compoundBalanceReportWith :: ReportSpec -> Journal -> PriceOracle -> [CBCSubreportSpec a] -> CompoundPeriodicReport a MixedAmount #

A helper for compoundBalanceReport, similar to multiBalanceReportWith.

sortRows :: ReportOpts -> Journal -> [MultiBalanceReportRow] -> [MultiBalanceReportRow] #

Sort the rows by amount or by account declaration order.

sortRowsLike :: [AccountName] -> [PeriodicReportRow DisplayName b] -> [PeriodicReportRow DisplayName b] #

A sorting helper: sort a list of things (eg report rows) keyed by account name to match the provided ordering of those same account names.

# Helper functions

makeReportQuery :: ReportSpec -> DateSpan -> ReportSpec #

Remove any date queries and insert queries from the report span. The user's query expanded to the report span if there is one (otherwise any date queries are left as-is, which handles the hledger-ui+future txns case above).

getPostingsByColumn :: ReportSpec -> Journal -> PriceOracle -> [DateSpan] -> [(DateSpan, [Posting])] #

Group postings, grouped by their column

getPostings :: ReportSpec -> Journal -> PriceOracle -> [Posting] #

Gather postings matching the query within the report period.

startingPostings :: ReportSpec -> Journal -> PriceOracle -> DateSpan -> [Posting] #

Postings needed to calculate starting balances.

Balances at report start date, from all earlier postings which otherwise match the query. These balances are unvalued. TODO: Do we want to check whether to bother calculating these? isHistorical and startDate is not nothing, otherwise mempty? This currently gives a failure with some totals which are supposed to be 0 being blank.

generateMultiBalanceReport :: ReportSpec -> Journal -> PriceOracle -> Set AccountName -> [(DateSpan, [Posting])] -> HashMap AccountName Account -> MultiBalanceReport #

Lay out a set of postings grouped by date span into a regular matrix with rows given by AccountName and columns by DateSpan, then generate a MultiBalanceReport from the columns.

tests_MultiBalanceReport :: TestTree #