@@ -13,7 +13,7 @@ mod config;
1313mod client;
1414mod inquirer;
1515
16- use client:: { Account , Transaction , Money , HistoricalAmountsWithCurrency , Balances , Outgoings , Incomings , get_accounts, get_account_balance, get_transactions_with_currency, get_balances, get_outgoings, get_incomings, get_outgoing, get_incoming} ;
16+ use client:: { Account , Transaction , Money , HistoricalAmountsWithCurrency , Balances , Outgoings , Incomings , get_accounts, get_account_balance, get_transactions_with_currency, get_counterparties , get_balances, get_outgoings, get_incomings, get_outgoing, get_incoming} ;
1717use client:: { Interval , Timeframe } ;
1818
1919use std:: path:: PathBuf ;
3535 teller init
3636 teller [list] accounts
3737 teller [list] transactions [<account> --timeframe=<tf> --show-description]
38+ teller [list] counterparties [<account> --timeframe=<tf> --count=<n>]
3839 teller [list] (balances|outgoings|incomings) [<account> --interval=<itv> --timeframe=<tf> --output=<of>]
3940 teller [show] balance [<account> --hide-currency]
4041 teller [show] outgoing [<account> --hide-currency]
@@ -45,6 +46,7 @@ Commands:
4546 init Configure.
4647 list accounts List accounts.
4748 list transactions List transactions.
49+ list counterparties List outgoing amounts grouped by counterparties.
4850 list balances List balances during a timeframe.
4951 list outgoings List outgoings during a timeframe.
5052 list incomings List incomings during a timeframe.
@@ -57,8 +59,9 @@ Commands:
5759Options:
5860 -h --help Show this screen.
5961 -V --version Show version.
60- -i --interval=<itv> Group by an interval of time (default: monthly).
61- -t --timeframe=<tf> Operate upon a named period of time (default: 6-months).
62+ -i --interval=<itv> Group by an interval of time [default: monthly].
63+ -t --timeframe=<tf> Operate upon a named period of time [default: 6-months].
64+ -c --count=<n> Only the top N elements [default: 10].
6265 -d --show-description Show descriptions against transactions.
6366 -c --hide-currency Show money without currency codes.
6467 -o --output=<of> Output in a particular format (e.g. spark).
@@ -71,6 +74,7 @@ struct Args {
7174 cmd_show : bool ,
7275 cmd_accounts : bool ,
7376 cmd_transactions : bool ,
77+ cmd_counterparties : bool ,
7478 cmd_balances : bool ,
7579 cmd_outgoings : bool ,
7680 cmd_incomings : bool ,
@@ -80,6 +84,7 @@ struct Args {
8084 arg_account : AccountType ,
8185 flag_interval : Interval ,
8286 flag_timeframe : Timeframe ,
87+ flag_count : i64 ,
8388 flag_show_description : bool ,
8489 flag_hide_currency : bool ,
8590 flag_output : OutputFormat ,
@@ -312,6 +317,15 @@ fn pick_command(arguments: Args) {
312317 Some ( config) => list_transactions ( & config, & arg_account, & flag_timeframe, & flag_show_description) ,
313318 }
314319 } ,
320+ Args { cmd_counterparties, ref arg_account, ref flag_timeframe, flag_count, .. } if cmd_counterparties == true => {
321+ match get_config ( ) {
322+ None => {
323+ error ! ( "Configuration could not be found or created so command not executed" ) ;
324+ exit ( 1 )
325+ }
326+ Some ( config) => list_counterparties ( & config, & arg_account, & flag_timeframe, & flag_count) ,
327+ }
328+ } ,
315329 Args { cmd_balances, ref arg_account, ref flag_interval, ref flag_timeframe, ref flag_output, .. } if cmd_balances == true => {
316330 match get_config ( ) {
317331 None => {
@@ -471,6 +485,37 @@ fn list_transactions(config: &Config, account: &AccountType, timeframe: &Timefra
471485 }
472486}
473487
488+ fn represent_list_counterparties ( counterparties : & Vec < ( String , String ) > , currency : & str , count : & i64 ) {
489+ let mut counterparties_table = String :: new ( ) ;
490+
491+ counterparties_table. push_str ( & format ! ( "row\t counterparty\t amount ({})\n " , currency) ) ;
492+ let skip_n = counterparties. len ( ) - ( * count as usize ) ;
493+ for ( idx, counterparty) in counterparties. iter ( ) . skip ( skip_n) . enumerate ( ) {
494+ let row_number = ( idx + 1 ) as u32 ;
495+ let new_counterparty_row = format ! ( "{}\t {}\t {}\n " , row_number, counterparty. 0 , counterparty. 1 ) ;
496+ counterparties_table = counterparties_table + & new_counterparty_row;
497+ }
498+
499+ let mut tw = TabWriter :: new ( Vec :: new ( ) ) ;
500+ write ! ( & mut tw, "{}" , counterparties_table) . unwrap ( ) ;
501+ tw. flush ( ) . unwrap ( ) ;
502+
503+ let counterparties_str = String :: from_utf8 ( tw. unwrap ( ) ) . unwrap ( ) ;
504+
505+ println ! ( "{}" , counterparties_str)
506+ }
507+
508+ fn list_counterparties ( config : & Config , account : & AccountType , timeframe : & Timeframe , count : & i64 ) {
509+ let account_id = get_account_id ( & config, & account) ;
510+ match get_counterparties ( & config, & account_id, & timeframe) {
511+ Ok ( counterparties_with_currency) => represent_list_counterparties ( & counterparties_with_currency. counterparties , & counterparties_with_currency. currency , & count) ,
512+ Err ( e) => {
513+ error ! ( "Unable to list counterparties: {}" , e) ;
514+ exit ( 1 )
515+ } ,
516+ }
517+ }
518+
474519fn represent_list_amounts ( amount_type : & str , hac : & HistoricalAmountsWithCurrency , output : & OutputFormat ) {
475520 match * output {
476521 OutputFormat :: Spark => {
0 commit comments