rename amount show functions
This commit is contained in:
		
							parent
							
								
									782d05aa61
								
							
						
					
					
						commit
						aac492c746
					
				| @ -124,7 +124,7 @@ showBalanceReport opts args l = acctsstr ++ totalstr | |||||||
|       acctsstr = concatMap (showAccountTreeWithBalances acctnamestoshow) $ subs treetoshow |       acctsstr = concatMap (showAccountTreeWithBalances acctnamestoshow) $ subs treetoshow | ||||||
|       totalstr = if isZeroAmount total  |       totalstr = if isZeroAmount total  | ||||||
|                  then ""  |                  then ""  | ||||||
|                  else printf "--------------------\n%20s\n" $ showAmountRounded total |                  else printf "--------------------\n%20s\n" $ showAmount total | ||||||
|       showingsubs = ShowSubs `elem` opts |       showingsubs = ShowSubs `elem` opts | ||||||
|       pats@(apats,dpats) = parseAccountDescriptionArgs args |       pats@(apats,dpats) = parseAccountDescriptionArgs args | ||||||
|       maxdepth = if null args && not showingsubs then 1 else 9999 |       maxdepth = if null args && not showingsubs then 1 else 9999 | ||||||
|  | |||||||
| @ -46,12 +46,12 @@ import Ledger.Commodity | |||||||
| amounttests = TestList [ | amounttests = TestList [ | ||||||
|               ] |               ] | ||||||
| 
 | 
 | ||||||
| instance Show Amount where show = showAmountRounded | instance Show Amount where show = showAmount | ||||||
| 
 | 
 | ||||||
| -- | Get the string representation of an amount, based on its commodity's | -- | Get the string representation of an amount, based on its commodity's | ||||||
| -- display settings. | -- display settings. | ||||||
| showAmountRounded :: Amount -> String | showAmount :: Amount -> String | ||||||
| showAmountRounded (Amount (Commodity {symbol=sym,side=side,spaced=spaced,precision=p}) q) | showAmount (Amount (Commodity {symbol=sym,side=side,spaced=spaced,precision=p}) q) | ||||||
|     | side==L = printf "%s%s%s" sym space quantity |     | side==L = printf "%s%s%s" sym space quantity | ||||||
|     | side==R = printf "%s%s%s" quantity space sym |     | side==R = printf "%s%s%s" quantity space sym | ||||||
|     where  |     where  | ||||||
| @ -60,17 +60,17 @@ showAmountRounded (Amount (Commodity {symbol=sym,side=side,spaced=spaced,precisi | |||||||
|       punctuatethousands = id |       punctuatethousands = id | ||||||
| 
 | 
 | ||||||
| -- | Get the string representation of an amount, rounded, or showing just "0" if it's zero. | -- | Get the string representation of an amount, rounded, or showing just "0" if it's zero. | ||||||
| showAmountRoundedOrZero :: Amount -> String | showAmountOrZero :: Amount -> String | ||||||
| showAmountRoundedOrZero a | showAmountOrZero a | ||||||
|     | isZeroAmount a = "0" |     | isZeroAmount a = "0" | ||||||
|     | otherwise = showAmountRounded a |     | otherwise = showAmount a | ||||||
| 
 | 
 | ||||||
| -- | is this amount zero, when displayed with its given precision ? | -- | is this amount zero, when displayed with its given precision ? | ||||||
| isZeroAmount :: Amount -> Bool | isZeroAmount :: Amount -> Bool | ||||||
| isZeroAmount a@(Amount c _ ) = nonzerodigits == "" | isZeroAmount a@(Amount c _ ) = nonzerodigits == "" | ||||||
|     where |     where | ||||||
|       nonzerodigits = filter (flip notElem "-+,.0") quantitystr |       nonzerodigits = filter (flip notElem "-+,.0") quantitystr | ||||||
|       quantitystr = withoutsymbol $ showAmountRounded a |       quantitystr = withoutsymbol $ showAmount a | ||||||
|       withoutsymbol = drop (length $ symbol c) -- XXX |       withoutsymbol = drop (length $ symbol c) -- XXX | ||||||
| 
 | 
 | ||||||
| punctuatethousands :: String -> String | punctuatethousands :: String -> String | ||||||
|  | |||||||
| @ -83,7 +83,7 @@ showEntry e = | |||||||
|       showtxn t = showacct t ++ "  " ++ (showamount $ tamount t) ++ (showcomment $ tcomment t) |       showtxn t = showacct t ++ "  " ++ (showamount $ tamount t) ++ (showcomment $ tcomment t) | ||||||
|       showtxnnoamt t = showacct t ++ "              " ++ (showcomment $ tcomment t) |       showtxnnoamt t = showacct t ++ "              " ++ (showcomment $ tcomment t) | ||||||
|       showacct t = "    " ++ (showaccountname $ taccount t) |       showacct t = "    " ++ (showaccountname $ taccount t) | ||||||
|       showamount = printf "%12s" . showAmountRounded |       showamount = printf "%12s" . showAmount | ||||||
|       showaccountname s = printf "%-34s" s |       showaccountname s = printf "%-34s" s | ||||||
|       showcomment s = if (length s) > 0 then "  ; "++s else "" |       showcomment s = if (length s) > 0 then "  ; "++s else "" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ showLedgerTransaction :: RawTransaction -> String | |||||||
| showLedgerTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ tamount t)  | showLedgerTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ tamount t)  | ||||||
|     where |     where | ||||||
|       showaccountname = printf "%-22s" . elideRight 22 |       showaccountname = printf "%-22s" . elideRight 22 | ||||||
|       showamount = printf "%12s" . showAmountRoundedOrZero |       showamount = printf "%12s" . showAmountOrZero | ||||||
| 
 | 
 | ||||||
| elideRight width s = | elideRight width s = | ||||||
|     case length s > width of |     case length s > width of | ||||||
|  | |||||||
| @ -46,5 +46,5 @@ showTransactionAndBalance t b = | |||||||
|     (replicate 32 ' ') ++ (showLedgerTransaction $ RawTransaction (account t) (amount t) "") ++ (showBalance b) |     (replicate 32 ' ') ++ (showLedgerTransaction $ RawTransaction (account t) (amount t) "") ++ (showBalance b) | ||||||
| 
 | 
 | ||||||
| showBalance :: Amount -> String | showBalance :: Amount -> String | ||||||
| showBalance b = printf " %12s" (showAmountRoundedOrZero b) | showBalance b = printf " %12s" (showAmountOrZero b) | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user