From 4b3c6afe7599ae65749724d6e12ade060e943863 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 3 Apr 2018 13:06:52 +0100 Subject: [PATCH] lib: new generic PeriodicReport, and some report-related type aliases --- hledger-lib/Hledger/Reports.hs | 2 ++ hledger-lib/Hledger/Reports/ReportTypes.hs | 40 ++++++++++++++++++++++ hledger-lib/hledger-lib.cabal | 8 +++++ hledger-lib/package.yaml | 2 ++ 4 files changed, 52 insertions(+) create mode 100644 hledger-lib/Hledger/Reports/ReportTypes.hs diff --git a/hledger-lib/Hledger/Reports.hs b/hledger-lib/Hledger/Reports.hs index 4a9131486..17e80d9e1 100644 --- a/hledger-lib/Hledger/Reports.hs +++ b/hledger-lib/Hledger/Reports.hs @@ -10,6 +10,7 @@ javascript, or whatever. module Hledger.Reports ( module Hledger.Reports.ReportOptions, + module Hledger.Reports.ReportTypes, module Hledger.Reports.EntriesReport, module Hledger.Reports.PostingsReport, module Hledger.Reports.TransactionsReports, @@ -25,6 +26,7 @@ where import Test.HUnit import Hledger.Reports.ReportOptions +import Hledger.Reports.ReportTypes import Hledger.Reports.EntriesReport import Hledger.Reports.PostingsReport import Hledger.Reports.TransactionsReports diff --git a/hledger-lib/Hledger/Reports/ReportTypes.hs b/hledger-lib/Hledger/Reports/ReportTypes.hs new file mode 100644 index 000000000..787cf5f80 --- /dev/null +++ b/hledger-lib/Hledger/Reports/ReportTypes.hs @@ -0,0 +1,40 @@ +{- | +New common report types, used by the BudgetReport for now, perhaps all reports later. +-} + +module Hledger.Reports.ReportTypes +where + +import Data.Decimal +import Hledger.Data + +type Percentage = Decimal + +type Change = MixedAmount -- ^ A change in balance during a certain period. +type Balance = MixedAmount -- ^ An ending balance as of some date. +type Total = MixedAmount -- ^ The sum of 'Change's in a report or a report row. Does not make sense for 'Balance's. +type Average = MixedAmount -- ^ The average of 'Change's or 'Balance's in a report or report row. + +-- | A generic tabular report of some value, where each row corresponds to an account +-- and each column is a date period. The column periods are usually consecutive subperiods +-- formed by splitting the overall report period by some report interval (daily, weekly, etc.) +-- Depending on the value type, this can be a report of balance changes, ending balances, +-- budget performance, etc. Successor to MultiBalanceReport. +data PeriodicReport a = + PeriodicReport + ( [DateSpan] -- ^ The subperiods formed by spliting the overall report period by the report interval. + -- For ending-balance reports, only the end date is significant. + -- Usually displayed as report columns. + , [PeriodicReportRow a] -- ^ One row per account in the report. + , PeriodicReportRow a -- ^ The grand totals row. The account name in this row is always empty. + ) + deriving (Show) + +type PeriodicReportRow a = + ( AccountName -- ^ A full account name. + , AccountName -- ^ Shortened form of the account name to display in tree mode. Usually the leaf name, possibly with parent accounts prefixed. + , Int -- ^ Indent level for displaying this account name in tree mode. 0, 1, 2... + , [a] -- ^ The data value for each subperiod. + , a -- ^ The total of this row's values. + , a -- ^ The average of this row's values. + ) diff --git a/hledger-lib/hledger-lib.cabal b/hledger-lib/hledger-lib.cabal index 9fda2022f..cefa19d37 100644 --- a/hledger-lib/hledger-lib.cabal +++ b/hledger-lib/hledger-lib.cabal @@ -131,6 +131,8 @@ library Hledger.Utils.UTF8IOCompat Text.Megaparsec.Compat other-modules: + Hledger.Reports.BudgetReport + Hledger.Reports.ReportTypes Paths_hledger_lib default-language: Haskell2010 @@ -209,10 +211,12 @@ test-suite doctests Hledger.Reports Hledger.Reports.BalanceHistoryReport Hledger.Reports.BalanceReport + Hledger.Reports.BudgetReport Hledger.Reports.EntriesReport Hledger.Reports.MultiBalanceReports Hledger.Reports.PostingsReport Hledger.Reports.ReportOptions + Hledger.Reports.ReportTypes Hledger.Reports.TransactionsReports Hledger.Utils Hledger.Utils.Color @@ -301,10 +305,12 @@ test-suite easytests Hledger.Reports Hledger.Reports.BalanceHistoryReport Hledger.Reports.BalanceReport + Hledger.Reports.BudgetReport Hledger.Reports.EntriesReport Hledger.Reports.MultiBalanceReports Hledger.Reports.PostingsReport Hledger.Reports.ReportOptions + Hledger.Reports.ReportTypes Hledger.Reports.TransactionsReports Hledger.Utils Hledger.Utils.Color @@ -394,10 +400,12 @@ test-suite hunittests Hledger.Reports Hledger.Reports.BalanceHistoryReport Hledger.Reports.BalanceReport + Hledger.Reports.BudgetReport Hledger.Reports.EntriesReport Hledger.Reports.MultiBalanceReports Hledger.Reports.PostingsReport Hledger.Reports.ReportOptions + Hledger.Reports.ReportTypes Hledger.Reports.TransactionsReports Hledger.Utils Hledger.Utils.Color diff --git a/hledger-lib/package.yaml b/hledger-lib/package.yaml index fa063c212..51277fee0 100644 --- a/hledger-lib/package.yaml +++ b/hledger-lib/package.yaml @@ -122,8 +122,10 @@ library: - Hledger.Read.TimeclockReader - Hledger.Reports - Hledger.Reports.ReportOptions + - Hledger.Reports.ReportTypes - Hledger.Reports.BalanceHistoryReport - Hledger.Reports.BalanceReport + - Hledger.Reports.BudgetReport - Hledger.Reports.EntriesReport - Hledger.Reports.MultiBalanceReports - Hledger.Reports.PostingsReport