Minor refactoring. Deleted dead code. Commented unused code.
This commit is contained in:
parent
bfa13f1aa0
commit
093224f779
|
@ -37,10 +37,10 @@ pub struct Account {
|
|||
|
||||
impl Account {
|
||||
|
||||
pub fn is_home_currency(&self, compare: &String, raw_acct_map: &HashMap<u16, RawAccount>) -> bool {
|
||||
let raw_acct = raw_acct_map.get(&self.raw_key).unwrap();
|
||||
&raw_acct.ticker == compare
|
||||
}
|
||||
// pub fn is_home_currency(&self, compare: &String, raw_acct_map: &HashMap<u16, RawAccount>) -> bool {
|
||||
// let raw_acct = raw_acct_map.get(&self.raw_key).unwrap();
|
||||
// &raw_acct.ticker == compare
|
||||
// }
|
||||
|
||||
pub fn get_sum_of_amts_in_lots(&self) -> d128 {
|
||||
let lots = self.list_of_lots.borrow();
|
||||
|
@ -82,9 +82,11 @@ impl Lot {
|
|||
self.movements.borrow().iter().for_each(|movement| amts += movement.amount);
|
||||
amts
|
||||
}
|
||||
pub fn sum_of_amts_in_lot_is_zero(&self) -> bool {
|
||||
d128!(0) == Self::get_sum_of_amts_in_lot(&self)
|
||||
}
|
||||
|
||||
// pub fn sum_of_amts_in_lot_is_zero(&self) -> bool {
|
||||
// d128!(0) == Self::get_sum_of_amts_in_lot(&self)
|
||||
// }
|
||||
|
||||
pub fn get_sum_of_basis_in_lot(&self) -> d128 {
|
||||
let mut amts = d128!(0);
|
||||
self.movements.borrow().iter().for_each(|movement| amts += movement.cost_basis.get());
|
||||
|
@ -218,10 +220,10 @@ impl Movement {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn direction(&self) -> Polarity {
|
||||
if self.amount < d128!(0.0) { Polarity::Outgoing }
|
||||
else { Polarity::Incoming }
|
||||
}
|
||||
// pub fn direction(&self) -> Polarity {
|
||||
// if self.amount < d128!(0.0) { Polarity::Outgoing }
|
||||
// else { Polarity::Incoming }
|
||||
// }
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
|
|
@ -171,20 +171,18 @@ pub fn inv_costing_from_cmd_arg(arg: String) -> Result<InventoryCostingMethod, &
|
|||
|
||||
pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bool, String), Box<dyn Error>> {
|
||||
|
||||
let election: bool;
|
||||
let date: String;
|
||||
match cutoff_date_arg {
|
||||
|
||||
if cutoff_date_arg.is_some() {
|
||||
|
||||
let provided_date = NaiveDate::parse_from_str(&cutoff_date_arg.clone().unwrap(), "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&cutoff_date_arg.clone().unwrap(), "%Y-%m-%d")
|
||||
Some(cutoff_date_arg) => {
|
||||
let provided_date = NaiveDate::parse_from_str(&cutoff_date_arg, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&cutoff_date_arg, "%Y-%m-%d")
|
||||
.expect("Date entered as -c command line arg has an incorrect format."));
|
||||
|
||||
println!("\nUse like-kind exchange treatment through {}? [Y/n/c] ('c' to 'change') ", provided_date);
|
||||
|
||||
let (election, date) = _elect_like_kind_arg(&cutoff_date_arg, provided_date)?;
|
||||
|
||||
fn _elect_like_kind_arg(cutoff_date_arg: &Option<String>, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> {
|
||||
fn _elect_like_kind_arg(cutoff_date_arg: &String, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> {
|
||||
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
|
@ -194,9 +192,10 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
|
|||
match input.trim().to_ascii_lowercase().as_str() {
|
||||
"y" | "ye" | "yes" | "" => {
|
||||
println!(" Using like-kind treatment through {}.\n", provided_date);
|
||||
Ok( (true, cutoff_date_arg.clone().unwrap()) )
|
||||
Ok( (true, cutoff_date_arg.to_string()) )
|
||||
},
|
||||
"n" | "no" => { println!(" Proceeding without like-kind treatment.\n");
|
||||
"n" | "no" => {
|
||||
println!(" Proceeding without like-kind treatment.\n");
|
||||
Ok( (false, "1-1-1".to_string()) )
|
||||
},
|
||||
"c" | "change" => {
|
||||
|
@ -223,9 +222,9 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
|
|||
}
|
||||
|
||||
return Ok((election, date))
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
None => {
|
||||
println!("\nContinue without like-kind exchange treatment? [Y/n] ");
|
||||
|
||||
let (election, date) = _no_elect_like_kind_arg()?;
|
||||
|
@ -237,7 +236,8 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
|
|||
stdin.lock().read_line(&mut input)?;
|
||||
|
||||
match input.trim().to_ascii_lowercase().as_str() {
|
||||
"y" | "ye" | "yes" | "" => { println!(" Proceeding without like-kind treatment.\n");
|
||||
"y" | "ye" | "yes" | "" => {
|
||||
println!(" Proceeding without like-kind treatment.\n");
|
||||
Ok( (false, "1-1-1".to_string()) )
|
||||
},
|
||||
"n" | "no" => {
|
||||
|
@ -263,4 +263,4 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
|
|||
return Ok((election, date))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -94,8 +94,6 @@ pub fn import_and_process_final(
|
|||
&mut rdr,
|
||||
transactions_map,
|
||||
action_records,
|
||||
raw_acct_map,
|
||||
acct_map
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -259,7 +259,7 @@ pub fn create_lots_and_movements(
|
|||
|
||||
fn get_lifo_by_creation_date(list_of_lots: &Ref<Vec<Rc<Lot>>>) -> Vec<usize> {
|
||||
let mut vec_of_indexes = [].to_vec();
|
||||
for (idx, lot) in list_of_lots.iter().enumerate() {
|
||||
for (idx, _lot) in list_of_lots.iter().enumerate() {
|
||||
vec_of_indexes.insert(0, idx)
|
||||
}
|
||||
let vec = vec_of_indexes;
|
||||
|
@ -277,7 +277,7 @@ pub fn create_lots_and_movements(
|
|||
}
|
||||
}
|
||||
let mut vec_of_indexes = [].to_vec();
|
||||
for (idx, lot) in reordered_vec.iter().enumerate() {
|
||||
for (idx, _lot) in reordered_vec.iter().enumerate() {
|
||||
vec_of_indexes.insert(0, idx)
|
||||
}
|
||||
let vec = vec_of_indexes;
|
||||
|
@ -286,7 +286,7 @@ pub fn create_lots_and_movements(
|
|||
|
||||
fn get_fifo_by_creation_date(list_of_lots: &Ref<Vec<Rc<Lot>>>) -> Vec<usize> {
|
||||
let mut vec_of_indexes = [].to_vec();
|
||||
for (idx, lot) in list_of_lots.iter().enumerate() {
|
||||
for (idx, _lot) in list_of_lots.iter().enumerate() {
|
||||
vec_of_indexes.push(idx)
|
||||
}
|
||||
let vec = vec_of_indexes;
|
||||
|
@ -304,7 +304,7 @@ pub fn create_lots_and_movements(
|
|||
}
|
||||
}
|
||||
let mut vec_of_indexes = [].to_vec();
|
||||
for (idx, lot) in reordered_vec.iter().enumerate() {
|
||||
for (idx, _lot) in reordered_vec.iter().enumerate() {
|
||||
vec_of_indexes.push(idx)
|
||||
}
|
||||
let vec = vec_of_indexes;
|
||||
|
@ -329,7 +329,6 @@ pub fn create_lots_and_movements(
|
|||
};
|
||||
|
||||
fit_into_lots(
|
||||
acct.raw_key,
|
||||
txn_num,
|
||||
*ar_num,
|
||||
whole_mvmt,
|
||||
|
@ -649,7 +648,6 @@ fn wrap_mvmt_and_push(
|
|||
}
|
||||
|
||||
fn fit_into_lots(
|
||||
acct_key: u16,
|
||||
txn_num: u32,
|
||||
spawning_ar_key: u32,
|
||||
mvmt_to_fit: Movement,
|
||||
|
@ -697,7 +695,6 @@ fn fit_into_lots(
|
|||
proceeds: Cell::new(d128!(0.0)),
|
||||
};
|
||||
fit_into_lots(
|
||||
acct.raw_key,
|
||||
txn_num,
|
||||
spawning_ar_key,
|
||||
possible_mvmt_to_fit,
|
||||
|
@ -771,7 +768,6 @@ fn fit_into_lots(
|
|||
};
|
||||
assert!(current_index_position < vec_of_ordered_index_values.len());
|
||||
fit_into_lots(
|
||||
acct.raw_key,
|
||||
txn_num,
|
||||
spawning_ar_key,
|
||||
remainder_mvmt_to_recurse,
|
||||
|
|
|
@ -117,8 +117,6 @@ pub fn import_transactions(
|
|||
rdr: &mut csv::Reader<File>,
|
||||
txns_map: &mut HashMap<u32, Transaction>,
|
||||
action_records: &mut HashMap<u32, ActionRecord>,
|
||||
raw_acct_map: &mut HashMap<u16, RawAccount>,
|
||||
acct_map: &mut HashMap<u16, Account>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let mut this_tx_number = 0;
|
||||
|
@ -138,7 +136,7 @@ pub fn import_transactions(
|
|||
let mut this_tx_date: &str = "";
|
||||
let mut this_proceeds: &str = "";
|
||||
let mut this_memo: &str = "";
|
||||
let mut this: String = "".to_string();
|
||||
let mut this: String;
|
||||
|
||||
// Next, create action_records.
|
||||
let mut action_records_map_keys_vec: Vec<u32> = [].to_vec();
|
||||
|
|
|
@ -8,6 +8,7 @@ pub fn round_d128_generalized(to_round: &d128, places_past_decimal: d128) -> d12
|
|||
let rounded: d128 = ((to_round * d128!(10).scaleb(places_past_decimal)).quantize(d128!(1e1))) / d128!(10).scaleb(places_past_decimal);
|
||||
rounded//.reduce()
|
||||
}
|
||||
|
||||
pub fn round_d128_1e2(to_round: &d128) -> d128 {
|
||||
let rounded: d128 = ((to_round * d128!(10).scaleb(d128!(2))).quantize(d128!(1e1))) / d128!(10).scaleb(d128!(2));
|
||||
rounded//.reduce()
|
||||
|
|
|
@ -203,16 +203,16 @@ impl ActionRecord {
|
|||
else { Polarity::Incoming }
|
||||
}
|
||||
|
||||
pub fn is_quote_acct_for_margin_exch(
|
||||
&self,
|
||||
raw_accts: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>
|
||||
) -> bool {
|
||||
// pub fn is_quote_acct_for_margin_exch(
|
||||
// &self,
|
||||
// raw_accts: &HashMap<u16, RawAccount>,
|
||||
// acct_map: &HashMap<u16, Account>
|
||||
// ) -> bool {
|
||||
|
||||
let acct = acct_map.get(&self.account_key).unwrap();
|
||||
let raw_acct = raw_accts.get(&acct.raw_key).unwrap();
|
||||
raw_acct.ticker.contains('_')
|
||||
}
|
||||
// let acct = acct_map.get(&self.account_key).unwrap();
|
||||
// let raw_acct = raw_accts.get(&acct.raw_key).unwrap();
|
||||
// raw_acct.ticker.contains('_')
|
||||
// }
|
||||
|
||||
pub fn get_mvmts_in_ar(
|
||||
&self,
|
||||
|
@ -220,7 +220,7 @@ impl ActionRecord {
|
|||
txns_map: &HashMap<u32, Transaction>,
|
||||
) -> Vec<Rc<Movement>> {
|
||||
|
||||
let polarity = Self::direction(self);
|
||||
// let polarity = Self::direction(self);
|
||||
let txn = txns_map.get(&self.tx_key).unwrap();
|
||||
let mut movements_in_ar = [].to_vec();
|
||||
let acct = acct_map.get(&self.account_key).unwrap();
|
||||
|
|
Loading…
Reference in New Issue