Search in sources :

Example 21 with StockTransaction

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

the class ReceiptGeneratorOperation method makeUniqueUnits.

/**
 * Generates an amount of UniquUnits and receipts them.
 *
 * @param amount               the amount to generate.
 * @param generateSalesChannel
 * @param generatePrice        if true a random customer and retailer price is set
 * @return the generated and receipted UniquUnits.
 */
// TODO: Create more Shipments on multiple contractors.
public List<UniqueUnit> makeUniqueUnits(int amount, boolean generateSalesChannel, boolean generatePrice) {
    final int minProducts = 5;
    final int maxProducts = 450;
    int amountProducts = (amount / 25);
    if (amountProducts <= minProducts)
        amountProducts = minProducts;
    if (amountProducts >= maxProducts)
        amountProducts = maxProducts;
    L.info("Generating {} Units", amount);
    SubMonitor m = monitorFactory.newSubMonitor("Generating " + amount + " Units", amount);
    m.start();
    List<ProductSpec> productSpecs = makeProductSpecs(amountProducts, generatePrice);
    List<UniqueUnit> units = new ArrayList<>();
    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 make UniqueUnits");
    L.debug("Transaction prepared {}", transaction);
    for (int i = 0; i < amount; i++) {
        ProductSpec productSpec = productSpecs.get(R.nextInt(productSpecs.size()));
        Product product = uniqueUnitAgent.findById(Product.class, productSpec.getProductId());
        UniqueUnit unit = unitGenerator.makeUniqueUnit(contractor, product);
        m.worked(1, "created SopoNr " + unit.getRefurbishId());
        if (generatePrice) {
            int price = R.nextInt(1000) + 1;
            unit.setPrice(PriceType.CUSTOMER, price, "Generated by ReceiptGeneratorOperation.makeUniqueUnits()");
            unit.setPrice(PriceType.RETAILER, price * 1.08, "Generated by ReceiptGeneratorOperation.makeUniqueUnits()");
        }
        if (generateSalesChannel)
            unit.setSalesChannel(R.nextBoolean() ? SalesChannel.CUSTOMER : SalesChannel.RETAILER);
        unitProcessor.receipt(unit, product, shipment, transaction, ReceiptOperation.SALEABLE, "SampleGenerator", "Generator");
        // Ad the now persisted instance.
        units.add(uniqueUnitAgent.findUnitByIdentifierEager(REFURBISHED_ID, unit.getRefurbishId()));
    }
    stockTransactionProcessor.rollIn(Arrays.asList(transaction), "JUnit");
    m.finish();
    return units;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Shipment(eu.ggnet.dwoss.stock.ee.entity.Shipment) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 22 with StockTransaction

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

the class AuditReporterOperation method onRollIn.

/**
 * Returns an audit report of units which are input between the dates.
 * <p/>
 * @return an audit report of units which are input between the dates.
 */
@Override
public FileJacket onRollIn() {
    SubMonitor m = monitorFactory.newSubMonitor("AuditReport", 100);
    m.message("loading UniqueUnits");
    m.start();
    List<StockTransaction> rollInTransactions = new StockTransactionEao(stocks.getEntityManager()).findByTypeAndStatus(StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED);
    List<Integer> uuIds = toUniqueUnitIds(rollInTransactions);
    List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uus.getEntityManager()).findByIds(uuIds);
    m.worked(5, "preparing Document");
    List<Object[]> rows = new ArrayList<>();
    for (UniqueUnit uu : uniqueUnits) {
        rows.add(new Object[] { uu.getRefurbishId(), uu.getProduct().getGroup().getNote(), uu.getProduct().getPartNo(), uu.getSerial(), ProductFormater.toName(uu.getProduct()), uu.getContractor(), UniqueUnitFormater.toSingleLineAccessories(uu), UniqueUnitFormater.toSingleLineComment(uu), UniqueUnitFormater.toSingleLineInternalComment(uu), uu.getCondition().getNote(), uu.getShipmentLabel(), uu.getProduct().getDescription(), "" });
    }
    CSheet sheet = new CSheet("Audit");
    STable table = new STable();
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, BLACK, WHITE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("SopoNr", 7)).add(new STableColumn("Warengruppe", 13)).add(new STableColumn("ArtikelNr", 15)).add(new STableColumn("Seriennummer", 27));
    table.add(new STableColumn("Name", 30)).add(new STableColumn("Lieferant", 12)).add(new STableColumn("Zubehör", 50)).add(new STableColumn("Bemerkung", 50));
    table.add(new STableColumn("Interne Bemerkung", 30)).add(new STableColumn("Zustand", 12)).add(new STableColumn("Shipment", 12)).add(new STableColumn("Beschreibung", 50));
    table.setModel(new STableModelList(rows));
    sheet.addBelow(table);
    CCalcDocument document = new TempCalcDocument();
    document.add(sheet);
    FileJacket fj = new FileJacket("Audit", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(document));
    m.finish();
    return fj;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) ArrayList(java.util.ArrayList) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) CSheet(eu.ggnet.lucidcalc.CSheet) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) STableColumn(eu.ggnet.lucidcalc.STableColumn) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) STable(eu.ggnet.lucidcalc.STable) STableModelList(eu.ggnet.lucidcalc.STableModelList) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CFormat(eu.ggnet.lucidcalc.CFormat) CBorder(eu.ggnet.lucidcalc.CBorder) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 23 with StockTransaction

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

