hledger/Ledger.hs

50 lines
1.7 KiB
Haskell
Raw Normal View History

module Ledger
where
2007-03-10 02:32:00 +03:00
import qualified Data.Map as Map
import Utils
2007-07-02 18:54:36 +04:00
import Types
import Account
import AccountName
import EntryTransaction
import RawLedger
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-07-02 23:39:34 +04:00
ledgerTransactions :: Ledger -> [EntryTransaction]
ledgerTransactions l = concatMap atransactions $ Map.elems $ accounts l
-- unoptimised
2007-07-02 23:39:34 +04:00
ledgerTransactionsMatching :: ([String],[String]) -> Ledger -> [EntryTransaction]
ledgerTransactionsMatching pats l = rawLedgerTransactionsMatching pats $ rawledger l
-- 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 =
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
-- 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
-- XXX optimise
2007-07-02 23:39:34 +04:00
showLedgerAccounts1 :: Ledger -> [String] -> Bool -> Int -> String
showLedgerAccounts1 l acctpats showsubs maxdepth =
concatMap
(showAccountTree (rawledger l))
2007-07-02 23:39:34 +04:00
(branches (rawLedgerAccountTreeMatching (rawledger l) acctpats showsubs maxdepth))