Search in sources :

Example 6 with LogicTransaction

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

the class CreditMemoReportIT method testCreditMemoReportOperation.

@Test
public void testCreditMemoReportOperation() throws IOException, InterruptedException {
    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();
    assertThat(uu1).describedAs("First generated UniqueUnit").isNotNull();
    StockUnit su1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId());
    assertThat(su1).describedAs("StockUnit of generated UniqueUnit").isNotNull();
    assertThat(su1.getStock()).describedAs("Stock of StockUnit of generated UniqueUnit").isNotNull();
    int stockIdOfUU1 = su1.getStock().getId();
    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();
    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 = support.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must exists", lt);
    assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
    // A CreditMemo for Unit1, negate prices on Annulation Invoice.
    for (Position pos : new ArrayList<>(doc.getPositions().values())) {
        if (pos.getUniqueUnitId() == uu1.getId() || pos.getType() == PRODUCT_BATCH || pos.getType() == SHIPPING_COST) {
            pos.setPrice(pos.getPrice() * -1);
        } else {
            doc.remove(pos);
        }
    }
    assertEquals("Document should have exactly one possition", 3, doc.getPositions().size());
    doc.setType(DocumentType.ANNULATION_INVOICE);
    doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
    Collection<Position> positions = doc.getPositions().values();
    // Report somethere in the past till now.
    FileJacket jacket = reportOperation.toXls(new Date(1352115909), new Date());
    assertNotNull(jacket);
    assertEquals(".xls", jacket.getSuffix());
    assertTrue(jacket.getContent().length > 0);
    List<LoadContainer> read = new JExcelLucidCalcReader().addColumn(0, String.class).addColumn(1, String.class).addColumn(2, String.class).addColumn(3, String.class).addColumn(4, String.class).addColumn(5, Double.class).addColumn(6, Double.class).read(jacket.toTemporaryFile(), LoadContainer.class);
    // HINT: Not a complete test, but some fileds at least.
    assertThat(positions.stream().map(Position::getPrice).collect(toSet())).containsOnly(read.stream().map(l -> l.netto).toArray((v) -> new Double[v]));
    assertThat(positions.stream().map(Position::toAfterTaxPrice).collect(toSet())).containsOnly(read.stream().map(l -> l.brutto).toArray((v) -> new Double[v]));
    assertThat(positions.stream().map(Position::getName).collect(toSet())).containsOnly(read.stream().map(l -> l.name).toArray((v) -> new String[v]));
}
Also used : java.util(java.util) CreditMemoReporter(eu.ggnet.dwoss.redtapext.ee.reporting.CreditMemoReporter) 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) SupportBean(eu.ggnet.dwoss.redtapext.op.itest.support.SupportBean) UnitOverseer(eu.ggnet.dwoss.redtapext.ee.UnitOverseer) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Inject(javax.inject.Inject) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) DocumentType(eu.ggnet.dwoss.rules.DocumentType) ToString(lombok.ToString) NaivBuilderUtil(eu.ggnet.dwoss.redtapext.op.itest.support.NaivBuilderUtil) EJB(javax.ejb.EJB) Collectors.toSet(java.util.stream.Collectors.toSet) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) FileJacket(eu.ggnet.dwoss.util.FileJacket) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) IOException(java.io.IOException) Test(org.junit.Test) SHIPPING_COST(eu.ggnet.dwoss.rules.PositionType.SHIPPING_COST) PRODUCT_BATCH(eu.ggnet.dwoss.rules.PositionType.PRODUCT_BATCH) eu.ggnet.dwoss.redtape.ee.entity(eu.ggnet.dwoss.redtape.ee.entity) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ArquillianProjectArchive(eu.ggnet.dwoss.redtapext.op.itest.support.ArquillianProjectArchive) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) AllArgsConstructor(lombok.AllArgsConstructor) Assert(org.junit.Assert) ReceiptGeneratorOperation(eu.ggnet.dwoss.receipt.ee.gen.ReceiptGeneratorOperation) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ToString(lombok.ToString) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Test(org.junit.Test)

Example 7 with LogicTransaction

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

the class RedTapeCloserOpertaionItBean method deleteStockUnit.

// delete Stockunit and logictransaction for specific stockunit
public void deleteStockUnit(int stockUnitId) {
    StockUnit unit = stockEm.find(StockUnit.class, stockUnitId);
    LogicTransaction transaction = stockEm.find(LogicTransaction.class, unit.getLogicTransaction().getId());
    stockEm.remove(unit);
    stockEm.remove(transaction);
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 8 with LogicTransaction

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

the class RedTapeOperationCapitalAssetCancelIT method testCancel.

@Test
public void testCancel() throws UserInfoException {
    UniqueUnit uu = receiptGenerator.makeUniqueUnit();
    uu.setPrice(CUSTOMER, 50., "JunitTestPrice");
    // Generate Dossier
    Dossier dos = redTapeWorker.create(capitalAssestCustomer, false, "Me");
    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());
    // Create Positions
    doc.append(NaivBuilderUtil.unit(uu));
    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());
    // Now Cancel it
    doc.add(Document.Condition.CANCELED);
    doc = redTapeWorker.update(doc, null, "tester");
    assertTrue("Document doesent contain the Condition Canceled " + doc, doc.getConditions().contains(Document.Condition.CANCELED));
    for (Position position : doc.getPositions(PositionType.UNIT).values()) {
        StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(position.getUniqueUnitId());
        assertNull(su + " should not have LogicTransaction", su.getLogicTransaction());
    }
}
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) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Date(java.util.Date)

Example 9 with LogicTransaction

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

