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,96 +171,96 @@ 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() {
|
||||
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."));
|
||||
|
||||
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")
|
||||
.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);
|
||||
|
||||
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)?;
|
||||
|
||||
let (election, date) = _elect_like_kind_arg(&cutoff_date_arg, provided_date)?;
|
||||
fn _elect_like_kind_arg(cutoff_date_arg: &String, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> {
|
||||
|
||||
fn _elect_like_kind_arg(cutoff_date_arg: &Option<String>, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> {
|
||||
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input)?;
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input)?;
|
||||
|
||||
|
||||
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()) )
|
||||
},
|
||||
"n" | "no" => { println!(" Proceeding without like-kind treatment.\n");
|
||||
Ok( (false, "1-1-1".to_string()) )
|
||||
},
|
||||
"c" | "change" => {
|
||||
println!("Please enter your desired like-kind exchange treatment cutoff date.");
|
||||
println!(" You must use the format %y-%m-%d (e.g., 2017-12-31, 17-12-31, and 9-6-1 are all acceptable).\n");
|
||||
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.to_string()) )
|
||||
},
|
||||
"n" | "no" => {
|
||||
println!(" Proceeding without like-kind treatment.\n");
|
||||
Ok( (false, "1-1-1".to_string()) )
|
||||
},
|
||||
"c" | "change" => {
|
||||
println!("Please enter your desired like-kind exchange treatment cutoff date.");
|
||||
println!(" You must use the format %y-%m-%d (e.g., 2017-12-31, 17-12-31, and 9-6-1 are all acceptable).\n");
|
||||
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input)?;
|
||||
string_utils::trim_newline(&mut input);
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input)?;
|
||||
string_utils::trim_newline(&mut input);
|
||||
|
||||
let newly_chosen_date = NaiveDate::parse_from_str(&input, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d")
|
||||
.expect("Date entered has an incorrect format. Program must abort."));
|
||||
// TODO: figure out how to make this fail gracefully and let the user input the date again
|
||||
println!(" Using like-kind treatment through {}.\n", newly_chosen_date);
|
||||
Ok( (true, input) )
|
||||
},
|
||||
_ => {
|
||||
println!("Please respond with 'y', 'n', or 'c' (or 'yes' or 'no' or 'change').");
|
||||
_elect_like_kind_arg(&cutoff_date_arg, provided_date)
|
||||
let newly_chosen_date = NaiveDate::parse_from_str(&input, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d")
|
||||
.expect("Date entered has an incorrect format. Program must abort."));
|
||||
// TODO: figure out how to make this fail gracefully and let the user input the date again
|
||||
println!(" Using like-kind treatment through {}.\n", newly_chosen_date);
|
||||
Ok( (true, input) )
|
||||
},
|
||||
_ => {
|
||||
println!("Please respond with 'y', 'n', or 'c' (or 'yes' or 'no' or 'change').");
|
||||
_elect_like_kind_arg(&cutoff_date_arg, provided_date)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok((election, date))
|
||||
}
|
||||
|
||||
return Ok((election, date))
|
||||
None => {
|
||||
println!("\nContinue without like-kind exchange treatment? [Y/n] ");
|
||||
|
||||
} else {
|
||||
let (election, date) = _no_elect_like_kind_arg()?;
|
||||
|
||||
println!("\nContinue without like-kind exchange treatment? [Y/n] ");
|
||||
fn _no_elect_like_kind_arg() -> Result<(bool, String), Box<dyn Error>> {
|
||||
|
||||
let (election, date) = _no_elect_like_kind_arg()?;
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input)?;
|
||||
|
||||
fn _no_elect_like_kind_arg() -> Result<(bool, String), Box<dyn Error>> {
|
||||
match input.trim().to_ascii_lowercase().as_str() {
|
||||
"y" | "ye" | "yes" | "" => {
|
||||
println!(" Proceeding without like-kind treatment.\n");
|
||||
Ok( (false, "1-1-1".to_string()) )
|
||||
},
|
||||
"n" | "no" => {
|
||||
println!("Please enter your desired like-kind exchange treatment cutoff date.");
|
||||
println!(" You must use the format %y-%m-%d (e.g., 2017-12-31, 17-12-31, and 9-6-1 are all acceptable).\n");
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input)?;
|
||||
string_utils::trim_newline(&mut input);
|
||||
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input)?;
|
||||
let newly_chosen_date = NaiveDate::parse_from_str(&input, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d")
|
||||
.expect("Date entered has an incorrect format. Program must abort."));
|
||||
// TODO: figure out how to make this fail gracefully and let the user input the date again
|
||||
println!(" Using like-kind treatment through {}.\n", newly_chosen_date);
|
||||
|
||||
match input.trim().to_ascii_lowercase().as_str() {
|
||||
"y" | "ye" | "yes" | "" => { println!(" Proceeding without like-kind treatment.\n");
|
||||
Ok( (false, "1-1-1".to_string()) )
|
||||
},
|
||||
"n" | "no" => {
|
||||
println!("Please enter your desired like-kind exchange treatment cutoff date.");
|
||||
println!(" You must use the format %y-%m-%d (e.g., 2017-12-31, 17-12-31, and 9-6-1 are all acceptable).\n");
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input)?;
|
||||
string_utils::trim_newline(&mut input);
|
||||
|
||||
let newly_chosen_date = NaiveDate::parse_from_str(&input, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d")
|
||||
.expect("Date entered has an incorrect format. Program must abort."));
|
||||
// TODO: figure out how to make this fail gracefully and let the user input the date again
|
||||
println!(" Using like-kind treatment through {}.\n", newly_chosen_date);
|
||||
|
||||
Ok( (true, input) )
|
||||
},
|
||||
_ => { println!("Please respond with 'y' or 'n' (or 'yes' or 'no')."); _no_elect_like_kind_arg() }
|
||||
Ok( (true, input) )
|
||||
},
|
||||
_ => { println!("Please respond with 'y' or 'n' (or 'yes' or 'no')."); _no_elect_like_kind_arg() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok((election, date))
|
||||
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,
|
||||
|
@ -660,7 +658,7 @@ fn fit_into_lots(
|
|||
ar_map: &HashMap<u32, ActionRecord>,
|
||||
raw_acct_map: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>,
|
||||
) {
|
||||
) {
|
||||
|
||||
let ar = ar_map.get(&spawning_ar_key).unwrap();
|
||||
let acct = acct_map.get(&ar.account_key).unwrap();
|
||||
|
@ -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