Search in sources :

Example 26 with LogicTransaction

use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction in project dwoss by gg-net.

the class RedTapeOperationCapitalAssetUpdateIT method testUpdate.

@Test
public void testUpdate() throws UserInfoException {
    UniqueUnit uu = receiptGenerator.makeUniqueUnit();
    uu.setPrice(CUSTOMER, 50., "JunitTestPrice");
    // Generate Dossier
    Dossier dos = redTapeWorker.create(capitalAssestCustomer, false, "Me");
    assertThat(dos.getActiveDocuments()).isNotEmpty();
    assertThat(dos.getActiveDocuments(CAPITAL_ASSET)).overridingErrorMessage("Expected a capital Asset Document but has " + dos.getActiveDocuments()).isNotEmpty();
    Document doc = dos.getActiveDocuments(DocumentType.CAPITAL_ASSET).get(0);
    assertTrue(doc.equalsContent(dos.getActiveDocuments(DocumentType.CAPITAL_ASSET).get(0)));
    // Commit explicit date to document for assertion
    doc = supportBean.changeActual(doc, new GregorianCalendar(2012, 3, 15).getTime());
    Position pos = NaivBuilderUtil.unit(uu);
    // Create Positions
    doc.append(pos);
    doc.append(NaivBuilderUtil.comment("Comment", "A nice comment"));
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos.getId(), uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    // update document
    Date date = doc.getActual();
    doc = redTapeWorker.update(doc, null, "Me");
    assertEquals("Same actual dates expected", date, doc.getActual());
    assertEquals("Only one Active Document expected", 1, doc.getDossier().getActiveDocuments().size());
    assertTrue(stockAgent.findAllEager(LogicTransaction.class).get(0).getUnits().size() == 1);
    assertEquals("Ammount of Documents", 2, redTapeAgent.findAll(Document.class).size());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) GregorianCalendar(java.util.GregorianCalendar) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) Date(java.util.Date)

Example 27 with LogicTransaction

use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction in project dwoss by gg-net.

the class RedTapeOperationComplaintIT method testCreditMemo.

@Test
public void testCreditMemo() throws UserInfoException {
    long customerId = customerGenerator.makeCustomer();
    List<UniqueUnit> units = receiptGenerator.makeUniqueUnits(2, true, true);
    UniqueUnit uu1 = units.get(0);
    UniqueUnit uu2 = units.get(1);
    Dossier dos = redTapeOperation.create(customerId, true, "Me");
    Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
    // Create Positions
    Position p1 = NaivBuilderUtil.unit(uu1);
    Position p2 = NaivBuilderUtil.unit(uu2);
    doc.append(p1);
    doc.append(p2);
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    doc = redTapeOperation.update(doc, null, "JUnit");
    doc.add(Document.Condition.PAID);
    doc.add(Document.Condition.PICKED_UP);
    doc.setType(DocumentType.INVOICE);
    doc = redTapeOperation.update(doc, null, "JUnit");
    LogicTransaction lt = supportBean.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must exists", lt);
    assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
    assertEquals("Document should have exactly two possitions", 2, doc.getPositions().size());
    doc.setType(DocumentType.COMPLAINT);
    doc.setDirective(Document.Directive.WAIT_FOR_COMPLAINT_COMPLETION);
    doc.removeAt(p2.getId());
    assertEquals("Document should have exactly one possitions", 1, doc.getPositions().size());
    doc = redTapeOperation.update(doc, null, "JUnit Test");
    lt = supportBean.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must still exists", lt);
    assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
    Arrays.asList(uu1.getId(), uu2.getId());
    assertTrue("Should contain the same UniqueUnitIds", lt.getUnits().stream().map(su -> su.getUniqueUnitId()).collect(Collectors.toSet()).containsAll(Arrays.asList(uu1.getId(), uu2.getId())));
    doc.add(Document.Condition.REJECTED);
    redTapeOperation.update(doc, null, "JUnit Test");
}
Also used : Arrays(java.util.Arrays) Arquillian(org.jboss.arquillian.junit.Arquillian) CustomerGeneratorOperation(eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGeneratorOperation) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) RedTapeWorker(eu.ggnet.dwoss.redtapext.ee.RedTapeWorker) Test(org.junit.Test) UnitOverseer(eu.ggnet.dwoss.redtapext.ee.UnitOverseer) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) eu.ggnet.dwoss.redtapext.op.itest.support(eu.ggnet.dwoss.redtapext.op.itest.support) List(java.util.List) eu.ggnet.dwoss.redtape.ee.entity(eu.ggnet.dwoss.redtape.ee.entity) DocumentType(eu.ggnet.dwoss.rules.DocumentType) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Assert(org.junit.Assert) EJB(javax.ejb.EJB) ReceiptGeneratorOperation(eu.ggnet.dwoss.receipt.ee.gen.ReceiptGeneratorOperation) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Test(org.junit.Test)

