Search in sources :

Example 1 with ReportLineEao

use of eu.ggnet.dwoss.report.ee.eao.ReportLineEao in project dwoss by gg-net.

the class RedTapeCloserOperation method poluteReporting.

/**
 * Actually creating reportLines from the reportable documents.
 * For each position of a {@link Document} a {@link ReportLine} is created with all information supplied.
 * <p>
 * Exceptions are:
 * <ul>
 * <li>A {@link Document} with a {@link Condition#CANCELED} which is silently ignored</li>
 * <li>A {@link Document} with a {@link DocumentType#COMPLAINT} which sets all prices on the {@link ReportLine} to 0 and
 * <ul>
 * <li>If the {@link Document} has the {@link Condition#WITHDRAWN} or {@link Condition#REJECTED}, set {@link ReportLine#workflowStatus} to
 * {@link ReportLine.WorkflowStatus#DISCHARGED}</li>
 * <li>If the {@link Document} has the {@link Condition#ACCEPTED}, set {@link ReportLine#workflowStatus} to
 * {@link ReportLine.WorkflowStatus#CHARGED}</li>
 * <li>Otherwise set {@link ReportLine#workflowStatus} to {@link ReportLine.WorkflowStatus#UNDER_PROGRESS}</li>
 * </ul>
 * </li>
 * <li>A {@link Document} with a {@link DocumentType#CREDIT_MEMO} gets its prices inverted</li>
 * </ul>
 * <p/>
 * @param reportable the documents to create lines from
 * @param monitor    a optional monitor.
 * @return the amount of created lines.
 */
private int poluteReporting(Set<Document> reportable, Date reporting, IMonitor monitor) {
    WarrantyService warrantyService = null;
    if (!warrantyServiceInstance.isUnsatisfied()) {
        warrantyService = warrantyServiceInstance.get();
    }
    SubMonitor m = SubMonitor.convert(monitor, reportable.size() + 10);
    m.start();
    ReportLineEao reportLineEao = new ReportLineEao(reportEm);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    ProductEao productEao = new ProductEao(uuEm);
    int amountCreate = 0;
    List<ReportLine> newLines = new ArrayList<>(reportable.size());
    for (Document document : reportable) {
        m.worked(1, "reported " + document.getIdentifier());
        // A canceled document must be closed, but must not create a reportline.
        if (document.getConditions().contains(Condition.CANCELED))
            continue;
        ReportLine l;
        for (Position position : document.getPositions().values()) {
            amountCreate++;
            l = new ReportLine();
            l.setActual(document.getActual());
            l.setAmount(position.getAmount());
            l.setBookingAccount(position.getBookingAccount().map(Ledger::getValue).orElse(-1));
            l.setCustomerId(document.getDossier().getCustomerId());
            l.setDescription(normalizeSpace(position.getDescription()));
            l.setDocumentId(document.getId());
            l.setDocumentIdentifier(document.getIdentifier());
            l.setDocumentType(document.getType());
            l.setDossierId(document.getDossier().getId());
            l.setDossierIdentifier(document.getDossier().getIdentifier());
            // TODO: We could use something else for a separator, but keep in mind that we want to avoid name, , , something.
            l.setInvoiceAddress(normalizeSpace(document.getInvoiceAddress().getDescription()));
            l.setName(normalizeSpace(position.getName()));
            l.setPositionType(position.getType());
            l.setPrice(position.getPrice());
            l.setReportingDate(reporting);
            l.setTax(position.getTax());
            // Set via Report afterwards
            l.setMarginPercentage(0);
            // Set via Report afterwards
            l.setPurchasePrice(0);
            UiCustomer c = customerService.asUiCustomer(document.getDossier().getCustomerId());
            if (c != null) {
                l.setCustomerCompany(c.getCompany());
                l.setCustomerName(c.toTitleNameLine());
                l.setCustomerEmail(c.getEmail());
            }
            // A Credit Memo gets its prices inverted
            if (document.getType() == DocumentType.CREDIT_MEMO) {
                l.setPrice(position.getPrice() * (-1));
            }
            // Special handling of complaints.
            if (document.getType() == DocumentType.COMPLAINT) {
                // A Complaint position has "tagging" effect, but shall never result in a plus or minus.
                l.setPrice(0);
                if (document.getConditions().contains(Condition.REJECTED) || document.getConditions().contains(Condition.WITHDRAWN)) {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.DISCHARGED);
                } else if (document.getConditions().contains(Condition.ACCEPTED)) {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.CHARGED);
                } else {
                    l.setWorkflowStatus(ReportLine.WorkflowStatus.UNDER_PROGRESS);
                }
            }
            // Extra information for Type Position
            if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
                UniqueUnit uu = Objects.requireNonNull(uniqueUnitEao.findById(position.getUniqueUnitId()), "No UniqueUnit with id=" + position.getUniqueUnitId());
                Product p = uu.getProduct();
                if (uu.getContractor() == p.getTradeName().getManufacturer()) {
                    l.setContractorPartNo(p.getPartNo());
                    l.setContractorReferencePrice(p.getPrice(MANUFACTURER_COST));
                } else {
                    l.setContractorPartNo(p.getAdditionalPartNo(uu.getContractor()));
                    l.setContractorReferencePrice(p.getPrice(CONTRACTOR_REFERENCE));
                }
                l.setManufacturerCostPrice(p.getPrice(MANUFACTURER_COST));
                l.setContractor(uu.getContractor());
                l.setContractorReferencePrice(p.getPrice(CONTRACTOR_REFERENCE));
                if (Math.abs(l.getContractorReferencePrice()) < 0.001)
                    l.setContractorReferencePrice(p.getPrice(MANUFACTURER_COST));
                l.setMfgDate(uu.getMfgDate());
                l.setRefurbishId(uu.getRefurbishId());
                l.setSerial(uu.getSerial());
                l.setUniqueUnitId(uu.getId());
                l.setSalesChannel(uu.getSalesChannel());
                l.setPartNo(p.getPartNo());
                l.setProductBrand(p.getTradeName());
                l.setProductName(p.getName());
                l.setProductGroup(p.getGroup());
                l.setProductId(p.getId());
                l.setGtin(p.getGtin());
            // Extra Information for Type Product Batch
            } else if (position.getType() == PositionType.PRODUCT_BATCH) {
                Product p = Objects.requireNonNull(productEao.findById(position.getUniqueUnitProductId()), "No Product for id=" + position.getUniqueUnitProductId());
                l.setPartNo(p.getPartNo());
                l.setProductBrand(p.getTradeName());
                l.setProductGroup(p.getGroup());
                l.setProductName(p.getName());
                l.setProductId(p.getId());
                l.setGtin(p.getGtin());
                l.setUniqueUnitId(position.getUniqueUnitId());
                l.setSerial(position.getSerial());
                l.setRefurbishId(position.getRefurbishedId());
                if (warrantyService != null) {
                    // If this is no warranty Partno, this will return null ;-)
                    l.setContractor(warrantyService.warrantyContractor(p.getPartNo()));
                }
            }
            reportEm.persist(l);
            newLines.add(l);
        }
    }
    reportEm.flush();
    m.message("Updateing References");
    for (ReportLine newLine : newLines) {
        // Not Refs for Product_Batches or Versandkosten jet.
        if (newLine.getUniqueUnitId() < 1)
            continue;
        if (newLine.getPositionType() == PositionType.PRODUCT_BATCH) {
            // TODO: also evaluate the productId.
            newLine.addAll(reportLineEao.findBySerialAndPositionTypeAndDossierId(newLine.getSerial(), newLine.getPositionType(), newLine.getDossierId()));
        } else {
            newLine.addAll(reportLineEao.findUnitsAlike(newLine.getUniqueUnitId(), newLine.getDossierId()));
        }
    }
    updateSingleReferences(newLines);
    m.worked(5);
    m.finish();
    return amountCreate;
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) WarrantyService(eu.ggnet.dwoss.mandator.api.service.WarrantyService) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer)

