Search in sources :

Example 16 with Position

use of eu.ggnet.dwoss.redtape.ee.entity.Position 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 17 with Position

use of eu.ggnet.dwoss.redtape.ee.entity.Position in project dwoss by gg-net.

the class PersistenceIT method example.

@Test
public void example() throws Exception {
    utx.begin();
    em.joinTransaction();
    Address addressOne = new Address("Test Straße 10, 123456 Testing");
    em.persist(addressOne);
    Dossier dos = new Dossier();
    dos.setComment("Ein Kommentar");
    dos.setCustomerId(10);
    dos.setPaymentMethod(PaymentMethod.DIRECT_DEBIT);
    Document doc = new Document();
    doc.add(Condition.PAID);
    doc.setActive(true);
    doc.setInvoiceAddress(addressOne);
    doc.setShippingAddress(addressOne);
    doc.setHistory(new DocumentHistory("Nutzer", "Bemerkung"));
    Position p = new PositionBuilder().type(PositionType.COMMENT).description("Comment").name("Comment").build();
    doc.append(p);
    doc.setDirective(Document.Directive.PREPARE_SHIPPING);
    dos.add(doc);
    em.persist(dos);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    Address addressTwo = new Address("Persistencstraße 42, 1337 PersistencTest");
    em.persist(addressTwo);
    addressOne = em.merge(addressOne);
    Dossier dossier = new Dossier();
    dossier.setComment("Das ist nun ein Weitere Kommentar");
    dossier.setCustomerId(12);
    dossier.setReminder(new Reminder(new Date(), new Date(), "Junit"));
    Document document = new Document();
    document.setActive(true);
    document.add(Condition.PAID);
    document.add(Condition.CONFIRMED);
    document.setInvoiceAddress(addressTwo);
    document.setShippingAddress(addressOne);
    document.setHistory(new DocumentHistory("Nutzer", "Bemerkung"));
    Position p1 = new PositionBuilder().type(PositionType.COMMENT).description("Kommentare über Kommentare").name("Kommentar").build();
    Position p2 = new PositionBuilder().type(PositionType.COMMENT).description("Noch mehr Kommentare").name("Kommentar").build();
    Position p3 = new PositionBuilder().type(PositionType.COMMENT).description("So das war aber der Letzte").name("Kommentar").build();
    document.append(p1);
    document.append(p2);
    document.append(p3);
    Document document1 = new Document();
    document1.setActive(false);
    document1.setInvoiceAddress(addressTwo);
    document1.setShippingAddress(addressOne);
    document1.setHistory(new DocumentHistory("Nutzer", "Bemerkung"));
    Position p4 = new PositionBuilder().type(PositionType.COMMENT).description("Ein zweites Doc mit Kommentaren").name("Kommentar").build();
    Position p5 = new PositionBuilder().type(PositionType.COMMENT).description("Was sind das für Kommentare").name("Kommentar").build();
    Position p6 = new PositionBuilder().type(PositionType.COMMENT).description("comment,comment.comment").name("Kommentar").build();
    document1.append(p4);
    document1.append(p5);
    document1.append(p6);
    document1.setDirective(Document.Directive.NONE);
    dossier.add(document1);
    em.persist(dossier);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    CriteriaQuery<Dossier> q = em.getCriteriaBuilder().createQuery(Dossier.class);
    List<Dossier> dossiers = em.createQuery(q.select(q.from(Dossier.class))).getResultList();
    PositionEao positionEao = new PositionEao(em);
    Logger L = LoggerFactory.getLogger(PersistenceIT.class);
    for (Dossier ds : dossiers) {
        L.info(ds.toMultiLine());
    }
    utx.commit();
}
Also used : PositionEao(eu.ggnet.dwoss.redtape.ee.eao.PositionEao) Reminder(eu.ggnet.dwoss.redtape.ee.entity.Reminder) Address(eu.ggnet.dwoss.redtape.ee.entity.Address) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) PositionBuilder(eu.ggnet.dwoss.redtape.ee.entity.PositionBuilder) Logger(org.slf4j.Logger) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Position

use of eu.ggnet.dwoss.redtape.ee.entity.Position in project dwoss by gg-net.

the class DocumentTest method testPartialCloneAndEqualsContent.