Example 28 with LogicTransaction

use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction in project dwoss by gg-net.

the class RedTapeOperationCreditMemoIT method testCreditMemo.

@Test
public void testCreditMemo() throws UserInfoException {
    // We need two stocks at least.
    List<Stock> allStocks = stockGenerator.makeStocksAndLocations(2);
    long customerId = customerGenerator.makeCustomer();
    List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(4, true, true);
    UniqueUnit uu1 = uus.get(0);
    UniqueUnit uu2 = uus.get(1);
    UniqueUnit uu3 = uus.get(2);
    UniqueUnit uu4 = uus.get(3);
    Product uuProduct1 = uu1.getProduct();
    int stockIdOfUU1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId()).getStock().getId();
    int alternateStockId = allStocks.stream().map(Stock::getId).filter(id -> id != stockIdOfUU1).findFirst().orElseThrow(() -> new RuntimeException("No alternate StockId found, impossible"));
    Dossier dos = redTapeWorker.create(customerId, true, "Me");
    Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
    // Create Positions
    doc.append(unit(uu1));
    doc.append(unit(uu2));
    doc.append(unit(uu3));
    doc.append(comment());
    doc.append(service());
    doc.append(batch(uuProduct1));
    doc.append(shippingcost());
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    doc = redTapeWorker.update(doc, null, "JUnit");
    doc.add(Document.Condition.PAID);
    doc.add(Document.Condition.PICKED_UP);
    doc.setType(DocumentType.INVOICE);
    doc = redTapeWorker.update(doc, null, "JUnit");
    LogicTransaction lt = supportBean.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must exists", lt);
    assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
    // A CreditMemo for a Unit, which is on the wrong Stock
    for (Position pos : new ArrayList<>(doc.getPositions().values())) {
        if (pos.getType() != PositionType.UNIT)
            doc.remove(pos);
        else if (pos.getUniqueUnitId() != uu1.getId())
            doc.remove(pos);
    }
    assertEquals("Document should have exactly one possition", 1, doc.getPositions().size());
    assertEquals("Position is exactly the same UniqueUnitId", uu1.getId(), doc.getPositions().get(1).getUniqueUnitId());
    doc.setType(DocumentType.CREDIT_MEMO);
    // Setting the Stock by force.
    supportBean.changeStock(uu1.getId(), alternateStockId);
    doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
    // Asserting Everything
    assertEquals("The Identifier of CreditMemo", "GS" + YY + "_00001", doc.getIdentifier());
    lt = supportBean.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must still exists", lt);
    assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
    for (StockUnit stockUnit : lt.getUnits()) {
        if (stockUnit.getUniqueUnitId() == uu1.getId()) {
            fail("The StockUnit of the CreditMemo should not be on the LogicTransaction of the Dossier");
        }
    }
    List<StockTransaction> sto = stockAgent.findStockTransactionEager(StockTransactionType.EXTERNAL_TRANSFER, StockTransactionStatusType.COMPLETED);
    assertEquals("One External Transfer Transaction", 1, sto.size());
    assertEquals("Only One Position on the Transaction should exist", 1, sto.get(0).getPositions().size());
    assertThat(uu1.getId()).as("The One Position should reference to the UniqueUnit of the CreditMemo").isEqualTo(sto.get(0).getPositions().get(0).getUniqueUnitId());
    assertEquals("The Transaction should contain exactlly one shadow of the UniqueUnit", 1, sto.size());
    StockUnit stockUnit1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId());
    assertEquals("The Stock of the StockUnit", stockIdOfUU1, stockUnit1.getStock().getId());
    assertNotNull("StockUnit should be on a LogicTransaction", stockUnit1.getLogicTransaction());
    Dossier dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit1.getLogicTransaction().getDossierId());
    assertNotNull("A Dossier on the SystemCustomer must exist", dossier);
    assertFalse(dossier.getActiveDocuments().isEmpty());
    assertFalse(dossier.getActiveDocuments().get(0).getPositions().isEmpty());
    assertEquals(2, dossier.getActiveDocuments().get(0).getPositions().size());
    boolean unit1Found = false;
    boolean commentFound = false;
    for (Position pos : dossier.getActiveDocuments().get(0).getPositions().values()) {
        if (pos.getType() == PositionType.UNIT) {
            assertEquals(uu1.getId(), pos.getUniqueUnitId());
            unit1Found = true;
        } else if (pos.getType() == PositionType.COMMENT) {
            commentFound = true;
        }
    }
    assertTrue(unit1Found);
    assertTrue(commentFound);
    Document invoice = doc.getDossier().getActiveDocuments(DocumentType.INVOICE).get(0);
    // A CreditMemo for a Unit, which is Rolled Out before.
    for (Position pos : new ArrayList<>(invoice.getPositions().values())) {
        if (pos.getType() != PositionType.UNIT)
            invoice.remove(pos);
        else if (pos.getUniqueUnitId() != uu2.getId())
            invoice.remove(pos);
    }
    assertEquals("Document should have exactly one possition", 1, invoice.getPositions().size());
    assertEquals("Position is exactly the same UniqueUnitId", uu2.getId(), invoice.getPositions().get(1).getUniqueUnitId());
    invoice.setType(DocumentType.CREDIT_MEMO);
    // Lets roll Out the Unit
    supportBean.rollOut(uu2.getId());
    // Do the second credit Memo and check if the Unit is back in the stock.
    StockUnit stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
    assertNull("StockUnit should not exist: " + stockUnit2, stockUnit2);
    doc = redTapeWorker.update(invoice, stockIdOfUU1, "JUnit");
    // Assert Everything
    assertEquals("The Identifier of CreditMemo", "GS" + YY + "_00002", doc.getIdentifier());
    stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
    assertNotNull("StockUnit exists", stockUnit2);
    assertNotNull("StockUnit should have LogicTransaction", stockUnit2.getLogicTransaction());
    assertThat(uu2.getId()).as("StockUnit is not the correct one").isEqualTo(stockUnit2.getUniqueUnitId());
    dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit2.getLogicTransaction().getDossierId());
    assertNotNull("A Dossier on the SystemCustomer must exist", dossier);
    assertFalse(dossier.getActiveDocuments().isEmpty());
    assertFalse(dossier.getActiveDocuments().get(0).getPositions().isEmpty());
    assertEquals(2, dossier.getActiveDocuments().get(0).getPositions().size());
    unit1Found = false;
    commentFound = false;
    for (Position pos : dossier.getActiveDocuments().get(0).getPositions().values()) {
        if (pos.getType() == PositionType.UNIT) {
            assertEquals(uu2.getId(), pos.getUniqueUnitId());
            unit1Found = true;
        } else if (pos.getType() == PositionType.COMMENT) {
            commentFound = true;
        }
    }
    assertTrue(unit1Found);
    assertTrue(commentFound);
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 29 with LogicTransaction