Example 2 with ReportLineEao

use of eu.ggnet.dwoss.report.ee.eao.ReportLineEao in project dwoss by gg-net.

the class ReportLineEaoIT method testFindByUniqueUnitId.

@Test
public void testFindByUniqueUnitId() throws Exception {
    String ISO = "yyyy-MM-dd";
    Date d1 = DateUtils.parseDate("2010-01-01", ISO);
    ReportLine line1 = new ReportLine("PersName1", "This is a TestDescription1", 137, "DW0037", 3, "RE0008", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
    line1.setReportingDate(DateUtils.parseDate("2009-01-01", ISO));
    line1.setUniqueUnitId(10);
    ReportLine line2 = new ReportLine("PersName2", "This is a TestDescription2", 1337, "DW0013", 3, "RE001", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
    line2.setReportingDate(DateUtils.parseDate("2009-07-10", ISO));
    line2.setUniqueUnitId(10);
    ReportLine line3 = new ReportLine("PersName3", "This is a TestDescription3", 13, "DW1337", 3, "RE0003", PositionType.UNIT, DocumentType.INVOICE, 2, 1, 0.19, 100, 37, "This is the Invoice Address", "123", 2, "SERIALNUMBER", new Date(), 3, "PArtNo", "test@gg-net.de");
    line3.setReportingDate(d1);
    utx.begin();
    em.joinTransaction();
    em.persist(line1);
    em.persist(line2);
    em.persist(line3);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    List<ReportLine> rls = new ReportLineEao(em).findByUniqueUnitId(10);
    assertEquals(2, rls.size());
    rls = new ReportLineEao(em).findByUniqueUnitId(1);
    assertTrue(rls.isEmpty());
    utx.commit();
}
Also used : ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) DateUtils.parseDate(org.apache.commons.lang3.time.DateUtils.parseDate) Test(org.junit.Test)

Example 3 with ReportLineEao

use of eu.ggnet.dwoss.report.ee.eao.ReportLineEao in project dwoss by gg-net.

the class ReportLineEaoIT method testFindProductIdMissingContractorPartNo.

@Test
public void testFindProductIdMissingContractorPartNo() throws Exception {
    utx.begin();
    em.joinTransaction();
    final Random R = new Random();
    final long PRODUCT_ID = 10;
    final TradeName CONTRACTOR = HP;
    // Different contarctor and productId
    em.persist(make(DELL, PRODUCT_ID + 5, null));
    // Different contarctor
    em.persist(make(DELL, PRODUCT_ID, null));
    // Different productId
    em.persist(make(CONTRACTOR, PRODUCT_ID + 5, null));
    // has already a contracotrPartNo
    em.persist(make(CONTRACTOR, PRODUCT_ID, "123556"));
    // Two matching Lines
    ReportLine l1 = make(CONTRACTOR, PRODUCT_ID, null);
    ReportLine l2 = make(CONTRACTOR, PRODUCT_ID, null);
    em.persist(l1);
    em.persist(l2);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    List<ReportLine> missing = new ReportLineEao(em).findByProductIdMissingContractorPartNo(PRODUCT_ID, CONTRACTOR);
    assertEquals(2, missing.size());
    assertTrue(missing.contains(l1));
    assertTrue(missing.contains(l2));
    utx.commit();
}
Also used : TradeName(eu.ggnet.dwoss.rules.TradeName) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) Test(org.junit.Test)

