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:
parent
3669422bbf
commit
16f8b78305
@ -63,6 +63,7 @@ module Hledger.Data.Amount (
|
|||||||
showAmount,
|
showAmount,
|
||||||
showAmountDebug,
|
showAmountDebug,
|
||||||
showAmountWithoutPrice,
|
showAmountWithoutPrice,
|
||||||
|
showMixedAmountOneLineWithoutPrice,
|
||||||
maxprecision,
|
maxprecision,
|
||||||
maxprecisionwithpoint,
|
maxprecisionwithpoint,
|
||||||
setAmountPrecision,
|
setAmountPrecision,
|
||||||
@ -501,6 +502,14 @@ showMixedAmountWithoutPrice m = concat $ intersperse "\n" $ map showfixedwidth a
|
|||||||
width = maximum $ map (length . showAmount) as
|
width = maximum $ map (length . showAmount) as
|
||||||
showfixedwidth = printf (printf "%%%ds" width) . showAmountWithoutPrice
|
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.
|
-- | Canonicalise a mixed amount's display styles using the provided commodity style map.
|
||||||
canonicaliseMixedAmount :: M.Map Commodity AmountStyle -> MixedAmount -> MixedAmount
|
canonicaliseMixedAmount :: M.Map Commodity AmountStyle -> MixedAmount -> MixedAmount
|
||||||
canonicaliseMixedAmount styles (Mixed as) = Mixed $ map (canonicaliseAmount styles) as
|
canonicaliseMixedAmount styles (Mixed as) = Mixed $ map (canonicaliseAmount styles) as
|
||||||
|
|||||||
@ -374,7 +374,7 @@ periodBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals))
|
|||||||
render
|
render
|
||||||
id
|
id
|
||||||
((" "++) . showDateSpan)
|
((" "++) . showDateSpan)
|
||||||
showMixedAmountWithoutPrice
|
showMixedAmountOneLineWithoutPrice
|
||||||
$ Table
|
$ Table
|
||||||
(T.Group NoLine $ map (Header . padright acctswidth) accts)
|
(T.Group NoLine $ map (Header . padright acctswidth) accts)
|
||||||
(T.Group NoLine $ map Header colspans)
|
(T.Group NoLine $ map Header colspans)
|
||||||
@ -398,7 +398,7 @@ cumulativeBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> [String]
|
|||||||
cumulativeBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) =
|
cumulativeBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) =
|
||||||
(["Ending balance (cumulative):"] ++) $
|
(["Ending balance (cumulative):"] ++) $
|
||||||
trimborder $ lines $
|
trimborder $ lines $
|
||||||
render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountWithoutPrice $
|
render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountOneLineWithoutPrice $
|
||||||
addtotalrow $
|
addtotalrow $
|
||||||
Table
|
Table
|
||||||
(T.Group NoLine $ map (Header . padright acctswidth) accts)
|
(T.Group NoLine $ map (Header . padright acctswidth) accts)
|
||||||
@ -419,7 +419,7 @@ historicalBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> [String]
|
|||||||
historicalBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) =
|
historicalBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) =
|
||||||
(["Ending balance (historical):"] ++) $
|
(["Ending balance (historical):"] ++) $
|
||||||
trimborder $ lines $
|
trimborder $ lines $
|
||||||
render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountWithoutPrice $
|
render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountOneLineWithoutPrice $
|
||||||
addtotalrow $
|
addtotalrow $
|
||||||
Table
|
Table
|
||||||
(T.Group NoLine $ map (Header . padright acctswidth) accts)
|
(T.Group NoLine $ map (Header . padright acctswidth) accts)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user