Search in sources :

Example 16 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class UnitDestroyerOperation method verifyScarpOrDeleteAble.

/**
 * Validates if a unit identified by refurbishedId is scrapable.
 * Throws Exception if:
 * <ul>
 * <li>No UniqueUnit,SopoUnit or StockUnit exists.</li>
 * <li>StockUnit is inTransaction</li>
 * <li>SopoUnit is in Auftrag or Balanced.</li>
 * </ul>
 *
 * @param refurbishId the refurbishedId
 * @return
 * @throws UserInfoException if not scrapable.
 */
@Override
public UniqueUnit verifyScarpOrDeleteAble(String refurbishId) throws UserInfoException {
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
    if (uniqueUnit == null)
        throw new UserInfoException("Keine Gerät mit SopoNr " + refurbishId + " gefunden");
    StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    StockUnit stockUnit = stockUnitEao.findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        throw new UserInfoException("Keine Lagergerät für SopoNr " + refurbishId + " gefunden, Verschrottung/Löschung unnötig");
    if (stockUnit.isInTransaction())
        throw new UserInfoException("StockUnit ist auf einer Transaktion, Verschrottung/Löschung unzulässig");
    uniqueUnit.fetchEager();
    return uniqueUnit;
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 17 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class UnitProcessorOperation method optionalUpdateStockUnit.

private StockUnit optionalUpdateStockUnit(UniqueUnit uniqueUnit) {
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        return null;
    stockUnit.setRefurbishId(uniqueUnit.getIdentifier(Identifier.REFURBISHED_ID));
    stockUnit.setName(uniqueUnit.getProduct().getName());
    L.debug("updating {}", stockUnit);
    return stockUnit;
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 18 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class UnitProcessorOperation method findEditableUnit.

/**
 * Returns a editable UniqueUnit.
 * An Exception is thrown if:
 * <ul>
 * <li>No UniqueUnit with refurbishedId</li>
 * <li>No StockUnit for UniqueUnit</li>
 * <li>StockUnit is on Transaction</li>
 * <li>No SopoUnit with refurbishedId</li>
 * <li>No SopoUnit UniqueUnit miss match</li>
 * </ul>
 * The Operation is discovert via:
 * <ul>
 * <li>If on an AlphaAcount, and operation is allowed, returns appropriated operation</li>
 * <li>If on no Auftrag, returns Sales</li>
 * <li>If on any other Auftrag, returns null</li>
 * </ul>
 *
 * @param refurbishedIdOrSerial the refurbishedId or the serial, both are tried
 * @return a EditableUnit with, the editable UniqueUnit, the refrencing StockUnit, the Operation it is in, and the PartNo
 * @throws UserInfoException if refurbishedId is not ok.
 */
@Override
public EditableUnit findEditableUnit(String refurbishedIdOrSerial) throws UserInfoException {
    if (StringUtils.isBlank(refurbishedIdOrSerial))
        throw new UserInfoException("Keine SopoNr/Seriennummer eingegeben");
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(REFURBISHED_ID, refurbishedIdOrSerial);
    if (uniqueUnit == null)
        uniqueUnit = uniqueUnitEao.findByIdentifier(SERIAL, refurbishedIdOrSerial);
    if (uniqueUnit == null)
        throw new UserInfoException("Keine Gerät mit SopoNr/Seriennummer " + refurbishedIdOrSerial + " gefunden");
    StockUnit stockUnit;
    ReceiptOperation operation = ReceiptOperation.SALEABLE;
    stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        throw new UserInfoException("Keine Lagergerät für SopoNr " + uniqueUnit.getIdentifier(REFURBISHED_ID) + " gefunden, bearbeitung unzulässig");
    LogicTransaction lt = new LogicTransactionEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (lt != null) {
        operation = receiptCustomers.getOperation(new DossierEao(redTapeEm).findById(lt.getDossierId()).getCustomerId()).orElse(ReceiptOperation.IN_SALE);
    }
    // Lazyinit
    uniqueUnit.fetchEager();
    return new EditableUnit(uniqueUnit, stockUnit, operation, uniqueUnit.getProduct() == null ? "" : uniqueUnit.getProduct().getPartNo());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 19 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class UnitProcessorOperation method update.

/**
 * Updates the UniqueUnit.
 * Multiphase Process.
 * <ol>
 * <li>Validate all input data.</li>
 * <li>Merge UniqueUnit and set Product</li>
 * <li>Overwrite StockUnit</li>
 * <li>Overwrite SopoUnit</li>
 * <li>If SopoUnit is on "Process equivalent Customer", remove it there.</li>
 * <li>Execute Operation [Sopo]:
 * <ul>
 * <li>If Operation == Sales, nothing more to do</li>
 * <li>Else findByTypeAndStatus the KundenId from Contractor and Operation -> create or reuse a Auftrag and add the SopoUnit</li>
 * </ul>
 * </li>
 * </ol>
 *
 * @param uniqueUnit       the UniqueUnit, must not be null
 * @param product          the Product, must not be null
 * @param updateOperation  the operation, must not be null
 * @param operationComment the comment of the operation, may be null
 * @param arranger
 */
@Override
public void update(UniqueUnit uniqueUnit, Product product, ReceiptOperation updateOperation, String operationComment, String arranger) throws IllegalArgumentException {
    L.info("Updateing UniqueUnit(id={},refurbishId={},name={}) with {} by {}", uniqueUnit.getId(), uniqueUnit.getRefurbishId(), ProductFormater.toNameWithPartNo(product), updateOperation, arranger);
    uniqueUnit = updateUniqueUnit(uniqueUnit, product);
    StockUnit stockUnit = optionalUpdateStockUnit(uniqueUnit);
    // These two operations define, that nothing in LT/RedTape/Sopo may be changed.
    if (updateOperation == ReceiptOperation.IN_SALE || stockUnit == null)
        return;
    boolean executeNextOperation = cleanUpOldOperation(uniqueUnit, stockUnit, updateOperation, operationComment, arranger);
    if (executeNextOperation)
        executeOperation(uniqueUnit, stockUnit, updateOperation, operationComment, arranger);
}
Also used : StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 20 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class UnitProcessorOperation method transfer.

/**
 * Transfers a UniqueUnits StockUnit to the supplied Stock.
 * <p>
 * <ul>
 * <li>Validate, if a StockUnit for the UniqueUnit exists, and this StockUnit is in Stock</li>
 * <li>Transfer StockUnit via {@link StockTransactionType#EXTERNAL_TRANSFER}</li>
 * <li>Update the SopoUnit</li>
 * </ul>
 * <p/>
 * @param uniqueUnit the uniqueUnit
 * @param stockId    the stockId
 * @param arranger
 * @return
 */
// TODO: Use StockTransactionEmo.resquestExternalTransfer and completeExternalTransfer
@Override
public UniqueUnit transfer(UniqueUnit uniqueUnit, int stockId, String arranger) {
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        throw new IllegalArgumentException("No StockUnit for " + uniqueUnit);
    if (stockUnit.isInTransaction())
        throw new IllegalArgumentException(stockUnit + " is on Transaction");
    Stock destination = new DefaultEao<>(Stock.class, stockEm).findById(stockId);
    StockTransaction st = new StockTransaction(StockTransactionType.EXTERNAL_TRANSFER);
    StockTransactionStatus status = new StockTransactionStatus(StockTransactionStatusType.COMPLETED, new Date());
    status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.ARRANGER, arranger));
    st.addStatus(status);
    st.setSource(stockUnit.getStock());
    st.setDestination(destination);
    st.addPosition(new StockTransactionPosition(stockUnit));
    stockEm.persist(st);
    stockUnit.setPosition(null);
    new StockLocationDiscoverer(stockEm).discoverAndSetLocation(stockUnit, destination);
    uniqueUnit = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
    uniqueUnit.addHistory("External Stock change from " + stockUnit.getStock() + " to " + destination + " by " + arranger);
    uniqueUnit.fetchEager();
    return uniqueUnit;
}
Also used : StockTransactionParticipation(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation) StockLocationDiscoverer(eu.ggnet.dwoss.stock.ee.emo.StockLocationDiscoverer) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Aggregations

StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)63 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)29 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)27 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)22 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)20 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)20 Test (org.junit.Test)19 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)18 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)13 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)11 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)9 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)8 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)7 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)6 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)6 java.util (java.util)6 Inject (javax.inject.Inject)6 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)5