mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 20:02:27 +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
|
rawLedgerTransactions = txns . entries
|
||||||
where
|
where
|
||||||
txns :: [LedgerEntry] -> [Transaction]
|
txns :: [LedgerEntry] -> [Transaction]
|
||||||
txns es = concat $ map flattenEntry es
|
txns es = concat $ map flattenEntry $ zip es (iterate (+1) 1)
|
||||||
|
|
||||||
rawLedgerAccountNamesUsed :: LedgerFile -> [AccountName]
|
rawLedgerAccountNamesUsed :: LedgerFile -> [AccountName]
|
||||||
rawLedgerAccountNamesUsed = accountNamesFromTransactions . rawLedgerTransactions
|
rawLedgerAccountNamesUsed = accountNamesFromTransactions . rawLedgerTransactions
|
||||||
|
@ -35,15 +35,15 @@ autofillEntry e =
|
|||||||
|
|
||||||
-- the print command shows cleaned up ledger file entries, something like:
|
-- the print command shows cleaned up ledger file entries, something like:
|
||||||
--
|
--
|
||||||
-- yyyy/mm/dd[ *][ CODE] description......... [ ; comment.............]
|
-- yyyy/mm/dd[ *][ CODE] description......... [ ; comment...............]
|
||||||
-- account name 1..................... ...$amount1[ ; comment.............]
|
-- account name 1..................... ...$amount1[ ; comment...............]
|
||||||
-- account name 2..................... ..$-amount1[ ; comment.............]
|
-- account name 2..................... ..$-amount1[ ; comment...............]
|
||||||
--
|
--
|
||||||
-- codewidth = 10
|
-- codewidth = 10
|
||||||
-- descwidth = 20
|
-- descwidth = 20
|
||||||
-- acctwidth = 35
|
-- acctwidth = 35
|
||||||
-- amtwidth = 11
|
-- amtwidth = 11
|
||||||
-- commentwidth = 20
|
-- commentwidth = 22
|
||||||
|
|
||||||
showEntry :: LedgerEntry -> String
|
showEntry :: LedgerEntry -> String
|
||||||
showEntry e =
|
showEntry e =
|
||||||
@ -52,9 +52,9 @@ showEntry e =
|
|||||||
description = concat [date, status, code, desc, comment]
|
description = concat [date, status, code, desc, comment]
|
||||||
date = showDate $ edate e
|
date = showDate $ edate e
|
||||||
status = if estatus e then " *" else ""
|
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)
|
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 (t1:t2:[]) = [showtxn t1, showtxnnoamt t2]
|
||||||
showtxns ts = map showtxn ts
|
showtxns ts = map showtxn ts
|
||||||
showtxn t = showacct t ++ " " ++ (showamount $ tamount t) ++ (showcomment $ tcomment t)
|
showtxn t = showacct t ++ " " ++ (showamount $ tamount t) ++ (showcomment $ tcomment t)
|
||||||
@ -62,7 +62,7 @@ showEntry e =
|
|||||||
showacct t = " " ++ (showaccountname $ taccount t)
|
showacct t = " " ++ (showaccountname $ taccount t)
|
||||||
showamount = printf "%11s" . showAmountRounded
|
showamount = printf "%11s" . showAmountRounded
|
||||||
showaccountname = printf "%-35s" . elideRight 35
|
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 :: [LedgerEntry] -> String
|
||||||
showEntries = concatMap showEntry
|
showEntries = concatMap showEntry
|
||||||
|
8
Makefile
8
Makefile
@ -24,14 +24,14 @@ xprofile: build
|
|||||||
ghcprof profs/$(TIME).xprof
|
ghcprof profs/$(TIME).xprof
|
||||||
|
|
||||||
#LEDGER=test.dat
|
#LEDGER=test.dat
|
||||||
compare:
|
compare: build
|
||||||
rm -f 1 2
|
rm -f 1 2
|
||||||
ledger -s balance >1
|
ledger -s balance >1
|
||||||
ledger register >>1
|
ledger register >>1
|
||||||
ledger print >>1
|
ledger print >>1
|
||||||
./hledger.hs -s balance >2
|
./hledger -s balance >2
|
||||||
./hledger.hs register >>2
|
./hledger register >>2
|
||||||
./hledger.hs print >>2
|
./hledger print >>2
|
||||||
diff 1 2
|
diff 1 2
|
||||||
|
|
||||||
haddock:
|
haddock:
|
||||||
|
10
NOTES
10
NOTES
@ -2,6 +2,7 @@ hledger project notes
|
|||||||
|
|
||||||
* TO DO
|
* TO DO
|
||||||
** bugs/cleanup
|
** bugs/cleanup
|
||||||
|
*** resolve output differences
|
||||||
** ledger features
|
** ledger features
|
||||||
*** handle mixed amounts, non-money currencies
|
*** handle mixed amounts, non-money currencies
|
||||||
**** handle precision per currency
|
**** handle precision per currency
|
||||||
@ -15,11 +16,11 @@ hledger project notes
|
|||||||
*** !include
|
*** !include
|
||||||
*** -j and -J graph data output
|
*** -j and -J graph data output
|
||||||
*** more speed
|
*** more speed
|
||||||
*** ledger 3.0-style elision
|
*** ledger 3-style elision
|
||||||
*** -p period expressions
|
*** -p period expressions
|
||||||
*** -d display expressions
|
*** -d display expressions
|
||||||
*** read gnucash files
|
*** read gnucash files
|
||||||
*** other ledger args, directives
|
*** other ledger 3 features
|
||||||
** new features
|
** new features
|
||||||
*** alternate timelog format
|
*** alternate timelog format
|
||||||
*** infer clock-out
|
*** infer clock-out
|
||||||
@ -36,9 +37,10 @@ hledger project notes
|
|||||||
*** literate docs
|
*** literate docs
|
||||||
*** better use of haddock
|
*** better use of haddock
|
||||||
*** differences
|
*** 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 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
|
** marketing
|
||||||
*** set up as a cabal/hackage project following wiki howto
|
*** set up as a cabal/hackage project following wiki howto
|
||||||
http://en.wikibooks.org/wiki/Haskell/Packaging
|
http://en.wikibooks.org/wiki/Haskell/Packaging
|
||||||
|
@ -9,11 +9,13 @@ import Amount
|
|||||||
import Currency
|
import Currency
|
||||||
|
|
||||||
|
|
||||||
flattenEntry :: LedgerEntry -> [Transaction]
|
-- we use the entry number e to remember the grouping of txns
|
||||||
flattenEntry (LedgerEntry d _ _ desc _ ts) = [Transaction d desc (taccount t) (tamount t) | t <- ts]
|
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 :: 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 :: [Transaction] -> [AccountName]
|
||||||
accountNamesFromTransactions ts = nub $ map account ts
|
accountNamesFromTransactions ts = nub $ map account ts
|
||||||
@ -40,18 +42,16 @@ showTransactionsWithBalances [] _ = []
|
|||||||
showTransactionsWithBalances ts b =
|
showTransactionsWithBalances ts b =
|
||||||
unlines $ showTransactionsWithBalances' ts dummyt b
|
unlines $ showTransactionsWithBalances' ts dummyt b
|
||||||
where
|
where
|
||||||
dummyt = Transaction "" "" "" (dollars 0)
|
dummyt = Transaction 0 "" "" "" (dollars 0)
|
||||||
showTransactionsWithBalances' [] _ _ = []
|
showTransactionsWithBalances' [] _ _ = []
|
||||||
showTransactionsWithBalances' (t:ts) tprev b =
|
showTransactionsWithBalances' (t:ts) tprev b =
|
||||||
(if sameentry t tprev
|
(if sameentry t tprev
|
||||||
then [showTransactionDescriptionAndBalance t b']
|
then [showTransactionAndBalance t b']
|
||||||
else [showTransactionAndBalance t b'])
|
else [showTransactionDescriptionAndBalance t b'])
|
||||||
++ (showTransactionsWithBalances' ts t b')
|
++ (showTransactionsWithBalances' ts t b')
|
||||||
where
|
where
|
||||||
b' = b + (amount t)
|
b' = b + (amount t)
|
||||||
sameentry (Transaction d1 desc1 _ _) (Transaction d2 desc2 _ _) =
|
sameentry (Transaction e1 _ _ _ _) (Transaction e2 _ _ _ _) = e1 == e2
|
||||||
d1 == d2 && desc1 == desc2
|
|
||||||
-- we forgot the entry-txn relationships.. good enough ?
|
|
||||||
|
|
||||||
showTransactionDescriptionAndBalance :: Transaction -> Amount -> String
|
showTransactionDescriptionAndBalance :: Transaction -> Amount -> String
|
||||||
showTransactionDescriptionAndBalance t b =
|
showTransactionDescriptionAndBalance t b =
|
||||||
|
1
Types.hs
1
Types.hs
@ -100,6 +100,7 @@ data LedgerFile = LedgerFile {
|
|||||||
-- we flatten LedgerEntries and LedgerTransactions into Transactions,
|
-- we flatten LedgerEntries and LedgerTransactions into Transactions,
|
||||||
-- which are simpler to query at the cost of some data duplication
|
-- which are simpler to query at the cost of some data duplication
|
||||||
data Transaction = Transaction {
|
data Transaction = Transaction {
|
||||||
|
entryno :: Int,
|
||||||
date :: Date,
|
date :: Date,
|
||||||
description :: String,
|
description :: String,
|
||||||
account :: AccountName,
|
account :: AccountName,
|
||||||
|
Loading…
Reference in New Issue
Block a user