@Test
public void testPartialCloneAndEqualsContent() {
    Dossier dos = new Dossier();
    Address a1 = new Address("ShippingAddress");
    Address a2 = new Address("InvoiceAddress");
    Address a3 = new Address("Another ShippingAddress");
    Address a4 = new Address("Another InvoiceAddress");
    Document doc1 = new Document();
    doc1.setShippingAddress(a1);
    doc1.setInvoiceAddress(a2);
    doc1.setType(DocumentType.ORDER);
    doc1.add(Document.Flag.CUSTOMER_BRIEFED);
    dos.add(doc1);
    doc1.append(Position.builder().amount(1).type(PositionType.UNIT).build());
    // copy and test equality
    Document doc2 = doc1.partialClone();
    doc2.setDossier(dos);
    assertTrue("The following Documents are not equal:\n" + doc1 + "\n" + doc2, doc1.equalsContent(doc2));
    // add and remove positions with equality test
    Position p1 = doc2.append(Position.builder().amount(1).type(PositionType.UNIT).build());
    Position p2 = doc2.append(Position.builder().amount(1).type(PositionType.UNIT).build());
    assertFalse("Should not be equals, but is.\n- " + doc1 + "\n- " + doc2, doc1.equalsContent(doc2));
    doc2.remove(p1);
    doc2.remove(p2);
    assertTrue(doc1.equalsContent(doc2));
    // add and remove flags with equality test
    doc2.setClosed(true);
    assertFalse(doc1.equalsContent(doc2));
    doc2.setClosed(false);
    assertTrue(doc1.equalsContent(doc2));
    // change Document type
    doc2.setType(DocumentType.INVOICE);
    assertFalse(doc1.equalsContent(doc2));
    doc2.setType(DocumentType.ORDER);
    assertTrue(doc1.equalsContent(doc2));
    // change Tax Type
    doc2.setTaxType(TaxType.UNTAXED);
    assertFalse(doc1.equalsContent(doc2));
    doc2.setTaxType(TaxType.GENERAL_SALES_TAX_DE_SINCE_2007);
    assertTrue(doc1.equalsContent(doc2));
    // change addresses
    doc2.setShippingAddress(a3);
    doc2.setInvoiceAddress(a4);
    assertFalse(doc2.equalsContent(doc1));
    doc2.setShippingAddress(a1);
    doc2.setInvoiceAddress(a2);
    assertTrue(doc2.equalsContent(doc1));
}
Also used : Address(eu.ggnet.dwoss.redtape.ee.entity.Address) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) Test(org.junit.Test)

Example 19 with Position

use of eu.ggnet.dwoss.redtape.ee.entity.Position in project dwoss by gg-net.

the class DossierTest method testGetRelevantPositions.

@Test
public void testGetRelevantPositions() {
    Dossier dos1 = new Dossier();
    Document dos1Order = new Document(DocumentType.ORDER, Document.Directive.CREATE_INVOICE, null);
    dos1Order.setActive(true);
    Position p1 = new Position();
    p1.setUniqueUnitId(1);
    p1.setType(PositionType.UNIT);
    Position p2 = new Position();
    p2.setType(PositionType.COMMENT);
    dos1Order.appendAll(p1, p2);
    dos1.add(dos1Order);
    assertEquals(1, dos1.getRelevantUniqueUnitIds().size());
    Position p3 = new Position();
    p3.setUniqueUnitId(2);
    p3.setType(PositionType.UNIT);
    dos1Order.append(p3);
    Document dos1Invoice = dos1Order.partialClone();
    dos1Invoice.setActive(true);
    dos1Invoice.setType(DocumentType.INVOICE);
    dos1.add(dos1Invoice);
    assertTrue(dos1.getRelevantUniqueUnitIds().containsAll(Arrays.asList(new Integer[] { 1, 2 })));
    Document dos1CreditMemo = new Document(DocumentType.CREDIT_MEMO, Document.Directive.BALANCE_REPAYMENT, null);
    dos1CreditMemo.setActive(true);
    dos1CreditMemo.append(p3.partialClone());
    dos1.add(dos1CreditMemo);
    assertEquals("Size should be 1", 1, dos1.getRelevantUniqueUnitIds().size());
    assertTrue("UniqueUnitId 1 should be in the list", dos1.getRelevantUniqueUnitIds().contains(1));
    Dossier dos2 = new Dossier();
    Document blocker = new Document(DocumentType.BLOCK, Document.Directive.NONE, null);
    blocker.setActive(true);
    Position pb1 = new Position();
    pb1.setUniqueUnitId(1);
    pb1.setType(PositionType.UNIT);
    Position pb2 = new Position();
    pb2.setUniqueUnitId(2);
    pb2.setType(PositionType.UNIT);
    Position pb3 = new Position();
    pb3.setUniqueUnitId(3);
    pb3.setType(PositionType.UNIT);
    Position pb4 = new Position();
    pb4.setUniqueUnitId(4);
    pb4.setType(PositionType.UNIT);
    Position pb5 = new Position();
    pb5.setUniqueUnitId(5);
    pb5.setType(PositionType.UNIT);
    blocker.appendAll(pb1, pb2, pb3, pb4, pb5);
    dos2.add(blocker);
    assertTrue("UnitId 1,2,3,4,5 should be in the list", dos2.getRelevantUniqueUnitIds().containsAll(Arrays.asList(new Integer[] { 1, 2, 3, 4, 5 })));
    pb5.setType(PositionType.SERVICE);
    assertTrue("UnitId 1,2,3,4 should be in the list", dos2.getRelevantUniqueUnitIds().containsAll(Arrays.asList(new Integer[] { 1, 2, 3, 4 })));
}
Also used : Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) Test(org.junit.Test)

