use of com.qcadoo.mes.costCalculation.print.dto.ComponentCostKey in project mes by qcadoo.
the class CostCalculationComponentsService method groupComponentCosts.
private Collection<ComponentsCalculationHolder> groupComponentCosts(List<ComponentsCalculationHolder> components) {
Map<ComponentCostKey, ComponentsCalculationHolder> groupedComponentCosts = new HashMap<>();
for (ComponentsCalculationHolder componentsCalculationHolder : components) {
ComponentCostKey componentCostKey = new ComponentCostKey(componentsCalculationHolder.getProduct().getId(), componentsCalculationHolder.getTechnologyInputProductType());
if (groupedComponentCosts.containsKey(componentCostKey)) {
ComponentsCalculationHolder groupedComponentCost = groupedComponentCosts.get(componentCostKey);
groupedComponentCost.setMaterialCost(groupedComponentCost.getMaterialCost().add(componentsCalculationHolder.getMaterialCost(), numberService.getMathContext()));
if (!Objects.isNull(groupedComponentCost.getLaborCost())) {
groupedComponentCost.setLaborCost(groupedComponentCost.getLaborCost().add(componentsCalculationHolder.getLaborCost(), numberService.getMathContext()));
}
groupedComponentCost.setSumOfCost(groupedComponentCost.getSumOfCost().add(componentsCalculationHolder.getSumOfCost(), numberService.getMathContext()));
groupedComponentCost.setQuantity(groupedComponentCost.getQuantity().add(componentsCalculationHolder.getQuantity(), numberService.getMathContext()));
groupedComponentCost.setCostPerUnit(groupedComponentCost.getCostPerUnit().add(componentsCalculationHolder.getCostPerUnit(), numberService.getMathContext()));
groupedComponentCosts.put(componentCostKey, groupedComponentCost);
} else {
groupedComponentCosts.put(componentCostKey, componentsCalculationHolder);
}
}
return groupedComponentCosts.values();
}
Aggregations