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

View File

@ -347,13 +347,19 @@ compoundBalanceReportAsSpreadsheet ::
compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr = compoundBalanceReportAsSpreadsheet fmt accountLabel maybeBlank ropts cbr =
let let
CompoundPeriodicReport title colspans subreports totalrow = cbr CompoundPeriodicReport title colspans subreports totalrow = cbr
headerrow = leadingHeaders =
Spr.headerCell accountLabel : 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) map (Spr.headerCell . reportPeriodName (balanceaccum_ ropts) colspans)
colspans ++ colspans ++
(guard (multiBalanceHasTotalsColumn ropts) >> [Spr.headerCell "Total"]) ++ (guard (multiBalanceHasTotalsColumn ropts) >> [Spr.headerCell "Total"]) ++
(guard (average_ ropts) >> [Spr.headerCell "Average"]) (guard (average_ ropts) >> [Spr.headerCell "Average"])
headerrow = leadingHeaders ++ dataHeaders
blankrow = blankrow =
fmap (Spr.horizontalSpan headerrow . Spr.defaultCell) maybeBlank fmap (Spr.horizontalSpan headerrow . Spr.defaultCell) maybeBlank