;refactor: extracted reportPeriodName for making report headings
This commit is contained in:
parent
4b9a76068f
commit
23bef9a01b
@ -260,20 +260,17 @@ budgetReportAsText ropts@ReportOpts{..} budgetr =
|
|||||||
budgetReportAsTable :: ReportOpts -> BudgetReport -> Table String String (Maybe MixedAmount, Maybe MixedAmount)
|
budgetReportAsTable :: ReportOpts -> BudgetReport -> Table String String (Maybe MixedAmount, Maybe MixedAmount)
|
||||||
budgetReportAsTable
|
budgetReportAsTable
|
||||||
ropts@ReportOpts{balancetype_}
|
ropts@ReportOpts{balancetype_}
|
||||||
(PeriodicReport periods rows (PeriodicReportRow _ coltots grandtot grandavg)) =
|
(PeriodicReport spans rows (PeriodicReportRow _ coltots grandtot grandavg)) =
|
||||||
addtotalrow $
|
addtotalrow $
|
||||||
Table
|
Table
|
||||||
(T.Group NoLine $ map Header accts)
|
(T.Group NoLine $ map Header accts)
|
||||||
(T.Group NoLine $ map Header colheadings)
|
(T.Group NoLine $ map Header colheadings)
|
||||||
(map rowvals rows)
|
(map rowvals rows)
|
||||||
where
|
where
|
||||||
colheadings = map mkheading periods
|
colheadings = map (reportPeriodName balancetype_ spans) spans
|
||||||
++ [" Total" | row_total_ ropts]
|
++ [" Total" | row_total_ ropts]
|
||||||
++ ["Average" | average_ ropts]
|
++ ["Average" | average_ ropts]
|
||||||
where
|
|
||||||
mkheading = case balancetype_ of
|
|
||||||
PeriodChange -> showDateSpanMonthAbbrev
|
|
||||||
_ -> maybe "" (showDate . prevday) . spanEnd
|
|
||||||
accts = map renderacct rows
|
accts = map renderacct rows
|
||||||
-- FIXME. Have to check explicitly for which to render here, since
|
-- FIXME. Have to check explicitly for which to render here, since
|
||||||
-- budgetReport sets accountlistmode to ALTree. Find a principled way to do
|
-- budgetReport sets accountlistmode to ALTree. Find a principled way to do
|
||||||
@ -290,6 +287,25 @@ budgetReportAsTable
|
|||||||
++ [grandavg | average_ ropts && not (null coltots)]
|
++ [grandavg | average_ ropts && not (null coltots)]
|
||||||
))
|
))
|
||||||
|
|
||||||
|
-- | Make a name for the given period in a multiperiod report, given
|
||||||
|
-- the type of balance being reported and the full set of report
|
||||||
|
-- periods. This will be used as a column heading (or row heading, in
|
||||||
|
-- a register summary report). We try to pick a useful name as follows:
|
||||||
|
--
|
||||||
|
-- - ending-balance reports: the period's end date
|
||||||
|
--
|
||||||
|
-- - balance change reports where the periods are months and all in the same year:
|
||||||
|
-- the short month name in the current locale
|
||||||
|
--
|
||||||
|
-- - all other balance change reports: a description of the datespan,
|
||||||
|
-- abbreviated to compact form if possible (see showDateSpan).
|
||||||
|
--
|
||||||
|
reportPeriodName :: BalanceType -> [DateSpan] -> DateSpan -> String
|
||||||
|
reportPeriodName balancetype spans =
|
||||||
|
case balancetype of
|
||||||
|
PeriodChange -> showDateSpanMonthAbbrev
|
||||||
|
_ -> maybe "" (showDate . prevday) . spanEnd
|
||||||
|
|
||||||
-- tests
|
-- tests
|
||||||
|
|
||||||
tests_BudgetReport = tests "BudgetReport" [
|
tests_BudgetReport = tests "BudgetReport" [
|
||||||
|
|||||||
@ -593,7 +593,7 @@ multiBalanceReportAsText ropts@ReportOpts{..} r =
|
|||||||
-- | Build a 'Table' from a multi-column balance report.
|
-- | Build a 'Table' from a multi-column balance report.
|
||||||
balanceReportAsTable :: ReportOpts -> MultiBalanceReport -> Table String String MixedAmount
|
balanceReportAsTable :: ReportOpts -> MultiBalanceReport -> Table String String MixedAmount
|
||||||
balanceReportAsTable opts@ReportOpts{average_, row_total_, balancetype_}
|
balanceReportAsTable opts@ReportOpts{average_, row_total_, balancetype_}
|
||||||
(PeriodicReport colspans items (PeriodicReportRow _ coltotals tot avg)) =
|
(PeriodicReport spans items (PeriodicReportRow _ coltotals tot avg)) =
|
||||||
maybetranspose $
|
maybetranspose $
|
||||||
addtotalrow $
|
addtotalrow $
|
||||||
Table
|
Table
|
||||||
@ -602,13 +602,9 @@ balanceReportAsTable opts@ReportOpts{average_, row_total_, balancetype_}
|
|||||||
(map rowvals items)
|
(map rowvals items)
|
||||||
where
|
where
|
||||||
totalscolumn = row_total_ && balancetype_ `notElem` [CumulativeChange, HistoricalBalance]
|
totalscolumn = row_total_ && balancetype_ `notElem` [CumulativeChange, HistoricalBalance]
|
||||||
colheadings = map mkheading colspans
|
colheadings = map (reportPeriodName balancetype_ spans) spans
|
||||||
++ [" Total" | totalscolumn]
|
++ [" Total" | totalscolumn]
|
||||||
++ ["Average" | average_]
|
++ ["Average" | average_]
|
||||||
where
|
|
||||||
mkheading = case balancetype_ of
|
|
||||||
PeriodChange -> showDateSpanMonthAbbrev
|
|
||||||
_ -> maybe "" (showDate . prevday) . spanEnd
|
|
||||||
accts = map renderacct items
|
accts = map renderacct items
|
||||||
renderacct row =
|
renderacct row =
|
||||||
replicate ((prrDepth row - 1) * 2) ' ' ++ T.unpack (prrDisplayName row)
|
replicate ((prrDepth row - 1) * 2) ' ' ++ T.unpack (prrDisplayName row)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user