use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.
the class ModelCardPdfService method mapToModelCardMaterialEntry.
private void mapToModelCardMaterialEntry(Entity modelCard, Map<Long, Map<Long, BigDecimal>> quantitiesInStock, List<ModelCardMaterialEntry> entries, Map.Entry<OperationProductComponentHolder, BigDecimal> neededProductQuantity, boolean forFamily, BigDecimal quantity, Locale locale) {
ModelCardMaterialEntry modelCardMaterialEntry = new ModelCardMaterialEntry();
Entity material = neededProductQuantity.getKey().getProduct();
Entity operationProductComponent = neededProductQuantity.getKey().getOperationProductComponent();
Entity technologyOperationComponent = neededProductQuantity.getKey().getTechnologyOperationComponent();
Entity warehouse = operationProductComponent.getBelongsToField(OperationProductInComponentFieldsPFTD.COMPONENTS_LOCATION);
Entity technologyInputProductType = operationProductComponent.getBelongsToField(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
modelCardMaterialEntry.setNodeNumber(technologyOperationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
modelCardMaterialEntry.setPriority(operationProductComponent.getIntegerField(OperationProductInComponentFields.PRIORITY));
if (Objects.nonNull(technologyInputProductType)) {
modelCardMaterialEntry.setTechnologyInputProductTypeId(technologyInputProductType.getId());
modelCardMaterialEntry.setTechnologyInputProductTypeName(technologyInputProductType.getStringField(TechnologyInputProductTypeFields.NAME));
}
modelCardMaterialEntry.setDescription(operationProductComponent.getStringField(OperationProductInComponentFields.DESCRIPTION));
if (forFamily && operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES) && !operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).isEmpty()) {
modelCardMaterialEntry.setNumber(translationService.translate("productFlowThruDivision.modelCard.report.productsBySize.label", locale));
List<Entity> productBySizeGroups = getProductBySizeGroups(operationProductComponent.getId());
for (Entity productBySizeGroup : productBySizeGroups) {
ModelCardMaterialEntry modelCardMaterialBySizeEntry = new ModelCardMaterialEntry();
Entity materialBySizeGroup = productBySizeGroup.getBelongsToField(ProductBySizeGroupFields.PRODUCT);
Entity sizeGroup = productBySizeGroup.getBelongsToField(ProductBySizeGroupFields.SIZE_GROUP);
modelCardMaterialBySizeEntry.setId(materialBySizeGroup.getId());
modelCardMaterialBySizeEntry.setNumber(materialBySizeGroup.getStringField(ProductFields.NUMBER));
modelCardMaterialBySizeEntry.setName(materialBySizeGroup.getStringField(ProductFields.NAME));
modelCardMaterialBySizeEntry.setUnit(materialBySizeGroup.getStringField(ProductFields.UNIT));
modelCardMaterialBySizeEntry.setWarehouseId(warehouse.getId());
modelCardMaterialBySizeEntry.setCurrentStock(BigDecimalUtils.convertNullToZero(quantitiesInStock.get(warehouse.getId()).get(materialBySizeGroup.getId())));
modelCardMaterialBySizeEntry.setNodeNumber(technologyOperationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
modelCardMaterialBySizeEntry.setPriority(operationProductComponent.getIntegerField(OperationProductInComponentFields.PRIORITY));
if (Objects.nonNull(technologyInputProductType)) {
modelCardMaterialBySizeEntry.setTechnologyInputProductTypeId(technologyInputProductType.getId());
}
Entity parent = materialBySizeGroup.getBelongsToField(ProductFields.PARENT);
if (!Objects.isNull(parent)) {
modelCardMaterialBySizeEntry.setParentId(parent.getId());
}
modelCardMaterialBySizeEntry.setSizeGroupId(sizeGroup.getId());
modelCardMaterialBySizeEntry.setSizeGroupNumber(sizeGroup.getStringField(SizeGroupFields.NUMBER));
BigDecimal norm = productBySizeGroup.getDecimalField(ProductBySizeGroupFields.QUANTITY);
modelCardMaterialBySizeEntry.setNorm(norm);
modelCardMaterialBySizeEntry.setNeededQuantity(numberService.setScaleWithDefaultMathContext(quantity.multiply(productBySizeGroup.getDecimalField(ProductBySizeGroupFields.QUANTITY), numberService.getMathContext())));
BigDecimal price = numberService.setScaleWithDefaultMathContext(productsCostCalculationService.calculateProductCostPerUnit(materialBySizeGroup, modelCard.getStringField(ModelCardFields.MATERIAL_COSTS_USED), modelCard.getBooleanField(ModelCardFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED)), 2);
modelCardMaterialBySizeEntry.setPrice(price);
modelCardMaterialBySizeEntry.setMaterialUnitCost(numberService.setScaleWithDefaultMathContext(norm.multiply(price, numberService.getMathContext()), 2));
entries.add(modelCardMaterialBySizeEntry);
}
} else if (material == null) {
BigDecimal norm = operationProductComponent.getDecimalField(OperationProductInComponentFields.QUANTITY);
modelCardMaterialEntry.setNorm(norm);
modelCardMaterialEntry.setNeededQuantity(numberService.setScaleWithDefaultMathContext(neededProductQuantity.getValue(), 2));
BigDecimal price = BigDecimalUtils.convertNullToZero(technologyInputProductType.getDecimalField(TechnologyInputProductTypeFields.AVERAGE_PRICE));
modelCardMaterialEntry.setPrice(price);
modelCardMaterialEntry.setMaterialUnitCost(numberService.setScaleWithDefaultMathContext(norm.multiply(price, numberService.getMathContext()), 2));
modelCardMaterialEntry.setUnit(operationProductComponent.getStringField(OperationProductInComponentFields.GIVEN_UNIT));
} else {
BigDecimal norm = operationProductComponent.getDecimalField(OperationProductInComponentFields.QUANTITY);
if (operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES)) {
Entity pbs = operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().filter(prbs -> prbs.getBelongsToField(ProductBySizeGroupFields.PRODUCT).getId().equals(material.getId())).findFirst().orElse(null);
if (Objects.nonNull(pbs)) {
norm = pbs.getDecimalField(ProductBySizeGroupFields.QUANTITY);
}
}
modelCardMaterialEntry.setNorm(norm);
modelCardMaterialEntry.setNeededQuantity(numberService.setScaleWithDefaultMathContext(neededProductQuantity.getValue(), 2));
modelCardMaterialEntry.setId(material.getId());
modelCardMaterialEntry.setNumber(material.getStringField(ProductFields.NUMBER));
modelCardMaterialEntry.setName(material.getStringField(ProductFields.NAME));
modelCardMaterialEntry.setUnit(material.getStringField(ProductFields.UNIT));
modelCardMaterialEntry.setWarehouseId(warehouse.getId());
modelCardMaterialEntry.setCurrentStock(BigDecimalUtils.convertNullToZero(quantitiesInStock.get(warehouse.getId()).get(material.getId())));
Entity parent = material.getBelongsToField(ProductFields.PARENT);
if (!Objects.isNull(parent)) {
modelCardMaterialEntry.setParentId(parent.getId());
}
BigDecimal price = numberService.setScaleWithDefaultMathContext(productsCostCalculationService.calculateProductCostPerUnit(material, modelCard.getStringField(ModelCardFields.MATERIAL_COSTS_USED), modelCard.getBooleanField(ModelCardFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED)), 2);
modelCardMaterialEntry.setPrice(price);
modelCardMaterialEntry.setMaterialUnitCost(numberService.setScaleWithDefaultMathContext(norm.multiply(price, numberService.getMathContext()), 2));
}
entries.add(modelCardMaterialEntry);
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.
the class OperationProductsExtractor method getOperationProductComponents.
private List<Entity> getOperationProductComponents(final Entity order, final Entity technologyOperationComponent) {
List<Entity> trackingOperationProductComponents = Lists.newArrayList();
Map<OperationProductComponentEntityType, Set<Entity>> entityTypeWithAlreadyAddedProducts = Maps.newHashMap();
String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
OperationProductComponentWithQuantityContainer productComponentQuantities = productQuantitiesService.getProductComponentQuantities(order);
for (Entry<OperationProductComponentHolder, BigDecimal> productComponentQuantity : productComponentQuantities.asMap().entrySet()) {
OperationProductComponentHolder operationProductComponentHolder = productComponentQuantity.getKey();
if (forEach(typeOfProductionRecording)) {
Entity operationComponent = operationProductComponentHolder.getTechnologyOperationComponent();
if (technologyOperationComponent == null) {
if (operationComponent != null) {
continue;
}
} else {
if ((operationComponent == null) || !technologyOperationComponent.getId().equals(operationComponent.getId())) {
continue;
}
}
} else if (cumulated(typeOfProductionRecording)) {
OperationProductComponentEntityType entityType = operationProductComponentHolder.getEntityType();
Entity product = operationProductComponentHolder.getProduct();
if ((product != null) && (entityType != null)) {
if (shouldSkipAddingProduct(operationProductComponentHolder, entityTypeWithAlreadyAddedProducts, typeOfProductionRecording)) {
if (entityTypeWithAlreadyAddedProducts.containsKey(entityType)) {
continue;
} else {
entityTypeWithAlreadyAddedProducts.put(entityType, Sets.newHashSet());
continue;
}
} else {
if (entityTypeWithAlreadyAddedProducts.containsKey(entityType)) {
Set<Entity> alreadAddedProducts = entityTypeWithAlreadyAddedProducts.get(entityType);
alreadAddedProducts.add(product);
entityTypeWithAlreadyAddedProducts.put(entityType, alreadAddedProducts);
} else {
entityTypeWithAlreadyAddedProducts.put(entityType, Sets.newHashSet(product));
}
}
}
}
Entity trackingOperationProductComponent = trackingOperationComponentBuilder.fromOperationProductComponentHolder(operationProductComponentHolder);
if (forEach(typeOfProductionRecording)) {
Optional<Entity> mabyExist = trackingOperationProductComponents.stream().filter(toc -> toc.getBelongsToField(L_PRODUCT).getId().equals(trackingOperationProductComponent.getBelongsToField(L_PRODUCT).getId())).findAny();
if (!mabyExist.isPresent()) {
trackingOperationProductComponents.add(trackingOperationProductComponent);
}
} else {
trackingOperationProductComponents.add(trackingOperationProductComponent);
}
}
return trackingOperationProductComponents;
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method traverseProductQuantitiesAndOperationRuns.
@Override
public void traverseProductQuantitiesAndOperationRuns(final Entity technology, Map<Long, Entity> entitiesById, final BigDecimal givenQuantity, final Entity operationComponent, final Entity previousOperationComponent, final OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer, final Set<OperationProductComponentHolder> nonComponents, final Map<Long, BigDecimal> operationRuns) {
if (Objects.isNull(previousOperationComponent)) {
Entity technologyProduct = technology.getBelongsToField(TechnologyFields.PRODUCT);
for (Entity operationProductOutComponent : operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS)) {
if (operationProductOutComponent.getBelongsToField(OperationProductOutComponentFields.PRODUCT).getId().equals(technologyProduct.getId())) {
BigDecimal outQuantity = operationProductComponentWithQuantityContainer.get(operationProductOutComponent);
multiplyProductQuantitiesAndAddOperationRuns(operationComponent, givenQuantity, outQuantity, operationProductComponentWithQuantityContainer, operationRuns);
break;
}
}
} else {
for (Entity operationProductInComponent : previousOperationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) {
boolean isntComponent = false;
for (Entity operationProductOutComponent : operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS)) {
if (!Objects.isNull(operationProductInComponent.getBelongsToField(OperationProductInComponentFields.PRODUCT)) && operationProductOutComponent.getBelongsToField(OperationProductOutComponentFields.PRODUCT).getId().equals(operationProductInComponent.getBelongsToField(OperationProductInComponentFields.PRODUCT).getId())) {
isntComponent = true;
BigDecimal outQuantity = operationProductComponentWithQuantityContainer.get(operationProductOutComponent);
BigDecimal inQuantity = operationProductComponentWithQuantityContainer.get(operationProductInComponent);
multiplyProductQuantitiesAndAddOperationRuns(operationComponent, inQuantity, outQuantity, operationProductComponentWithQuantityContainer, operationRuns);
break;
}
}
if (isntComponent) {
nonComponents.add(new OperationProductComponentHolder(operationProductInComponent));
}
}
}
for (Entity child : entitiesById.get(operationComponent.getId()).getHasManyField(TechnologyOperationComponentFields.CHILDREN)) {
traverseProductQuantitiesAndOperationRuns(technology, entitiesById, givenQuantity, child, operationComponent, operationProductComponentWithQuantityContainer, nonComponents, operationRuns);
}
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method getNeededProductQuantities.
private Map<Long, BigDecimal> getNeededProductQuantities(final List<Entity> orders, final MrpAlgorithm mrpAlgorithm, final Map<Long, BigDecimal> operationRuns, final boolean onTheFly) {
Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
OperationProductComponentWithQuantityContainer productComponentWithQuantities = getProductComponentWithQuantitiesForOrders(orders, operationRuns, nonComponents, onTheFly);
return getProductWithQuantities(productComponentWithQuantities, nonComponents, mrpAlgorithm, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.
the class ProductQuantitiesServiceImpl 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;
}
Aggregations