Search in sources :

Example 1 with MaterialCostKey

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;
}
Also used : HashMap(java.util.HashMap) CostCalculationMaterial(com.qcadoo.mes.costCalculation.print.dto.CostCalculationMaterial) ArrayList(java.util.ArrayList) MaterialCostKey(com.qcadoo.mes.costCalculation.print.dto.MaterialCostKey)

Aggregations

CostCalculationMaterial (com.qcadoo.mes.costCalculation.print.dto.CostCalculationMaterial)1 MaterialCostKey (com.qcadoo.mes.costCalculation.print.dto.MaterialCostKey)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1