Example 4 with ReportLineEao

use of eu.ggnet.dwoss.report.ee.eao.ReportLineEao in project dwoss by gg-net.

the class ReportLineEaoIT method testFindUnreported.

@Test
public void testFindUnreported() throws Exception {
    utx.begin();
    em.joinTransaction();
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startEarly, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startMid, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startMid, 7, Arrays.asList(PositionType.COMMENT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startFuture, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 50; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.HP), startMid, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startMid, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
        Report r = new Report("Report Test " + l.getId(), DELL, DateUtils.addDays(l.getReportingDate(), -1), DateUtils.addDays(l.getReportingDate(), 1));
        r.add(l);
        em.persist(r);
    }
    utx.commit();
    utx.begin();
    em.joinTransaction();
    List<ReportLine> rls = new ReportLineEao(em).findUnreported(DELL, DateFormats.ISO.parse("2012-01-14"), DateFormats.ISO.parse("2012-01-27"));
    // Units, Comments, ShipmentCost
    assertEquals(600, rls.size());
    rls = new ReportLineEao(em).findUnreported(DELL, DateFormats.ISO.parse("2012-01-14"), DateFormats.ISO.parse("2012-01-27"), PositionType.UNIT, PositionType.UNIT_ANNEX);
    assertEquals(300, rls.size());
    utx.commit();
}
Also used : ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) Test(org.junit.Test)

Example 5 with ReportLineEao

use of eu.ggnet.dwoss.report.ee.eao.ReportLineEao in project dwoss by gg-net.

the class ReportLineEaoIT method testFindLastReported.

@Test
public void testFindLastReported() throws Exception {
    utx.begin();
    em.joinTransaction();
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startEarly, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startMid, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startMid, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startFuture, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 50; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.HP), startMid, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
    }
    for (int i = 0; i < 300; i++) {
        ReportLine l = generator.makeReportLine(Arrays.asList(TradeName.DELL), startMid, 7, Arrays.asList(PositionType.UNIT), Arrays.asList(DocumentType.INVOICE));
        em.persist(l);
        Report r = new Report("Report Test " + l.getId(), DELL, addDays(l.getReportingDate(), -1), addDays(l.getReportingDate(), 1));
        r.add(l);
        em.persist(r);
    }
    utx.commit();
    Date max = DateFormats.ISO.parse("2012-01-20");
    utx.begin();
    em.joinTransaction();
    Date d2 = new ReportLineEao(em).findLastReported();
    assertTrue("Date " + d2 + " is not the expected " + max, DateUtils.isSameDay(max, d2));
    utx.commit();
}
Also used : ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) DateUtils.parseDate(org.apache.commons.lang3.time.DateUtils.parseDate) Test(org.junit.Test)

Aggregations

ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)11 Test (org.junit.Test)8 SimpleReportLine (eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine)7 DateUtils.parseDate (org.apache.commons.lang3.time.DateUtils.parseDate)4 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)3 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)2 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)2 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)2 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)1 WarrantyService (eu.ggnet.dwoss.mandator.api.service.WarrantyService)1 Ledger (eu.ggnet.dwoss.mandator.api.value.Ledger)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)1 Revenue (eu.ggnet.dwoss.report.ee.eao.Revenue)1 TradeName (eu.ggnet.dwoss.rules.TradeName)1 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)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 UniqueUnitHistory (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnitHistory)1