From b5087b88c5a8fd81c989021e51e04d8753e83ab1 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 4 Jul 2007 12:40:26 +0000 Subject: [PATCH] fix some display problems, preserve transaction grouping --- Ledger.hs | 2 +- LedgerEntry.hs | 14 +++++++------- Makefile | 8 ++++---- NOTES | 10 ++++++---- Transaction.hs | 18 +++++++++--------- Types.hs | 1 + 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Ledger.hs b/Ledger.hs index 5c4838d26..58a1aebea 100644 --- a/Ledger.hs +++ b/Ledger.hs @@ -15,7 +15,7 @@ rawLedgerTransactions :: LedgerFile -> [Transaction] rawLedgerTransactions = txns . entries where txns :: [LedgerEntry] -> [Transaction] - txns es = concat $ map flattenEntry es + txns es = concat $ map flattenEntry $ zip es (iterate (+1) 1) rawLedgerAccountNamesUsed :: LedgerFile -> [AccountName] rawLedgerAccountNamesUsed = accountNamesFromTransactions . rawLedgerTransactions diff --git a/LedgerEntry.hs b/LedgerEntry.hs index bcd55bbcf..fd45e7dfe 100644 --- a/LedgerEntry.hs +++ b/LedgerEntry.hs @@ -35,15 +35,15 @@ autofillEntry e = -- the print command shows cleaned up ledger file entries, something like: -- --- yyyy/mm/dd[ *][ CODE] description......... [ ; comment.............] --- account name 1..................... ...$amount1[ ; comment.............] --- account name 2..................... ..$-amount1[ ; comment.............] +-- yyyy/mm/dd[ *][ CODE] description......... [ ; comment...............] +-- account name 1..................... ...$amount1[ ; comment...............] +-- account name 2..................... ..$-amount1[ ; comment...............] -- -- codewidth = 10 -- descwidth = 20 -- acctwidth = 35 -- amtwidth = 11 --- commentwidth = 20 +-- commentwidth = 22 showEntry :: LedgerEntry -> String showEntry e = @@ -52,9 +52,9 @@ showEntry e = description = concat [date, status, code, desc, comment] date = showDate $ edate e status = if estatus e then " *" else "" - code = if (length $ ecode e) > 0 then " "++(printf "%-10s" $ ecode e) else "" + code = if (length $ ecode e) > 0 then (printf " (%s)" $ ecode e) else "" desc = " " ++ (elideRight 20 $ edescription e) - comment = if (length $ ecomment e) > 0 then " ; "++(printf "%-20s" $ ecomment e) else "" + comment = if (length $ ecomment e) > 0 then " ; "++(ecomment e) else "" showtxns (t1:t2:[]) = [showtxn t1, showtxnnoamt t2] showtxns ts = map showtxn ts showtxn t = showacct t ++ " " ++ (showamount $ tamount t) ++ (showcomment $ tcomment t) @@ -62,7 +62,7 @@ showEntry e = showacct t = " " ++ (showaccountname $ taccount t) showamount = printf "%11s" . showAmountRounded showaccountname = printf "%-35s" . elideRight 35 - showcomment s = if (length s) > 0 then " ; "++(printf "%-20s" $ elideRight 20 s) else "" + showcomment s = if (length s) > 0 then " ; "++s else "" showEntries :: [LedgerEntry] -> String showEntries = concatMap showEntry diff --git a/Makefile b/Makefile index 9f3d7483e..c2636e015 100644 --- a/Makefile +++ b/Makefile @@ -24,14 +24,14 @@ xprofile: build ghcprof profs/$(TIME).xprof #LEDGER=test.dat -compare: +compare: build rm -f 1 2 ledger -s balance >1 ledger register >>1 ledger print >>1 - ./hledger.hs -s balance >2 - ./hledger.hs register >>2 - ./hledger.hs print >>2 + ./hledger -s balance >2 + ./hledger register >>2 + ./hledger print >>2 diff 1 2 haddock: diff --git a/NOTES b/NOTES index 1f8355539..3f83b2d3a 100644 --- a/NOTES +++ b/NOTES @@ -2,6 +2,7 @@ hledger project notes * TO DO ** bugs/cleanup +*** resolve output differences ** ledger features *** handle mixed amounts, non-money currencies **** handle precision per currency @@ -15,11 +16,11 @@ hledger project notes *** !include *** -j and -J graph data output *** more speed -*** ledger 3.0-style elision +*** ledger 3-style elision *** -p period expressions *** -d display expressions *** read gnucash files -*** other ledger args, directives +*** other ledger 3 features ** new features *** alternate timelog format *** infer clock-out @@ -36,9 +37,10 @@ hledger project notes *** literate docs *** better use of haddock *** differences -**** ledger shows comments after descriptions as part of description +**** ledger shows comments after descriptions as part of description in register **** ledger does not sort register by date -**** ledger does not support -f- (no space) +**** ledger does not support -f- (without space) +**** hledger does not parse automated/periodic entries except at start of file ** marketing *** set up as a cabal/hackage project following wiki howto http://en.wikibooks.org/wiki/Haskell/Packaging diff --git a/Transaction.hs b/Transaction.hs index 4064dec36..5d062c98f 100644 --- a/Transaction.hs +++ b/Transaction.hs @@ -9,11 +9,13 @@ import Amount import Currency -flattenEntry :: LedgerEntry -> [Transaction] -flattenEntry (LedgerEntry d _ _ desc _ ts) = [Transaction d desc (taccount t) (tamount t) | t <- ts] +-- we use the entry number e to remember the grouping of txns +flattenEntry :: (LedgerEntry, Int) -> [Transaction] +flattenEntry (LedgerEntry d _ _ desc _ ts, e) = + [Transaction e d desc (taccount t) (tamount t) | t <- ts] transactionSetPrecision :: Int -> Transaction -> Transaction -transactionSetPrecision p (Transaction d desc a amt) = Transaction d desc a amt{precision=p} +transactionSetPrecision p (Transaction e d desc a amt) = Transaction e d desc a amt{precision=p} accountNamesFromTransactions :: [Transaction] -> [AccountName] accountNamesFromTransactions ts = nub $ map account ts @@ -40,18 +42,16 @@ showTransactionsWithBalances [] _ = [] showTransactionsWithBalances ts b = unlines $ showTransactionsWithBalances' ts dummyt b where - dummyt = Transaction "" "" "" (dollars 0) + dummyt = Transaction 0 "" "" "" (dollars 0) showTransactionsWithBalances' [] _ _ = [] showTransactionsWithBalances' (t:ts) tprev b = (if sameentry t tprev - then [showTransactionDescriptionAndBalance t b'] - else [showTransactionAndBalance t b']) + then [showTransactionAndBalance t b'] + else [showTransactionDescriptionAndBalance t b']) ++ (showTransactionsWithBalances' ts t b') where b' = b + (amount t) - sameentry (Transaction d1 desc1 _ _) (Transaction d2 desc2 _ _) = - d1 == d2 && desc1 == desc2 - -- we forgot the entry-txn relationships.. good enough ? + sameentry (Transaction e1 _ _ _ _) (Transaction e2 _ _ _ _) = e1 == e2 showTransactionDescriptionAndBalance :: Transaction -> Amount -> String showTransactionDescriptionAndBalance t b = diff --git a/Types.hs b/Types.hs index cd9ee820f..42522d6cf 100644 --- a/Types.hs +++ b/Types.hs @@ -100,6 +100,7 @@ data LedgerFile = LedgerFile { -- we flatten LedgerEntries and LedgerTransactions into Transactions, -- which are simpler to query at the cost of some data duplication data Transaction = Transaction { + entryno :: Int, date :: Date, description :: String, account :: AccountName,