Ignore ccs with no area, use hashset for tracking overhead ccs

This commit is contained in:
michaelpivato
2023-03-09 12:51:10 +10:30
parent 1e36bc68e4
commit 540e4c778d

View File

@@ -1,4 +1,4 @@
use std::{collections::HashMap, io::Read, path::Path}; use std::{collections::{HashMap, HashSet}, io::Read, path::Path};
use itertools::Itertools; use itertools::Itertools;
use nalgebra::{DMatrix, Dynamic, LU}; use nalgebra::{DMatrix, Dynamic, LU};
@@ -199,6 +199,9 @@ where
let cost_centre: HashMap<String, String> = cost_centre?; let cost_centre: HashMap<String, String> = cost_centre?;
let name = cost_centre.get("Code").unwrap(); let name = cost_centre.get("Code").unwrap();
let area = cost_centre.get("Area").unwrap(); let area = cost_centre.get("Area").unwrap();
if area.is_empty() {
continue;
}
area_ccs area_ccs
.entry(area.clone()) .entry(area.clone())
.or_insert(Vec::new()) .or_insert(Vec::new())
@@ -224,7 +227,7 @@ where
let mut overhead_other_total: Vec<(String, String, f64)> = Vec::new(); let mut overhead_other_total: Vec<(String, String, f64)> = Vec::new();
// Save overhead ccs, so we later know whether a to cc is overhead or operating // Save overhead ccs, so we later know whether a to cc is overhead or operating
let mut overhead_ccs: Vec<String> = Vec::new(); let mut overhead_ccs: HashSet<String> = HashSet::new();
// overhead department -> total (summed limit to costs) // overhead department -> total (summed limit to costs)
let mut overhead_cc_totals: HashMap<String, f64> = HashMap::new(); let mut overhead_cc_totals: HashMap<String, f64> = HashMap::new();
// For each overhead area, get the cost centres in the area (overhead cost centres), and get all cost centres // For each overhead area, get the cost centres in the area (overhead cost centres), and get all cost centres
@@ -246,7 +249,9 @@ where
} }
let mut current_area_ccs = current_area_ccs.unwrap().clone(); let mut current_area_ccs = current_area_ccs.unwrap().clone();
overhead_ccs.append(&mut current_area_ccs); for cc in current_area_ccs {
overhead_ccs.insert(cc);
}
let overhead_ccs = area_ccs.get(area_name).unwrap(); let overhead_ccs = area_ccs.get(area_name).unwrap();
// TODO: This depends on the area limit criteria. For now just doing any limit criteria // TODO: This depends on the area limit criteria. For now just doing any limit criteria
let mut limited_ccs: Vec<String> = Vec::new(); let mut limited_ccs: Vec<String> = Vec::new();
@@ -325,7 +330,7 @@ where
from_overhead_department: from_overhead_department.clone(), from_overhead_department: from_overhead_department.clone(),
to_department: to_department.clone(), to_department: to_department.clone(),
percent: percent / overhead_cc_totals.get(from_overhead_department).unwrap(), percent: percent / overhead_cc_totals.get(from_overhead_department).unwrap(),
to_department_type: if overhead_ccs.contains(&to_department) { to_department_type: if overhead_ccs.contains(to_department) {
DepartmentType::Overhead DepartmentType::Overhead
} else { } else {
DepartmentType::Operating DepartmentType::Operating
@@ -422,7 +427,11 @@ fn split_allocation_statistic_range(
// Removes quotes and padding from accounts int he allocation statistic account range. // Removes quotes and padding from accounts int he allocation statistic account range.
// e.g. "'100' " becomes "100" // e.g. "'100' " becomes "100"
fn remove_quote_and_padding(s: &str) -> String { fn remove_quote_and_padding(s: &str) -> String {
s.trim()[1..s.trim().len() - 1].to_owned() if s.contains('\'') {
s.trim()[1..s.trim().len() - 1].to_owned()
} else {
s.trim().to_owned()
}
} }
// Perform the reciprocal allocation (matrix) method to allocate servicing departments (indirect) costs // Perform the reciprocal allocation (matrix) method to allocate servicing departments (indirect) costs