Search in sources :

Example 1 with ComponentCostKey

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

Aggregations

ComponentCostKey (com.qcadoo.mes.costCalculation.print.dto.ComponentCostKey)1 ComponentsCalculationHolder (com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1