use of eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao 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();
}
use of eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao in project dwoss by gg-net.
the class StockTransactionProcessorOperation method rollIn.
/**
* Rolls all StockTransaction in, completing them and setting the Stock.
*
* @param detachtedTransactions the transactions
* @param arranger the arranger
*/
@Override
public List<Integer> rollIn(List<StockTransaction> detachtedTransactions, String arranger) {
SubMonitor m = monitorFactory.newSubMonitor("RollIn", detachtedTransactions.size() * 2);
StockTransactionEao stockTransactionEao = new StockTransactionEao(stockEm);
StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
List<StockTransaction> transactions = new ArrayList<>();
m.message("loading Transactions");
for (StockTransaction detachedTransaction : detachtedTransactions) {
transactions.add(stockTransactionEao.findById(detachedTransaction.getId()));
m.worked(1);
}
m.setWorkRemaining(3);
m.message("rolling in");
List<StockUnit> stockUnits = stockTransactionEmo.completeRollIn(arranger, transactions);
m.worked(2, "adding History");
for (StockUnit stockUnit : stockUnits) {
if (mandator.isApplyDefaultChannelOnRollIn()) {
SalesChannel channel = stockUnit.getStock().getPrimaryChannel();
channelChanger.fire(new SalesChannelChange(stockUnit.getUniqueUnitId(), channel));
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName() + " with " + channel.getName(), arranger));
} else {
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName(), arranger));
}
}
m.finish();
return stockUnits.stream().map(x -> x.getId()).collect(Collectors.toList());
}
use of eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao in project dwoss by gg-net.
the class StockTransactionEmo method request.
/**
* Request a StockTransaction with the selected parameters.
*
* @param transactionType the type
* @param statusType the status
* @param sourceId the source, if null only the destination is used.
* @param destinationId the destination, if null only the source is used
* @param arrangerName the arranger
* @param comment the comment
* @return always a persisted transactions with the supplied parameters
*/
// TODO: Still not implemented to findByTypeAndStatus a transaction with source an destination. (For Transfer)
private StockTransaction request(StockTransactionType transactionType, StockTransactionStatusType statusType, Integer sourceId, Integer destinationId, String arrangerName, String comment) {
StockTransactionEao stockTransactionEao = new StockTransactionEao(em);
List<StockTransaction> stockTransactions;
if (sourceId != null)
stockTransactions = stockTransactionEao.findBySource(sourceId, transactionType, statusType, arrangerName, comment);
else
stockTransactions = stockTransactionEao.findByDestination(destinationId, transactionType, statusType, arrangerName, comment);
if (!stockTransactions.isEmpty())
return stockTransactions.get(0);
DefaultEao<Stock> stockEao = new DefaultEao<>(Stock.class, em);
StockTransaction st = new StockTransaction(transactionType);
st.setComment(comment);
StockTransactionStatus status = new StockTransactionStatus(statusType, new Date());
status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.ARRANGER, arrangerName));
st.addStatus(status);
if (sourceId != null)
st.setSource(stockEao.findById(sourceId));
if (destinationId != null)
st.setDestination(stockEao.findById(destinationId));
em.persist(st);
return st;
}
use of eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao in project dwoss by gg-net.
the class UnitProcessorOperation method receiptAndAddStockUnit.
private StockUnit receiptAndAddStockUnit(UniqueUnit uniqueUnit, StockTransaction transaction) {
StockUnit stockUnit = new StockUnit();
stockUnit.setUniqueUnitId(uniqueUnit.getId());
stockUnit.setRefurbishId(uniqueUnit.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
stockUnit.setName(uniqueUnit.getProduct().getTradeName().getName() + " " + uniqueUnit.getProduct().getName());
transaction = new StockTransactionEao(stockEm).findById(transaction.getId());
transaction.addPosition(new StockTransactionPosition(stockUnit));
// implies persist on transaction commit
L.debug("adding {} to {}", stockUnit, transaction);
return stockUnit;
}
use of eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao 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;
}
Aggregations