Search in sources :

Example 11 with OperationProductComponentHolder

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

the class ProductQuantitiesWithComponentsServiceImpl method getOperationProductComponentWithQuantities.

private Map<OperationProductComponentHolder, BigDecimal> getOperationProductComponentWithQuantities(final OperationProductComponentWithQuantityContainer productComponentWithQuantities, final Set<OperationProductComponentHolder> nonComponents, final boolean onlyComponents, final boolean onlyMaterials) {
    Map<OperationProductComponentHolder, BigDecimal> productWithQuantities = Maps.newHashMap();
    for (Map.Entry<OperationProductComponentHolder, BigDecimal> productComponentWithQuantity : productComponentWithQuantities.asMap().entrySet()) {
        OperationProductComponentHolder operationProductComponentHolder = productComponentWithQuantity.getKey();
        if (onlyComponents && nonComponents.contains(operationProductComponentHolder)) {
            continue;
        }
        if (onlyMaterials) {
            Entity product = operationProductComponentHolder.getProduct();
            if (hasAcceptedMasterTechnology(product)) {
                continue;
            }
        }
        addOPCQuantitiesToList(productComponentWithQuantity, productWithQuantities);
    }
    return productWithQuantities;
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 12 with OperationProductComponentHolder

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

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

the class TechnologyExportService method createRows.

private void createRows(final List<Entity> technologies, final String exportDate, final BufferedWriter bufferedWriter) throws IOException {
    for (Entity technology : technologies) {
        String technologyNumber = normalizeString(technology.getStringField(TechnologyFields.NUMBER));
        String technologyName = normalizeString(technology.getStringField(TechnologyFields.NAME));
        String technologyState = translationService.translate("technologies.technology.state.value." + technology.getStringField(TechnologyFields.STATE), LocaleContextHolder.getLocale());
        String isDefaultTechnology = defaultTechnologyToString(technology.getBooleanField(TechnologyFields.MASTER));
        String standardPerformance = numberService.format(technologyService.getStandardPerformance(technology).orElse(null));
        String technologyStateChange = DateFormat.getDateInstance().format(productStructureTreeService.getLastTechnologyStateChange(technology).getDateField(TechnologyStateChangeFields.DATE_AND_TIME));
        String technologyAcceptStateChange = getTechnologyAcceptStateChange(technology);
        String technologyOutdatedStateChange = getTechnologyOutdatedStateChange(technology);
        String technologyProduct = normalizeString(technology.getBelongsToField(TechnologyFields.PRODUCT).getStringField(ProductFields.NUMBER));
        Map<OperationProductComponentHolder, BigDecimal> materialQuantitiesByOPC = productQuantitiesWithComponentsService.getNeededProductQuantitiesByOPC(technology, BigDecimal.ONE, MrpAlgorithm.ONLY_MATERIALS);
        for (Map.Entry<OperationProductComponentHolder, BigDecimal> neededProductQuantity : materialQuantitiesByOPC.entrySet()) {
            Entity material = neededProductQuantity.getKey().getProduct();
            bufferedWriter.append(BACKSLASH).append(technologyNumber).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(technologyName).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(technologyState).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(isDefaultTechnology).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(standardPerformance).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(technologyStateChange).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(technologyAcceptStateChange).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(technologyOutdatedStateChange).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(technologyProduct).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(normalizeString(material.getStringField(ProductFields.NUMBER))).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(normalizeString(material.getStringField(ProductFields.NAME))).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(numberService.format(neededProductQuantity.getValue())).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(normalizeString(material.getStringField(ProductFields.UNIT))).append(BACKSLASH);
            bufferedWriter.append(exportedCsvSeparator);
            bufferedWriter.append(BACKSLASH).append(exportDate).append(BACKSLASH);
            bufferedWriter.append(NEWLINE);
        }
    }
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 14 with OperationProductComponentHolder

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

the class CostCalculationComponentsService method fillComponentsQuantity.

private void fillComponentsQuantity(List<ComponentsCalculationHolder> components, Entity technology, BigDecimal quantity) {
    Map<OperationProductComponentHolder, BigDecimal> componentQuantitiesByOPC = productQuantitiesWithComponentsService.getNeededProductQuantitiesByOPC(technology, quantity, MrpAlgorithm.ALL_PRODUCTS_IN);
    DataDefinition operationProductComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
    for (ComponentsCalculationHolder component : components) {
        for (Map.Entry<OperationProductComponentHolder, BigDecimal> cq : componentQuantitiesByOPC.entrySet()) {
            if (cq.getKey().getTechnologyOperationComponentId().equals(component.getToc().getBelongsToField(TechnologyOperationComponentFields.PARENT).getId()) && cq.getKey().getProductId().equals(component.getProduct().getId())) {
                component.setQuantity(cq.getValue());
                String technologyInputProductTypeName = "";
                Entity technologyInputProductType = operationProductComponentDD.get(cq.getKey().getOperationProductComponentId()).getBelongsToField(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
                if (technologyInputProductType != null) {
                    technologyInputProductTypeName = technologyInputProductType.getStringField(TechnologyInputProductTypeFields.NAME);
                }
                component.setTechnologyInputProductType(technologyInputProductTypeName);
                break;
            }
        }
    }
}
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) BigDecimal(java.math.BigDecimal)

Example 15 with OperationProductComponentHolder

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

the class CostCalculationMaterialsService method getSortedMaterialsFromProductQuantities.

public List<CostCalculationMaterial> getSortedMaterialsFromProductQuantities(final Entity costCalculation, final Entity technology) {
    List<CostCalculationMaterial> materialCosts = Lists.newArrayList();
    BigDecimal quantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY);
    Map<OperationProductComponentHolder, BigDecimal> materialQuantitiesByOPC = getNeededProductQuantitiesByOPC(costCalculation, technology, quantity);
    DataDefinition operationProductComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
    String technologyNumber = technology.getStringField(TechnologyFields.NUMBER);
    String finalProductNumber = technology.getBelongsToField(TechnologyFields.PRODUCT).getStringField(ProductFields.NUMBER);
    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);
            if (!operationProductComponent.getBooleanField(OperationProductInComponentFields.VARIOUS_QUANTITIES_IN_PRODUCTS_BY_SIZE)) {
                productQuantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY).multiply(productsBySize.stream().findFirst().get().getDecimalField(ProductBySizeGroupFields.QUANTITY), numberService.getMathContext());
            }
            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());
        }
        String technologyInputProductTypeName = "";
        Entity technologyInputProductType = operationProductComponent.getBelongsToField(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
        if (technologyInputProductType != null) {
            technologyInputProductTypeName = technologyInputProductType.getStringField(TechnologyInputProductTypeFields.NAME);
        }
        CostCalculationMaterial costCalculationMaterial = new CostCalculationMaterial();
        costCalculationMaterial.setTechnologyNumber(technologyNumber);
        costCalculationMaterial.setFinalProductNumber(finalProductNumber);
        costCalculationMaterial.setProductQuantity(productQuantity);
        costCalculationMaterial.setCostPerUnit(costPerUnit);
        costCalculationMaterial.setCostForGivenQuantity(costForGivenQuantity);
        costCalculationMaterial.setTechnologyInputProductType(technologyInputProductTypeName);
        costCalculationMaterial.setDifferentProductsInDifferentSizes(operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES));
        if (product != null) {
            costCalculationMaterial.setUnit(product.getStringField(ProductFields.UNIT));
            costCalculationMaterial.setProductNumber(product.getStringField(ProductFields.NUMBER));
            costCalculationMaterial.setProductName(product.getStringField(ProductFields.NAME));
        } else {
            costCalculationMaterial.setUnit(operationProductComponent.getStringField(OperationProductInComponentFields.GIVEN_UNIT));
            costCalculationMaterial.setProductNumber("");
            costCalculationMaterial.setProductName("");
        }
        if (operationProductComponent.getBooleanField(OperationProductInComponentFields.VARIOUS_QUANTITIES_IN_PRODUCTS_BY_SIZE)) {
            BigDecimal sumOfQuantity = operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().map(q -> q.getDecimalField(ProductBySizeGroupFields.QUANTITY)).reduce(BigDecimal.ZERO, BigDecimal::add);
            costForGivenQuantity = costForGivenQuantity.divide(sumOfQuantity, numberService.getMathContext());
            costCalculationMaterial.setProductQuantity(null);
            costCalculationMaterial.setCostPerUnit(costForGivenQuantity);
        }
        materialCosts.add(costCalculationMaterial);
    }
    return groupMaterialCosts(materialCosts);
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) HashMap(java.util.HashMap) ProductQuantitiesWithComponentsService(com.qcadoo.mes.technologies.ProductQuantitiesWithComponentsService) ArrayList(java.util.ArrayList) CostCalculationFields(com.qcadoo.mes.costCalculation.constants.CostCalculationFields) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) PluginManager(com.qcadoo.plugin.api.PluginManager) MrpAlgorithm(com.qcadoo.mes.technologies.constants.MrpAlgorithm) Service(org.springframework.stereotype.Service) Map(java.util.Map) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) OperationProductInComponentFields(com.qcadoo.mes.technologies.constants.OperationProductInComponentFields) CostCalculationMaterial(com.qcadoo.mes.costCalculation.print.dto.CostCalculationMaterial) OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) DataDefinition(com.qcadoo.model.api.DataDefinition) ProductBySizeGroupFields(com.qcadoo.mes.technologies.constants.ProductBySizeGroupFields) Entity(com.qcadoo.model.api.Entity) List(java.util.List) TechnologyInputProductTypeFields(com.qcadoo.mes.technologies.constants.TechnologyInputProductTypeFields) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) Comparator(java.util.Comparator) MaterialCostKey(com.qcadoo.mes.costCalculation.print.dto.MaterialCostKey) Entity(com.qcadoo.model.api.Entity) CostCalculationMaterial(com.qcadoo.mes.costCalculation.print.dto.CostCalculationMaterial) DataDefinition(com.qcadoo.model.api.DataDefinition) HashMap(java.util.HashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

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