From 089564b04b1a15908b6b0298ba43109162916865 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Thu, 5 Nov 2020 20:21:12 +1100 Subject: [PATCH] lib,cli: Use Text for CompoundPeriodicReport titles. --- hledger-lib/Hledger/Reports/ReportTypes.hs | 11 ++++++----- hledger/Hledger/Cli/Commands/Balancesheet.hs | 5 +++-- hledger/Hledger/Cli/Commands/Balancesheetequity.hs | 6 ++++-- hledger/Hledger/Cli/Commands/Cashflow.hs | 6 ++++-- hledger/Hledger/Cli/CompoundBalanceCommand.hs | 12 ++++++------ 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/hledger-lib/Hledger/Reports/ReportTypes.hs b/hledger-lib/Hledger/Reports/ReportTypes.hs index 3c21da01b..e982e2edd 100644 --- a/hledger-lib/Hledger/Reports/ReportTypes.hs +++ b/hledger-lib/Hledger/Reports/ReportTypes.hs @@ -32,9 +32,10 @@ module Hledger.Reports.ReportTypes , prrDepth ) where -import Data.Aeson -import Data.Decimal +import Data.Aeson (ToJSON(..)) +import Data.Decimal (Decimal) import Data.Maybe (mapMaybe) +import Data.Text (Text) #if !(MIN_VERSION_base(4,11,0)) import Data.Semigroup (Semigroup(..)) #endif @@ -144,16 +145,16 @@ prrMapMaybeName f row = case f $ prrName row of -- It is used in compound balance report commands like balancesheet, -- cashflow and incomestatement. data CompoundPeriodicReport a b = CompoundPeriodicReport - { cbrTitle :: String + { cbrTitle :: Text , cbrDates :: [DateSpan] - , cbrSubreports :: [(String, PeriodicReport a b, Bool)] + , cbrSubreports :: [(Text, PeriodicReport a b, Bool)] , cbrTotals :: PeriodicReportRow () b } deriving (Show, Functor, Generic, ToJSON) -- | Description of one subreport within a compound balance report. -- Part of a "CompoundBalanceCommandSpec", but also used in hledger-lib. 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 , 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 diff --git a/hledger/Hledger/Cli/Commands/Balancesheet.hs b/hledger/Hledger/Cli/Commands/Balancesheet.hs index cb5a42d1a..5bc817c97 100644 --- a/hledger/Hledger/Cli/Commands/Balancesheet.hs +++ b/hledger/Hledger/Cli/Commands/Balancesheet.hs @@ -1,5 +1,6 @@ -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TemplateHaskell #-} {-| The @balancesheet@ command prints a simple balance sheet. diff --git a/hledger/Hledger/Cli/Commands/Balancesheetequity.hs b/hledger/Hledger/Cli/Commands/Balancesheetequity.hs index 0cacf504a..fe3170b86 100644 --- a/hledger/Hledger/Cli/Commands/Balancesheetequity.hs +++ b/hledger/Hledger/Cli/Commands/Balancesheetequity.hs @@ -1,5 +1,7 @@ -{-# LANGUAGE QuasiQuotes, RecordWildCards #-} -{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TemplateHaskell #-} {-| The @balancesheetequity@ command prints a simple balance sheet. diff --git a/hledger/Hledger/Cli/Commands/Cashflow.hs b/hledger/Hledger/Cli/Commands/Cashflow.hs index 3e87b3546..7b4ce4257 100644 --- a/hledger/Hledger/Cli/Commands/Cashflow.hs +++ b/hledger/Hledger/Cli/Commands/Cashflow.hs @@ -1,5 +1,7 @@ -{-# LANGUAGE QuasiQuotes, RecordWildCards #-} -{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TemplateHaskell #-} {-| The @cashflow@ command prints a simplified cashflow statement. It just diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index 132ef8f03..d55e034c3 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -149,7 +149,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r -- make a CompoundBalanceReport. cbr' = compoundBalanceReport rspec{rsOpts=ropts'} j cbcqueries - cbr = cbr'{cbrTitle=T.unpack title} + cbr = cbr'{cbrTitle=title} -- render appropriately render = case outputFormatFromOpts opts of @@ -192,7 +192,7 @@ Balance Sheet compoundBalanceReportAsText :: ReportOpts -> CompoundPeriodicReport DisplayName MixedAmount -> String compoundBalanceReportAsText ropts (CompoundPeriodicReport title _colspans subreports (PeriodicReportRow _ coltotals grandtotal grandavg)) = - title ++ "\n\n" ++ + T.unpack title ++ "\n\n" ++ balanceReportTableAsText ropts bigtable' where bigtable = @@ -218,7 +218,7 @@ compoundBalanceReportAsText ropts -- convert to table Table lefthdrs tophdrs cells = balanceReportAsTable ropts r -- 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. 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 ropts (CompoundPeriodicReport title colspans subreports (PeriodicReportRow _ coltotals grandtotal grandavg)) = addtotals $ - padRow (T.pack title) + padRow title : ( "Account" : map showDateSpanMonthAbbrev colspans ++ (if row_total_ ropts then ["Total"] else []) @@ -241,7 +241,7 @@ compoundBalanceReportAsCsv ropts (CompoundPeriodicReport title colspans subrepor where -- | Add a subreport title row and drop the heading row. subreportAsCsv ropts (subreporttitle, multibalreport, _) = - padRow (T.pack subreporttitle) : + padRow subreporttitle : tail (multiBalanceReportAsCsv ropts multibalreport) padRow s = take numcols $ s : repeat "" where @@ -288,7 +288,7 @@ compoundBalanceReportAsHtml ropts cbr = -- Make rows for a subreport: its title row, not the headings row, -- 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) = let (_,bodyrows,mtotalsrow) = multiBalanceReportHtmlRows ropts mbr