diff --git a/Cargo.toml b/Cargo.toml index 0e31ed5..cd97c33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cryptools" -version = "0.8.2" +version = "0.8.3" authors = ["scoobybejesus "] edition = "2018" description = "Command-line utility for processing cryptocurrency transactions into 'lots' and 'movements'." diff --git a/src/crptls_lib/transaction.rs b/src/crptls_lib/transaction.rs index 7f08a67..31d670b 100644 --- a/src/crptls_lib/transaction.rs +++ b/src/crptls_lib/transaction.rs @@ -241,16 +241,36 @@ impl Transaction { let ic_raw_acct = raw_accts.get(&ic_acct.raw_key).unwrap(); let ic_ticker = &ic_raw_acct.ticker; - if tx_type == TxType::Exchange { - format!("Paid {} {} for {} {}, valued at {} {}.", - og_amt, og_ticker, ic_amt, ic_ticker, self.proceeds, home_currency) + let og_amt_and_ticker; + if og_raw_acct.is_home_currency(home_currency) { + og_amt_and_ticker = format!("{:.2} {}", + og_amt.to_string().as_str().parse::()?, og_ticker + ); } else { - format!("Transferred {} {} to another account. Received {} {}, likely after a transaction fee.", - og_amt, og_ticker, ic_amt, ic_ticker) + og_amt_and_ticker = format!("{} {}", og_amt, og_ticker); + } + + let ic_amt_and_ticker; + if ic_raw_acct.is_home_currency(home_currency) { + ic_amt_and_ticker = format!("{:.2} {}", + ic_amt.to_string().as_str().parse::()?, ic_ticker + ); + } else { + ic_amt_and_ticker = format!("{} {}", ic_amt, ic_ticker); + } + + if tx_type == TxType::Exchange { + format!("Paid {} for {}, valued at {:.2} {}.", + og_amt_and_ticker, ic_amt_and_ticker, + self.proceeds.to_string().as_str().parse::()?, home_currency) + } else { + format!("Transferred {} to another account. Received {}, likely after a transaction fee.", + og_amt_and_ticker, ic_amt_and_ticker) } } else { - format!("Margin profit or loss valued at {} {}.", self.proceeds, home_currency) + format!("Margin profit or loss valued at {:.2} {}.", + self.proceeds.to_string().as_str().parse::()?, home_currency) } } else { @@ -263,11 +283,13 @@ impl Transaction { if amt > d128!(0.0) { - format!("Received {} {} valued at {} {}.", amt, ticker, self.proceeds, home_currency) + format!("Received {} {} valued at {:.2} {}.", amt, ticker, + self.proceeds.to_string().as_str().parse::()?, home_currency) } else { - format!("Spent {} {} valued at {} {}.", amt, ticker, self.proceeds, home_currency) + format!("Spent {} {} valued at {:.2} {}.", amt, ticker, + self.proceeds.to_string().as_str().parse::()?, home_currency) } }; diff --git a/src/export_je.rs b/src/export_je.rs index ffaf246..9083839 100644 --- a/src/export_je.rs +++ b/src/export_je.rs @@ -174,10 +174,10 @@ depending on the bookkeeping practices you employ."; if let Some(cb) = cost_basis_ic { debits += cb; - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20.2}{:5}{:>20}", acct_string_ic, "", - cb.to_string(), + cb.to_string().as_str().parse::()?, "", "", )?; @@ -185,12 +185,12 @@ depending on the bookkeeping practices you employ."; if let Some(cb) = cost_basis_og { credits += cb; - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20}{:5}{:>20.2}", acct_string_og, "", "", "", - cb.to_string(), + cb.to_string().as_str().parse::()?, )?; } @@ -199,20 +199,20 @@ depending on the bookkeeping practices you employ."; if lt_gain_loss > d128!(0) { credits += lt_gain_loss.abs(); let ltg_string = format!("Long-term gain disposing {}", amount_lt.abs()); - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20}{:5}{:>20.2}", ltg_string, "", "", "", - lt_gain_loss.to_string(), + lt_gain_loss.to_string().as_str().parse::()?, )?; } else { debits += lt_gain_loss.abs(); let ltl_string = format!("Long-term loss disposing {}", amount_lt.abs()); - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20.2}{:5}{:>20}", ltl_string, "", - lt_gain_loss.abs().to_string(), + lt_gain_loss.abs().to_string().as_str().parse::()?, "", "", )?; @@ -224,20 +224,20 @@ depending on the bookkeeping practices you employ."; if st_gain_loss > d128!(0) { credits += st_gain_loss.abs(); let stg_string = format!("Short-term gain disposing {}", amount_st.abs()); - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20}{:5}{:>20.2}", stg_string, "", "", "", - st_gain_loss.to_string(), + st_gain_loss.to_string().as_str().parse::()?, )?; } else { debits += st_gain_loss.abs(); let stl_string = format!("Short-term loss disposing {}", amount_st.abs()); - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20.2}{:5}{:>20}", stl_string, "", - st_gain_loss.abs().to_string(), + st_gain_loss.abs().to_string().as_str().parse::()?, "", "", )?; @@ -246,21 +246,21 @@ depending on the bookkeeping practices you employ."; if income != d128!(0) { credits += income; - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20}{:5}{:>20.2}", "Income", "", "", "", - income.to_string(), + income.to_string().as_str().parse::()?, )?; } if expense != d128!(0) { debits += expense.abs(); - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20.2}{:5}{:>20}", "Expense", "", - expense.abs().to_string(), + expense.abs().to_string().as_str().parse::()?, "", "", )?; @@ -274,12 +274,12 @@ depending on the bookkeeping practices you employ."; "--------------------", )?; - writeln!(file, "{:50}{:5}{:>20}{:5}{:>20}", + writeln!(file, "{:50}{:5}{:>20.2}{:5}{:>20.2}", " Totals", "", - debits, + debits.to_string().as_str().parse::()?, "", - credits, + credits.to_string().as_str().parse::()?, )?; writeln!(file, "\n (Txn {} on {}. {}. {})", diff --git a/src/export_txt.rs b/src/export_txt.rs index 2673ce5..8483b61 100644 --- a/src/export_txt.rs +++ b/src/export_txt.rs @@ -148,7 +148,7 @@ Enable like-kind treatment: {}", let lot_sum_row; if raw_acct.is_home_currency(home_currency) { - lot_sum_row = format!("\t• Σ: {:.2} {}, with remaining cost basis of {:.2} {} and basis date of {}", + lot_sum_row = format!(" • Σ: {:.2} {}, with remaining cost basis of {:.2} {} and basis date of {}", formatted_sum.to_string().as_str().parse::()?, ticker, formatted_basis.to_string().as_str().parse::()?, @@ -156,7 +156,7 @@ Enable like-kind treatment: {}", lot.date_for_basis_purposes ) } else { - lot_sum_row = format!("\t• Σ: {} {}, with remaining cost basis of {:.2} {} and basis date of {}", + lot_sum_row = format!(" • Σ: {} {}, with remaining cost basis of {:.2} {} and basis date of {}", formatted_sum, ticker, formatted_basis.to_string().as_str().parse::()?, @@ -165,7 +165,7 @@ Enable like-kind treatment: {}", ) } writeln!(file, "{}", lot_sum_row)?; - writeln!(file, "\t Movements:")?; + writeln!(file, " Movements:")?; for (m_idx, mvmt) in lot.movements.borrow().iter().enumerate() { @@ -175,7 +175,7 @@ Enable like-kind treatment: {}", let description_string: String; if raw_acct.is_home_currency(home_currency) { - description_string = format!("\t\t{}.\t{:<8.2} {} (Txn #{:>4}) {:>9} txn on {:10}. - {}", + description_string = format!("\t{}. {:<8.2} {} (Txn #{:>4}) {:>9} txn on {:10}. - {}", (m_idx+1), mvmt.amount.to_string().as_str().parse::()?, ticker, @@ -185,7 +185,7 @@ Enable like-kind treatment: {}", txn.user_memo ); } else { - description_string = format!("\t\t{}.\t{:<8} {} (Txn #{:>4}) {:>9} txn on {:10}. - {}", + description_string = format!("\t{}. {:<8} {} (Txn #{:>4}) {:>9} txn on {:10}. - {}", (m_idx+1), mvmt.amount, ticker, @@ -216,7 +216,7 @@ Enable like-kind treatment: {}", let income = mvmt.get_income(ars, raw_acct_map, acct_map, txns_map)?; let expense = mvmt.get_expense(ars, raw_acct_map, acct_map, txns_map)?; - let activity_str = format!("\t\t\tProceeds: {:>10.2}; Cost basis: {:>10.2}; for Gain/loss: {} {:>10.2}; Inc.: {:>10.2}; Exp.: {:>10.2}.", + let activity_str = format!("\t Proceeds: {:>10.2}; Cost basis: {:>10.2}; for Gain/loss: {} {:>10.2}; Inc.: {:>10.2}; Exp.: {:>10.2}.", lk_proceeds.to_string().as_str().parse::()?, lk_cost_basis.to_string().as_str().parse::()?, mvmt.get_term(acct_map, ars),