ledger 2.x-like elision, register output should now be identical

This commit is contained in:
Simon Michael 2007-02-13 05:42:55 +00:00
parent 41e83c4688
commit c45ad065d8
2 changed files with 37 additions and 17 deletions

View File

@ -33,12 +33,15 @@ Amount ca qa `amountAdd` Amount cb qb = Amount ca (qa + qb)
Amount ca qa `amountSub` Amount cb qb = Amount ca (qa - qb) Amount ca qa `amountSub` Amount cb qb = Amount ca (qa - qb)
Amount ca qa `amountMult` Amount cb qb = Amount ca (qa * qb) Amount ca qa `amountMult` Amount cb qb = Amount ca (qa * qb)
instance Show Amount where instance Show Amount where show = amountRoundedOrZero
show (Amount cur qty) =
let roundedqty = printf "%.2f" qty in amountRoundedOrZero :: Amount -> String
case roundedqty of amountRoundedOrZero (Amount cur qty) =
"0.00" -> "0" let rounded = printf "%.2f" qty in
otherwise -> cur ++ roundedqty case rounded of
"0.00" -> "0"
"-0.00" -> "0"
otherwise -> cur ++ rounded
-- modifier & periodic entries -- modifier & periodic entries
@ -60,14 +63,14 @@ instance Show PeriodicEntry where
-- entries -- entries
-- a register entry is displayed as two or more lines like this: -- a register entry is displayed as two or more lines like this:
-- date description account amount balance -- date description account amount balance
-- DDDDDDDDDD dddddddddddddddddddd aaaaaaaaaaaaaaaaaaaaa AAAAAAAAAAAA AAAAAAAAAAAA -- DDDDDDDDDD dddddddddddddddddddd aaaaaaaaaaaaaaaaaaaaaa AAAAAAAAAAA AAAAAAAAAAAA
-- aaaaaaaaaaaaaaaaaaaaa AAAAAAAAAAAA AAAAAAAAAAAA -- aaaaaaaaaaaaaaaaaaaaaa AAAAAAAAAAA AAAAAAAAAAAA
-- ... ... ... -- ... ... ...
-- dateWidth = 10 -- dateWidth = 10
-- descWidth = 20 -- descWidth = 20
-- acctWidth = 21 -- acctWidth = 22
-- amtWidth = 12 -- amtWidth = 11
-- balWidth = 12 -- balWidth = 12
data Entry = Entry { data Entry = Entry {
@ -80,7 +83,9 @@ data Entry = Entry {
instance Show Entry where show = showEntry instance Show Entry where show = showEntry
showEntry e = printf "%-10s %-20s " (edate e) (take 20 $ edescription e) showEntry e = (showDate $ edate e) ++ " " ++ (showDescription $ edescription e) ++ " "
showDate d = printf "%-10s" d
showDescription s = printf "%-20s" (elideRight 20 s)
isEntryBalanced :: Entry -> Bool isEntryBalanced :: Entry -> Bool
isEntryBalanced e = (sumTransactions . etransactions) e == 0 isEntryBalanced e = (sumTransactions . etransactions) e == 0
@ -99,8 +104,24 @@ data Transaction = Transaction {
instance Show Transaction where show = showTransaction instance Show Transaction where show = showTransaction
showTransaction t = printf "%-21s %12.2s" (take 21 $ taccount t) (show $ tamount t) showTransaction t = (showAccount $ taccount t) ++ " " ++ (showAmount $ tamount t)
showAmount amt = printf "%11s" (show amt)
showAccount s = printf "%-22s" (elideRight 22 s)
elideRight width s =
case length s > width of
True -> take (width - 2) s ++ ".."
False -> s
-- elideAccountRight width abbrevlen a =
-- case length a > width of
-- False -> a
-- True -> abbreviateAccountComponent abbrevlen a
-- abbreviateAccountComponent abbrevlen a =
-- let components = splitAtElement ':' a in
-- case
autofillTransactions :: [Transaction] -> [Transaction] autofillTransactions :: [Transaction] -> [Transaction]
autofillTransactions ts = autofillTransactions ts =
let (ns, as) = partition isNormal ts let (ns, as) = partition isNormal ts
@ -171,7 +192,7 @@ showTransactionAndBalance :: EntryTransaction -> Amount -> String
showTransactionAndBalance t b = showTransactionAndBalance t b =
(replicate 32 ' ') ++ (showTransaction $ transaction t) ++ (showBalance b) (replicate 32 ' ') ++ (showTransaction $ transaction t) ++ (showBalance b)
showBalance b = printf " %12.2s" (show b) showBalance b = printf " %12s" (amountRoundedOrZero b)
-- accounts -- accounts

3
TODO
View File

@ -1,12 +1,11 @@
features features
register
svn-style truncation
balance balance
show top-level acct balances show top-level acct balances
show all account balances show all account balances
print print
entry entry
-j and -J graph data output -j and -J graph data output
svn-style elision
!include !include
read timelog files read timelog files
-p period expressions -p period expressions