Example 20 with Position

use of eu.ggnet.dwoss.redtape.ee.entity.Position in project dwoss by gg-net.

the class DocumentEquals method equalsMessage.

/**
 * Checks if two documents are not equal returning a string containing the message what is not equal or null.
 *
 * @param d1 Document one
 * @param d2 Document two
 * @return null if equal or a string describing the difference.
 */
public String equalsMessage(Document d1, Document d2) {
    if (d1 == null)
        return "d1 is null";
    if (d2 == null)
        return "d2 is null";
    if (properties.contains(SETTLEMENTS))
        if (!Objects.equals(d1.getSettlements(), d2.getSettlements()))
            return "Settlements are not equal, d1=" + d1.getSettlements() + ", d2=" + d2.getSettlements();
    if (properties.contains(ACTUAL)) {
        if (d1.getActual() == null && d2.getActual() != null)
            return "Actual is not equal, d1=" + d1.getActual() + ", d2=" + d2.getActual();
        if (d1.getActual() != null && d2.getActual() == null)
            return "Actual is not equal, d1=" + d1.getActual() + ", d2=" + d2.getActual();
        if (!DateUtils.isSameDay(d1.getActual(), d2.getActual()))
            return "Actual is not equal, d1=" + d1.getActual() + ", d2=" + d2.getActual();
    }
    if (properties.contains(IDENTIFIER))
        if (!Objects.equals(d1.getIdentifier(), d2.getIdentifier()))
            return "Identifier is not equal, d1=" + d1.getIdentifier() + ", d2=" + d2.getIdentifier();
    if (properties.contains(CONDITIONS))
        if (!Objects.equals(d1.getConditions(), d2.getConditions()))
            return "Conditions are not equal, d1=" + d1.getConditions() + ", d2=" + d2.getConditions();
    if (properties.contains(TYPE))
        if (d1.getType() != d2.getType())
            return "Type is not equal, d1=" + d1.getType() + ", d2=" + d2.getType();
    if (properties.contains(DOSSIER))
        if (!d1.getDossier().equals(d2.getDossier()))
            return "Dossier is not equal, d1=" + d1.getDossier() + ", d2=" + d2.getDossier();
    if (properties.contains(ID))
        if (d1.getId() != d2.getId())
            return "Id is not equal, d1=" + d1.getId() + ", d2=" + d2.getId();
    if (properties.contains(ACTIVE))
        if (d1.isActive() != d2.isActive())
            return "Active is not equal, d1=" + d1.isActive() + ", d2=" + d2.isActive();
    if (properties.contains(HISTORY))
        if (!Objects.equals(d1.getHistory(), d2.getHistory()))
            return "History is not equal, d1=" + d1.getHistory() + ", d2=" + d2.getHistory();
    if (properties.contains(PREDECESSOR))
        if (!Objects.equals(d1.getPredecessor(), d2.getPredecessor()))
            return "Predecessor is not equal, d1=" + d1.getPredecessor() + ", d2=" + d2.getPredecessor();
    if (properties.contains(FLAGS))
        if (!Objects.equals(d1.getFlags(), d2.getFlags()))
            return "Flags is not equal, d1=" + d1.getFlags() + ", d2=" + d2.getFlags();
    if (properties.contains(DIRECTIVE))
        if (d1.getDirective() != d2.getDirective())
            return "Directive is not equal, d1=" + d1.getDirective() + ", d2=" + d2.getDirective();
    if (properties.contains(INVOICE_ADDRESS))
        if (!Objects.equals(d1.getInvoiceAddress(), d2.getInvoiceAddress()))
            return "Invoiceaddress is not equal, d1=" + d1.getInvoiceAddress() + ", d2=" + d2.getInvoiceAddress();
    if (properties.contains(SHIPPING_ADDRESS))
        if (!Objects.equals(d1.getShippingAddress(), d2.getShippingAddress()))
            return "Shippingaddress is not equal, d1=" + d1.getShippingAddress() + ", d2=" + d2.getShippingAddress();
    if (properties.contains(CLOSED))
        if (d1.isClosed() != d2.isClosed())
            return "Closed is not equal, d1=" + d1.isClosed() + ", d2=" + d2.isClosed();
    if (properties.contains(TAXTYPE))
        if (d1.getTaxType() != d2.getTaxType())
            return "TaxType is not equal, d1=" + d1.getTaxType() + ", d2=" + d2.getTaxType();
    if (positionTypes.size() == PositionType.values().length)
        if (d1.getPositions().size() != d2.getPositions().size())
            return "Positions.size is not equal, d1=" + d1.getPositions().size() + ", d2=" + d2.getPositions().size();
    if (positionTypes.size() == PositionType.values().length && positionOrder) {
        Iterator<Position> p1 = new TreeSet<>(d1.getPositions().values()).iterator();
        Iterator<Position> p2 = new TreeSet<>(d2.getPositions().values()).iterator();
        while (p1.hasNext()) {
            Position p1p = p1.next();
            Position p2p = p2.next();
            if (!p1p.equalsContent(p2p))
                return "Positions are not equal d1=" + p1p + ", d2=" + p2p;
        }
    } else {
        List<Position> d1Poss = new ArrayList<>();
        List<Position> d2Poss = new ArrayList<>();
        for (Position pos : d1.getPositions().values()) {
            if (positionTypes.contains(pos.getType()))
                d1Poss.add(pos);
        }
        for (Position pos : d2.getPositions().values()) {
            if (positionTypes.contains(pos.getType()))
                d2Poss.add(pos);
        }
        if (d1Poss.size() != d2Poss.size())
            return "Posistions subSiz is not equal d1=" + d1Poss.size() + ", d2=" + d2Poss.size() + ", evaluating only types " + positionTypes;
        for (Position pos1 : d1Poss) {
            boolean existAndIsEqual = false;
            for (Position pos2 : d2Poss) {
                if (pos1.equalsContentWithoutId(pos2))
                    existAndIsEqual = true;
            }
            if (!existAndIsEqual)
                return "Subpositions are not equal d1=" + d1Poss + ", d2=" + d2Poss;
        }
    }
    return null;
}
Also used : Position(eu.ggnet.dwoss.redtape.ee.entity.Position)

Aggregations

Position (eu.ggnet.dwoss.redtape.ee.entity.Position)37 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)23 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)11 Test (org.junit.Test)8 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)6 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)5 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)5 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)5 OkCancelDialog (eu.ggnet.dwoss.util.OkCancelDialog)5 RedTapeWorker (eu.ggnet.dwoss.redtapext.ee.RedTapeWorker)4 AfterInvoicePosition (eu.ggnet.dwoss.redtapext.ui.cao.document.AfterInvoicePosition)4 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)4 CreditMemoView (eu.ggnet.dwoss.redtapext.ui.cao.document.annulation.CreditMemoView)3 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)3 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)3 UNIT (eu.ggnet.dwoss.rules.PositionType.UNIT)3 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)3 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)3 Logger (org.slf4j.Logger)3 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)2