Search in sources :

Example 11 with OperationProductComponentWithQuantityContainer

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

the class MrpAlgorithmStrategyTS method perform.

public Map<Long, BigDecimal> perform(final OperationProductComponentWithQuantityContainer productComponentWithQuantities, final Set<OperationProductComponentHolder> nonComponents, final MrpAlgorithm mrpAlgorithm, final String operationProductComponentModelName) {
    OperationProductComponentWithQuantityContainer allWithSameEntityType = productComponentWithQuantities.getAllWithSameEntityType(operationProductComponentModelName);
    Map<Long, BigDecimal> productWithQuantities = Maps.newHashMap();
    for (Entry<OperationProductComponentHolder, BigDecimal> productComponentWithQuantity : allWithSameEntityType.asMap().entrySet()) {
        OperationProductComponentHolder operationProductComponentHolder = productComponentWithQuantity.getKey();
        if (nonComponents.contains(operationProductComponentHolder)) {
            Entity product = operationProductComponentHolder.getProduct();
            Entity technologyOperationComponent = operationProductComponentHolder.getTechnologyOperationComponent();
            if (technologyOperationComponent != null) {
                List<Entity> children = technologyOperationComponent.getHasManyField(CHILDREN).find().add(SearchRestrictions.eq(TechnologyOperationComponentFieldsTS.IS_SUBCONTRACTING, true)).list().getEntities();
                boolean isSubcontracting = false;
                for (Entity child : children) {
                    Entity operationProductOutComponent = child.getHasManyField(OPERATION_PRODUCT_OUT_COMPONENTS).find().add(SearchRestrictions.belongsTo(PRODUCT, product)).setMaxResults(1).uniqueResult();
                    if (operationProductOutComponent != null) {
                        isSubcontracting = true;
                    }
                }
                if (!isSubcontracting) {
                    continue;
                }
            }
        }
        productQuantitiesService.addProductQuantitiesToList(productComponentWithQuantity, productWithQuantities);
    }
    return productWithQuantities;
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal)

Example 12 with OperationProductComponentWithQuantityContainer

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

the class ProductQuantitiesWithComponentsServiceImpl method getProductComponentQuantities.

@Override
public ProductQuantitiesHolder getProductComponentQuantities(final Entity technology, final BigDecimal givenQuantity) {
    Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
    OperationProductComponentWithQuantityContainer productQuantities = getProductComponentWithQuantitiesForTechnology(technology, givenQuantity, operationRuns, nonComponents);
    return new ProductQuantitiesHolder(productQuantities, operationRuns);
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) ProductQuantitiesHolder(com.qcadoo.mes.technologies.dto.ProductQuantitiesHolder) BigDecimal(java.math.BigDecimal)

Example 13 with OperationProductComponentWithQuantityContainer

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

the class ProductQuantitiesWithComponentsServiceImpl method getNeededProductQuantitiesByOPC.