use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction in project dwoss by gg-net.

the class RedTapeOperationOrderInvoiceIT method testInvoiceDocument.

@Test
public void testInvoiceDocument() throws UserInfoException {
    long customerId = customerGenerator.makeCustomer();
    List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(4, true, true);
    UniqueUnit uu1 = uus.get(0);
    UniqueUnit uu2 = uus.get(1);
    UniqueUnit uu3 = uus.get(2);
    UniqueUnit uu4 = uus.get(3);
    Product uuProduct1 = uu1.getProduct();
    // Generate Dossier
    Dossier dos = redTapeWorker.create(customerId, true, "Me");
    Document doc1 = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc1).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
    doc1.add(Document.Flag.CUSTOMER_BRIEFED);
    doc1.add(Document.Flag.CUSTOMER_EXACTLY_BRIEFED);
    // Create Positions
    Position p1 = NaivBuilderUtil.unit(uu1);
    Position p2 = NaivBuilderUtil.unit(uu2);
    Position p4 = NaivBuilderUtil.comment();
    Position p5 = NaivBuilderUtil.service();
    Position p6 = NaivBuilderUtil.batch(uuProduct1);
    Position p7 = NaivBuilderUtil.shippingcost();
    doc1.append(p1);
    doc1.append(p2);
    doc1.append(p4);
    doc1.append(p5);
    doc1.append(p6);
    doc1.append(p7);
    Position p3 = NaivBuilderUtil.unit(uu3);
    Position p8 = NaivBuilderUtil.unit(uu4);
    Dossier dos2 = redTapeWorker.create(customerId, false, "Me2");
    Document doc2 = dos2.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc2).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos2.toMultiLine()).isNotNull();
    doc2.append(p3);
    doc2.append(p8);
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    doc1 = redTapeWorker.update(doc1, null, "Junit Test");
    doc1.add(Document.Condition.PAID);
    doc1.add(Document.Condition.PICKED_UP);
    doc1.setType(DocumentType.INVOICE);
    doc1 = redTapeWorker.update(doc1, null, "tester");
    String format = new SimpleDateFormat("YY").format(new Date());
    assertEquals("The Identifier of Invoice", "RS" + format + "_00001", doc1.getIdentifier());
    assertFalse("Document must not contain " + Document.Flag.CUSTOMER_BRIEFED, doc1.getFlags().contains(Document.Flag.CUSTOMER_BRIEFED));
    assertFalse("Document must not contain " + Document.Flag.CUSTOMER_EXACTLY_BRIEFED, doc1.getFlags().contains(Document.Flag.CUSTOMER_EXACTLY_BRIEFED));
    LogicTransaction lt = logicTransactionEao.findByDossierId(doc1.getDossier().getId());
    assertNotNull("A LogicTrasaction must exists", lt);
    assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
    doc2.setType(DocumentType.INVOICE);
    Document update2 = redTapeWorker.update(doc2, null, "Junit");
    assertEquals("RS" + format + "_00002", update2.getIdentifier());
    Date now = new Date();
    Date start = DateUtils.addDays(now, -1);
    Date end = DateUtils.addDays(now, 1);
    FileJacket fj = sageExporter.toXml(start, end);
    String result = Strings.fromByteArray(fj.getContent());
    assertThat(result).as("SageXml spot Test").isNotBlank().contains(dos.getIdentifier(), dos2.getIdentifier()).contains(Double.toString(TwoDigits.round(p7.getPrice() * p7.getAmount())).replace(".", ",")).contains(Double.toString(TwoDigits.round(p6.getPrice() * p6.getAmount())).replace(".", ","));
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 30 with LogicTransaction

use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction in project dwoss by gg-net.

the class SupportBean method findByDossierId.

public LogicTransaction findByDossierId(long id) {
    LogicTransaction lt = logicTransactionEao.findByDossierId(id);
    lt.getUnits().size();
    return lt;
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)

Aggregations

LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)30 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)22 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)15 Test (org.junit.Test)11 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)10 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)8 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)7 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)7 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)7 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)7 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)6 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)6 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)5 LogicTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo)5 Inject (javax.inject.Inject)5 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)4 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)4 java.util (java.util)4 CustomerGeneratorOperation (eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGeneratorOperation)3 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)3