use of de.metas.handlingunits.IHandlingUnitsDAO in project metasfresh-webui-api by metasfresh.
the class PackingInfoProcessParams method getAvailableLuPIItems.
private List<I_M_HU_PI_Item> getAvailableLuPIItems(@NonNull final I_M_HU_PI_Item_Product pip, @Nullable final I_C_BPartner bPartner) {
final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
final I_M_HU_PI piOfCurrentPip = pip.getM_HU_PI_Item().getM_HU_PI_Version().getM_HU_PI();
final List<I_M_HU_PI_Item> luPIItems = handlingUnitsDAO.retrieveParentPIItemsForParentPI(piOfCurrentPip, // huUnitType
null, bPartner);
return luPIItems;
}
use of de.metas.handlingunits.IHandlingUnitsDAO in project metasfresh-webui-api by metasfresh.
the class WEBUI_M_ReceiptSchedule_ReceiveHUs_UsingConfig method createM_HU_LUTU_Configuration.
@Override
protected I_M_HU_LUTU_Configuration createM_HU_LUTU_Configuration(final I_M_HU_LUTU_Configuration template) {
// Validate parameters
final int M_LU_HU_PI_ID = p_M_LU_HU_PI_ID;
final int M_HU_PI_Item_Product_ID = p_M_HU_PI_Item_Product_ID;
final BigDecimal qtyCU = p_QtyCU;
final BigDecimal qtyTU = p_QtyTU;
final BigDecimal qtyLU = p_QtyLU;
if (M_HU_PI_Item_Product_ID <= 0) {
throw new FillMandatoryException(PARAM_M_HU_PI_Item_Product_ID);
}
if (qtyCU == null || qtyCU.signum() <= 0) {
throw new FillMandatoryException(PARAM_QtyCU);
}
if (qtyTU == null || qtyTU.signum() <= 0) {
throw new FillMandatoryException(PARAM_QtyTU);
}
final I_M_HU_LUTU_Configuration lutuConfigurationNew = InterfaceWrapperHelper.copy().setFrom(template).copyToNew(I_M_HU_LUTU_Configuration.class);
//
// CU
lutuConfigurationNew.setQtyCU(qtyCU);
lutuConfigurationNew.setIsInfiniteQtyCU(false);
//
// TU
final I_M_HU_PI_Item_Product tuPIItemProduct = InterfaceWrapperHelper.create(getCtx(), M_HU_PI_Item_Product_ID, I_M_HU_PI_Item_Product.class, ITrx.TRXNAME_None);
final I_M_HU_PI tuPI = tuPIItemProduct.getM_HU_PI_Item().getM_HU_PI_Version().getM_HU_PI();
lutuConfigurationNew.setM_HU_PI_Item_Product(tuPIItemProduct);
lutuConfigurationNew.setM_TU_HU_PI(tuPI);
lutuConfigurationNew.setQtyTU(qtyTU);
lutuConfigurationNew.setIsInfiniteQtyTU(false);
// LU
if (M_LU_HU_PI_ID > 0) {
if (qtyLU == null || qtyLU.signum() <= 0) {
throw new FillMandatoryException(PARAM_QtyLU);
}
final I_M_HU_PI luPI = InterfaceWrapperHelper.create(getCtx(), M_LU_HU_PI_ID, I_M_HU_PI.class, ITrx.TRXNAME_None);
final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
final I_M_HU_PI_Version luPIV = handlingUnitsDAO.retrievePICurrentVersion(luPI);
final I_M_HU_PI_Item luPI_Item = handlingUnitsDAO.retrieveParentPIItemsForParentPI(tuPI, X_M_HU_PI_Version.HU_UNITTYPE_LoadLogistiqueUnit, lutuConfigurationNew.getC_BPartner()).stream().filter(piItem -> piItem.getM_HU_PI_Version_ID() == luPIV.getM_HU_PI_Version_ID()).findFirst().orElseThrow(() -> new AdempiereException(tuPI.getName() + " cannot be loaded to " + luPI.getName()));
lutuConfigurationNew.setM_LU_HU_PI(luPI);
lutuConfigurationNew.setM_LU_HU_PI_Item(luPI_Item);
lutuConfigurationNew.setQtyLU(qtyLU);
lutuConfigurationNew.setIsInfiniteQtyLU(false);
} else {
lutuConfigurationNew.setM_LU_HU_PI(null);
lutuConfigurationNew.setM_LU_HU_PI_Item(null);
lutuConfigurationNew.setQtyLU(BigDecimal.ZERO);
}
return lutuConfigurationNew;
}
use of de.metas.handlingunits.IHandlingUnitsDAO 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.IHandlingUnitsDAO in project metasfresh-webui-api by metasfresh.
the class WEBUIHUCreationWithSerialNumberService method createCUsBatch.
private Set<Integer> createCUsBatch(final HUEditorRow.HUEditorRowHierarchy huEditorRowHierarchy, final int maxCUsAllowedPerBatch) {
final Set<Integer> splitCUIDs = new HashSet<>();
final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
final HUEditorRow cuRow = huEditorRowHierarchy.getCuRow();
final HUEditorRow parentRow = huEditorRowHierarchy.getParentRow();
final int initialQtyCU = cuRow.getQtyCU().intValueExact();
I_M_HU huToSplit = cuRow.getM_HU();
int numberOfCUsToCreate;
if (parentRow == null) {
// The CU will not be split when its qty gets to 1. So make sure the selected CU gets in the list of split CUs
final int selectedCUID = huToSplit.getM_HU_ID();
splitCUIDs.add(selectedCUID);
numberOfCUsToCreate = maxCUsAllowedPerBatch < initialQtyCU ? maxCUsAllowedPerBatch : initialQtyCU;
for (int i = 0; i < numberOfCUsToCreate; i++) {
final List<I_M_HU> createdCUs = newHUTransformation().cuToNewCU(huToSplit, BigDecimal.ONE);
splitCUIDs.addAll(createdCUs.stream().map(I_M_HU::getM_HU_ID).collect(ImmutableSet.toImmutableSet()));
}
} else {
Check.assume(parentRow.isTU(), " Parent row must be TU: " + parentRow);
I_M_HU parentHU = parentRow.getM_HU();
if (isAggregateHU(parentRow)) {
final HUEditorRow luRow = huEditorRowHierarchy.getTopLevelRow();
parentHU = createNonAggregatedTU(parentRow, luRow);
huToSplit = handlingUnitsDAO.retrieveIncludedHUs(parentHU).get(0);
}
final int tuCapacity = calculateTUCapacity(parentHU);
numberOfCUsToCreate = Util.getMinimumOfThree(tuCapacity, maxCUsAllowedPerBatch, initialQtyCU);
for (int i = 0; i < numberOfCUsToCreate; i++) {
final List<I_M_HU> createdCUs = newHUTransformation().cuToExistingTU(huToSplit, BigDecimal.ONE, parentHU);
splitCUIDs.addAll(createdCUs.stream().map(I_M_HU::getM_HU_ID).collect(ImmutableSet.toImmutableSet()));
}
}
return splitCUIDs;
}
use of de.metas.handlingunits.IHandlingUnitsDAO in project metasfresh-webui-api by metasfresh.
the class WEBUI_Picking_PickQtyToNewHU method createTU.
/**
* Creates a new M_HU within the processe's interited trx.
*
* @param itemProduct
* @param locator
* @return
*/
private static final I_M_HU createTU(@NonNull final I_M_HU_PI_Item_Product itemProduct, @NonNull final I_M_Locator locator) {
final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
final IHUTrxBL huTrxBL = Services.get(IHUTrxBL.class);
final I_M_HU_PI huPI = itemProduct.getM_HU_PI_Item().getM_HU_PI_Version().getM_HU_PI();
return huTrxBL.createHUContextProcessorExecutor().call(huContext -> handlingUnitsDAO.createHUBuilder(huContext).setM_HU_Item_Parent(// no parent
null).setM_HU_PI_Item_Product(itemProduct).setM_Locator(locator).setHUStatus(X_M_HU.HUSTATUS_Active).create(huPI));
}
Aggregations