@Override
public Map<OperationProductComponentHolder, BigDecimal> getNeededProductQuantitiesByOPC(Entity technology, BigDecimal givenQuantity, MrpAlgorithm mrpAlgorithm) {
    Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
    Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
    OperationProductComponentWithQuantityContainer productComponentWithQuantities = getProductComponentWithQuantitiesForTechnology(technology, givenQuantity, operationRuns, nonComponents);
    OperationProductComponentWithQuantityContainer allWithSameEntityType = productComponentWithQuantities.getAllWithSameEntityType(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
    if (mrpAlgorithm.equals(MrpAlgorithm.ALL_PRODUCTS_IN)) {
        return getOperationProductComponentWithQuantities(allWithSameEntityType, nonComponents, false, false);
    } else if (mrpAlgorithm.equals(MrpAlgorithm.ONLY_COMPONENTS)) {
        return getOperationProductComponentWithQuantities(allWithSameEntityType, nonComponents, true, false);
    } else if (mrpAlgorithm.equals(MrpAlgorithm.COMPONENTS_AND_SUBCONTRACTORS_PRODUCTS)) {
        return getOperationProductComponentWithQuantities(allWithSameEntityType, nonComponents, false, false);
    } else {
        return getOperationProductComponentWithQuantities(allWithSameEntityType, nonComponents, true, true);
    }
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal)

Example 14 with OperationProductComponentWithQuantityContainer

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

the class ProductQuantitiesServiceImplTest method shouldNotRoundToTheIntegerOperationRunsIfOperationComponentHasDivisableProductQuantities.

@Test
public void shouldNotRoundToTheIntegerOperationRunsIfOperationComponentHasDivisableProductQuantities() {
    // given
    when(operationComponent1.getBooleanField("areProductQuantitiesDivisible")).thenReturn(true);
    when(operationComponent2.getBooleanField("areProductQuantitiesDivisible")).thenReturn(true);
    // when
    OperationProductComponentWithQuantityContainer productQuantities = productQuantitiesService.getProductComponentQuantities(order);
    // then
    assertEquals(0, new BigDecimal(45).compareTo(productQuantities.get(productInComponent1)));
    assertEquals(0, new BigDecimal(9).compareTo(productQuantities.get(productInComponent2)));
    assertEquals(0, new BigDecimal(4.5).compareTo(productQuantities.get(productInComponent3)));
    assertEquals(0, new BigDecimal(9).compareTo(productQuantities.get(productOutComponent2)));
    assertEquals(0, new BigDecimal(4.5).compareTo(productQuantities.get(productOutComponent4)));
}
Also used : OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 15 with OperationProductComponentWithQuantityContainer

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

the class WorkPlansColumnFillerTest method shouldReturnCorrectColumnValuesForProducts.

@Test
public void shouldReturnCorrectColumnValuesForProducts() {
    // given
    EntityTree operComps = mockEntityTree(asList(operationComponent));
    EntityTree operComps2 = mockEntityTree(asList(operationComponent));
    given(technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)).willReturn(operComps, operComps2);
    given(operationComponent.getId()).willReturn(1L);
    EntityList prodInComps = mockEntityList(asList(operationProductComponent));
    EntityList prodInComps2 = mockEntityList(asList(operationProductComponent));
    given(operationProductComponent.getBelongsToField("operationComponent")).willReturn(operationComponent);
    given(operationProductComponent.getBelongsToField(L_PRODUCT)).willReturn(product);
    given(operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)).willReturn(prodInComps, prodInComps2);
    EntityList prodOutComps = mockEntityList(new ArrayList<Entity>());
    given(operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS)).willReturn(prodOutComps);
    given(operationProductComponent.getDataDefinition()).willReturn(operationProductComponentDD);
    given(operationProductComponentDD.getName()).willReturn(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
    OperationProductComponentWithQuantityContainer quantities = new OperationProductComponentWithQuantityContainer();
    quantities.put(operationProductComponent, new BigDecimal(11));
    given(productQuantitiesService.getProductComponentQuantities(order)).willReturn(quantities);
    // when
    Map<Entity, Map<String, String>> columnValues = workPlansColumnFiller.getValues(asList(order));
    // then
    assertEquals(1, columnValues.size());
    assertEquals("product (123)", columnValues.get(operationProductComponent).get(L_PRODUCT_NAME));
    assertEquals("11.00000 abc", columnValues.get(operationProductComponent).get(L_PLANNED_QUANTITY));
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) EntityList(com.qcadoo.model.api.EntityList) EntityTree(com.qcadoo.model.api.EntityTree) Map(java.util.Map) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

OperationProductComponentWithQuantityContainer (com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer)31 BigDecimal (java.math.BigDecimal)26 Entity (com.qcadoo.model.api.Entity)18 OperationProductComponentHolder (com.qcadoo.mes.technologies.dto.OperationProductComponentHolder)16 EntityTree (com.qcadoo.model.api.EntityTree)5 ProductQuantitiesHolder (com.qcadoo.mes.technologies.dto.ProductQuantitiesHolder)4 Lists (com.google.common.collect.Lists)3 Maps (com.google.common.collect.Maps)3 Sets (com.google.common.collect.Sets)3 DataDefinition (com.qcadoo.model.api.DataDefinition)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 Test (org.junit.Test)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 Transactional (org.springframework.transaction.annotation.Transactional)3 com.qcadoo.mes.basic.constants (com.qcadoo.mes.basic.constants)2 com.qcadoo.mes.technologies.constants (com.qcadoo.mes.technologies.constants)2 OperationProductComponentEntityType (com.qcadoo.mes.technologies.dto.OperationProductComponentEntityType)2 OperationProductComponentMessage (com.qcadoo.mes.technologies.dto.OperationProductComponentMessage)2