Search in sources :

Example 31 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class ProductQuantitiesServiceImpl method getNeededProductQuantities.

@Override
public Map<Long, BigDecimal> getNeededProductQuantities(final Entity technology, final BigDecimal givenQuantity, final MrpAlgorithm mrpAlgorithm) {
    Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
    OperationProductComponentWithQuantityContainer productComponentWithQuantities = getProductComponentWithQuantitiesForTechnology(technology, null, givenQuantity, operationRuns, nonComponents);
    return getProductWithQuantities(productComponentWithQuantities, nonComponents, mrpAlgorithm, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal)

Example 32 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder 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 33 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class MasterOrdersMaterialRequirementHelper method createMasterOrdersMaterialRequirementProducts.

private void createMasterOrdersMaterialRequirementProducts(final List<Entity> masterOrdersMaterialRequirementProducts, final List<Entity> masterOrders) {
    for (Entity masterOrder : masterOrders) {
        List<Entity> masterOrderProducts = masterOrder.getHasManyField(MasterOrderFields.MASTER_ORDER_PRODUCTS);
        for (Entity masterOrderProduct : masterOrderProducts) {
            Entity masterOrderProductTechnology = masterOrderProduct.getBelongsToField(MasterOrderProductFields.TECHNOLOGY);
            Entity masterOrderProductProduct = masterOrderProduct.getBelongsToField(MasterOrderProductFields.PRODUCT);
            BigDecimal masterOrderQuantity = masterOrderProduct.getDecimalField(MasterOrderProductFields.MASTER_ORDER_QUANTITY);
            Entity technology = getTechnology(masterOrderProductTechnology, masterOrderProductProduct);
            if (Objects.nonNull(technology)) {
                Map<OperationProductComponentHolder, BigDecimal> neededQuantities = productQuantitiesService.getNeededProductQuantities(technology, masterOrderProductProduct, masterOrderQuantity);
                for (Map.Entry<OperationProductComponentHolder, BigDecimal> neededProductQuantity : neededQuantities.entrySet()) {
                    Entity product = neededProductQuantity.getKey().getProduct();
                    Entity technologyInputProductType = neededProductQuantity.getKey().getTechnologyInputProductType();
                    BigDecimal neededQuantity = neededProductQuantity.getValue();
                    createMasterOrdersMaterialRequirementProduct(masterOrdersMaterialRequirementProducts, product, technologyInputProductType, neededQuantity);
                }
            }
        }
    }
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 34 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class SalesPlanMaterialRequirementHelper method createSalesPlanMaterialRequirementProducts.

private void createSalesPlanMaterialRequirementProducts(final List<Entity> salesPlanMaterialRequirementProducts, final Entity salesPlan) {
    List<Entity> salesPlanProducts = salesPlan.getHasManyField(SalesPlanFields.PRODUCTS);
    for (Entity salesPlanProduct : salesPlanProducts) {
        Entity salesPlanProductTechnology = salesPlanProduct.getBelongsToField(SalesPlanProductFields.TECHNOLOGY);
        Entity salesPlanProductProduct = salesPlanProduct.getBelongsToField(SalesPlanProductFields.PRODUCT);
        BigDecimal plannedQuantity = salesPlanProduct.getDecimalField(SalesPlanProductFields.PLANNED_QUANTITY);
        Entity technology = getTechnology(salesPlanProductTechnology, salesPlanProductProduct);
        if (Objects.nonNull(technology)) {
            Map<OperationProductComponentHolder, BigDecimal> neededQuantities = productQuantitiesService.getNeededProductQuantities(technology, salesPlanProductProduct, plannedQuantity);
            for (Map.Entry<OperationProductComponentHolder, BigDecimal> neededProductQuantity : neededQuantities.entrySet()) {
                Long productId = neededProductQuantity.getKey().getProductId();
                Long operationProductComponentId = neededProductQuantity.getKey().getOperationProductComponentId();
                Entity product = neededProductQuantity.getKey().getProduct();
                BigDecimal neededQuantity = neededProductQuantity.getValue();
                if (Objects.isNull(productId)) {
                    List<Entity> productBySizeGroups = technologyService.getProductBySizeGroups(operationProductComponentId);
                    for (Entity productBySizeGroup : productBySizeGroups) {
                        createSalesPlanMaterialRequirementProductFromProductBySizeGroup(salesPlanMaterialRequirementProducts, productBySizeGroup, plannedQuantity);
                    }
                } else {
                    createSalesPlanMaterialRequirementProductFromProduct(salesPlanMaterialRequirementProducts, product, neededQuantity);
                }
            }
        }
    }
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 35 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class MrpAlgorithmStrategyTSTest method init.

@Before
public void init() {
    algorithmStrategyTS = new MrpAlgorithmStrategyTS();
    MockitoAnnotations.initMocks(this);
    ReflectionTestUtils.setField(algorithmStrategyTS, "productQuantitiesService", productQuantitiesService);
    EntityList opComp1InComp = mockEntityListIterator(asList(productInComponent1, productInComponent3));
    EntityList opComp1OutComp = mockEntityListIterator(asList(productOutComponent2));
    EntityList opComp2InComp = mockEntityListIterator(asList(productInComponent2));
    EntityList opComp2OutComp = mockEntityListIterator(asList(productOutComponent4));
    when(operComp1.getHasManyField("operationProductInComponents")).thenReturn(opComp1InComp);
    when(operComp1.getHasManyField("operationProductOutComponents")).thenReturn(opComp1OutComp);
    when(operComp2.getHasManyField("operationProductInComponents")).thenReturn(opComp2InComp);
    when(operComp2.getHasManyField("operationProductOutComponents")).thenReturn(opComp2OutComp);
    when(productInComponent1.getField("quantity")).thenReturn(new BigDecimal(5));
    when(productInComponent3.getField("quantity")).thenReturn(BigDecimal.ONE);
    when(productOutComponent2.getField("quantity")).thenReturn(BigDecimal.ONE);
    when(productInComponent2.getField("quantity")).thenReturn(new BigDecimal(2));
    when(productOutComponent4.getField("quantity")).thenReturn(BigDecimal.ONE);
    productComponentQuantities = new OperationProductComponentWithQuantityContainer();
    nonComponents = Sets.newHashSet();
    productComponentQuantities.put(productInComponent1, new BigDecimal(5));
    productComponentQuantities.put(productInComponent3, BigDecimal.ONE);
    productComponentQuantities.put(productOutComponent2, BigDecimal.ONE);
    productComponentQuantities.put(productOutComponent4, BigDecimal.ONE);
    productComponentQuantities.put(productInComponent2, new BigDecimal(2));
    nonComponents.add(new OperationProductComponentHolder(productInComponent2));
    when(product1.getId()).thenReturn(1L);
    when(product2.getId()).thenReturn(2L);
    when(product3.getId()).thenReturn(3L);
    when(product4.getId()).thenReturn(4L);
    when(productInComponent1.getBelongsToField("product")).thenReturn(product1);
    when(productInComponent2.getBelongsToField("product")).thenReturn(product2);
    when(productInComponent3.getBelongsToField("product")).thenReturn(product3);
    when(productOutComponent2.getBelongsToField("product")).thenReturn(product2);
    when(productOutComponent4.getBelongsToField("product")).thenReturn(product4);
    when(productInComponent1.getBelongsToField("operationComponent")).thenReturn(operComp1);
    when(productInComponent3.getBelongsToField("operationComponent")).thenReturn(operComp1);
    when(productOutComponent2.getBelongsToField("operationComponent")).thenReturn(operComp1);
    when(productInComponent2.getBelongsToField("operationComponent")).thenReturn(operComp2);
    when(productOutComponent4.getBelongsToField("operationComponent")).thenReturn(operComp2);
    when(ddIn.getName()).thenReturn("productInComponent");
    when(ddOut.getName()).thenReturn("productOutComponent");
    when(productInComponent1.getDataDefinition()).thenReturn(ddIn);
    when(productInComponent2.getDataDefinition()).thenReturn(ddIn);
    when(productInComponent3.getDataDefinition()).thenReturn(ddIn);
    when(productOutComponent2.getDataDefinition()).thenReturn(ddOut);
    when(productOutComponent4.getDataDefinition()).thenReturn(ddOut);
    when(ddIn.getName()).thenReturn("operationProductInComponent");
    when(ddOut.getName()).thenReturn("operationProductOutComponent");
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) EntityList(com.qcadoo.model.api.EntityList) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Aggregations

OperationProductComponentHolder (com.qcadoo.mes.technologies.dto.OperationProductComponentHolder)35 BigDecimal (java.math.BigDecimal)31 Entity (com.qcadoo.model.api.Entity)23 OperationProductComponentWithQuantityContainer (com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer)14 Map (java.util.Map)11 DataDefinition (com.qcadoo.model.api.DataDefinition)4 List (java.util.List)4 Lists (com.google.common.collect.Lists)3 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 OperationProductInComponentFields (com.qcadoo.mes.technologies.constants.OperationProductInComponentFields)2 ProductBySizeGroupFields (com.qcadoo.mes.technologies.constants.ProductBySizeGroupFields)2 TechnologiesConstants (com.qcadoo.mes.technologies.constants.TechnologiesConstants)2