use of de.metas.handlingunits.IHandlingUnitsBL in project metasfresh-webui-api by metasfresh.
the class HUPackingInfos method of.
public static final IHUPackingInfo of(final I_M_HU hu) {
Check.assumeNotNull(hu, "Parameter hu is not null");
final IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);
if (handlingUnitsBL.isAggregateHU(hu)) {
return new AggregatedTUPackingInfo(hu);
}
final String huUnitType = handlingUnitsBL.getHU_UnitType(hu);
if (X_M_HU_PI_Version.HU_UNITTYPE_LoadLogistiqueUnit.equals(huUnitType)) {
return new LUPIPackingInfo(handlingUnitsBL.getPI(hu));
} else if (X_M_HU_PI_Version.HU_UNITTYPE_TransportUnit.equals(huUnitType)) {
return new TUPackingInfo(hu);
} else if (X_M_HU_PI_Version.HU_UNITTYPE_VirtualPI.equals(huUnitType)) {
return new VHUPackingInfo(hu);
}
throw new IllegalArgumentException("HU type not supported: " + huUnitType + "\n HU: " + hu);
}
use of de.metas.handlingunits.IHandlingUnitsBL in project metasfresh-webui-api by metasfresh.
the class HUEditorRowAttributesProvider method createAttributeStorageFactory.
private final IAttributeStorageFactory createAttributeStorageFactory() {
final IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);
final IAttributeStorageFactoryService attributeStorageFactoryService = Services.get(IAttributeStorageFactoryService.class);
final IHUStorageFactory storageFactory = handlingUnitsBL.getStorageFactory();
final IAttributeStorageFactory huAttributeStorageFactory = attributeStorageFactoryService.createHUAttributeStorageFactory(storageFactory);
return huAttributeStorageFactory;
}
use of de.metas.handlingunits.IHandlingUnitsBL in project metasfresh-webui-api by metasfresh.
the class SqlHUEditorViewRepository method createHUEditorRow.
private HUEditorRow createHUEditorRow(@NonNull final I_M_HU hu, final int topLevelHUId) {
// final Stopwatch stopwatch = Stopwatch.createStarted();
final IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);
final boolean aggregatedTU = handlingUnitsBL.isAggregateHU(hu);
final String huUnitTypeCode = handlingUnitsBL.getHU_UnitType(hu);
final HUEditorRowType huRecordType;
if (aggregatedTU) {
huRecordType = HUEditorRowType.TU;
} else {
huRecordType = HUEditorRowType.ofHU_UnitType(huUnitTypeCode);
}
final String huUnitTypeDisplayName = huRecordType.getName();
final JSONLookupValue huUnitTypeLookupValue = JSONLookupValue.of(huUnitTypeCode, huUnitTypeDisplayName);
final JSONLookupValue huStatus = createHUStatusLookupValue(hu);
final boolean processed = rowProcessedPredicate.isProcessed(hu);
final int huId = hu.getM_HU_ID();
final HUEditorRowId rowId = HUEditorRowId.ofHU(huId, topLevelHUId);
final HUEditorRow.Builder huEditorRow = HUEditorRow.builder(windowId).setRowId(rowId).setType(huRecordType).setTopLevel(topLevelHUId <= 0).setProcessed(processed).setBPartnerId(hu.getC_BPartner_ID()).setAttributesProvider(attributesProvider).setCode(hu.getValue()).setHUUnitType(huUnitTypeLookupValue).setHUStatus(huStatus).setPackingInfo(extractPackingInfo(hu, huRecordType));
// Acquire Best Before Date if required
if (showBestBeforeDate) {
huEditorRow.setBestBeforeDate(extractBestBeforeDate(attributesProvider, rowId));
}
// Locator
if (showLocator) {
huEditorRow.setLocator(createLocatorLookupValue(hu.getM_Locator_ID()));
}
//
// Product/UOM/Qty if there is only one product stored
final IHUProductStorage singleProductStorage = getSingleProductStorage(hu);
if (singleProductStorage != null) {
huEditorRow.setProduct(createProductLookupValue(singleProductStorage.getM_Product())).setUOM(createUOMLookupValue(singleProductStorage.getC_UOM())).setQtyCU(singleProductStorage.getQty());
}
//
// Included HUs
final int topLevelHUIdEffective = topLevelHUId > 0 ? topLevelHUId : huId;
if (aggregatedTU) {
final IHUStorageFactory storageFactory = handlingUnitsBL.getStorageFactory();
storageFactory.getStorage(hu).getProductStorages().stream().map(huStorage -> createHUEditorRow(huId, topLevelHUIdEffective, huStorage, processed)).forEach(huEditorRow::addIncludedRow);
} else if (X_M_HU_PI_Version.HU_UNITTYPE_LoadLogistiqueUnit.equals(huUnitTypeCode)) {
final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
handlingUnitsDAO.retrieveIncludedHUs(hu).stream().map(includedHU -> createHUEditorRow(includedHU, topLevelHUIdEffective)).forEach(huEditorRow::addIncludedRow);
} else if (X_M_HU_PI_Version.HU_UNITTYPE_TransportUnit.equals(huUnitTypeCode)) {
final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
final IHUStorageFactory storageFactory = handlingUnitsBL.getStorageFactory();
handlingUnitsDAO.retrieveIncludedHUs(hu).stream().map(includedVHU -> storageFactory.getStorage(includedVHU)).flatMap(vhuStorage -> vhuStorage.getProductStorages().stream()).map(vhuProductStorage -> createHUEditorRow(huId, topLevelHUIdEffective, vhuProductStorage, processed)).forEach(huEditorRow::addIncludedRow);
} else if (X_M_HU_PI_Version.HU_UNITTYPE_VirtualPI.equals(huUnitTypeCode)) {
// do nothing
} else {
throw new HUException("Unknown HU_UnitType=" + huUnitTypeCode + " for " + hu);
}
final HUEditorRow huEditorRowBuilt = huEditorRow.build();
return huEditorRowBuilt;
}
use of de.metas.handlingunits.IHandlingUnitsBL in project metasfresh-webui-api by metasfresh.
the class WebuiHUTransformCommand method action_SplitTU_To_NewTUs.
/**
* Split a given number of TUs from current selected TU line to new TUs.
*
* @param tuRow
* @param qtyTU
* @param tuPI
* @return
*/
private WebuiHUTransformCommandResult action_SplitTU_To_NewTUs(final HUEditorRow tuRow, final BigDecimal qtyTU) {
final IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);
// TODO: if qtyTU is the "maximum", then don't do anything, but show a user message
final I_M_HU fromTU = tuRow.getM_HU();
final I_M_HU fromTopLevelHU = handlingUnitsBL.getTopLevelParent(fromTU);
final List<I_M_HU> createdHUs = newHUTransformation().tuToNewTUs(fromTU, qtyTU);
final WebuiHUTransformCommandResultBuilder resultBuilder = WebuiHUTransformCommandResult.builder().huIdsToAddToView(createdHUs.stream().map(I_M_HU::getM_HU_ID).collect(ImmutableSet.toImmutableSet()));
if (handlingUnitsBL.isDestroyedRefreshFirst(fromTopLevelHU)) {
resultBuilder.huIdToRemoveFromView(fromTopLevelHU.getM_HU_ID());
} else {
resultBuilder.huIdChanged(fromTopLevelHU.getM_HU_ID());
}
return resultBuilder.build();
}
Aggregations