mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 10:17:35 +03:00
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,
|
||||
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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user