2007-02-16 12:00:17 +03:00
|
|
|
module Ledger
|
|
|
|
where
|
|
|
|
import Utils
|
2007-02-18 21:12:02 +03:00
|
|
|
import AccountName
|
2007-02-16 14:51:30 +03:00
|
|
|
import BasicTypes
|
2007-02-16 12:00:17 +03:00
|
|
|
import Entry
|
|
|
|
import EntryTransaction
|
|
|
|
|
|
|
|
|
|
|
|
data Ledger = Ledger {
|
|
|
|
modifier_entries :: [ModifierEntry],
|
|
|
|
periodic_entries :: [PeriodicEntry],
|
|
|
|
entries :: [Entry]
|
|
|
|
} deriving (Eq)
|
|
|
|
|
|
|
|
instance Show Ledger where
|
|
|
|
show l = printf "Ledger with %d normal, %d modifier, %d periodic entries"
|
2007-02-20 00:20:06 +03:00
|
|
|
(length $ modifier_entries l)
|
|
|
|
(length $ periodic_entries l)
|
|
|
|
(length $ entries l)
|
2007-02-16 12:00:17 +03:00
|
|
|
|
|
|
|
ledgerTransactions :: Ledger -> [EntryTransaction]
|
|
|
|
ledgerTransactions l = entryTransactionsFrom $ entries l
|
|
|
|
|
|
|
|
ledgerTransactionsMatching :: ([String],[String]) -> Ledger -> [EntryTransaction]
|
|
|
|
ledgerTransactionsMatching ([],[]) l = ledgerTransactionsMatching ([".*"],[".*"]) l
|
|
|
|
ledgerTransactionsMatching (rs,[]) l = ledgerTransactionsMatching (rs,[".*"]) l
|
|
|
|
ledgerTransactionsMatching ([],rs) l = ledgerTransactionsMatching ([".*"],rs) l
|
|
|
|
ledgerTransactionsMatching (acctregexps,descregexps) l =
|
|
|
|
intersect
|
|
|
|
(concat [filter (matchTransactionAccount r) ts | r <- acctregexps])
|
|
|
|
(concat [filter (matchTransactionDescription r) ts | r <- descregexps])
|
|
|
|
where ts = ledgerTransactions l
|
|
|
|
|
2007-02-16 14:51:30 +03:00
|
|
|
accountNamesFromTransactions :: [EntryTransaction] -> [AccountName]
|
|
|
|
accountNamesFromTransactions ts = nub $ map account ts
|
|
|
|
|
2007-02-16 12:00:17 +03:00
|
|
|
ledgerAccountNamesUsed :: Ledger -> [AccountName]
|
|
|
|
ledgerAccountNamesUsed l = accountNamesFromTransactions $ entryTransactionsFrom $ entries l
|
|
|
|
|
|
|
|
ledgerAccountNames :: Ledger -> [AccountName]
|
|
|
|
ledgerAccountNames = sort . expandAccountNames . ledgerAccountNamesUsed
|
|
|
|
|
|
|
|
ledgerTopAccountNames :: Ledger -> [AccountName]
|
|
|
|
ledgerTopAccountNames l = filter (notElem ':') (ledgerAccountNames l)
|
|
|
|
|
|
|
|
ledgerAccountNamesMatching :: [String] -> Ledger -> [AccountName]
|
|
|
|
ledgerAccountNamesMatching [] l = ledgerAccountNamesMatching [".*"] l
|
|
|
|
ledgerAccountNamesMatching acctregexps l =
|
|
|
|
concat [filter (matchAccountName r) accountNames | r <- acctregexps]
|
|
|
|
where accountNames = ledgerTopAccountNames l
|
|
|
|
|
2007-02-16 14:51:30 +03:00
|
|
|
ledgerAccountNameTree :: Ledger -> Tree AccountName
|
|
|
|
ledgerAccountNameTree l = accountNameTreeFrom $ ledgerAccountNames l
|
2007-02-16 12:00:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
|