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

Safe Haskell | None
Language | GHC2021

Hledger.Reports.ReportTypes

Description

New common report types, used by the BudgetReport for now, perhaps all reports later.

Synopsis

- data PeriodicReport a b = PeriodicReport {
  - prDates :: [DateSpan]
  - prRows :: [PeriodicReportRow a b]
  - prTotals :: PeriodicReportRow () b
  }
- data PeriodicReportRow a b = PeriodicReportRow {
  - prrName :: a
  - prrAmounts :: [b]
  - prrTotal :: b
  - prrAverage :: b
  }
- type Percentage = Decimal
- type Change = MixedAmount
- type Balance = MixedAmount
- type Total = MixedAmount
- type Average = MixedAmount
- periodicReportSpan :: PeriodicReport a b -> DateSpan
- prMapName :: (a -> b) -> PeriodicReport a c -> PeriodicReport b c
- prMapMaybeName :: (a -> Maybe b) -> PeriodicReport a c -> PeriodicReport b c
- data CompoundPeriodicReport a b = CompoundPeriodicReport {
  - cbrTitle :: Text
  - cbrDates :: [DateSpan]
  - cbrSubreports :: [(Text, PeriodicReport a b, Bool)]
  - cbrTotals :: PeriodicReportRow () b
  }
- data CBCSubreportSpec a = CBCSubreportSpec {
  - cbcsubreporttitle :: Text
  - cbcsubreportquery :: Query
  - cbcsubreportoptions :: ReportOpts -> ReportOpts
  - cbcsubreporttransform :: PeriodicReport DisplayName MixedAmount -> PeriodicReport a MixedAmount
  - cbcsubreportincreasestotal :: Bool
  }
- data DisplayName = DisplayName {
  - displayFull :: AccountName
  - displayName :: AccountName
  - displayIndent :: NumberOfIndents
  }
- flatDisplayName :: AccountName -> DisplayName
- treeDisplayName :: AccountName -> DisplayName
- prrShowDebug :: PeriodicReportRow DisplayName MixedAmount -> String
- prrFullName :: PeriodicReportRow DisplayName a -> AccountName
- prrDisplayName :: PeriodicReportRow DisplayName a -> AccountName
- prrIndent :: PeriodicReportRow DisplayName a -> Int
- prrAdd :: Semigroup b => PeriodicReportRow a b -> PeriodicReportRow a b -> PeriodicReportRow a b

# Documentation

data PeriodicReport a b Source #

A periodic report is a generic tabular report, where each row corresponds to some label (usually an account name) and each column to a date period. The column periods are usually consecutive subperiods formed by splitting the overall report period by some report interval (daily, weekly, etc.). It has:

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

- an account label
- the account's depth
- A list of amounts, one for each column. Depending on the value type, these can represent balance changes, ending balances, budget performance, etc. (for example, see `BalanceAccumulation` and Hledger.Cli.Commands.Balance).
- the total of the row's amounts for a periodic report, or zero for cumulative/historical reports (since summing end balances generally doesn't make sense).
- 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.

Constructors

PeriodicReport |

Fields

- prDates :: [DateSpan]
- prRows :: [PeriodicReportRow a b]
- prTotals :: PeriodicReportRow () b

#### Instances

Instances details

