trim even more fat from amounts
This commit is contained in:
parent
06e224dc4a
commit
676845b269
@ -73,8 +73,6 @@ module Hledger.Data.Amount (
|
|||||||
-- ** rendering
|
-- ** rendering
|
||||||
showMixedAmount,
|
showMixedAmount,
|
||||||
showMixedAmountDebug,
|
showMixedAmountDebug,
|
||||||
showMixedAmountOrZero,
|
|
||||||
showMixedAmountOrZeroWithoutPrice,
|
|
||||||
showMixedAmountWithoutPrice,
|
showMixedAmountWithoutPrice,
|
||||||
showMixedAmountWithPrecision,
|
showMixedAmountWithPrecision,
|
||||||
-- * misc.
|
-- * misc.
|
||||||
@ -376,20 +374,6 @@ showMixedAmountWithoutPrice m = concat $ intersperse "\n" $ map showfixedwidth a
|
|||||||
width = maximum $ map (length . show) as
|
width = maximum $ map (length . show) as
|
||||||
showfixedwidth = printf (printf "%%%ds" width) . showAmountWithoutPrice
|
showfixedwidth = printf (printf "%%%ds" width) . showAmountWithoutPrice
|
||||||
|
|
||||||
-- | Get the string representation of a mixed amount, and if it
|
|
||||||
-- appears to be all zero just show a bare 0, ledger-style.
|
|
||||||
showMixedAmountOrZero :: MixedAmount -> String
|
|
||||||
showMixedAmountOrZero a | a == missingamt = ""
|
|
||||||
| isZeroMixedAmount a = "0"
|
|
||||||
| otherwise = showMixedAmount a
|
|
||||||
|
|
||||||
-- | Get the string representation of a mixed amount, or a bare 0,
|
|
||||||
-- without any \@ prices.
|
|
||||||
showMixedAmountOrZeroWithoutPrice :: MixedAmount -> String
|
|
||||||
showMixedAmountOrZeroWithoutPrice a
|
|
||||||
| isZeroMixedAmount a = "0"
|
|
||||||
| otherwise = showMixedAmountWithoutPrice a
|
|
||||||
|
|
||||||
-- | Replace a mixed amount's commodity with the canonicalised version from
|
-- | Replace a mixed amount's commodity with the canonicalised version from
|
||||||
-- the provided commodity map.
|
-- the provided commodity map.
|
||||||
canonicaliseMixedAmountCommodity :: Maybe (Map.Map String Commodity) -> MixedAmount -> MixedAmount
|
canonicaliseMixedAmountCommodity :: Maybe (Map.Map String Commodity) -> MixedAmount -> MixedAmount
|
||||||
@ -463,11 +447,6 @@ tests_Hledger_Data_Amount = TestList [
|
|||||||
showMixedAmount (Mixed []) `is` "0"
|
showMixedAmount (Mixed []) `is` "0"
|
||||||
showMixedAmount missingamt `is` ""
|
showMixedAmount missingamt `is` ""
|
||||||
|
|
||||||
,"showMixedAmountOrZero" ~: do
|
|
||||||
showMixedAmountOrZero (Mixed [Amount dollar 0 Nothing]) `is` "0"
|
|
||||||
showMixedAmountOrZero (Mixed []) `is` "0"
|
|
||||||
showMixedAmountOrZero missingamt `is` ""
|
|
||||||
|
|
||||||
,"showMixedAmountWithoutPrice" ~: do
|
,"showMixedAmountWithoutPrice" ~: do
|
||||||
let a = (dollars 1){price=Just $ UnitPrice $ Mixed [euros 2]}
|
let a = (dollars 1){price=Just $ UnitPrice $ Mixed [euros 2]}
|
||||||
showMixedAmountWithoutPrice (Mixed [a]) `is` "$1.00"
|
showMixedAmountWithoutPrice (Mixed [a]) `is` "$1.00"
|
||||||
|
|||||||
@ -39,7 +39,7 @@ showPosting (Posting{paccount=a,pamount=amt,pcomment=com,ptype=t}) =
|
|||||||
BalancedVirtualPosting -> (\s -> "["++s++"]", acctnamewidth-2)
|
BalancedVirtualPosting -> (\s -> "["++s++"]", acctnamewidth-2)
|
||||||
VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2)
|
VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2)
|
||||||
_ -> (id,acctnamewidth)
|
_ -> (id,acctnamewidth)
|
||||||
showamount = padleft 12 . showMixedAmountOrZero
|
showamount = padleft 12 . showMixedAmount
|
||||||
comment = if null com then "" else " ; " ++ com
|
comment = if null com then "" else " ; " ++ com
|
||||||
-- XXX refactor
|
-- XXX refactor
|
||||||
showPostingForRegister :: Posting -> String
|
showPostingForRegister :: Posting -> String
|
||||||
@ -53,7 +53,7 @@ showPostingForRegister (Posting{paccount=a,pamount=amt,ptype=t}) =
|
|||||||
BalancedVirtualPosting -> (\s -> "["++s++"]", acctnamewidth-2)
|
BalancedVirtualPosting -> (\s -> "["++s++"]", acctnamewidth-2)
|
||||||
VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2)
|
VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2)
|
||||||
_ -> (id,acctnamewidth)
|
_ -> (id,acctnamewidth)
|
||||||
showamount = padleft 12 . showMixedAmountOrZeroWithoutPrice
|
showamount = padleft 12 . showMixedAmountWithoutPrice
|
||||||
|
|
||||||
isReal :: Posting -> Bool
|
isReal :: Posting -> Bool
|
||||||
isReal p = ptype p == RegularPosting
|
isReal p = ptype p == RegularPosting
|
||||||
|
|||||||
@ -95,7 +95,7 @@ showTransaction' elide effective t =
|
|||||||
where w = maximum $ map (length . paccount) ps
|
where w = maximum $ map (length . paccount) ps
|
||||||
showstatus p = if pstatus p then "* " else ""
|
showstatus p = if pstatus p then "* " else ""
|
||||||
showamt =
|
showamt =
|
||||||
padleft 12 . showMixedAmountOrZero
|
padleft 12 . showMixedAmount
|
||||||
showcomment s = if null s then "" else " ; "++s
|
showcomment s = if null s then "" else " ; "++s
|
||||||
|
|
||||||
-- | Show an account name, clipped to the given width if any, and
|
-- | Show an account name, clipped to the given width if any, and
|
||||||
|
|||||||
@ -54,7 +54,7 @@ postingsReportItemAsText _ (dd, p, b) = concatTopPadded [datedesc, pstr, " ", ba
|
|||||||
datedescwidth = 32
|
datedescwidth = 32
|
||||||
datewidth = 10
|
datewidth = 10
|
||||||
pstr = showPostingForRegister p
|
pstr = showPostingForRegister p
|
||||||
bal = padleft 12 (showMixedAmountOrZeroWithoutPrice b)
|
bal = padleft 12 (showMixedAmountWithoutPrice b)
|
||||||
|
|
||||||
-- XXX
|
-- XXX
|
||||||
showPostingWithBalanceForVty showtxninfo p b = postingsReportItemAsText defreportopts $ mkpostingsReportItem showtxninfo p b
|
showPostingWithBalanceForVty showtxninfo p b = postingsReportItemAsText defreportopts $ mkpostingsReportItem showtxninfo p b
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user