2007-07-02 23:15:39 +04:00
|
|
|
module RawLedger
|
|
|
|
where
|
|
|
|
import qualified Data.Map as Map
|
|
|
|
|
|
|
|
import Utils
|
|
|
|
import AccountName
|
|
|
|
import Types
|
|
|
|
import Entry
|
|
|
|
import EntryTransaction
|
|
|
|
|
|
|
|
|
|
|
|
instance Show RawLedger where
|
|
|
|
show l = printf "RawLedger with %d entries"
|
|
|
|
((length $ entries l) +
|
|
|
|
(length $ modifier_entries l) +
|
|
|
|
(length $ periodic_entries l))
|
|
|
|
|
2007-07-02 23:39:34 +04:00
|
|
|
rawLedgerTransactions :: RawLedger -> [EntryTransaction]
|
|
|
|
rawLedgerTransactions l = entryTransactionsFrom $ entries l
|
|
|
|
|
|
|
|
rawLedgerTransactionsMatching :: ([String],[String]) -> RawLedger -> [EntryTransaction]
|
|
|
|
rawLedgerTransactionsMatching ([],[]) l = rawLedgerTransactionsMatching ([".*"],[".*"]) l
|
|
|
|
rawLedgerTransactionsMatching (rs,[]) l = rawLedgerTransactionsMatching (rs,[".*"]) l
|
|
|
|
rawLedgerTransactionsMatching ([],rs) l = rawLedgerTransactionsMatching ([".*"],rs) l
|
|
|
|
rawLedgerTransactionsMatching (acctregexps,descregexps) l =
|
2007-07-02 23:15:39 +04:00
|
|
|
intersect
|
|
|
|
(concat [filter (matchTransactionAccount r) ts | r <- acctregexps])
|
|
|
|
(concat [filter (matchTransactionDescription r) ts | r <- descregexps])
|
2007-07-02 23:39:34 +04:00
|
|
|
where ts = rawLedgerTransactions l
|
2007-07-02 23:15:39 +04:00
|
|
|
|
2007-07-02 23:39:34 +04:00
|
|
|
rawLedgerAccountTransactions :: RawLedger -> AccountName -> [EntryTransaction]
|
|
|
|
rawLedgerAccountTransactions l a = rawLedgerTransactionsMatching (["^" ++ a ++ "$"], []) l
|
2007-07-02 23:15:39 +04:00
|
|
|
|
|
|
|
accountNamesFromTransactions :: [EntryTransaction] -> [AccountName]
|
|
|
|
accountNamesFromTransactions ts = nub $ map account ts
|
|
|
|
|
2007-07-02 23:39:34 +04:00
|
|
|
rawLedgerAccountNamesUsed :: RawLedger -> [AccountName]
|
|
|
|
rawLedgerAccountNamesUsed l = accountNamesFromTransactions $ entryTransactionsFrom $ entries l
|
2007-07-02 23:15:39 +04:00
|
|
|
|
2007-07-02 23:39:34 +04:00
|
|
|
rawLedgerAccountNames :: RawLedger -> [AccountName]
|
|
|
|
rawLedgerAccountNames = sort . expandAccountNames . rawLedgerAccountNamesUsed
|
2007-07-02 23:15:39 +04:00
|
|
|
|
2007-07-02 23:39:34 +04:00
|
|
|
rawLedgerTopAccountNames :: RawLedger -> [AccountName]
|
|
|
|
rawLedgerTopAccountNames l = filter (notElem ':') (rawLedgerAccountNames l)
|
2007-07-02 23:15:39 +04:00
|
|
|
|
2007-07-02 23:39:34 +04:00
|
|
|
rawLedgerAccountNamesMatching :: [String] -> RawLedger -> [AccountName]
|
|
|
|
rawLedgerAccountNamesMatching [] l = rawLedgerAccountNamesMatching [".*"] l
|
|
|
|
rawLedgerAccountNamesMatching acctregexps l =
|
2007-07-02 23:15:39 +04:00
|
|
|
concat [filter (matchAccountName r) accountNames | r <- acctregexps]
|
2007-07-02 23:39:34 +04:00
|
|
|
where accountNames = rawLedgerTopAccountNames l
|
2007-07-02 23:15:39 +04:00
|
|
|
|
2007-07-02 23:39:34 +04:00
|
|
|
rawLedgerAccountNameTree :: RawLedger -> Tree AccountName
|
|
|
|
rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l
|
2007-07-02 23:15:39 +04:00
|
|
|
|
|
|
|
|
|
|
|
|