show mixed amounts vertically

This commit is contained in:
Simon Michael 2008-11-22 09:07:04 +00:00
parent 383d940b2d
commit a7384a9183
5 changed files with 13 additions and 10 deletions

View File

@ -132,7 +132,7 @@ showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr)
collapse = Collapse `elem` opts
totalstr = if isZeroMixedAmount total
then ""
else printf "--------------------\n%20s\n" $ showMixedAmount total
else printf "--------------------\n%s\n" $ padleft 20 $ showMixedAmount total
total = sum $ map (abalance . ledgerAccount l) $ nonredundantaccts
nonredundantaccts = filter (not . hasparentshowing) matchedacctnames
hasparentshowing aname = (parentAccountName $ aname) `elem` matchedacctnames
@ -175,8 +175,8 @@ showAccountTreeWithBalances matchednames t = showAccountTreeWithBalances' matche
subsindented = showsubs (indent+1) ""
showsubs i p = concatMap (showAccountTreeWithBalances' matchednames i p) subs
hasmatchedsubs = not $ null $ filter ((`elem` matchednames) . aname) $ concatMap flatten subs
this = showbal ++ spaces ++ prefix ++ leafname ++ "\n"
showbal = printf "%20s" $ showMixedAmount bal
amt = padleft 20 $ showMixedAmount bal
this = concatTopPadded [amt, spaces ++ prefix ++ leafname] ++ "\n"
spaces = " " ++ replicate (indent * 2) ' '
leafname = accountLeafName fullname
ismatched = fullname `elem` matchednames
@ -184,3 +184,4 @@ showAccountTreeWithBalances matchednames t = showAccountTreeWithBalances' matche
numsubs = length subs
subbal = abalance $ root $ head subs
matched = fullname `elem` matchednames

View File

@ -134,8 +134,11 @@ isZeroMixedAmount = all isZeroAmount . amounts . normaliseMixedAmount
-- | Get the string representation of a mixed amount, showing each of
-- its component amounts.
showMixedAmount :: MixedAmount -> String
showMixedAmount m = concat $ intersperse ", " $ map show as
where (Mixed as) = normaliseMixedAmount m
showMixedAmount m = concat $ intersperse "\n" $ map showfixedwidth as
where
(Mixed as) = normaliseMixedAmount m
width = maximum $ map (length . show) $ as
showfixedwidth = printf (printf "%%%ds" width) . show
-- | Get the string representation of a mixed amount, and if it
-- appears to be all zero just show a bare 0, ledger-style.

View File

@ -19,14 +19,14 @@ nullrawtxn = RawTransaction "" nullmixedamt "" RegularTransaction
showRawTransaction :: RawTransaction -> String
showRawTransaction (RawTransaction a amt _ ttype) =
showaccountname a ++ " " ++ (showamount amt)
concatTopPadded [showaccountname a ++ " ", showamount amt]
where
showaccountname = printf "%-22s" . bracket . elideAccountName width
showamount = printf "%12s" . showMixedAmountOrZero
(bracket,width) = case ttype of
BalancedVirtualTransaction -> (\s -> "["++s++"]", 20)
VirtualTransaction -> (\s -> "("++s++")", 20)
otherwise -> (id,22)
showamount = padleft 12 . showMixedAmountOrZero
isReal :: RawTransaction -> Bool
isReal t = rttype t == RegularTransaction

1
NOTES
View File

@ -6,7 +6,6 @@ implementations were its consequences." --Niklaus Wirth
* to do
** errors
*** display mixed amounts vertically, not horizontally
** features
*** flexible date expressions, for easier time reports
**** more formats

View File

@ -43,11 +43,11 @@ showRegisterReport opts args l = showtxns ts nulltxn nullmixedamt
-- show one transaction line, with or without the entry details
showtxn :: Bool -> Transaction -> MixedAmount -> String
showtxn omitdesc t b = entrydesc ++ txn ++ bal ++ "\n"
showtxn omitdesc t b = concatBottomPadded [entrydesc ++ txn ++ " ", bal] ++ "\n"
where
entrydesc = if omitdesc then replicate 32 ' ' else printf "%s %s " date desc
date = show $ da
desc = printf "%-20s" $ elideRight 20 de :: String
txn = showRawTransaction $ RawTransaction a amt "" tt
bal = printf " %12s" (showMixedAmountOrZero b)
bal = padleft 12 (showMixedAmountOrZero b)
Transaction{date=da,description=de,account=a,amount=amt,ttype=tt} = t