Search in sources :

Example 1 with LogicTransaction

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

the class UnitDestroyerOperation method scrapDelete.

private void scrapDelete(final long targetCustomerId, final String operation, final UniqueUnit uniqueUnit, final String reason, final String arranger) {
    UniqueUnit uu = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
    Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) targetCustomerId, "Blockaddresse KundenId " + targetCustomerId, "Erzeugung durch " + operation, arranger);
    Dossier dos = doc.getDossier();
    doc.append(Position.builder().type(PositionType.UNIT).amount(1).bookingAccount(postLedger.get(PositionType.UNIT, doc.getTaxType()).orElse(null)).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).build());
    doc.append(Position.builder().type(PositionType.COMMENT).amount(1).name(operation).description(reason + " by " + arranger).build());
    LogicTransaction lt = new LogicTransactionEmo(stockEm).request(dos.getId());
    // Implicit removes it from an existing LogicTransaction
    lt.add(stockUnit);
    StockTransaction st = stockTransactionEmo.requestDestroyPrepared(stockUnit.getStock().getId(), arranger, reason);
    st.addUnit(stockUnit);
    stockTransactionEmo.completeDestroy(arranger, Arrays.asList(st));
    uu.addHistory(operation + " of Unit via " + st);
    uu.setInternalComment(uu.getInternalComment() + ", " + operation + " of Unit.");
    uu.setSalesChannel(UNKNOWN);
    L.info("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), dos.getIdentifier());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 2 with LogicTransaction

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

the class UnitProcessorOperation method cleanUpOldOperation.

private boolean cleanUpOldOperation(UniqueUnit uniqueUnit, StockUnit stockUnit, ReceiptOperation updateOperation, String operationComment, String arranger) {
    LogicTransaction oldLogicTransaction = stockUnit.getLogicTransaction();
    if (oldLogicTransaction != null) {
        Dossier oldDossier = new DossierEao(redTapeEm).findById(oldLogicTransaction.getDossierId());
        ReceiptOperation oldOperation = receiptCustomers.getOperation(oldDossier.getCustomerId()).orElse(null);
        Document oldDocument = oldDossier.getActiveDocuments().get(0);
        redTapeEm.flush();
        redTapeEm.refresh(oldDocument, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
        if (!oldDocument.isActive())
            throw new RuntimeException("The Document(id={}) has changed to inactive while locking, this was very unlikely, inform Administrator");
        Position oldPosition = oldDocument.getPositionByUniqueUnitId(uniqueUnit.getId());
        if (oldOperation == updateOperation) {
            oldPosition.setDescription(oldPosition.getDescription() + ", Aufnahme: " + operationComment);
            L.debug("old operation and update operation are {}, nothing more to do", updateOperation);
            return false;
        }
        // cleanUp old Block and Auftrag
        convertToComment(oldPosition, updateOperation);
        L.debug("Old Operation cleanup, removed uniqueUnit(id={},refurbishId={}) from Dossier({})", new Object[] { uniqueUnit.getId(), uniqueUnit.getRefurbishId(), oldDossier.getIdentifier() });
    }
    if (updateOperation == ReceiptOperation.SALEABLE) {
        if (oldLogicTransaction != null)
            oldLogicTransaction.remove(stockUnit);
        uniqueUnit.addHistory("Released for Sale by " + arranger);
        L.debug("update operation is {}, nothing more to do", updateOperation);
        return false;
    }
    return true;
}
Also used : StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Example 3 with LogicTransaction

use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction 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 4 with LogicTransaction

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

the class UnitProcessorOperation method executeOperation.

private void executeOperation(UniqueUnit uniqueUnit, StockUnit stockUnit, ReceiptOperation operation, String operationComment, String arranger) {
    long customerId = receiptCustomers.getCustomerId(uniqueUnit.getContractor(), operation);
    Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) customerId, "Blockaddresse KundenId " + customerId, "Erzeugung durch " + operation, arranger);
    L.debug("requestActiveDocumentBlock = {} with dossier = {}", doc, doc.getDossier());
    redTapeEm.flush();
    redTapeEm.refresh(doc, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
    L.debug("Refreshed requestActiveDocumentBlock to = {} with dossier = {}", doc, doc.getDossier());
    if (!doc.isActive())
        throw new RuntimeException("The Document(id={}) has changed to inactive while locking, this was very unlikely, inform Administrator");
    doc.append(toPosition(uniqueUnit, operationComment, doc.getTaxType()));
    LogicTransaction lt = new LogicTransactionEmo(stockEm).request(doc.getDossier().getId(), LockModeType.PESSIMISTIC_FORCE_INCREMENT);
    // Implicit removes it from an existing LogicTransaction
    lt.add(stockUnit);
    L.debug("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), doc.getDossier().getIdentifier());
    uniqueUnit.addHistory("RecepitOeration:" + operation + ", " + operationComment + " by " + arranger);
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo)

Example 5 with LogicTransaction

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

the class RedTapeCloserOperation method filterOpenStockTransactions.

/**
 * Filters out all {@link Document}'s with associated {@link StockUnit}'s on an open {@link StockTransaction}.
 * See {@link StockTransactionStatusType} and {@link StockTransaction#POSSIBLE_STATUS_TYPES} for details about open {@link StockTransaction}.
 * <p>
 * <p/>
 * @param documents the documents as reference
 * @param monitor   a optional monitor
 * @return all documents which are not on open transactions.
 */
private Set<Document> filterOpenStockTransactions(Set<Document> documents, IMonitor monitor) {
    SubMonitor m = SubMonitor.convert(monitor, documents.size());
    m.start();
    m.message(" filtere");
    for (Iterator<Document> it = documents.iterator(); it.hasNext(); ) {
        Document document = it.next();
        m.worked(1, " filtere " + document.getIdentifier());
        LogicTransaction lt = ltEao.findByDossierId(document.getDossier().getId());
        if (lt == null)
            continue;
        for (StockUnit stockUnit : lt.getUnits()) {
            if (!validator.validate(stockUnit).isEmpty() || stockUnit.isInTransaction() || stockUnit.getStock() == null) {
                it.remove();
                L.warn("Closing: The Dossier(id={},customerId={}) has the Unit(refurbhisId={})" + " which is in an invalid state (validation error,open StockTransaction), excluding Dossier from closing.", document.getDossier().getId(), document.getDossier().getCustomerId(), stockUnit.getRefurbishId());
                break;
            }
        }
    }
    m.finish();
    return documents;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Aggregations

LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)30 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)22 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)15 Test (org.junit.Test)11 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)10 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)8 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)7 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)7 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)7 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)7 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)6 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)6 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)5 LogicTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo)5 Inject (javax.inject.Inject)5 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)4 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)4 java.util (java.util)4 CustomerGeneratorOperation (eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGeneratorOperation)3 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)3