use of eu.ggnet.dwoss.redtape.ee.emo.DossierEmo 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.redtape.ee.emo.DossierEmo in project dwoss by gg-net.
the class UnitProcessorOperation method executeOperation.
private void executeOperation(UniqueUnit uniqueUnit, StockUnit stockUnit, ReceiptOperation operation, String operationComment, String arranger) {
long customerId = receiptCustomers.getCustomerId(uniqueUnit.getContractor(), operation);
Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) customerId, "Blockaddresse KundenId " + customerId, "Erzeugung durch " + operation, arranger);
L.debug("requestActiveDocumentBlock = {} with dossier = {}", doc, doc.getDossier());
redTapeEm.flush();
redTapeEm.refresh(doc, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
L.debug("Refreshed requestActiveDocumentBlock to = {} with dossier = {}", doc, doc.getDossier());
if (!doc.isActive())
throw new RuntimeException("The Document(id={}) has changed to inactive while locking, this was very unlikely, inform Administrator");
doc.append(toPosition(uniqueUnit, operationComment, doc.getTaxType()));
LogicTransaction lt = new LogicTransactionEmo(stockEm).request(doc.getDossier().getId(), LockModeType.PESSIMISTIC_FORCE_INCREMENT);
// Implicit removes it from an existing LogicTransaction
lt.add(stockUnit);
L.debug("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), doc.getDossier().getIdentifier());
uniqueUnit.addHistory("RecepitOeration:" + operation + ", " + operationComment + " by " + arranger);
}
use of eu.ggnet.dwoss.redtape.ee.emo.DossierEmo in project dwoss by gg-net.
the class DossierEmoIT method testRequest.
@Test
public void testRequest() throws Exception {
DossierEmo dossierEmo = new DossierEmo(em);
utx.begin();
em.joinTransaction();
Document document = dossierEmo.requestActiveDocumentBlock(1, "Addresse", "Comment", "Test");
assertNotNull(document);
Dossier dossier = document.getDossier();
assertTrue(dossier.getId() > 0);
assertNotNull(dossier.getActiveDocuments());
assertFalse(dossier.getActiveDocuments().isEmpty());
utx.commit();
utx.begin();
em.joinTransaction();
Document document2 = dossierEmo.requestActiveDocumentBlock(1, "Addresse", "Comment", "Test");
assertNotNull(document2);
Dossier dossier2 = document2.getDossier();
assertEquals(dossier.getId(), dossier2.getId());
utx.commit();
}
use of eu.ggnet.dwoss.redtape.ee.emo.DossierEmo in project dwoss by gg-net.
the class DossierEmoIT method testRemoveHistory.
@Test
public void testRemoveHistory() throws Exception {
DossierEmo dossierEmo = new DossierEmo(em);
utx.begin();
em.joinTransaction();
Document last = dossierEmo.requestActiveDocumentBlock(2, "Addresse Zwei", "Comment", "Test");
last.setActive(false);
Dossier dossier = last.getDossier();
for (int i = 0; i < 20; i++) {
Document d = new Document(DocumentType.BLOCK, Document.Directive.NONE, new DocumentHistory("JUnit", "JUnit"));
d.append(Position.builder().amount(1).type(PositionType.COMMENT).name("JUnit").description("JUnit").build());
d.setActive(false);
d.setInvoiceAddress(last.getInvoiceAddress());
d.setShippingAddress(last.getShippingAddress());
d.setPredecessor(last);
dossier.add(d);
em.persist(d);
last = d;
}
last.setActive(true);
utx.commit();
utx.begin();
em.joinTransaction();
dossier = new DossierEao(em).findById(dossier.getId());
assertTrue(dossier.getDocuments().size() > 10);
dossierEmo.removeHistoryFromBlock(dossier.getId());
utx.commit();
utx.begin();
em.joinTransaction();
dossier = new DossierEao(em).findById(dossier.getId());
assertEquals(1, dossier.getDocuments().size());
utx.commit();
}
Aggregations