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;
}
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;
}
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();
}
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();
}
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();
}
Aggregations