2007-02-16 12:00:17 +03:00
|
|
|
module Ledger
|
|
|
|
where
|
2007-03-10 02:32:00 +03:00
|
|
|
import qualified Data.Map as Map
|
|
|
|
|
2007-02-16 12:00:17 +03:00
|
|
|
import Utils
|
2007-07-02 18:54:36 +04:00
|
|
|
import Types
|
2007-07-02 23:15:39 +04:00
|
|
|
import Account
|
|
|
|
import AccountName
|
2007-02-16 12:00:17 +03:00
|
|
|
import EntryTransaction
|
2007-07-02 23:15:39 +04:00
|
|
|
import RawLedger
|
|
|
|
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-02 23:15:39 +04:00
|
|
|
cacheLedger :: RawLedger -> Ledger
|
|
|
|
cacheLedger l =
|
|
|
|
Ledger
|
|
|
|
l
|
2007-07-02 23:39:34 +04:00
|
|
|
(rawLedgerAccountNameTree l)
|
|
|
|
(Map.fromList [(a, rawLedgerAccount l a) | a <- rawLedgerAccountNames l])
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-02 23:39:34 +04:00
|
|
|
ledgerTransactions :: Ledger -> [EntryTransaction]
|
|
|
|
ledgerTransactions l = concatMap atransactions $ Map.elems $ accounts l
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-02 23:15:39 +04:00
|
|
|
-- unoptimised
|
2007-07-02 23:39:34 +04:00
|
|
|
ledgerTransactionsMatching :: ([String],[String]) -> Ledger -> [EntryTransaction]
|
|
|
|
ledgerTransactionsMatching pats l = rawLedgerTransactionsMatching pats $ rawledger l
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-02 23:15:39 +04:00
|
|
|
-- XXX optimise
|
2007-07-02 23:39:34 +04:00
|
|
|
ledgerTransactionsMatching1 :: ([String],[String]) -> Ledger -> [EntryTransaction]
|
|
|
|
ledgerTransactionsMatching1 ([],[]) l = rawLedgerTransactionsMatching ([".*"],[".*"]) (rawledger l)
|
|
|
|
ledgerTransactionsMatching1 (rs,[]) l = rawLedgerTransactionsMatching (rs,[".*"]) (rawledger l)
|
|
|
|
ledgerTransactionsMatching1 ([],rs) l = rawLedgerTransactionsMatching ([".*"],rs) (rawledger l)
|
|
|
|
ledgerTransactionsMatching1 (acctregexps,descregexps) l =
|
2007-02-16 12:00:17 +03: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 = ledgerTransactions l
|
2007-07-02 23:15:39 +04:00
|
|
|
|
|
|
|
-- unoptimised
|
2007-07-02 23:39:34 +04:00
|
|
|
showLedgerAccounts :: Ledger -> [String] -> Bool -> Int -> String
|
|
|
|
showLedgerAccounts l acctpats showsubs maxdepth =
|
|
|
|
showRawLedgerAccounts (rawledger l) acctpats showsubs maxdepth
|
2007-07-02 23:15:39 +04:00
|
|
|
|
|
|
|
-- XXX optimise
|
2007-07-02 23:39:34 +04:00
|
|
|
showLedgerAccounts1 :: Ledger -> [String] -> Bool -> Int -> String
|
|
|
|
showLedgerAccounts1 l acctpats showsubs maxdepth =
|
2007-07-02 23:15:39 +04:00
|
|
|
concatMap
|
|
|
|
(showAccountTree (rawledger l))
|
2007-07-02 23:39:34 +04:00
|
|
|
(branches (rawLedgerAccountTreeMatching (rawledger l) acctpats showsubs maxdepth))
|
2007-02-16 12:00:17 +03:00
|
|
|
|