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