From 5c5a0bb67a9ae91685be4cd1b3d3b66ad58343fd Mon Sep 17 00:00:00 2001 From: scoobybejesus Date: Tue, 10 Sep 2019 22:49:18 -0400 Subject: [PATCH] Added two new txt account reports. --- src/main.rs | 12 ++++ src/txt_export.rs | 174 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+) diff --git a/src/main.rs b/src/main.rs index afd002c..c3b0a79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -299,6 +299,18 @@ fn main() -> Result<(), Box> { &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, + )?; + } // use tests::test; diff --git a/src/txt_export.rs b/src/txt_export.rs index a1d4545..b7644f0 100644 --- a/src/txt_export.rs +++ b/src/txt_export.rs @@ -183,3 +183,177 @@ Enable like-kind treatment: {}", Ok(()) } + +pub fn _2_account_lot_summary_to_txt( + settings: &ImportProcessParameters, + raw_acct_map: &HashMap, + acct_map: &HashMap, +) -> Result<(), Box> { + +// ===================================== +// Bank USD +// Account balance: -220.0000000 USD; Total cost basis: -220.0000000 +// Lot 1 • Σ: -220.0000000, with remaining cost basis of -220.0000000 and basis date of 2016-01-01 + +// ===================================== +// Exchange BTC +// Account balance: 0.5000000 BTC; Total cost basis: 450.0000000 +// Lot 1 • Σ: 0E-7, with remaining cost basis of 0E-7 and basis date of 2016-01-01 +// Lot 2 • Σ: 0E-7, with remaining cost basis of 0.0 and basis date of 2016-03-01 +// Lot 3 • Σ: 0E-7, with remaining cost basis of 0.0 and basis date of 2016-04-01 +// Lot 4 • Σ: 0.5000000, with remaining cost basis of 450.0 and basis date of 2016-10-01 + + + + let file_name = PathBuf::from("2_Acct_lot_summary.txt"); + let path = PathBuf::from(&settings.export_path.clone()); + let full_path: PathBuf = [path, file_name].iter().collect(); + + let mut file = OpenOptions::new() + .write(true) + .create(true) + .truncate(true) + .open(full_path)?; + + let length = acct_map.len(); + + writeln!(file, "Account Listing - All Lots - All Movements - with high level of detail. +\nCosting method used: {}. +Home currency: {} +Enable like-kind treatment: {}", + settings.costing_method, + settings.home_currency, + settings.enable_like_kind_treatment + )?; + + if settings.enable_like_kind_treatment { + writeln!(file, "Like-kind cut-off date: {}.", + settings.lk_cutoff_date_string + )?; + } + + for j in 1..=length { + + let acct = acct_map.get(&(j as u16)).unwrap(); + let raw_acct = raw_acct_map.get(&acct.raw_key).unwrap(); + + if acct.list_of_lots.borrow().len() > 0 { + + writeln!(file, "\n=====================================")?; + writeln!(file, "{} {}", raw_acct.name, raw_acct.ticker)?; + writeln!(file, "Account balance: {} {}; Total cost basis: {}", + acct.get_sum_of_amts_in_lots(), + raw_acct.ticker, + acct.get_sum_of_basis_in_lots() + )?; + } + if raw_acct.is_margin { writeln!(file, "Margin Account")?; } + + for (lot_idx, lot) in acct.list_of_lots.borrow().iter().enumerate() { + + let lot_basis = lot.get_sum_of_basis_in_lot(); + let movements_sum = lot.get_sum_of_amts_in_lot(); + + if acct.list_of_lots.borrow().len() > 0 { + + writeln!(file, " Lot {} • Σ: {}, with remaining cost basis of {} and basis date of {}", + (lot_idx+1), + movements_sum, + lot_basis, + lot.date_for_basis_purposes + )?; + } + } + } + + Ok(()) +} + +pub fn _3_account_lot_summary_non_zero_to_txt( + settings: &ImportProcessParameters, + raw_acct_map: &HashMap, + acct_map: &HashMap, +) -> Result<(), Box> { + +// ===================================== +// Exchange BTC +// Account balance: 0.5000000 BTC; Total cost basis: 450.0000000 +// Lot 4 • Σ: 0.5000000, with remaining cost basis of 450.0 and basis date of 2016-10-01 + +// ===================================== +// Simplewallet XMR +// Account balance: 400.0000000 XMR; Total cost basis: 2000.0 +// Lot 1 • Σ: 400.0000000, with remaining cost basis of 2000.0 and basis date of 2018-02-01 + + + + let file_name = PathBuf::from("3_Acct_lot_summary_non_zero.txt"); + let path = PathBuf::from(&settings.export_path.clone()); + let full_path: PathBuf = [path, file_name].iter().collect(); + + let mut file = OpenOptions::new() + .write(true) + .create(true) + .truncate(true) + .open(full_path)?; + + let length = acct_map.len(); + + writeln!(file, "Account Listing - All Lots - All Movements - with high level of detail. +\nCosting method used: {}. +Home currency: {} +Enable like-kind treatment: {}", + settings.costing_method, + settings.home_currency, + settings.enable_like_kind_treatment + )?; + + if settings.enable_like_kind_treatment { + writeln!(file, "Like-kind cut-off date: {}.", + settings.lk_cutoff_date_string + )?; + } + + for j in 1..=length { + + let acct = acct_map.get(&(j as u16)).unwrap(); + let raw_acct = raw_acct_map.get(&acct.raw_key).unwrap(); + let amt_in_acct = acct.get_sum_of_amts_in_lots(); + + if acct.list_of_lots.borrow().len() > 0 { + if amt_in_acct > d128!(0) { + + writeln!(file, "\n=====================================")?; + writeln!(file, "{} {}", raw_acct.name, raw_acct.ticker)?; + writeln!(file, "Account balance: {} {}; Total cost basis: {}", + amt_in_acct, + raw_acct.ticker, + acct.get_sum_of_basis_in_lots() + )?; + } else { + continue + } + } + if raw_acct.is_margin { writeln!(file, "Margin Account")?; } + + for (lot_idx, lot) in acct.list_of_lots.borrow().iter().enumerate() { + + let lot_basis = lot.get_sum_of_basis_in_lot(); + let movements_sum = lot.get_sum_of_amts_in_lot(); + + if acct.list_of_lots.borrow().len() > 0 { + if movements_sum > d128!(0) { + + writeln!(file, " Lot {} • Σ: {}, with remaining cost basis of {} and basis date of {}", + (lot_idx+1), + movements_sum, + lot_basis, + lot.date_for_basis_purposes + )?; + } + } + } + } + + Ok(()) +} \ No newline at end of file