support -C/--cleared flag to filter by entry status (not transaction status)
This commit is contained in:
		
							parent
							
								
									c00a1811c5
								
							
						
					
					
						commit
						57603db7b9
					
				| @ -43,9 +43,10 @@ rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l | |||||||
| 
 | 
 | ||||||
| -- | Remove ledger entries we are not interested in. | -- | Remove ledger entries we are not interested in. | ||||||
| -- Keep only those which fall between the begin and end dates, and match | -- Keep only those which fall between the begin and end dates, and match | ||||||
| -- the description pattern. | -- the description pattern, and match the cleared flag. | ||||||
| filterRawLedger :: String -> String -> [String] -> RawLedger -> RawLedger | filterRawLedger :: String -> String -> [String] -> Bool -> RawLedger -> RawLedger | ||||||
| filterRawLedger begin end pats =  | filterRawLedger begin end pats clearedonly =  | ||||||
|  |     filterRawLedgerEntriesByClearedStatus clearedonly . | ||||||
|     filterRawLedgerEntriesByDate begin end . |     filterRawLedgerEntriesByDate begin end . | ||||||
|     filterRawLedgerEntriesByDescription pats |     filterRawLedgerEntriesByDescription pats | ||||||
| 
 | 
 | ||||||
| @ -67,6 +68,12 @@ filterRawLedgerEntriesByDate begin end (RawLedger ms ps es f) = | |||||||
|       matchdate e = (null begin || d >= d1) && (null end || d < d2) |       matchdate e = (null begin || d >= d1) && (null end || d < d2) | ||||||
|                     where d = parsedate $ edate e |                     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 | -- | Check if a set of ledger account/description patterns matches the | ||||||
| -- given account name or entry description, applying ledger's special | -- given account name or entry description, applying ledger's special | ||||||
|  | |||||||
| @ -25,6 +25,7 @@ options = [ | |||||||
|  Option ['f'] ["file"]         (ReqArg File "FILE")        "ledger file; - means use standard input", |  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 ['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 ['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 ['s'] ["showsubs"]     (NoArg  ShowSubs)           "in the balance report, include subaccounts", | ||||||
|  Option ['h'] ["help","usage"] (NoArg  Help)               "show this help", |  Option ['h'] ["help","usage"] (NoArg  Help)               "show this help", | ||||||
|  Option ['V'] ["version"]      (NoArg  Version)            "show version" |  Option ['V'] ["version"]      (NoArg  Version)            "show version" | ||||||
| @ -35,6 +36,7 @@ data Opt = | |||||||
|     File String |  |     File String |  | ||||||
|     Begin String |  |     Begin String |  | ||||||
|     End String |  |     End String |  | ||||||
|  |     Cleared |  | ||||||
|     ShowSubs | |     ShowSubs | | ||||||
|     Help | |     Help | | ||||||
|     Version |     Version | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								Utils.hs
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Utils.hs
									
									
									
									
									
								
							| @ -21,7 +21,7 @@ rawledgerfromfile f = do | |||||||
| ledgerfromfile :: FilePath -> IO Ledger | ledgerfromfile :: FilePath -> IO Ledger | ||||||
| ledgerfromfile f = do | ledgerfromfile f = do | ||||||
|   l  <- rawledgerfromfile f |   l  <- rawledgerfromfile f | ||||||
|   return $ cacheLedger $ filterRawLedger "" "" [] l |   return $ cacheLedger $ filterRawLedger "" "" [] False l | ||||||
| 
 | 
 | ||||||
| -- | get a RawLedger from the file your LEDGER environment variable | -- | get a RawLedger from the file your LEDGER environment variable | ||||||
| -- variable points to or (WARNING) an empty one if there was a problem. | -- variable points to or (WARNING) an empty one if there was a problem. | ||||||
| @ -35,7 +35,7 @@ myrawledger = do | |||||||
| myledger :: IO Ledger | myledger :: IO Ledger | ||||||
| myledger = do | myledger = do | ||||||
|   l <- myrawledger |   l <- myrawledger | ||||||
|   return $ cacheLedger $ filterRawLedger "" "" [] l |   return $ cacheLedger $ filterRawLedger "" "" [] False l | ||||||
| 
 | 
 | ||||||
| -- | get a named account from your ledger file | -- | get a named account from your ledger file | ||||||
| myaccount :: AccountName -> IO Account | myaccount :: AccountName -> IO Account | ||||||
|  | |||||||
| @ -70,8 +70,9 @@ 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 . normaliseRawLedgerAmounts . filterRawLedger begin end descpats |       runthecommand = cmd opts args . cacheLedger . normaliseRawLedgerAmounts . filterRawLedger begin end descpats cleared | ||||||
|       begin = beginDateFromOpts opts |       begin = beginDateFromOpts opts | ||||||
|       end = endDateFromOpts opts |       end = endDateFromOpts opts | ||||||
|  |       cleared = Cleared `elem` opts | ||||||
|       descpats = snd $ parseAccountDescriptionArgs args |       descpats = snd $ parseAccountDescriptionArgs args | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user