Search in sources :

Example 1 with StockTransaction

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

use of eu.ggnet.dwoss.stock.ee.entity.StockTransaction 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)

Example 3 with StockTransaction

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

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

the class ReceiptGeneratorOperation method makeUniqueUnit.

/**
 * Generates one UniquUnits and receipts it.
 *
 * @return the generated UniquUnits.
 */
public UniqueUnit makeUniqueUnit() {
    Stock stock = findOrMakeStock();
    TradeName contractor = new ArrayList<>(contractors.all()).get(R.nextInt(contractors.all().size()));
    Shipment shipment = new Shipment("TEST-SHIPMENT-" + R.nextInt(10), contractor, TradeName.ACER, Shipment.Status.OPENED);
    stockEm.persist(shipment);
    StockTransaction transaction = stockTransactionEmo.requestRollInPrepared(stock.getId(), "SampleGenerator", "Rollin via makeUniqueUnit");
    ProductSpec productSpec = makeProductSpec();
    Product product = uniqueUnitAgent.findById(Product.class, productSpec.getProductId());
    UniqueUnit unit = unitGenerator.makeUniqueUnit(contractor, product);
    unitProcessor.receipt(unit, product, shipment, transaction, ReceiptOperation.SALEABLE, "SampleGenerator", "Generator");
    stockTransactionProcessor.rollIn(Arrays.asList(transaction), "JUnit");
    return uniqueUnitAgent.findUnitByIdentifierEager(REFURBISHED_ID, unit.getRefurbishId());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Shipment(eu.ggnet.dwoss.stock.ee.entity.Shipment) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 5 with StockTransaction

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

the class StockTransactionEaoIT method testfind.

@Test
public void testfind() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s1 = new Stock(0, "TEEEEEEEST");
    Stock s2 = new Stock(1, "TEEEEEEEST");
    em.persist(s1);
    em.persist(s2);
    StockTransaction st1 = new StockTransaction(StockTransactionType.ROLL_IN);
    st1.setDestination(s1);
    st1.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    st1.addStatus(new StockTransactionStatus(StockTransactionStatusType.COMPLETED, new Date()));
    StockTransaction st2 = new StockTransaction(StockTransactionType.ROLL_IN);
    st2.setDestination(s1);
    st2.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    StockTransaction st3 = new StockTransaction(StockTransactionType.DESTROY);
    st3.setSource(s1);
    st3.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    StockTransaction st4 = new StockTransaction(StockTransactionType.ROLL_IN);
    st4.setDestination(s2);
    StockTransactionStatus status = new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date());
    status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.PICKER, "Hugo"));
    st4.addStatus(status);
    st4.setComment("Muh");
    em.persist(st1);
    em.persist(st2);
    em.persist(st3);
    em.persist(st4);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransactionEao stockTransactionEao = new StockTransactionEao(em);
    List<StockTransaction> sts = stockTransactionEao.findByDestination(s1.getId(), StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED);
    assertNotNull(sts);
    assertEquals(1, sts.size());
    assertEquals(st2.getId(), sts.get(0).getId());
    sts = stockTransactionEao.findByDestination(s2.getId(), StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED, "Hugo", "Muh");
    assertNotNull(sts);
    assertEquals(1, sts.size());
    assertEquals(st4.getId(), sts.get(0).getId());
    utx.commit();
}
Also used : StockTransactionParticipation(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Aggregations

StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)36 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)21 Test (org.junit.Test)21 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)20 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)10 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)10 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)10 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)8 Date (java.util.Date)8 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)7 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)7 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)5 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)5 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)4 Shipment (eu.ggnet.dwoss.stock.ee.entity.Shipment)4 StockTransactionParticipation (eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation)4 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)3 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)3 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)3 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)3