Added two new txt account reports.

This commit is contained in:
scoobybejesus 2019-09-10 22:49:18 -04:00
parent 530ebfeb35
commit 5c5a0bb67a
2 changed files with 186 additions and 0 deletions

View File

@ -299,6 +299,18 @@ fn main() -> Result<(), Box<dyn Error>> {
&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;

View File

@ -183,3 +183,177 @@ Enable like-kind treatment: {}",
Ok(())
}
pub fn _2_account_lot_summary_to_txt(
settings: &ImportProcessParameters,
raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>,
) -> Result<(), Box<dyn Error>> {
// =====================================
// 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<u16, RawAccount>,
acct_map: &HashMap<u16, Account>,
) -> Result<(), Box<dyn Error>> {
// =====================================
// 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(())
}