Search in sources :

Example 1 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.

the class StockTransactionEmoIT method testRequestRollInPrepared.

@Test
public void testRequestRollInPrepared() throws Exception {
    List<Stock> stocks = gen.makeStocksAndLocations(2);
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(em);
    utx.begin();
    em.joinTransaction();
    StockTransaction st1 = stockTransactionEmo.requestRollInPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    assertNotNull(st1);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransaction st2 = stockTransactionEmo.requestRollInPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    assertNotNull(st2);
    assertEquals(st1.getId(), st2.getId());
    st2.addStatus(new StockTransactionStatus(COMPLETED, new Date()));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransaction st3 = stockTransactionEmo.requestRollInPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    assertNotNull(st3);
    assertFalse(st1.getId() == st3.getId());
    utx.commit();
}
Also used : StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 2 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo 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 3 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.

the class RedTapeUpdateRepaymentWorkflow method optionalTransferToDestination.

/**
 * Validate if all StockUnits are on the destination Stock, and if not transfer them.
 *
 * @param stockUnits the stockUnits to validate
 */
void optionalTransferToDestination(List<StockUnit> stockUnits, int destinationId) {
    List<StockUnit> onWrongStock = new ArrayList<>();
    for (StockUnit stockUnit : stockUnits) {
        // We are ignoring everything on a transaction.
        if (stockUnit.isInTransaction())
            continue;
        if (stockUnit.getStock().getId() != destinationId)
            onWrongStock.add(stockUnit);
    }
    if (onWrongStock.isEmpty())
        return;
    StockTransactionEmo transactionEmo = new StockTransactionEmo(stockEm);
    StockTransaction transfer = transactionEmo.requestExternalTransferPrepare(onWrongStock.get(0).getStock().getId(), destinationId, arranger, "Transfer durch Gutschrift");
    for (StockUnit stockUnit : onWrongStock) transfer.addUnit(stockUnit);
    List<StockUnit> transferdUnits = transactionEmo.completeExternalTransfer(arranger, Arrays.asList(transfer));
    L.info("Destination {} for units on wrong stock used: {}", transferdUnits);
}
Also used : StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 4 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.

the class SalesChannelHandlerOperation method update.

/**
 * Updates the salesChanel of all supplied units
 * <p/>
 * @param lines              a list of salesChannelLines, must not be null.
 * @param arranger
 * @param transactionComment
 * @return true if something was changed.
 * @throws de.dw.util.UserInfoException
 */
@Override
public boolean update(final List<SalesChannelLine> lines, String arranger, String transactionComment) throws UserInfoException {
    SubMonitor m = monitorFactory.newSubMonitor("Import der Verkaufskanäle", 100);
    m.start();
    Map<Stock, List<Integer>> destinationsWithStockUnitIds = lines.stream().filter(// No Destination change
    l -> l.getDestination() != null).sorted(// Sort
    new LastCharsRefurbishIdSorter()).collect(Collectors.groupingBy(SalesChannelLine::getDestination, Collectors.mapping(SalesChannelLine::getUnitId, Collectors.toList())));
    StockTransactionEmo emo = new StockTransactionEmo(stockEm);
    SortedMap<Integer, String> histories = new TreeMap<>();
    for (Entry<Stock, List<Integer>> entry : destinationsWithStockUnitIds.entrySet()) {
        histories.putAll(emo.prepare(Transfer.builder().destinationStockId(entry.getKey().getId()).stockUnitIds(entry.getValue()).arranger(arranger).comment(transactionComment).maxTransactionSize(10).build(), m));
    }
    m.setWorkRemaining(lines.size());
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    boolean hasChanged = false;
    for (SalesChannelLine line : lines) {
        m.worked(1, "verarbeite " + line.getRefurbishedId());
        if (!line.hasChanged())
            continue;
        hasChanged = true;
        UniqueUnit uu = uniqueUnitEao.findByIdentifier(Identifier.REFURBISHED_ID, line.getRefurbishedId());
        uu.setSalesChannel(line.getSalesChannel());
        uu.addHistory("SalesChannel set to " + line.getSalesChannel() + " by " + arranger);
        if (histories.containsKey(uu.getId()))
            uu.addHistory(histories.get(uu.getId()));
    }
    m.finish();
    return hasChanged;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) SalesChannelLine(eu.ggnet.dwoss.stock.ee.model.SalesChannelLine) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)

Example 5 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.

the class StockTransactionEmoIT method testRequestDestroyPrepared.

@Test
public void testRequestDestroyPrepared() throws Exception {
    List<Stock> stocks = gen.makeStocksAndLocations(2);
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(em);
    utx.begin();
    em.joinTransaction();
    StockTransaction st1 = stockTransactionEmo.requestDestroyPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    assertNotNull(st1);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransaction st2 = stockTransactionEmo.requestDestroyPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    assertNotNull(st2);
    assertEquals(st1.getId(), st2.getId());
    st2.addStatus(new StockTransactionStatus(COMPLETED, new Date()));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransaction st3 = stockTransactionEmo.requestDestroyPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    assertNotNull(st3);
    assertFalse(st1.getId() == st3.getId());
    utx.commit();
}
Also used : StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Aggregations

StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)9 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)8 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)6 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)6 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)5 Test (org.junit.Test)5 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)3 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)3 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)2 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)1 DossierEmo (eu.ggnet.dwoss.redtape.ee.emo.DossierEmo)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)1 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)1 StockTransactionEao (eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)1 LogicTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo)1 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)1 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)1 SalesChannelLine (eu.ggnet.dwoss.stock.ee.model.SalesChannelLine)1