mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
filter transactions by account substring
This commit is contained in:
parent
0b5cb44b43
commit
960187f531
59
Models.hs
59
Models.hs
@ -92,11 +92,13 @@ entryLines e =
|
||||
[firstline] ++ otherlines
|
||||
where
|
||||
t:ts = transactions e
|
||||
entrydesc = printf "%-10s %-20s " (date e) (take 20 $ description e)
|
||||
firstline = (entrydesc ++ (show t), amount t)
|
||||
firstline = (entrydesc e ++ (show t), amount t)
|
||||
otherlines = map (\t -> (prependSpace $ show t, amount t)) ts
|
||||
prependSpace = (replicate 32 ' ' ++)
|
||||
|
||||
entrydesc e = printf "%-10s %-20s " (date e) (take 20 $ description e)
|
||||
|
||||
|
||||
instance Show Transaction where
|
||||
show t = printf "%-25s %10s" (take 25 $ account t) (show $ amount t)
|
||||
|
||||
@ -128,7 +130,9 @@ entryLinesWithBalances ((str,amt):els) bal =
|
||||
[(str',amt,bal')] ++ entryLinesWithBalances els bal'
|
||||
where
|
||||
bal' = bal + amt
|
||||
str' = str ++ (printf " %10.2s" (show bal'))
|
||||
str' = str ++ (showBalance bal')
|
||||
|
||||
showBalance b = printf " %10.2s" (show b)
|
||||
|
||||
-- misc
|
||||
|
||||
@ -151,12 +155,50 @@ normalAndAutoTransactions ts =
|
||||
partition isNormal ts
|
||||
where isNormal t = (currency $ amount t) /= "AUTO"
|
||||
|
||||
-- transactions
|
||||
|
||||
sumTransactions :: [Transaction] -> Amount
|
||||
sumTransactions ts = sum [amount t | t <- ts]
|
||||
|
||||
transactionsFromEntries :: [Entry] -> [Transaction]
|
||||
transactionsFromEntries es = concat $ map transactions es
|
||||
|
||||
matchTransactionAccount :: String -> Transaction -> Bool
|
||||
matchTransactionAccount s t = s `isInfixOf` (account t)
|
||||
|
||||
transactionsWithEntries :: [Entry] -> [(Transaction,Entry)]
|
||||
transactionsWithEntries es = [(t,e) | e <- es, t <- transactions e]
|
||||
|
||||
showTransactionsWithBalances :: [(Transaction,Entry)] -> Amount -> String
|
||||
showTransactionsWithBalances [] _ = []
|
||||
showTransactionsWithBalances tes b =
|
||||
unlines $ showTransactionsWithBalances' tes b
|
||||
where
|
||||
showTransactionsWithBalances' [] _ = []
|
||||
showTransactionsWithBalances' ((t,e):rest) b =
|
||||
[showTransactionWithBalance t e b'] ++ (showTransactionsWithBalances' rest b')
|
||||
where b' = b + (amount t)
|
||||
|
||||
showTransactionWithBalance :: Transaction -> Entry -> Amount -> String
|
||||
showTransactionWithBalance t e b =
|
||||
(entrydesc e) ++ (show t) ++ (showBalance b)
|
||||
|
||||
transactionsMatching :: String -> Ledger -> [(Transaction,Entry)]
|
||||
transactionsMatching s l = filter (\(t,e) -> matchTransactionAccount s t) (transactionsWithEntries $ entries l)
|
||||
|
||||
-- entries
|
||||
|
||||
entriesMatching :: String -> Ledger -> [Entry]
|
||||
entriesMatching s l = filterEntriesByAccount s (entries l)
|
||||
|
||||
filterEntriesByAccount :: String -> [Entry] -> [Entry]
|
||||
filterEntriesByAccount s es = filter (matchEntryAccount s) es
|
||||
|
||||
matchEntryAccount :: String -> Entry -> Bool
|
||||
matchEntryAccount s e = any (matchTransactionAccount s) (transactions e)
|
||||
|
||||
-- accounts
|
||||
|
||||
accountsFromTransactions :: [Transaction] -> [Account]
|
||||
accountsFromTransactions ts = nub $ map account ts
|
||||
|
||||
@ -180,14 +222,3 @@ splitAtElement e l =
|
||||
accountTree :: Ledger -> [Account]
|
||||
accountTree = sort . expandAccounts . accountsUsed
|
||||
|
||||
entriesMatching :: String -> Ledger -> [Entry]
|
||||
entriesMatching s l = filterEntriesByAccount s (entries l)
|
||||
|
||||
filterEntriesByAccount :: String -> [Entry] -> [Entry]
|
||||
filterEntriesByAccount s es = filter (matchEntryAccount s) es
|
||||
|
||||
matchEntryAccount :: String -> Entry -> Bool
|
||||
matchEntryAccount s e = any (matchTransactionAccount s) (transactions e)
|
||||
|
||||
matchTransactionAccount :: String -> Transaction -> Bool
|
||||
matchTransactionAccount s t = s `isInfixOf` (account t)
|
||||
|
12
TODO
12
TODO
@ -1,16 +1,8 @@
|
||||
features
|
||||
register
|
||||
account matching
|
||||
match transactions, not entries
|
||||
|
||||
$ ledger reg equi
|
||||
2007/01/01 opening balance equity:opening balan.. $-4.82 $-4.82
|
||||
2007/01/25 balance adjustment equity $91.15 $86.33
|
||||
$ hledger reg equi
|
||||
2007/01/01 opening balance assets:cash $4.82 $4.82
|
||||
equity:opening balances $-4.82 0
|
||||
2007/01/25 balance adjustment equity $91.15 $91.15
|
||||
assets:cash $-91.15 0
|
||||
don't show duplicate transaction descriptions
|
||||
better transaction/entry data structure
|
||||
description matching
|
||||
regexp matching
|
||||
|
||||
|
@ -61,4 +61,4 @@ doWithParsed a p =
|
||||
|
||||
printRegister :: [String] -> Ledger -> IO ()
|
||||
printRegister args ledger =
|
||||
putStr $ showEntriesWithBalances (entriesMatching (head (args ++ [""])) ledger) 0
|
||||
putStr $ showTransactionsWithBalances (transactionsMatching (head (args ++ [""])) ledger) 0
|
||||
|
Loading…
Reference in New Issue
Block a user