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
|
|
|
|
(ledgerAccountNameTree l)
|
|
|
|
(Map.fromList [(a, ledgerAccount l a) | a <- ledgerAccountNames l])
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-02 23:15:39 +04:00
|
|
|
cLedgerTransactions :: Ledger -> [EntryTransaction]
|
|
|
|
cLedgerTransactions l = concatMap atransactions $ Map.elems $ accounts l
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-02 23:15:39 +04:00
|
|
|
-- unoptimised
|
|
|
|
cLedgerTransactionsMatching :: ([String],[String]) -> Ledger -> [EntryTransaction]
|
|
|
|
cLedgerTransactionsMatching pats l = ledgerTransactionsMatching pats $ rawledger l
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-02 23:15:39 +04:00
|
|
|
-- XXX optimise
|
|
|
|
cLedgerTransactionsMatching1 :: ([String],[String]) -> Ledger -> [EntryTransaction]
|
|
|
|
cLedgerTransactionsMatching1 ([],[]) l = ledgerTransactionsMatching ([".*"],[".*"]) (rawledger l)
|
|
|
|
cLedgerTransactionsMatching1 (rs,[]) l = ledgerTransactionsMatching (rs,[".*"]) (rawledger l)
|
|
|
|
cLedgerTransactionsMatching1 ([],rs) l = ledgerTransactionsMatching ([".*"],rs) (rawledger l)
|
|
|
|
cLedgerTransactionsMatching1 (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:15:39 +04:00
|
|
|
where ts = cLedgerTransactions l
|
|
|
|
|
|
|
|
-- unoptimised
|
|
|
|
showCLedgerAccounts :: Ledger -> [String] -> Bool -> Int -> String
|
|
|
|
showCLedgerAccounts l acctpats showsubs maxdepth =
|
|
|
|
showLedgerAccounts (rawledger l) acctpats showsubs maxdepth
|
|
|
|
|
|
|
|
-- XXX optimise
|
|
|
|
showCLedgerAccounts1 :: Ledger -> [String] -> Bool -> Int -> String
|
|
|
|
showCLedgerAccounts1 l acctpats showsubs maxdepth =
|
|
|
|
concatMap
|
|
|
|
(showAccountTree (rawledger l))
|
|
|
|
(branches (ledgerAccountTreeMatching (rawledger l) acctpats showsubs maxdepth))
|
2007-02-16 12:00:17 +03:00
|
|
|
|