Search in sources :

Example 6 with ComponentsCalculationHolder

use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.

the class CostCalculationComponentsService method addChildCost.

private void addChildCost(ComponentsCalculationHolder component, ComponentsCalculationHolder child, List<ComponentsCalculationHolder> allOperations, Map<Long, Entity> entitiesById, MathContext mathContext) {
    ComponentsCalculationHolder _component = component;
    if (child != null) {
        BigDecimal materialCost = BigDecimalUtils.convertNullToZero(component.getMaterialCost()).add(BigDecimalUtils.convertNullToZero(child.getMaterialCost()), mathContext);
        BigDecimal laborCost = BigDecimalUtils.convertNullToZero(component.getLaborCost()).add(BigDecimalUtils.convertNullToZero(child.getLaborCost()), mathContext);
        component.setLaborCost(numberService.setScaleWithDefaultMathContext(laborCost, 2));
        component.setMaterialCost(numberService.setScaleWithDefaultMathContext(materialCost, 2));
        _component = child;
    }
    for (Entity toc : entitiesById.get(_component.getToc().getId()).getHasManyField(TechnologyOperationComponentFields.CHILDREN)) {
        ComponentsCalculationHolder nextChild = allOperations.stream().filter(op -> op.getToc().getId().equals(toc.getId())).findFirst().orElse(null);
        addChildCost(component, nextChild, allOperations, entitiesById, mathContext);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) BigDecimal(java.math.BigDecimal)

Example 7 with ComponentsCalculationHolder

use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.

the class CostCalculationComponentsService method addMaterialCost.

private void addMaterialCost(final Entity costCalculation, final List<ComponentsCalculationHolder> allOperationComponents, final Entity technology, final BigDecimal quantity) {
    MathContext mathContext = numberService.getMathContext();
    Map<OperationProductComponentHolder, BigDecimal> materialQuantitiesByOPC = productQuantitiesWithComponentsService.getNeededProductQuantitiesByOPC(technology, quantity, MrpAlgorithm.ONLY_MATERIALS);
    DataDefinition operationProductComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
    for (Map.Entry<OperationProductComponentHolder, BigDecimal> neededProductQuantity : materialQuantitiesByOPC.entrySet()) {
        Entity product = neededProductQuantity.getKey().getProduct();
        Entity operationProductComponent = operationProductComponentDD.get(neededProductQuantity.getKey().getOperationProductComponentId());
        BigDecimal costPerUnit = productsCostCalculationService.calculateOperationProductCostPerUnit(costCalculation, product, operationProductComponent);
        BigDecimal productQuantity = neededProductQuantity.getValue();
        BigDecimal costForGivenQuantity = costPerUnit.multiply(BigDecimalUtils.convertNullToZero(productQuantity), numberService.getMathContext());
        if (operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES)) {
            List<Entity> productsBySize = operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS);
            BigDecimal sumOfCosts = BigDecimal.ZERO;
            for (Entity pbs : productsBySize) {
                Entity p = pbs.getBelongsToField(ProductBySizeGroupFields.PRODUCT);
                BigDecimal costPerUnitPBS = productsCostCalculationService.calculateProductCostPerUnit(p, costCalculation.getStringField(CostCalculationFields.MATERIAL_COSTS_USED), costCalculation.getBooleanField(CostCalculationFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED));
                BigDecimal q = costCalculation.getDecimalField(CostCalculationFields.QUANTITY).multiply(pbs.getDecimalField(ProductBySizeGroupFields.QUANTITY), numberService.getMathContext());
                BigDecimal costPBS = numberService.setScaleWithDefaultMathContext(costPerUnitPBS.multiply(q));
                sumOfCosts = sumOfCosts.add(costPBS, numberService.getMathContext());
            }
            costForGivenQuantity = sumOfCosts.divide(new BigDecimal(productsBySize.size()), numberService.getMathContext());
        }
        ComponentsCalculationHolder cc = allOperationComponents.stream().filter(bc -> bc.getToc().getId().equals(neededProductQuantity.getKey().getTechnologyOperationComponentId())).findFirst().orElse(null);
        if (Objects.nonNull(cc)) {
            BigDecimal materialCost = BigDecimalUtils.convertNullToZero(cc.getMaterialCost()).add(BigDecimalUtils.convertNullToZero(costForGivenQuantity), mathContext);
            cc.setMaterialCost(numberService.setScaleWithDefaultMathContext(materialCost, 2));
        }
    }
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) DataDefinition(com.qcadoo.model.api.DataDefinition) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MathContext(java.math.MathContext) BigDecimal(java.math.BigDecimal)

Example 8 with ComponentsCalculationHolder

