From ac9aa106fd18171a5b9993a1e2e524d698cd4447 Mon Sep 17 00:00:00 2001 From: scoobybejesus Date: Sun, 20 Oct 2019 20:56:52 -0400 Subject: [PATCH] New file. Factored export calls out of main. --- src/export_all.rs | 87 +++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 60 ++------------------------------ 2 files changed, 89 insertions(+), 58 deletions(-) create mode 100644 src/export_all.rs diff --git a/src/export_all.rs b/src/export_all.rs new file mode 100644 index 0000000..6754d58 --- /dev/null +++ b/src/export_all.rs @@ -0,0 +1,87 @@ +// Copyright (c) 2017-2019, scoobybejesus +// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt + +use std::error::Error; +use std::collections::{HashMap}; + +use crate::transaction::{Transaction, ActionRecord}; +use crate::account::{Account, RawAccount}; +use crate::core_functions::{ImportProcessParameters}; +use crate::csv_export; +use crate::txt_export; + + +pub fn export( + settings: &ImportProcessParameters, + action_records_map: &HashMap, + raw_acct_map: &HashMap, + account_map: &HashMap, + transactions_map: &HashMap, +) -> Result<(), Box> { + + println!("Creating all reports now."); + + csv_export::_1_account_sums_to_csv( + &settings, + &raw_acct_map, + &account_map + ); + + csv_export::_2_account_sums_nonzero_to_csv( + &account_map, + &settings, + &raw_acct_map + ); + + csv_export::_3_account_sums_to_csv_with_orig_basis( + &settings, + &raw_acct_map, + &account_map + ); + + csv_export::_4_transaction_mvmt_detail_to_csv( + &settings, + &action_records_map, + &raw_acct_map, + &account_map, + &transactions_map + )?; + + csv_export::_5_transaction_mvmt_summaries_to_csv( + &settings, + &action_records_map, + &raw_acct_map, + &account_map, + &transactions_map + )?; + + csv_export::_6_transaction_mvmt_detail_to_csv_w_orig( + &settings, + &action_records_map, + &raw_acct_map, + &account_map, + &transactions_map + )?; + + txt_export::_1_account_lot_detail_to_txt( + &settings, + &raw_acct_map, + &account_map, + &transactions_map, + &action_records_map + )?; + + txt_export::_2_account_lot_summary_to_txt( + &settings, + &raw_acct_map, + &account_map, + )?; + + txt_export::_3_account_lot_summary_non_zero_to_txt( + &settings, + &raw_acct_map, + &account_map, + )?; + +Ok(()) +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index fc4f6d6..4bca91e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,7 @@ mod wizard; mod skip_wizard; mod setup; mod tui; +mod export_all; @@ -148,70 +149,13 @@ fn main() -> Result<(), Box> { if should_export_all { - println!("Creating reports now."); - - csv_export::_1_account_sums_to_csv( - &settings, - &raw_acct_map, - &account_map - ); - - csv_export::_2_account_sums_nonzero_to_csv( - &account_map, - &settings, - &raw_acct_map - ); - - csv_export::_3_account_sums_to_csv_with_orig_basis( - &settings, - &raw_acct_map, - &account_map - ); - - csv_export::_4_transaction_mvmt_detail_to_csv( + export_all::export( &settings, &action_records_map, &raw_acct_map, &account_map, &transactions_map )?; - - csv_export::_5_transaction_mvmt_summaries_to_csv( - &settings, - &action_records_map, - &raw_acct_map, - &account_map, - &transactions_map - )?; - - csv_export::_6_transaction_mvmt_detail_to_csv_w_orig( - &settings, - &action_records_map, - &raw_acct_map, - &account_map, - &transactions_map - )?; - - txt_export::_1_account_lot_detail_to_txt( - &settings, - &raw_acct_map, - &account_map, - &transactions_map, - &action_records_map - )?; - - txt_export::_2_account_lot_summary_to_txt( - &settings, - &raw_acct_map, - &account_map, - )?; - - txt_export::_3_account_lot_summary_non_zero_to_txt( - &settings, - &raw_acct_map, - &account_map, - )?; - } if present_print_menu_tui {