move entry filter functions to RawLedger
This commit is contained in:
parent
7c25dbc4a3
commit
d1dfcafc39
@ -74,39 +74,6 @@ cacheLedger acctpat l =
|
|||||||
in
|
in
|
||||||
Ledger l ant amap maxprecision acctpat filteredant filteredamap
|
Ledger l ant amap maxprecision acctpat filteredant filteredamap
|
||||||
|
|
||||||
-- | Remove ledger entries we are not interested in.
|
|
||||||
-- Keep only those which fall between the begin and end dates, and match
|
|
||||||
-- the description patterns.
|
|
||||||
filterLedgerEntries :: String -> String -> Regex -> RawLedger -> RawLedger
|
|
||||||
filterLedgerEntries begin end descpat =
|
|
||||||
filterLedgerEntriesByDate begin end .
|
|
||||||
filterLedgerEntriesByDescription descpat
|
|
||||||
|
|
||||||
-- | Keep only entries whose description matches the description pattern.
|
|
||||||
filterLedgerEntriesByDescription :: Regex -> RawLedger -> RawLedger
|
|
||||||
filterLedgerEntriesByDescription descpat (RawLedger ms ps es f) =
|
|
||||||
RawLedger ms ps (filter matchdesc es) f
|
|
||||||
where
|
|
||||||
matchdesc :: Entry -> Bool
|
|
||||||
matchdesc e = case matchRegex descpat (edescription e) of
|
|
||||||
Nothing -> False
|
|
||||||
otherwise -> True
|
|
||||||
|
|
||||||
-- | Keep only entries which fall between begin and end dates.
|
|
||||||
-- We include entries on the begin date and exclude entries on the end
|
|
||||||
-- date, like ledger. An empty date string means no restriction.
|
|
||||||
filterLedgerEntriesByDate :: String -> String -> RawLedger -> RawLedger
|
|
||||||
filterLedgerEntriesByDate begin end (RawLedger ms ps es f) =
|
|
||||||
RawLedger ms ps (filter matchdate es) f
|
|
||||||
where
|
|
||||||
matchdate :: Entry -> Bool
|
|
||||||
matchdate e = (begin == "" || entrydate >= begindate) &&
|
|
||||||
(end == "" || entrydate < enddate)
|
|
||||||
where
|
|
||||||
begindate = parsedate begin :: UTCTime
|
|
||||||
enddate = parsedate end
|
|
||||||
entrydate = parsedate $ edate e
|
|
||||||
|
|
||||||
-- | List a 'Ledger' 's account names.
|
-- | List a 'Ledger' 's account names.
|
||||||
accountnames :: Ledger -> [AccountName]
|
accountnames :: Ledger -> [AccountName]
|
||||||
accountnames l = drop 1 $ flatten $ accountnametree l
|
accountnames l = drop 1 $ flatten $ accountnametree l
|
||||||
|
|||||||
@ -37,3 +37,37 @@ rawLedgerAccountNames = sort . expandAccountNames . rawLedgerAccountNamesUsed
|
|||||||
|
|
||||||
rawLedgerAccountNameTree :: RawLedger -> Tree AccountName
|
rawLedgerAccountNameTree :: RawLedger -> Tree AccountName
|
||||||
rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l
|
rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l
|
||||||
|
|
||||||
|
-- | Remove ledger entries we are not interested in.
|
||||||
|
-- Keep only those which fall between the begin and end dates, and match
|
||||||
|
-- the description pattern.
|
||||||
|
filterRawLedgerEntries :: String -> String -> Regex -> RawLedger -> RawLedger
|
||||||
|
filterRawLedgerEntries begin end descpat =
|
||||||
|
filterRawLedgerEntriesByDate begin end .
|
||||||
|
filterRawLedgerEntriesByDescription descpat
|
||||||
|
|
||||||
|
-- | Keep only entries whose description matches the description pattern.
|
||||||
|
filterRawLedgerEntriesByDescription :: Regex -> RawLedger -> RawLedger
|
||||||
|
filterRawLedgerEntriesByDescription descpat (RawLedger ms ps es f) =
|
||||||
|
RawLedger ms ps (filter matchdesc es) f
|
||||||
|
where
|
||||||
|
matchdesc :: Entry -> Bool
|
||||||
|
matchdesc e = case matchRegex descpat (edescription e) of
|
||||||
|
Nothing -> False
|
||||||
|
otherwise -> True
|
||||||
|
|
||||||
|
-- | Keep only entries which fall between begin and end dates.
|
||||||
|
-- We include entries on the begin date and exclude entries on the end
|
||||||
|
-- date, like ledger. An empty date string means no restriction.
|
||||||
|
filterRawLedgerEntriesByDate :: String -> String -> RawLedger -> RawLedger
|
||||||
|
filterRawLedgerEntriesByDate begin end (RawLedger ms ps es f) =
|
||||||
|
RawLedger ms ps (filter matchdate es) f
|
||||||
|
where
|
||||||
|
matchdate :: Entry -> Bool
|
||||||
|
matchdate e = (begin == "" || entrydate >= begindate) &&
|
||||||
|
(end == "" || entrydate < enddate)
|
||||||
|
where
|
||||||
|
begindate = parsedate begin :: UTCTime
|
||||||
|
enddate = parsedate end
|
||||||
|
entrydate = parsedate $ edate e
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ parseLedgerAndDo :: [Opt] -> [String] -> ([Opt] -> [String] -> Ledger -> IO ())
|
|||||||
parseLedgerAndDo opts args cmd =
|
parseLedgerAndDo opts args cmd =
|
||||||
ledgerFilePathFromOpts opts >>= parseLedgerFile >>= either printParseError runthecommand
|
ledgerFilePathFromOpts opts >>= parseLedgerFile >>= either printParseError runthecommand
|
||||||
where
|
where
|
||||||
runthecommand = cmd opts args . cacheLedger acctpat . filterLedgerEntries begin end descpat
|
runthecommand = cmd opts args . cacheLedger acctpat . filterRawLedgerEntries begin end descpat
|
||||||
begin = beginDateFromOpts opts
|
begin = beginDateFromOpts opts
|
||||||
end = endDateFromOpts opts
|
end = endDateFromOpts opts
|
||||||
acctpat = regexFor acctpats
|
acctpat = regexFor acctpats
|
||||||
@ -81,7 +81,7 @@ myrawledger = do
|
|||||||
myledger :: IO Ledger
|
myledger :: IO Ledger
|
||||||
myledger = do
|
myledger = do
|
||||||
l <- myrawledger
|
l <- myrawledger
|
||||||
return $ cacheLedger wildcard $ filterLedgerEntries "" "" wildcard l
|
return $ cacheLedger wildcard $ filterRawLedgerEntries "" "" wildcard l
|
||||||
|
|
||||||
-- | get a Ledger from the given file path
|
-- | get a Ledger from the given file path
|
||||||
rawledgerfromfile :: String -> IO RawLedger
|
rawledgerfromfile :: String -> IO RawLedger
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user