mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 03:42:25 +03:00
fix some display problems, preserve transaction grouping
This commit is contained in:
parent
6dc6186c0d
commit
b5087b88c5
@ -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
|
||||
|
@ -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
|
||||
|
8
Makefile
8
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:
|
||||
|
10
NOTES
10
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
|
||||
|
@ -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 =
|
||||
|
1
Types.hs
1
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,
|
||||
|
Loading…
Reference in New Issue
Block a user