cli: Cli.Balance.balanceReportAsCvs: now based on balanceReportAsSpreadsheet

This warrants consistency of ODS, HTML and CSV export.
This commit is contained in:
Henning Thielemann 2024-08-10 11:00:49 +02:00
parent 37be769540
commit 48723c930c

View File

@ -430,26 +430,8 @@ totalRowHeadingBudgetCsv = "Total:"
-- | Render a single-column balance report as CSV.
balanceReportAsCsv :: ReportOpts -> BalanceReport -> CSV
balanceReportAsCsv opts (items, total) =
headers : concatMap (\(a, _, _, b) -> rows a b) items ++ if no_total_ opts then [] else rows totalRowHeadingCsv total
where
headers = "account" : case layout_ opts of
LayoutBare -> ["commodity", "balance"]
_ -> ["balance"]
rows :: AccountName -> MixedAmount -> [[T.Text]]
rows name ma = case layout_ opts of
LayoutBare ->
map (\a -> [showName name, acommodity a, renderAmount $ mixedAmount a])
. amounts $ mixedAmountStripCosts ma
_ -> [[showName name, renderAmount ma]]
showName = accountNameDrop (drop_ opts)
renderAmount amt = wbToText $ showMixedAmountB bopts amt
where
bopts = machineFmt{displayCommodity=showcomm, displayCommodityOrder = commorder}
(showcomm, commorder)
| layout_ opts == LayoutBare = (False, Just $ S.toList $ maCommodities amt)
| otherwise = (True, Nothing)
balanceReportAsCsv opts =
map (map Ods.cellContent) . balanceReportAsSpreadsheet opts
-- | Render a single-column balance report as plain text.
balanceReportAsText :: ReportOpts -> BalanceReport -> TB.Builder