Search in sources :

Example 1 with DossierEmo

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());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 2 with DossierEmo

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);
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo)

Example 3 with DossierEmo

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();
}
Also used : DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) Test(org.junit.Test)

Example 4 with DossierEmo

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();
}
Also used : DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) Test(org.junit.Test)

Aggregations

DossierEmo (eu.ggnet.dwoss.redtape.ee.emo.DossierEmo)4 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)2 LogicTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo)2 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)2 Test (org.junit.Test)2 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)1 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)1 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)1 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)1 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)1 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)1 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)1 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)1