the class LogicTransactionEmoIT method testEquilibrate.

@Test
public void testEquilibrate() throws Exception {
    L.info("starting test equilibrate");
    utx.begin();
    em.joinTransaction();
    Stock s = new Stock(0);
    s.setName("Test-0");
    L.debug("Persisted {}", s);
    em.persist(s);
    // StockEntityHelper.createOrUpdateMasterData(em);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    s = em.merge(s);
    L.debug("Merged {}", s);
    LogicTransaction logicTransaction = new LogicTransaction();
    LogicTransaction logicTransaction1 = new LogicTransaction();
    LogicTransaction logicTransaction2 = new LogicTransaction();
    StockUnit stockUnit1 = new StockUnit("Unit1", "Unit1", 1);
    StockUnit stockUnit2 = new StockUnit("Unit2", "Unit2", 2);
    StockUnit stockUnit3 = new StockUnit("Unit3", "Unit3", 3);
    StockUnit stockUnit4 = new StockUnit("Unit4", "Unit4", 4);
    StockUnit stockUnit5 = new StockUnit("Unit5", "Unit5", 5);
    StockUnit stockUnit6 = new StockUnit("Unit6", "Unit6", 6);
    StockUnit stockUnit7 = new StockUnit("Unit7", "Unit7", 7);
    StockUnit stockUnit8 = new StockUnit("Unit8", "Unit8", 8);
    stockUnit1.setStock(s);
    stockUnit2.setStock(s);
    stockUnit3.setStock(s);
    stockUnit4.setStock(s);
    stockUnit5.setStock(s);
    stockUnit6.setStock(s);
    stockUnit7.setStock(s);
    stockUnit8.setStock(s);
    logicTransaction.setDossierId(1l);
    logicTransaction1.setDossierId(1l);
    logicTransaction2.setDossierId(1l);
    em.persist(logicTransaction);
    em.persist(logicTransaction1);
    em.persist(logicTransaction2);
    em.persist(stockUnit1);
    em.persist(stockUnit2);
    em.persist(stockUnit3);
    em.persist(stockUnit4);
    em.persist(stockUnit5);
    em.persist(stockUnit6);
    em.persist(stockUnit7);
    em.persist(stockUnit8);
    logicTransaction.add(stockUnit1);
    logicTransaction.add(stockUnit2);
    logicTransaction1.add(stockUnit3);
    logicTransaction1.add(stockUnit4);
    logicTransaction2.add(stockUnit5);
    logicTransaction2.add(stockUnit6);
    L.debug("pre commit");
    utx.commit();
    L.debug("Post Commit");
    utx.begin();
    em.joinTransaction();
    LogicTransaction find = em.find(LogicTransaction.class, 1l);
    assertTrue("Size was not 2. find=" + find, find.getUnits().size() == 2);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit2 })));
    utx.commit();
    LogicTransactionEmo emo = new LogicTransactionEmo(em);
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(1l, Arrays.asList(new Integer[] { 1, 2, 7, 8 }));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = em.find(LogicTransaction.class, 1l);
    assertTrue("Size was not 4. find=" + find, find.getUnits().size() == 4);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit2, stockUnit7, stockUnit8 })));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(1l, Arrays.asList(new Integer[] { 1, 2, 8 }));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = em.find(LogicTransaction.class, 1l);
    assertTrue("Size was not 3. find=" + find, find.getUnits().size() == 3);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit2, stockUnit8 })));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(1l, Arrays.asList(new Integer[] { 1, 7, 8 }));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = em.find(LogicTransaction.class, 1l);
    assertTrue("Size was not 3. find=" + find, find.getUnits().size() == 3);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit7, stockUnit8 })));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(1l, Arrays.asList(new Integer[] {}));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = em.find(LogicTransaction.class, 1l);
    assertTrue("LT was not null. find=" + find, find == null);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(5l, Arrays.asList(new Integer[] { 1, 2, 7, 8 }));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = new LogicTransactionEao(em).findByDossierId(5l);
    assertTrue("LT was Null.", find != null);
    assertTrue("Size was not 4. find=" + find, find.getUnits().size() == 4);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit2, stockUnit7, stockUnit8 })));
    utx.commit();
    L.info("stopping test equilibrate");
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Example 10 with LogicTransaction

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

the class StockUnitEaoIT method testFindByNoLogicTransaction.

@Test
public void testFindByNoLogicTransaction() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s = new Stock(0, "TEEEEEEEEEEEEEEEEEEEEEst");
    em.persist(s);
    StockLocation sl = new StockLocation("Lagerplatz");
    s.addStockLocation(sl);
    StockUnit s1 = new StockUnit("G1", 1);
    StockUnit s2 = new StockUnit("G2", 2);
    StockUnit s3 = new StockUnit("G3", 3);
    StockUnit s4 = new StockUnit("G4", 4);
    s.addUnit(s1, sl);
    s.addUnit(s2, sl);
    s.addUnit(s3, sl);
    s.addUnit(s4, sl);
    em.persist(s);
    em.persist(new Stock(1, "teeeeeeeeeeest"));
    LogicTransaction lt = new LogicTransaction();
    lt.setDossierId(1);
    lt.add(s4);
    em.persist(lt);
    utx.commit();
    List<StockUnit> sts = sus.findByNoLogicTransaction();
    assertEquals(3, sts.size());
    List<Integer> uuids = sus.findByNoLogicTransactionAsUniqueUnitId();
    assertEquals(3, uuids.size());
}
Also used : StockLocation(eu.ggnet.dwoss.stock.ee.entity.StockLocation) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

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