Ignore ccs with no area, use hashset for tracking overhead ccs
This commit is contained in:
@@ -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 nalgebra::{DMatrix, Dynamic, LU};
|
||||
@@ -199,6 +199,9 @@ where
|
||||
let cost_centre: HashMap<String, String> = cost_centre?;
|
||||
let name = cost_centre.get("Code").unwrap();
|
||||
let area = cost_centre.get("Area").unwrap();
|
||||
if area.is_empty() {
|
||||
continue;
|
||||
}
|
||||
area_ccs
|
||||
.entry(area.clone())
|
||||
.or_insert(Vec::new())
|
||||
@@ -224,7 +227,7 @@ where
|
||||
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
|
||||
let mut overhead_ccs: Vec<String> = Vec::new();
|
||||
let mut overhead_ccs: HashSet<String> = HashSet::new();
|
||||
// overhead department -> total (summed limit to costs)
|
||||
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
|
||||
@@ -246,7 +249,9 @@ where
|
||||
}
|
||||
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();
|
||||
// TODO: This depends on the area limit criteria. For now just doing any limit criteria
|
||||
let mut limited_ccs: Vec<String> = Vec::new();
|
||||
@@ -325,7 +330,7 @@ where
|
||||
from_overhead_department: from_overhead_department.clone(),
|
||||
to_department: to_department.clone(),
|
||||
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
|
||||
} else {
|
||||
DepartmentType::Operating
|
||||
@@ -422,7 +427,11 @@ fn split_allocation_statistic_range(
|
||||
// Removes quotes and padding from accounts int he allocation statistic account range.
|
||||
// e.g. "'100' " becomes "100"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user