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;
}
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);
}
}
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);
}
}
}
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;
}
}
}
}
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);
}
Aggregations