use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder 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)

Example 9 with ComponentsCalculationHolder

use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.

the class CostCalculationComponentsService method addLaborCost.

private void addLaborCost(final Entity costCalculation, List<ComponentsCalculationHolder> allOperationComponents, List<Entity> calculationOperationComponents) {
    if (!SourceOfOperationCosts.STANDARD_LABOR_COSTS.equals(SourceOfOperationCosts.parseString(costCalculation.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS)))) {
        for (Entity calculationOperationComponent : calculationOperationComponents) {
            BigDecimal totalMachineOperationCost = calculationOperationComponent.getDecimalField(CalculationOperationComponentFields.TOTAL_MACHINE_OPERATION_COST);
            BigDecimal totalLaborOperationCost = calculationOperationComponent.getDecimalField(CalculationOperationComponentFields.TOTAL_LABOR_OPERATION_COST);
            ComponentsCalculationHolder holder = allOperationComponents.stream().filter(bc -> bc.getToc().getId().equals(calculationOperationComponent.getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT).getId())).findFirst().orElse(null);
            if (Objects.nonNull(holder)) {
                BigDecimal cost = BigDecimalUtils.convertNullToZero(totalMachineOperationCost).add(BigDecimalUtils.convertNullToZero(totalLaborOperationCost), numberService.getMathContext());
                holder.setLaborCost(numberService.setScaleWithDefaultMathContext(cost, 2));
            }
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) BigDecimal(java.math.BigDecimal)

Example 10 with ComponentsCalculationHolder

use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.

the class CostCalculationComponentsService method fillComponentsCosts.

private void fillComponentsCosts(final EntityTree operationComponents, final List<ComponentsCalculationHolder> components, final List<ComponentsCalculationHolder> allOperationComponents, final BigDecimal quantity) {
    Map<Long, Entity> entitiesById = new LinkedHashMap<>();
    for (Entity entity : operationComponents) {
        entitiesById.put(entity.getId(), entity);
    }
    for (ComponentsCalculationHolder component : components) {
        ComponentsCalculationHolder holder = allOperationComponents.stream().filter(op -> op.getToc().getId().equals(component.getToc().getId())).findFirst().get();
        component.setMaterialCost(holder.getMaterialCost());
        component.setLaborCost(holder.getLaborCost());
        addChildCost(component, null, allOperationComponents, entitiesById, numberService.getMathContext());
        BigDecimal sumOfCost = BigDecimalUtils.convertNullToZero(component.getLaborCost()).add(BigDecimalUtils.convertNullToZero(component.getMaterialCost()), numberService.getMathContext());
        BigDecimal costPerUnit = sumOfCost.divide(quantity, numberService.getMathContext());
        component.setSumOfCost(numberService.setScaleWithDefaultMathContext(sumOfCost, 2));
        component.setCostPerUnit(numberService.setScaleWithDefaultMathContext(costPerUnit, 2));
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ComponentsCalculationHolder (com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder)10 Entity (com.qcadoo.model.api.Entity)8 BigDecimal (java.math.BigDecimal)7 LinkedHashMap (java.util.LinkedHashMap)5 DataDefinition (com.qcadoo.model.api.DataDefinition)4 HashMap (java.util.HashMap)4 OperationProductComponentHolder (com.qcadoo.mes.technologies.dto.OperationProductComponentHolder)3 Map (java.util.Map)3 ComponentCostKey (com.qcadoo.mes.costCalculation.print.dto.ComponentCostKey)2 MathContext (java.math.MathContext)2 CostCalculationFields (com.qcadoo.mes.costCalculation.constants.CostCalculationFields)1 SourceOfOperationCosts (com.qcadoo.mes.costCalculation.constants.SourceOfOperationCosts)1 CostCalculationMaterial (com.qcadoo.mes.costCalculation.print.dto.CostCalculationMaterial)1 CalculationOperationComponentFields (com.qcadoo.mes.costNormsForOperation.constants.CalculationOperationComponentFields)1 ProductQuantitiesWithComponentsService (com.qcadoo.mes.technologies.ProductQuantitiesWithComponentsService)1 MrpAlgorithm (com.qcadoo.mes.technologies.constants.MrpAlgorithm)1 OperationProductInComponentFields (com.qcadoo.mes.technologies.constants.OperationProductInComponentFields)1 ProductBySizeGroupFields (com.qcadoo.mes.technologies.constants.ProductBySizeGroupFields)1 TechnologiesConstants (com.qcadoo.mes.technologies.constants.TechnologiesConstants)1 TechnologyInputProductTypeFields (com.qcadoo.mes.technologies.constants.TechnologyInputProductTypeFields)1