payees: add --used/--declared flags, like accounts
This commit is contained in:
		
							parent
							
								
									bf328e4e3c
								
							
						
					
					
						commit
						540c65994c
					
				| @ -17,6 +17,7 @@ module Hledger.Cli.Commands.Payees ( | |||||||
| 
 | 
 | ||||||
| import Data.List.Extra (nubSort) | import Data.List.Extra (nubSort) | ||||||
| import qualified Data.Text.IO as T | import qualified Data.Text.IO as T | ||||||
|  | import System.Console.CmdArgs.Explicit as C | ||||||
| 
 | 
 | ||||||
| import Hledger | import Hledger | ||||||
| import Hledger.Cli.CliOptions | import Hledger.Cli.CliOptions | ||||||
| @ -25,14 +26,24 @@ import Hledger.Cli.CliOptions | |||||||
| -- | Command line options for this command. | -- | Command line options for this command. | ||||||
| payeesmode = hledgerCommandMode | payeesmode = hledgerCommandMode | ||||||
|   $(embedFileRelative "Hledger/Cli/Commands/Payees.txt") |   $(embedFileRelative "Hledger/Cli/Commands/Payees.txt") | ||||||
|   [] |   [flagNone ["declared"] (setboolopt "declared") "show payees declared with payee directives" | ||||||
|  |   ,flagNone ["used"] (setboolopt "used") "show payees referenced by transactions" | ||||||
|  |   ] | ||||||
|   [generalflagsgroup1] |   [generalflagsgroup1] | ||||||
|   hiddenflags |   hiddenflags | ||||||
|   ([], Just $ argsFlag "[QUERY]") |   ([], Just $ argsFlag "[QUERY]") | ||||||
| 
 | 
 | ||||||
| -- | The payees command. | -- | The payees command. | ||||||
| payees :: CliOpts -> Journal -> IO () | payees :: CliOpts -> Journal -> IO () | ||||||
| payees CliOpts{reportspec_=rspec} j = do | payees CliOpts{rawopts_=rawopts, reportspec_=ReportSpec{rsQuery=query}} j = do | ||||||
|   let ts = entriesReport rspec j |   let  | ||||||
|       payees = nubSort $ map transactionPayee ts |     declared = boolopt "declared" rawopts | ||||||
|  |     used     = boolopt "used"     rawopts | ||||||
|  |     -- XXX matchesPayee is currently an alias for matchesDescription, not sure if it matters | ||||||
|  |     matcheddeclaredpayees = filter (matchesPayeeWIP query) $ journalPayeesDeclared j | ||||||
|  |     matchedusedpayees     = map transactionPayee $ filter (matchesTransaction query) $ jtxns j | ||||||
|  |     payees = nubSort $ | ||||||
|  |       if | declared     && not used -> matcheddeclaredpayees | ||||||
|  |          | not declared && used     -> matchedusedpayees | ||||||
|  |          | otherwise                -> matcheddeclaredpayees ++ matchedusedpayees | ||||||
|   mapM_ T.putStrLn payees |   mapM_ T.putStrLn payees | ||||||
|  | |||||||
| @ -3,12 +3,17 @@ List the unique payee/payer names that appear in transactions. | |||||||
| 
 | 
 | ||||||
| _FLAGS | _FLAGS | ||||||
| 
 | 
 | ||||||
| This command lists the unique payee/payer names that appear in transactions, | This command lists unique payee/payer names which have been  | ||||||
| in alphabetic order.  | declared with payee directives (--declared),  | ||||||
| You can add a query to select a subset of transactions. | used in transaction descriptions (--used),  | ||||||
| The payee/payer is the part of the transaction description before a | character | or both (the default). | ||||||
|  | 
 | ||||||
|  | The payee/payer is the part of the transaction description before a | character  | ||||||
| (or if there is no |, the whole description). | (or if there is no |, the whole description). | ||||||
| 
 | 
 | ||||||
|  | You can add query arguments to select a subset of transactions. This implies --used. | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| Example: | Example: | ||||||
| ```shell | ```shell | ||||||
| $ hledger payees | $ hledger payees | ||||||
|  | |||||||
| @ -2,18 +2,32 @@ | |||||||
| 
 | 
 | ||||||
| # basic payees report | # basic payees report | ||||||
| < | < | ||||||
| 2018/1/1 foo  ; foo: | payee qux | ||||||
|  | 
 | ||||||
|  | 2018/1/1 foo | ||||||
|   a |   a | ||||||
| 
 | 
 | ||||||
| 2018/1/1 bar | baz | 2018/1/2 bar | baz | ||||||
|   a |   a | ||||||
| 
 | 
 | ||||||
|  | 2018/1/3 foo | ||||||
|  |   a | ||||||
|  | 
 | ||||||
|  | # declared and used payees, the default | ||||||
| $ hledger -f - payees | $ hledger -f - payees | ||||||
| bar | bar | ||||||
| foo | foo | ||||||
| >= | qux | ||||||
| 
 | 
 | ||||||
| # filtering transactions by tag | # used payees | ||||||
| $ hledger -f - payees tag:foo | $ hledger -f - payees --used | ||||||
|  | bar | ||||||
|  | foo | ||||||
|  | 
 | ||||||
|  | # declared payees | ||||||
|  | $ hledger -f - payees --declared | ||||||
|  | qux | ||||||
|  | 
 | ||||||
|  | # payees used in transactions matched by a query | ||||||
|  | $ hledger -f - payees date:2018-01-03 | ||||||
| foo | foo | ||||||
| >= |  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user