fix: balcmds: don't repeat "total" and "Net:" headers in HTML output

This commit is contained in:
Simon Michael 2024-06-12 03:53:00 +01:00
parent 1a242c1264
commit 9788a06223
2 changed files with 10 additions and 3 deletions

View File

@ -580,7 +580,8 @@ multiBalanceReportAsCsvHelper ishtml opts@ReportOpts{..} (PeriodicReport colspan
where showName = accountNameDrop drop_ . prrFullName
totalrows
| no_total_ = mempty
| otherwise = map ("total" :) $ rowAsText opts colspans tr
| ishtml = zipWith (:) ("total":repeat "") $ rowAsText opts colspans tr
| otherwise = map ("total" :) $ rowAsText opts colspans tr
rowAsText = if ishtml then multiBalanceRowAsHtmlText else multiBalanceRowAsCsvText
-- | Render a multi-column balance report as HTML.

View File

@ -29,6 +29,7 @@ import Hledger
import Hledger.Cli.Commands.Balance
import Hledger.Cli.CliOptions
import Hledger.Cli.Utils (unsupportedOutputFormatError, writeOutputLazyText)
import Data.Function ((&))
-- | Description of a compound balance report command,
-- from which we generate the command's cmdargs mode and IO action.
@ -337,8 +338,13 @@ compoundBalanceReportAsHtml ropts cbr =
++ mtotalsrows
++ [blankrow]
totalrows | no_total_ ropts || length subreports == 1 = []
| otherwise = multiBalanceReportHtmlFootRow ropts <$> (("Net:" :) <$> multiBalanceRowAsCsvText ropts colspans totalrow)
totalrows =
if no_total_ ropts || length subreports == 1 then []
else
multiBalanceRowAsCsvText ropts colspans totalrow -- make a table of rendered lines of the report totals row
& zipWith (:) ("Net:":repeat "") -- insert a headings column, with Net: on the first line only
& map (multiBalanceReportHtmlFootRow ropts) -- convert to a list of HTML totals rows
in do
style_ (T.unlines [""
,"td { padding:0 0.5em; }"