cli: CompoundBalance.compoundBalanceReportAsSpreadsheet: somehow support layout tidy

However, it is not quite correct since it contains totals and net values.
This commit is contained in:
Henning Thielemann 2024-10-16 00:07:21 +02:00 committed by Simon Michael
parent 270360a103
commit 49f1af04ef
2 changed files with 14 additions and 5 deletions

View File

@ -266,6 +266,7 @@ module Hledger.Cli.Commands.Balance (
,multiBalanceHasTotalsColumn
,addTotalBorders
,simpleDateSpanCell
,tidyColumnLabels
,nbsp
,RowClass(..)
-- ** Tests
@ -777,9 +778,7 @@ multiBalanceReportAsSpreadsheetParts fmt opts@ReportOpts{..} (PeriodicReport col
addHeaderBorders $
hCell "account" "account" :
case layout_ of
LayoutTidy ->
map headerCell
["period", "start_date", "end_date", "commodity", "value"]
LayoutTidy -> map headerCell tidyColumnLabels
LayoutBare -> headerCell "commodity" : dateHeaders
_ -> dateHeaders
dateHeaders =
@ -802,6 +801,10 @@ multiBalanceReportAsSpreadsheetParts fmt opts@ReportOpts{..} (PeriodicReport col
map (map (fmap wbToText)) .
multiBalanceRowAsCellBuilders fmt opts colspans rc dsCell
tidyColumnLabels :: [Text]
tidyColumnLabels =
["period", "start_date", "end_date", "commodity", "value"]
-- | Render a multi-column balance report as HTML.
multiBalanceReportAsHtml :: ReportOpts -> MultiBalanceReport -> Html ()

View File

@ -347,13 +347,19 @@ compoundBalanceReportAsSpreadsheet ::
compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr =
let
CompoundPeriodicReport title colspans subreports totalrow = cbr
headerrow =
leadingHeaders =
Spr.headerCell accountLabel :
(guard (layout_ ropts == LayoutBare) >> [Spr.headerCell "Commodity"]) ++
case layout_ ropts of
LayoutTidy -> map Spr.headerCell tidyColumnLabels
LayoutBare -> [Spr.headerCell "Commodity"]
_ -> []
dataHeaders =
(guard (layout_ ropts /= LayoutTidy) >>) $
map (Spr.headerCell . reportPeriodName (balanceaccum_ ropts) colspans)
colspans ++
(guard (multiBalanceHasTotalsColumn ropts) >> [Spr.headerCell "Total"]) ++
(guard (average_ ropts) >> [Spr.headerCell "Average"])
headerrow = leadingHeaders ++ dataHeaders
blankrow =
fmap (Spr.horizontalSpan headerrow . Spr.defaultCell) maybeBlank