Bifunctor PeriodicReport Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods bimap :: (a -> b) -> (c -> d) -> PeriodicReport a c -> PeriodicReport b d Source # first :: (a -> b) -> PeriodicReport a c -> PeriodicReport b c Source # second :: (b -> c) -> PeriodicReport a b -> PeriodicReport a c Source #
Functor (PeriodicReport a) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods fmap :: (a0 -> b) -> PeriodicReport a a0 -> PeriodicReport a b Source # (<$) :: a0 -> PeriodicReport a b -> PeriodicReport a a0 Source #
(ToJSON a, ToJSON b) => ToJSON (PeriodicReport a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods toJSON :: PeriodicReport a b -> Value Source # toEncoding :: PeriodicReport a b -> Encoding Source # toJSONList :: [PeriodicReport a b] -> Value Source # toEncodingList :: [PeriodicReport a b] -> Encoding Source # omitField :: PeriodicReport a b -> Bool Source #
Generic (PeriodicReport a b) Source # |

Instance details

Defined in Hledger.Reports.ReportTypes

Associated Types

type Rep (PeriodicReport a b) |

Instance details

Defined in Hledger.Reports.ReportTypes

type Rep (PeriodicReport a b) = D1 ('MetaData "PeriodicReport" "Hledger.Reports.ReportTypes" "hledger-lib-1.52.1-Hezqb1EQJRFEYYQgNd1QQB" 'False) (C1 ('MetaCons "PeriodicReport" 'PrefixI 'True) (S1 ('MetaSel ('Just "prDates") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [DateSpan]) :*: (S1 ('MetaSel ('Just "prRows") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [PeriodicReportRow a b]) :*: S1 ('MetaSel ('Just "prTotals") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PeriodicReportRow () b)))))

Methods

from :: PeriodicReport a b -> Rep (PeriodicReport a b) x Source #

to :: Rep (PeriodicReport a b) x -> PeriodicReport a b Source #

(Show a, Show b) => Show (PeriodicReport a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods showsPrec :: Int -> PeriodicReport a b -> ShowS Source # show :: PeriodicReport a b -> String Source # showList :: [PeriodicReport a b] -> ShowS Source #
HasAmounts b => HasAmounts (PeriodicReport a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods styleAmounts :: Map CommoditySymbol AmountStyle -> PeriodicReport a b -> PeriodicReport a b Source #
HasAmounts b => HasAmounts (Text, PeriodicReport a b, Bool) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods styleAmounts :: Map CommoditySymbol AmountStyle -> (Text, PeriodicReport a b, Bool) -> (Text, PeriodicReport a b, Bool) Source #
type Rep (PeriodicReport a b) Source # |

Instance details

Defined in Hledger.Reports.ReportTypes

type Rep (PeriodicReport a b) = D1 ('MetaData "PeriodicReport" "Hledger.Reports.ReportTypes" "hledger-lib-1.52.1-Hezqb1EQJRFEYYQgNd1QQB" 'False) (C1 ('MetaCons "PeriodicReport" 'PrefixI 'True) (S1 ('MetaSel ('Just "prDates") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [DateSpan]) :*: (S1 ('MetaSel ('Just "prRows") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [PeriodicReportRow a b]) :*: S1 ('MetaSel ('Just "prTotals") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PeriodicReportRow () b)))))

data PeriodicReportRow a b Source #

Constructors

PeriodicReportRow |

Fields

- prrName :: a
- prrAmounts :: [b]
- prrTotal :: b
- prrAverage :: b

#### Instances

Instances details

Bifunctor PeriodicReportRow Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods bimap :: (a -> b) -> (c -> d) -> PeriodicReportRow a c -> PeriodicReportRow b d Source # first :: (a -> b) -> PeriodicReportRow a c -> PeriodicReportRow b c Source # second :: (b -> c) -> PeriodicReportRow a b -> PeriodicReportRow a c Source #
Functor (PeriodicReportRow a) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods fmap :: (a0 -> b) -> PeriodicReportRow a a0 -> PeriodicReportRow a b Source # (<$) :: a0 -> PeriodicReportRow a b -> PeriodicReportRow a a0 Source #
(ToJSON b, ToJSON a) => ToJSON (PeriodicReportRow a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods toJSON :: PeriodicReportRow a b -> Value Source # toEncoding :: PeriodicReportRow a b -> Encoding Source # toJSONList :: [PeriodicReportRow a b] -> Value Source # toEncodingList :: [PeriodicReportRow a b] -> Encoding Source # omitField :: PeriodicReportRow a b -> Bool Source #
Semigroup b => Semigroup (PeriodicReportRow a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods (<>) :: PeriodicReportRow a b -> PeriodicReportRow a b -> PeriodicReportRow a b Source # sconcat :: NonEmpty (PeriodicReportRow a b) -> PeriodicReportRow a b Source # stimes :: Integral b0 => b0 -> PeriodicReportRow a b -> PeriodicReportRow a b Source #
Generic (PeriodicReportRow a b) Source # |

Instance details

Defined in Hledger.Reports.ReportTypes

Associated Types

type Rep (PeriodicReportRow a b) |

Instance details

Defined in Hledger.Reports.ReportTypes

type Rep (PeriodicReportRow a b) = D1 ('MetaData "PeriodicReportRow" "Hledger.Reports.ReportTypes" "hledger-lib-1.52.1-Hezqb1EQJRFEYYQgNd1QQB" 'False) (C1 ('MetaCons "PeriodicReportRow" 'PrefixI 'True) ((S1 ('MetaSel ('Just "prrName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "prrAmounts") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [b])) :*: (S1 ('MetaSel ('Just "prrTotal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b) :*: S1 ('MetaSel ('Just "prrAverage") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b))))

Methods

from :: PeriodicReportRow a b -> Rep (PeriodicReportRow a b) x Source #

to :: Rep (PeriodicReportRow a b) x -> PeriodicReportRow a b Source #

(Show a, Show b) => Show (PeriodicReportRow a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods showsPrec :: Int -> PeriodicReportRow a b -> ShowS Source # show :: PeriodicReportRow a b -> String Source # showList :: [PeriodicReportRow a b] -> ShowS Source #
HasAmounts b => HasAmounts (PeriodicReportRow a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods styleAmounts :: Map CommoditySymbol AmountStyle -> PeriodicReportRow a b -> PeriodicReportRow a b Source #
type Rep (PeriodicReportRow a b) Source # |

Instance details

Defined in Hledger.Reports.ReportTypes

type Rep (PeriodicReportRow a b) = D1 ('MetaData "PeriodicReportRow" "Hledger.Reports.ReportTypes" "hledger-lib-1.52.1-Hezqb1EQJRFEYYQgNd1QQB" 'False) (C1 ('MetaCons "PeriodicReportRow" 'PrefixI 'True) ((S1 ('MetaSel ('Just "prrName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "prrAmounts") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [b])) :*: (S1 ('MetaSel ('Just "prrTotal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b) :*: S1 ('MetaSel ('Just "prrAverage") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b))))

type Percentage = Decimal Source #

type Change Source #

Arguments

= MixedAmount | A change in balance during a certain period.

type Balance Source #

Arguments

= MixedAmount | An ending balance as of some date.

type Total Source #

Arguments

= MixedAmount | The sum of `Change`s in a report or a report row. Does not make sense for `Balance`s.

type Average Source #

Arguments

= MixedAmount | The average of `Change`s or `Balance`s in a report or report row.

periodicReportSpan :: PeriodicReport a b -> DateSpan Source #

Figure out the overall date span of a PeriodicReport

prMapName :: (a -> b) -> PeriodicReport a c -> PeriodicReport b c Source #

Map a function over the row names.

prMapMaybeName :: (a -> Maybe b) -> PeriodicReport a c -> PeriodicReport b c Source #

Map a function over the row names, possibly discarding some.

data CompoundPeriodicReport a b Source #

A compound balance report has:

- an overall title
- the period (date span) of each column
- one or more named, normal-positive multi balance reports, with columns corresponding to the above, and a flag indicating whether they increased or decreased the overall totals
- a list of overall totals for each column, and their grand total and average

It is used in compound balance report commands like balancesheet, cashflow and incomestatement.

Constructors

CompoundPeriodicReport |

Fields

- cbrTitle :: Text
- cbrDates :: [DateSpan]
- cbrSubreports :: [(Text, PeriodicReport a b, Bool)]
- cbrTotals :: PeriodicReportRow () b

#### Instances

Instances details

Functor (CompoundPeriodicReport a) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods fmap :: (a0 -> b) -> CompoundPeriodicReport a a0 -> CompoundPeriodicReport a b Source # (<$) :: a0 -> CompoundPeriodicReport a b -> CompoundPeriodicReport a a0 Source #
(ToJSON b, ToJSON a) => ToJSON (CompoundPeriodicReport a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods toJSON :: CompoundPeriodicReport a b -> Value Source # toEncoding :: CompoundPeriodicReport a b -> Encoding Source # toJSONList :: [CompoundPeriodicReport a b] -> Value Source # toEncodingList :: [CompoundPeriodicReport a b] -> Encoding Source # omitField :: CompoundPeriodicReport a b -> Bool Source #
Generic (CompoundPeriodicReport a b) Source # |

Instance details

Defined in Hledger.Reports.ReportTypes

Associated Types

type Rep (CompoundPeriodicReport a b) |

Instance details

Defined in Hledger.Reports.ReportTypes

type Rep (CompoundPeriodicReport a b) = D1 ('MetaData "CompoundPeriodicReport" "Hledger.Reports.ReportTypes" "hledger-lib-1.52.1-Hezqb1EQJRFEYYQgNd1QQB" 'False) (C1 ('MetaCons "CompoundPeriodicReport" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cbrTitle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "cbrDates") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [DateSpan])) :*: (S1 ('MetaSel ('Just "cbrSubreports") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Text, PeriodicReport a b, Bool)]) :*: S1 ('MetaSel ('Just "cbrTotals") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PeriodicReportRow () b)))))

Methods

from :: CompoundPeriodicReport a b -> Rep (CompoundPeriodicReport a b) x Source #

to :: Rep (CompoundPeriodicReport a b) x -> CompoundPeriodicReport a b Source #

(Show a, Show b) => Show (CompoundPeriodicReport a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods showsPrec :: Int -> CompoundPeriodicReport a b -> ShowS Source # show :: CompoundPeriodicReport a b -> String Source # showList :: [CompoundPeriodicReport a b] -> ShowS Source #
HasAmounts b => HasAmounts (CompoundPeriodicReport a b) Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods styleAmounts :: Map CommoditySymbol AmountStyle -> CompoundPeriodicReport a b -> CompoundPeriodicReport a b Source #
type Rep (CompoundPeriodicReport a b) Source # |

Instance details

Defined in Hledger.Reports.ReportTypes

type Rep (CompoundPeriodicReport a b) = D1 ('MetaData "CompoundPeriodicReport" "Hledger.Reports.ReportTypes" "hledger-lib-1.52.1-Hezqb1EQJRFEYYQgNd1QQB" 'False) (C1 ('MetaCons "CompoundPeriodicReport" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cbrTitle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "cbrDates") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [DateSpan])) :*: (S1 ('MetaSel ('Just "cbrSubreports") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Text, PeriodicReport a b, Bool)]) :*: S1 ('MetaSel ('Just "cbrTotals") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PeriodicReportRow () b)))))

data CBCSubreportSpec a Source #

Description of one subreport within a compound balance report. Part of a CompoundBalanceCommandSpec, but also used in hledger-lib.

Constructors

CBCSubreportSpec |

Fields

- cbcsubreporttitle :: Text

  The title to use for the subreport

- cbcsubreportquery :: Query

  The Query to use for the subreport

- cbcsubreportoptions :: ReportOpts -> ReportOpts

  A function to transform the ReportOpts used to produce the subreport

- cbcsubreporttransform :: PeriodicReport DisplayName MixedAmount -> PeriodicReport a MixedAmount

  A function to transform the result of the subreport

- cbcsubreportincreasestotal :: Bool

  Whether the subreport and overall report total are of the same sign (e.g. Assets are normally positive in a balance sheet report, as is the overall total. Liabilities are normally of the opposite sign.)

data DisplayName Source #

A full name, display name, and indent level for an account.

Constructors

DisplayName |

Fields

- displayFull :: AccountName
- displayName :: AccountName
- displayIndent :: NumberOfIndents

#### Instances

Instances details

ToJSON DisplayName Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods toJSON :: DisplayName -> Value Source # toEncoding :: DisplayName -> Encoding Source # toJSONList :: [DisplayName] -> Value Source # toEncodingList :: [DisplayName] -> Encoding Source # omitField :: DisplayName -> Bool Source #
Show DisplayName Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods showsPrec :: Int -> DisplayName -> ShowS Source # show :: DisplayName -> String Source # showList :: [DisplayName] -> ShowS Source #
Eq DisplayName Source # |
Instance details Defined in Hledger.Reports.ReportTypes Methods (==) :: DisplayName -> DisplayName -> Bool Source # (/=) :: DisplayName -> DisplayName -> Bool Source #
Ord DisplayName Source # |

Instance details

Defined in Hledger.Reports.ReportTypes

Methods

compare :: DisplayName -> DisplayName -> Ordering Source #

(<) :: DisplayName -> DisplayName -> Bool Source #

(<=) :: DisplayName -> DisplayName -> Bool Source #

(>) :: DisplayName -> DisplayName -> Bool Source #

(>=) :: DisplayName -> DisplayName -> Bool Source #

max :: DisplayName -> DisplayName -> DisplayName Source #

min :: DisplayName -> DisplayName -> DisplayName Source #

flatDisplayName :: AccountName -> DisplayName Source #

Construct a display name for a list report, where full names are shown unindented.

treeDisplayName :: AccountName -> DisplayName Source #

Construct a display name for a tree report, where leaf names (possibly prefixed by boring parents) are shown indented).

prrShowDebug :: PeriodicReportRow DisplayName MixedAmount -> String Source #

prrFullName :: PeriodicReportRow DisplayName a -> AccountName Source #

Get the full canonical account name from a PeriodicReportRow containing a DisplayName.

prrDisplayName :: PeriodicReportRow DisplayName a -> AccountName Source #

Get the account display name from a PeriodicReportRow containing a DisplayName.

prrIndent :: PeriodicReportRow DisplayName a -> Int Source #

Get the indent level from a PeriodicReportRow containing a DisplayName.

prrAdd :: Semigroup b => PeriodicReportRow a b -> PeriodicReportRow a b -> PeriodicReportRow a b Source #

Add two `PeriodicReportRows`, preserving the name of the first.