Example 24 with StockTransaction

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

the class StockTransactionEmoIT method testCompleteDestroy.

@Test
public void testCompleteDestroy() throws Exception {
    List<Stock> stocks = gen.makeStocksAndLocations(2);
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(em);
    StockUnitEao stockUnitEao = new StockUnitEao(em);
    utx.begin();
    em.joinTransaction();
    Stock s1 = em.find(Stock.class, stocks.get(0).getId());
    for (int i = 1; i <= 10; i++) {
        StockUnit su = new StockUnit(Integer.toString(i), i);
        su.setStock(s1);
        em.persist(su);
    }
    List<StockUnit> units = stockUnitEao.findAll();
    assertNotNull(units);
    for (StockUnit stockUnit : units) {
        assertTrue(stockUnit.isInStock());
        assertFalse(stockUnit.isInTransaction());
        assertEquals(s1, stockUnit.getStock());
    }
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransaction st1 = stockTransactionEmo.requestDestroyPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    for (StockUnit stockUnit : stockUnitEao.findAll()) {
        st1.addUnit(stockUnit);
    }
    assertEquals(units.size(), st1.getPositions().size());
    List<Integer> uids = stockTransactionEmo.completeDestroy("Horst", Arrays.asList(st1));
    assertNotNull(uids);
    assertEquals(units.size(), uids.size());
    utx.commit();
    utx.begin();
    em.joinTransaction();
    List<StockUnit> stockUnits = stockUnitEao.findAll();
    assertTrue(stockUnits.isEmpty());
    utx.commit();
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) 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 25 with StockTransaction

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

the class StockTransactionEmoIT method testPrepare.

@Test
public void testPrepare() throws Exception {
    List<Stock> stocks = gen.makeStocksAndLocations(2);
    int transactionSize = 5;
    utx.begin();
    em.joinTransaction();
    Stock s1 = em.find(Stock.class, stocks.get(0).getId());
    for (int i = 1; i <= 15; i++) {
        StockUnit su = new StockUnit(Integer.toString(i), i);
        su.setStock(s1);
        em.persist(su);
    }
    utx.commit();
    utx.begin();
    em.joinTransaction();
    List<Integer> units = new StockUnitEao(em).findAll().stream().map(StockUnit::getId).collect(Collectors.toList());
    assertEquals("Assert 15 persisted Stockunits", 15, units.size());
    // prepare
    new StockTransactionEmo(em).prepare(Transfer.builder().destinationStockId(stocks.get(1).getId()).stockUnitIds(units).arranger("UnitTest").comment("Test prepare").maxTransactionSize(transactionSize).build(), null);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransactionEao stEao = new StockTransactionEao(em);
    List<StockTransaction> findByDestination = stEao.findAll();
    assertEquals("Assert three transactions", 3, findByDestination.size());
    for (StockTransaction transaction : findByDestination) {
        List<StockTransactionPosition> positions = transaction.getPositions();
        assertEquals("Assert five posititons", 5, positions.size());
    }
    utx.commit();
}
Also used : StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) 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

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