Add numeric accounts as property to lib, redistribute floating point errors for each account in overhead allocation
This commit is contained in:
@@ -549,7 +549,7 @@ fn do_solve_reciprocal<T: ReciprocalAllocationSolver>(
|
||||
let calculated_overheads = solver.solve(&overhead_costs_vec);
|
||||
|
||||
let mut operating_slice_costs = vec![0.; operating_department_mappings.len()];
|
||||
for cost in total_costs.summed_department_costs {
|
||||
for cost in &total_costs.summed_department_costs {
|
||||
if operating_department_mappings.contains_key(&cost.department) {
|
||||
let elem = &mut operating_slice_costs
|
||||
[*operating_department_mappings.get(&cost.department).unwrap()];
|
||||
@@ -579,9 +579,30 @@ fn do_solve_reciprocal<T: ReciprocalAllocationSolver>(
|
||||
value: *calculated.get(*index).unwrap(),
|
||||
})
|
||||
.collect();
|
||||
// Redistribute floating point errors (only for ccs we actually allocated from/to)
|
||||
// TODO: Still not sure if this is 100% correct, however it appears with this we match up
|
||||
// with the line totals. I think this is because ppm just evenly redistributes floating point
|
||||
// errors, whereas we keep the amounts proportional to the intial amounts
|
||||
let initial_cost: f64 = total_costs
|
||||
.summed_department_costs
|
||||
.iter()
|
||||
.filter(|cost| {
|
||||
operating_department_mappings.contains_key(&cost.department)
|
||||
|| overhead_department_mappings.contains_key(&cost.department)
|
||||
})
|
||||
.map(|cost| cost.value)
|
||||
.sum();
|
||||
let new_cost: f64 = converted_result.iter().map(|cost| cost.value).sum();
|
||||
let diff = initial_cost - new_cost;
|
||||
final_account_costs.push(AccountCost {
|
||||
account: total_costs.account,
|
||||
summed_department_costs: converted_result,
|
||||
summed_department_costs: converted_result
|
||||
.into_iter()
|
||||
.map(|cost| TotalDepartmentCost {
|
||||
department: cost.department,
|
||||
value: cost.value + cost.value / new_cost * diff,
|
||||
})
|
||||
.collect(),
|
||||
});
|
||||
}
|
||||
Ok(final_account_costs)
|
||||
|
||||
Reference in New Issue
Block a user