lib: new generic PeriodicReport, and some report-related type aliases

This commit is contained in:
Simon Michael 2018-04-03 13:06:52 +01:00
parent d2f5d7101e
commit 4b3c6afe75
4 changed files with 52 additions and 0 deletions

View File

@ -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

View File

@ -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.
)

View File

@ -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

View File

@ -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