balance: show multi-commodity amts on one line (fixes #186)

To avoid totally breaking the layout of multicolumn balance reports when
there are multi-commodity balances, these are now rendered on a single
line, comma separated. Simple balance reports still use the old vertical
format for now.
This commit is contained in:
Simon Michael 2014-07-03 07:45:55 -07:00
parent 3669422bbf
commit 16f8b78305
2 changed files with 12 additions and 3 deletions

View File

@ -63,6 +63,7 @@ module Hledger.Data.Amount (
showAmount,
showAmountDebug,
showAmountWithoutPrice,
showMixedAmountOneLineWithoutPrice,
maxprecision,
maxprecisionwithpoint,
setAmountPrecision,
@ -501,6 +502,14 @@ showMixedAmountWithoutPrice m = concat $ intersperse "\n" $ map showfixedwidth a
width = maximum $ map (length . showAmount) as
showfixedwidth = printf (printf "%%%ds" width) . showAmountWithoutPrice
-- | Get the one-line string representation of a mixed amount, but without
-- any \@ prices.
showMixedAmountOneLineWithoutPrice :: MixedAmount -> String
showMixedAmountOneLineWithoutPrice m = concat $ intersperse ", " $ map showAmountWithoutPrice as
where
(Mixed as) = normaliseMixedAmountPreservingFirstPrice $ stripPrices m
stripPrices (Mixed as) = Mixed $ map stripprice as where stripprice a = a{aprice=NoPrice}
-- | Canonicalise a mixed amount's display styles using the provided commodity style map.
canonicaliseMixedAmount :: M.Map Commodity AmountStyle -> MixedAmount -> MixedAmount
canonicaliseMixedAmount styles (Mixed as) = Mixed $ map (canonicaliseAmount styles) as

View File

@ -374,7 +374,7 @@ periodBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals))
render
id
((" "++) . showDateSpan)
showMixedAmountWithoutPrice
showMixedAmountOneLineWithoutPrice
$ Table
(T.Group NoLine $ map (Header . padright acctswidth) accts)
(T.Group NoLine $ map Header colspans)
@ -398,7 +398,7 @@ cumulativeBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> [String]
cumulativeBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) =
(["Ending balance (cumulative):"] ++) $
trimborder $ lines $
render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountWithoutPrice $
render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountOneLineWithoutPrice $
addtotalrow $
Table
(T.Group NoLine $ map (Header . padright acctswidth) accts)
@ -419,7 +419,7 @@ historicalBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> [String]
historicalBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) =
(["Ending balance (historical):"] ++) $
trimborder $ lines $
render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountWithoutPrice $
render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountOneLineWithoutPrice $
addtotalrow $
Table
(T.Group NoLine $ map (Header . padright acctswidth) accts)