use of com.qcadoo.mes.costCalculation.print.dto.MaterialCostKey in project mes by qcadoo.
the class CostCalculationMaterialsService method groupMaterialCosts.
private List<CostCalculationMaterial> groupMaterialCosts(List<CostCalculationMaterial> materialCosts) {
List<CostCalculationMaterial> groupedMaterialCostsList = new ArrayList<>();
Map<MaterialCostKey, CostCalculationMaterial> groupedMaterialCosts = new HashMap<>();
for (CostCalculationMaterial costCalculationMaterial : materialCosts) {
if (costCalculationMaterial.isDifferentProductsInDifferentSizes()) {
groupedMaterialCostsList.add(costCalculationMaterial);
} else {
MaterialCostKey materialCostKey = new MaterialCostKey(costCalculationMaterial.getProductNumber(), costCalculationMaterial.getProductName(), costCalculationMaterial.getUnit(), costCalculationMaterial.getTechnologyInputProductType());
if (groupedMaterialCosts.containsKey(materialCostKey)) {
CostCalculationMaterial groupedMaterialCost = groupedMaterialCosts.get(materialCostKey);
groupedMaterialCost.setProductQuantity(groupedMaterialCost.getProductQuantity().add(costCalculationMaterial.getProductQuantity(), numberService.getMathContext()));
groupedMaterialCost.setCostForGivenQuantity(groupedMaterialCost.getCostForGivenQuantity().add(costCalculationMaterial.getCostForGivenQuantity(), numberService.getMathContext()));
groupedMaterialCosts.put(materialCostKey, groupedMaterialCost);
} else {
groupedMaterialCosts.put(materialCostKey, costCalculationMaterial);
}
}
}
groupedMaterialCostsList.addAll(groupedMaterialCosts.values());
groupedMaterialCostsList.sort(Comparator.comparing(CostCalculationMaterial::getCostForGivenQuantity));
return groupedMaterialCostsList;
}
Aggregations