lib,cli: Use Text for CompoundPeriodicReport titles.

This commit is contained in:
Stephen Morgan 2020-11-05 20:21:12 +11:00
parent 541c4fc18c
commit 089564b04b
5 changed files with 23 additions and 17 deletions

View File

@ -32,9 +32,10 @@ module Hledger.Reports.ReportTypes
, prrDepth , prrDepth
) where ) where
import Data.Aeson import Data.Aeson (ToJSON(..))
import Data.Decimal import Data.Decimal (Decimal)
import Data.Maybe (mapMaybe) import Data.Maybe (mapMaybe)
import Data.Text (Text)
#if !(MIN_VERSION_base(4,11,0)) #if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup (Semigroup(..)) import Data.Semigroup (Semigroup(..))
#endif #endif
@ -144,16 +145,16 @@ prrMapMaybeName f row = case f $ prrName row of
-- It is used in compound balance report commands like balancesheet, -- It is used in compound balance report commands like balancesheet,
-- cashflow and incomestatement. -- cashflow and incomestatement.
data CompoundPeriodicReport a b = CompoundPeriodicReport data CompoundPeriodicReport a b = CompoundPeriodicReport
{ cbrTitle :: String { cbrTitle :: Text
, cbrDates :: [DateSpan] , cbrDates :: [DateSpan]
, cbrSubreports :: [(String, PeriodicReport a b, Bool)] , cbrSubreports :: [(Text, PeriodicReport a b, Bool)]
, cbrTotals :: PeriodicReportRow () b , cbrTotals :: PeriodicReportRow () b
} deriving (Show, Functor, Generic, ToJSON) } deriving (Show, Functor, Generic, ToJSON)
-- | Description of one subreport within a compound balance report. -- | Description of one subreport within a compound balance report.
-- Part of a "CompoundBalanceCommandSpec", but also used in hledger-lib. -- Part of a "CompoundBalanceCommandSpec", but also used in hledger-lib.
data CBCSubreportSpec a = CBCSubreportSpec data CBCSubreportSpec a = CBCSubreportSpec
{ cbcsubreporttitle :: String -- ^ The title to use for the subreport { cbcsubreporttitle :: Text -- ^ The title to use for the subreport
, cbcsubreportquery :: Journal -> Query -- ^ The Query to use for the subreport , cbcsubreportquery :: Journal -> Query -- ^ The Query to use for the subreport
, cbcsubreportoptions :: ReportOpts -> ReportOpts -- ^ A function to transform the ReportOpts used to produce 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 , cbcsubreporttransform :: PeriodicReport DisplayName MixedAmount -> PeriodicReport a MixedAmount -- ^ A function to transform the result of the subreport

View File

@ -1,5 +1,6 @@
{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-| {-|
The @balancesheet@ command prints a simple balance sheet. The @balancesheet@ command prints a simple balance sheet.

View File

@ -1,5 +1,7 @@
{-# LANGUAGE QuasiQuotes, RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-| {-|
The @balancesheetequity@ command prints a simple balance sheet. The @balancesheetequity@ command prints a simple balance sheet.

View File

@ -1,5 +1,7 @@
{-# LANGUAGE QuasiQuotes, RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-| {-|
The @cashflow@ command prints a simplified cashflow statement. It just The @cashflow@ command prints a simplified cashflow statement. It just

View File

@ -149,7 +149,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r
-- make a CompoundBalanceReport. -- make a CompoundBalanceReport.
cbr' = compoundBalanceReport rspec{rsOpts=ropts'} j cbcqueries cbr' = compoundBalanceReport rspec{rsOpts=ropts'} j cbcqueries
cbr = cbr'{cbrTitle=T.unpack title} cbr = cbr'{cbrTitle=title}
-- render appropriately -- render appropriately
render = case outputFormatFromOpts opts of render = case outputFormatFromOpts opts of
@ -192,7 +192,7 @@ Balance Sheet
compoundBalanceReportAsText :: ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount -> String compoundBalanceReportAsText :: ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount -> String
compoundBalanceReportAsText ropts compoundBalanceReportAsText ropts
(CompoundPeriodicReport title _colspans subreports (PeriodicReportRow _ coltotals grandtotal grandavg)) = (CompoundPeriodicReport title _colspans subreports (PeriodicReportRow _ coltotals grandtotal grandavg)) =
title ++ "\n\n" ++ T.unpack title ++ "\n\n" ++
balanceReportTableAsText ropts bigtable' balanceReportTableAsText ropts bigtable'
where where
bigtable = bigtable =
@ -218,7 +218,7 @@ compoundBalanceReportAsText ropts
-- convert to table -- convert to table
Table lefthdrs tophdrs cells = balanceReportAsTable ropts r Table lefthdrs tophdrs cells = balanceReportAsTable ropts r
-- tweak the layout -- tweak the layout
t = Table (Tab.Group SingleLine [Header title, lefthdrs]) tophdrs ([]:cells) t = Table (Tab.Group SingleLine [Header $ T.unpack title, lefthdrs]) tophdrs ([]:cells)
-- | Add the second table below the first, discarding its column headings. -- | Add the second table below the first, discarding its column headings.
concatTables (Table hLeft hTop dat) (Table hLeft' _ dat') = concatTables (Table hLeft hTop dat) (Table hLeft' _ dat') =
@ -231,7 +231,7 @@ concatTables (Table hLeft hTop dat) (Table hLeft' _ dat') =
compoundBalanceReportAsCsv :: ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount -> CSV compoundBalanceReportAsCsv :: ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount -> CSV
compoundBalanceReportAsCsv ropts (CompoundPeriodicReport title colspans subreports (PeriodicReportRow _ coltotals grandtotal grandavg)) = compoundBalanceReportAsCsv ropts (CompoundPeriodicReport title colspans subreports (PeriodicReportRow _ coltotals grandtotal grandavg)) =
addtotals $ addtotals $
padRow (T.pack title) padRow title
: ( "Account" : ( "Account"
: map showDateSpanMonthAbbrev colspans : map showDateSpanMonthAbbrev colspans
++ (if row_total_ ropts then ["Total"] else []) ++ (if row_total_ ropts then ["Total"] else [])
@ -241,7 +241,7 @@ compoundBalanceReportAsCsv ropts (CompoundPeriodicReport title colspans subrepor
where where
-- | Add a subreport title row and drop the heading row. -- | Add a subreport title row and drop the heading row.
subreportAsCsv ropts (subreporttitle, multibalreport, _) = subreportAsCsv ropts (subreporttitle, multibalreport, _) =
padRow (T.pack subreporttitle) : padRow subreporttitle :
tail (multiBalanceReportAsCsv ropts multibalreport) tail (multiBalanceReportAsCsv ropts multibalreport)
padRow s = take numcols $ s : repeat "" padRow s = take numcols $ s : repeat ""
where where
@ -288,7 +288,7 @@ compoundBalanceReportAsHtml ropts cbr =
-- Make rows for a subreport: its title row, not the headings row, -- Make rows for a subreport: its title row, not the headings row,
-- the data rows, any totals row, and a blank row for whitespace. -- the data rows, any totals row, and a blank row for whitespace.
subreportrows :: (String, MultiBalanceReport, Bool) -> [Html ()] subreportrows :: (T.Text, MultiBalanceReport, Bool) -> [Html ()]
subreportrows (subreporttitle, mbr, _increasestotal) = subreportrows (subreporttitle, mbr, _increasestotal) =
let let
(_,bodyrows,mtotalsrow) = multiBalanceReportHtmlRows ropts mbr (_,bodyrows,mtotalsrow) = multiBalanceReportHtmlRows ropts mbr