diff --git a/src/csv_export.rs b/src/csv_export.rs index af41087..5369c29 100644 --- a/src/csv_export.rs +++ b/src/csv_export.rs @@ -268,7 +268,7 @@ pub fn _4_transaction_mvmt_detail_to_csv( let date = txn.date.format("%Y/%m/%d").to_string(); let tx_number = txn.tx_number.to_string(); let tx_type = txn.transaction_type(&ars, &raw_acct_map, &acct_map)?; - let memo = txn.memo.to_string(); + let memo = txn.user_memo.to_string(); let mut amount = d128!(0); amount += mvmt.amount; // To prevent printing -5E+1 instead of 50, for example let ticker = raw_acct.ticker.to_string(); @@ -354,7 +354,7 @@ pub fn _5_transaction_mvmt_summaries_to_csv( let txn_date_string = txn.date.format("%Y/%m/%d").to_string(); let tx_num_string = "Txn ".to_string() + &txn.tx_number.to_string(); let tx_type_string = txn.transaction_type(ars, &raw_acct_map, &acct_map)?.to_string(); - let tx_memo_string = txn.memo.to_string(); + let tx_memo_string = txn.user_memo.to_string(); let mut term_st: Option = None; let mut term_lt: Option = None; let mut ticker: Option = None; @@ -508,7 +508,8 @@ pub fn _6_transaction_mvmt_detail_to_csv_w_orig( "Date".to_string(), "Txn#".to_string(), "Type".to_string(), - "Memo".to_string(), + "User Memo".to_string(), + "Auto Memo".to_string(), "Amount".to_string(), "Ticker".to_string(), "Term".to_string(), @@ -546,7 +547,8 @@ pub fn _6_transaction_mvmt_detail_to_csv_w_orig( let date = txn.date.format("%Y/%m/%d").to_string(); let tx_number = txn.tx_number.to_string(); let tx_type = txn.transaction_type(&ars, &raw_acct_map, &acct_map)?; - let memo = txn.memo.to_string(); + let user_memo = txn.user_memo.to_string(); + let auto_memo = txn.get_auto_memo(ars, raw_acct_map,acct_map)?; let mut amount = d128!(0); amount += mvmt.amount; // To prevent printing -5E+1 instead of 50, for example let ticker = raw_acct.ticker.to_string(); @@ -574,7 +576,8 @@ pub fn _6_transaction_mvmt_detail_to_csv_w_orig( row.push(date); row.push("Txn ".to_string() + &tx_number); row.push(tx_type.to_string()); - row.push(memo); + row.push(user_memo); + row.push(auto_memo); row.push(amount.to_string()); row.push(ticker); row.push(term); diff --git a/src/csv_import_accts_txns.rs b/src/csv_import_accts_txns.rs index 7ca2e13..aa32c9e 100644 --- a/src/csv_import_accts_txns.rs +++ b/src/csv_import_accts_txns.rs @@ -208,7 +208,7 @@ pub(crate) fn import_transactions( tx_number: this_tx_number, date_as_string: this_tx_date.to_string(), date: tx_date, - memo: this_memo.to_string(), + user_memo: this_memo.to_string(), proceeds: proceeds_parsed, action_record_idx_vec: action_records_map_keys_vec, }; diff --git a/src/transaction.rs b/src/transaction.rs index bc2f9c6..5d323f9 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -19,7 +19,7 @@ pub struct Transaction { pub tx_number: u32, // Does NOT start at zero. First txn is 1. pub date_as_string: String, pub date: NaiveDate, - pub memo: String, + pub user_memo: String, pub proceeds: f32, pub action_record_idx_vec: Vec, } @@ -209,6 +209,60 @@ impl Transaction { Ok(both_are_non_home_curr) } + + pub fn get_auto_memo( + &self, + ars: &HashMap, + raw_accts: &HashMap, + acct_map: &HashMap + ) -> Result> { + + let auto_memo = if self.action_record_idx_vec.len() == 2 { + + let marginness = self.marginness(ars, raw_accts, acct_map); + + if (marginness == TxHasMargin::NoARs) | (marginness == TxHasMargin::TwoARs) { + + let og_amt = ars.get(&self.action_record_idx_vec[0]).unwrap().amount; + let og_acct_key = ars.get(&self.action_record_idx_vec[0]).unwrap().account_key; + let og_acct = acct_map.get(&og_acct_key).unwrap(); + let og_raw_acct = raw_accts.get(&og_acct.raw_key).unwrap(); + let og_ticker = &og_raw_acct.ticker; + + let ic_amt = ars.get(&self.action_record_idx_vec[1]).unwrap().amount; + let ic_acct_key = ars.get(&self.action_record_idx_vec[1]).unwrap().account_key; + let ic_acct = acct_map.get(&ic_acct_key).unwrap(); + let ic_raw_acct = raw_accts.get(&ic_acct.raw_key).unwrap(); + let ic_ticker = &ic_raw_acct.ticker; + + format!("Paid {} {} for {} {}", og_amt, og_ticker, ic_amt, ic_ticker) + + } else { + + format!("Margin profit or loss") + } + + } else { + + let amt = ars.get(&self.action_record_idx_vec[0]).unwrap().amount; + let acct_key = ars.get(&self.action_record_idx_vec[0]).unwrap().account_key; + let acct = acct_map.get(&acct_key).unwrap(); + let raw_acct = raw_accts.get(&acct.raw_key).unwrap(); + let ticker = &raw_acct.ticker; + + if amt > d128!(0.0) { + + format!("Received {} {}", amt, ticker) + + } else { + + format!("Spent {} {}", amt, ticker) + + } + }; + + Ok(auto_memo) + } } #[derive(Clone, Debug)] diff --git a/src/txt_export.rs b/src/txt_export.rs index 566ebc2..bfe2575 100644 --- a/src/txt_export.rs +++ b/src/txt_export.rs @@ -134,7 +134,7 @@ Enable like-kind treatment: {}", mvmt.transaction_key, tx_type, mvmt.date_as_string, - txn.memo + txn.user_memo ); writeln!(file, "{}", description_str)?;