support -C/--cleared flag to filter by entry status (not transaction status)

This commit is contained in:
Simon Michael 2008-10-16 09:04:44 +00:00
parent c00a1811c5
commit 57603db7b9
4 changed files with 16 additions and 6 deletions

View File

@ -43,9 +43,10 @@ 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.
filterRawLedger :: String -> String -> [String] -> RawLedger -> RawLedger
filterRawLedger begin end pats =
-- the description pattern, and match the cleared flag.
filterRawLedger :: String -> String -> [String] -> Bool -> RawLedger -> RawLedger
filterRawLedger begin end pats clearedonly =
filterRawLedgerEntriesByClearedStatus clearedonly .
filterRawLedgerEntriesByDate begin end .
filterRawLedgerEntriesByDescription pats
@ -67,6 +68,12 @@ filterRawLedgerEntriesByDate begin end (RawLedger ms ps es f) =
matchdate e = (null begin || d >= d1) && (null end || d < d2)
where d = parsedate $ edate e
-- | Keep only entries with cleared status, if the flag is true, otherwise
-- do no filtering.
filterRawLedgerEntriesByClearedStatus :: Bool -> RawLedger -> RawLedger
filterRawLedgerEntriesByClearedStatus False l = l
filterRawLedgerEntriesByClearedStatus True (RawLedger ms ps es f) =
RawLedger ms ps (filter estatus es) f
-- | Check if a set of ledger account/description patterns matches the
-- given account name or entry description, applying ledger's special

View File

@ -25,6 +25,7 @@ options = [
Option ['f'] ["file"] (ReqArg File "FILE") "ledger file; - means use standard input",
Option ['b'] ["begin"] (ReqArg Begin "YYYY/MM/DD") "report on entries on or after this date",
Option ['e'] ["end"] (ReqArg End "YYYY/MM/DD") "report on entries prior to this date",
Option ['C'] ["cleared"] (NoArg Cleared) "report only on cleared transactions",
Option ['s'] ["showsubs"] (NoArg ShowSubs) "in the balance report, include subaccounts",
Option ['h'] ["help","usage"] (NoArg Help) "show this help",
Option ['V'] ["version"] (NoArg Version) "show version"
@ -35,6 +36,7 @@ data Opt =
File String |
Begin String |
End String |
Cleared |
ShowSubs |
Help |
Version

View File

@ -21,7 +21,7 @@ rawledgerfromfile f = do
ledgerfromfile :: FilePath -> IO Ledger
ledgerfromfile f = do
l <- rawledgerfromfile f
return $ cacheLedger $ filterRawLedger "" "" [] l
return $ cacheLedger $ filterRawLedger "" "" [] False l
-- | get a RawLedger from the file your LEDGER environment variable
-- variable points to or (WARNING) an empty one if there was a problem.
@ -35,7 +35,7 @@ myrawledger = do
myledger :: IO Ledger
myledger = do
l <- myrawledger
return $ cacheLedger $ filterRawLedger "" "" [] l
return $ cacheLedger $ filterRawLedger "" "" [] False l
-- | get a named account from your ledger file
myaccount :: AccountName -> IO Account

View File

@ -70,8 +70,9 @@ parseLedgerAndDo :: [Opt] -> [String] -> ([Opt] -> [String] -> Ledger -> IO ())
parseLedgerAndDo opts args cmd =
ledgerFilePathFromOpts opts >>= parseLedgerFile >>= either printParseError runthecommand
where
runthecommand = cmd opts args . cacheLedger . normaliseRawLedgerAmounts . filterRawLedger begin end descpats
runthecommand = cmd opts args . cacheLedger . normaliseRawLedgerAmounts . filterRawLedger begin end descpats cleared
begin = beginDateFromOpts opts
end = endDateFromOpts opts
cleared = Cleared `elem` opts
descpats = snd $ parseAccountDescriptionArgs args