show mixed amounts vertically
This commit is contained in:
parent
383d940b2d
commit
a7384a9183
@ -132,7 +132,7 @@ showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr)
|
|||||||
collapse = Collapse `elem` opts
|
collapse = Collapse `elem` opts
|
||||||
totalstr = if isZeroMixedAmount total
|
totalstr = if isZeroMixedAmount total
|
||||||
then ""
|
then ""
|
||||||
else printf "--------------------\n%20s\n" $ showMixedAmount total
|
else printf "--------------------\n%s\n" $ padleft 20 $ showMixedAmount total
|
||||||
total = sum $ map (abalance . ledgerAccount l) $ nonredundantaccts
|
total = sum $ map (abalance . ledgerAccount l) $ nonredundantaccts
|
||||||
nonredundantaccts = filter (not . hasparentshowing) matchedacctnames
|
nonredundantaccts = filter (not . hasparentshowing) matchedacctnames
|
||||||
hasparentshowing aname = (parentAccountName $ aname) `elem` matchedacctnames
|
hasparentshowing aname = (parentAccountName $ aname) `elem` matchedacctnames
|
||||||
@ -175,8 +175,8 @@ showAccountTreeWithBalances matchednames t = showAccountTreeWithBalances' matche
|
|||||||
subsindented = showsubs (indent+1) ""
|
subsindented = showsubs (indent+1) ""
|
||||||
showsubs i p = concatMap (showAccountTreeWithBalances' matchednames i p) subs
|
showsubs i p = concatMap (showAccountTreeWithBalances' matchednames i p) subs
|
||||||
hasmatchedsubs = not $ null $ filter ((`elem` matchednames) . aname) $ concatMap flatten subs
|
hasmatchedsubs = not $ null $ filter ((`elem` matchednames) . aname) $ concatMap flatten subs
|
||||||
this = showbal ++ spaces ++ prefix ++ leafname ++ "\n"
|
amt = padleft 20 $ showMixedAmount bal
|
||||||
showbal = printf "%20s" $ showMixedAmount bal
|
this = concatTopPadded [amt, spaces ++ prefix ++ leafname] ++ "\n"
|
||||||
spaces = " " ++ replicate (indent * 2) ' '
|
spaces = " " ++ replicate (indent * 2) ' '
|
||||||
leafname = accountLeafName fullname
|
leafname = accountLeafName fullname
|
||||||
ismatched = fullname `elem` matchednames
|
ismatched = fullname `elem` matchednames
|
||||||
@ -184,3 +184,4 @@ showAccountTreeWithBalances matchednames t = showAccountTreeWithBalances' matche
|
|||||||
numsubs = length subs
|
numsubs = length subs
|
||||||
subbal = abalance $ root $ head subs
|
subbal = abalance $ root $ head subs
|
||||||
matched = fullname `elem` matchednames
|
matched = fullname `elem` matchednames
|
||||||
|
|
||||||
|
|||||||
@ -134,8 +134,11 @@ isZeroMixedAmount = all isZeroAmount . amounts . normaliseMixedAmount
|
|||||||
-- | Get the string representation of a mixed amount, showing each of
|
-- | Get the string representation of a mixed amount, showing each of
|
||||||
-- its component amounts.
|
-- its component amounts.
|
||||||
showMixedAmount :: MixedAmount -> String
|
showMixedAmount :: MixedAmount -> String
|
||||||
showMixedAmount m = concat $ intersperse ", " $ map show as
|
showMixedAmount m = concat $ intersperse "\n" $ map showfixedwidth as
|
||||||
where (Mixed as) = normaliseMixedAmount m
|
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
|
-- | Get the string representation of a mixed amount, and if it
|
||||||
-- appears to be all zero just show a bare 0, ledger-style.
|
-- appears to be all zero just show a bare 0, ledger-style.
|
||||||
|
|||||||
@ -19,14 +19,14 @@ nullrawtxn = RawTransaction "" nullmixedamt "" RegularTransaction
|
|||||||
|
|
||||||
showRawTransaction :: RawTransaction -> String
|
showRawTransaction :: RawTransaction -> String
|
||||||
showRawTransaction (RawTransaction a amt _ ttype) =
|
showRawTransaction (RawTransaction a amt _ ttype) =
|
||||||
showaccountname a ++ " " ++ (showamount amt)
|
concatTopPadded [showaccountname a ++ " ", showamount amt]
|
||||||
where
|
where
|
||||||
showaccountname = printf "%-22s" . bracket . elideAccountName width
|
showaccountname = printf "%-22s" . bracket . elideAccountName width
|
||||||
showamount = printf "%12s" . showMixedAmountOrZero
|
|
||||||
(bracket,width) = case ttype of
|
(bracket,width) = case ttype of
|
||||||
BalancedVirtualTransaction -> (\s -> "["++s++"]", 20)
|
BalancedVirtualTransaction -> (\s -> "["++s++"]", 20)
|
||||||
VirtualTransaction -> (\s -> "("++s++")", 20)
|
VirtualTransaction -> (\s -> "("++s++")", 20)
|
||||||
otherwise -> (id,22)
|
otherwise -> (id,22)
|
||||||
|
showamount = padleft 12 . showMixedAmountOrZero
|
||||||
|
|
||||||
isReal :: RawTransaction -> Bool
|
isReal :: RawTransaction -> Bool
|
||||||
isReal t = rttype t == RegularTransaction
|
isReal t = rttype t == RegularTransaction
|
||||||
|
|||||||
1
NOTES
1
NOTES
@ -6,7 +6,6 @@ implementations were its consequences." --Niklaus Wirth
|
|||||||
|
|
||||||
* to do
|
* to do
|
||||||
** errors
|
** errors
|
||||||
*** display mixed amounts vertically, not horizontally
|
|
||||||
** features
|
** features
|
||||||
*** flexible date expressions, for easier time reports
|
*** flexible date expressions, for easier time reports
|
||||||
**** more formats
|
**** more formats
|
||||||
|
|||||||
@ -43,11 +43,11 @@ showRegisterReport opts args l = showtxns ts nulltxn nullmixedamt
|
|||||||
|
|
||||||
-- show one transaction line, with or without the entry details
|
-- show one transaction line, with or without the entry details
|
||||||
showtxn :: Bool -> Transaction -> MixedAmount -> String
|
showtxn :: Bool -> Transaction -> MixedAmount -> String
|
||||||
showtxn omitdesc t b = entrydesc ++ txn ++ bal ++ "\n"
|
showtxn omitdesc t b = concatBottomPadded [entrydesc ++ txn ++ " ", bal] ++ "\n"
|
||||||
where
|
where
|
||||||
entrydesc = if omitdesc then replicate 32 ' ' else printf "%s %s " date desc
|
entrydesc = if omitdesc then replicate 32 ' ' else printf "%s %s " date desc
|
||||||
date = show $ da
|
date = show $ da
|
||||||
desc = printf "%-20s" $ elideRight 20 de :: String
|
desc = printf "%-20s" $ elideRight 20 de :: String
|
||||||
txn = showRawTransaction $ RawTransaction a amt "" tt
|
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
|
Transaction{date=da,description=de,account=a,amount=amt,ttype=tt} = t
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user