Search in sources :

Example 36 with ReportLine

use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.

the class ResolveRepaymentBeanITHelper method generateLines.

public void generateLines(int amount) {
    for (int i = 0; i < amount; i++) {
        ReportLine makeReportLine = generator.makeReportLine(Arrays.asList(TradeName.AMAZON), DateUtils.addDays(new Date(), -30), 25);
        makeReportLine.setPositionType(PositionType.UNIT);
        makeReportLine.setDocumentType(DocumentType.ANNULATION_INVOICE);
        reportLineEao.getEntityManager().persist(makeReportLine);
    }
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Date(java.util.Date)

Example 37 with ReportLine

use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.

the class ContractorPricePartNoImporterOperation method fromContractorXls.

// Manufacturer PartNo | EAN | Name | Contractor Reference Price | ContractorPartNo <br />
/**
 * See {@link ContractorPricePartNoImporter#fromContractorXls(de.dw.rules.TradeName, de.dw.util.FileJacket, java.lang.String) }.
 * <p/>
 * @param inFile   the inFile
 * @param arranger the arranger
 * @return
 */
@Override
public Reply<Void> fromContractorXls(TradeName contractor, FileJacket inFile, String arranger) {
    final SubMonitor m = monitorFactory.newSubMonitor(contractor + " Preise und Artikelnummern importieren", 100);
    m.start();
    m.message("Reading File");
    ProductEao productEao = new ProductEao(uuEm);
    ReportLineEao reportLineEao = new ReportLineEao(reportEm);
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class).addColumn(1, String.class).addColumn(2, String.class).addColumn(3, Double.class).addColumn(4, String.class);
    List<ContractorImport> imports = reader.read(inFile.toTemporaryFile(), ContractorImport.class);
    List<String> errors = reader.getErrors();
    List<String> info = new ArrayList<>();
    // here for size, needed down below
    List<ReportLine> missingContractorPartNo = reportLineEao.findMissingContractorPartNo(contractor);
    m.worked(5);
    m.setWorkRemaining((int) (imports.size() + imports.size() * 0.5 + missingContractorPartNo.size()));
    int databaseLines = 0;
    int updatedGtin = 0;
    int newPrices = 0;
    int updatedPrices = 0;
    int updatedContractorPartNo = 0;
    Map<Product, SortedSet<ContractorImport>> importable = new HashMap<>();
    for (ContractorImport ci : imports) {
        m.worked(1, "Preparing and Sorting (" + ci.manufacturerPartNo + ")");
        if (!ci.hasManufacturerPartNoOrGtin()) {
            errors.add("No ManufacturerPartNo or EAN found for " + ci);
            continue;
        }
        Product p = null;
        // First, try finding it via gtin
        if (ci.hasValidGtin())
            p = productEao.findByGtin(Long.parseLong(ci.gtin));
        // Second try finding it via the partNo field raw
        if (p == null && !StringUtils.isBlank(ci.manufacturerPartNo))
            p = productEao.findByPartNo(ci.manufacturerPartNo);
        if (p == null) {
            // Third, try it by regex matching of part no patterns
            // Todo: implement more partno patterns an use them here, or add the type of import to this method.
            Matcher matcher = AcerRules.PART_NO_PATTERN.matcher(ci.manufacturerPartNo);
            if (matcher.find())
                p = productEao.findByPartNo(matcher.group());
        }
        if (p == null) {
            errors.add("No UniqueUnit.Product Entity found for PartNo " + ci.manufacturerPartNo + " bzw. Gtin " + ci.gtin + ", Ignoring");
            continue;
        }
        databaseLines++;
        if (importable.containsKey(p)) {
            // sorting based on product
            importable.get(p).add(ci);
        } else {
            SortedSet<ContractorImport> set = new TreeSet<>(Comparator.comparing(ContractorImport::getReferencePrice));
            set.add(ci);
            importable.put(p, set);
        }
    }
    // update size
    m.setWorkRemaining(missingContractorPartNo.size() + importable.size());
    for (Entry<Product, SortedSet<ContractorImport>> entry : importable.entrySet()) {
        Product p = entry.getKey();
        // only us the importline with the lowest price.
        ContractorImport ci = entry.getValue().first();
        m.worked(1, "Importing " + ProductFormater.toDetailedName(p));
        if (p.getGtin() == 0 && ci.hasValidGtin()) {
            // Optional set of gtin, if it is missing.
            p.setGtin(Long.parseLong(ci.gtin));
            updatedGtin++;
        }
        if (ci.getReferencePrice() > 0.01 && !TwoDigits.equals(p.getPrice(CONTRACTOR_REFERENCE), ci.getReferencePrice())) {
            // If price is valid and not equal, set it.
            double oldPrice = p.getPrice(CONTRACTOR_REFERENCE);
            if (p.hasPrice(CONTRACTOR_REFERENCE))
                updatedPrices++;
            else
                newPrices++;
            p.setPrice(CONTRACTOR_REFERENCE, ci.getReferencePrice(), "Import by " + arranger);
            info.add(ProductFormater.toDetailedName(p) + " added/updated contractor reference price from " + oldPrice + " to " + ci.getReferencePrice());
        } else {
            errors.add(ci + " hat keinen Preis");
        }
        if (ci.hasValidContractorPartNo(contractor)) {
            // If partNo is valid, set it.
            String contractorPartNo = ci.toNormalizeContractorPart(contractor);
            if (!contractorPartNo.equals(p.getAdditionalPartNo(contractor))) {
                info.add(ProductFormater.toDetailedName(p) + " added/updated contractor partno from " + p.getAdditionalPartNo(contractor) + " to " + contractorPartNo);
                p.setAdditionalPartNo(contractor, contractorPartNo);
                updatedContractorPartNo++;
            }
        } else {
            errors.add(ci.violationMessagesOfContractorPartNo(contractor));
        }
    }
    uuEm.flush();
    // Also update existing report lines, which have unset values.
    // TODO: This should happen from the report component on needed basis or as event call. not here.
    m.message("Updateing existing Reportlines");
    int updatedReportLinePartNo = 0;
    int updatedReportLineReferencePrice = 0;
    int updatedReportLineGtin = 0;
    for (ReportLine line : missingContractorPartNo) {
        Product product = uuEm.find(Product.class, line.getProductId());
        m.worked(1, "Updating ReportLine: " + line.getId());
        String head = "ReportLine(id=" + line.getId() + ") of " + ProductFormater.toDetailedName(product);
        String msg = "";
        if (product.getAdditionalPartNo(contractor) != null) {
            line.setContractorPartNo(product.getAdditionalPartNo(contractor));
            msg += " contractorPartNo:" + line.getContractorPartNo();
            updatedReportLinePartNo++;
        }
        if (product.hasPrice(CONTRACTOR_REFERENCE) && line.getContractorReferencePrice() == 0) {
            line.setContractorReferencePrice(product.getPrice(CONTRACTOR_REFERENCE));
            msg += " contractorReferencePrice:" + line.getContractorReferencePrice();
            updatedReportLineReferencePrice++;
        }
        if (product.getGtin() != line.getGtin()) {
            line.setGtin(product.getGtin());
            msg += " gtin:" + line.getGtin();
            updatedReportLineGtin++;
        }
        if (StringUtils.isBlank(msg)) {
            errors.add(head + ", no updateable values found in product.");
        } else {
            info.add(head + " updated " + msg);
        }
    }
    String summary = "Zeilen, mit gefunden (db)Artikeln: " + databaseLines + " (Entweder über PartNo oder Gtin)\n" + "GTIN/EAN aktuallisiert: " + updatedGtin + "\n" + "Neue Preise hinterlegt: " + newPrices + "\n" + "Preise aktualisiert: " + updatedPrices + "\n" + "Lieferantenartikelnummer aktualisiert: " + updatedContractorPartNo + "\n" + "Report-Fehlende GTIN/Preise/Artikelnummern Zeilen: " + missingContractorPartNo.size() + "\n" + "Report-GTIN/EAN aktuallisiert: " + updatedReportLineGtin + "\n" + "Report-Preise aktualisiert: " + updatedReportLineReferencePrice + "\n" + "Report-Lieferantenartikelnummer aktualisiert: " + updatedReportLinePartNo;
    StringBuilder details = new StringBuilder();
    if (!info.isEmpty()) {
        details.append("Infos\n-----\n");
        info.forEach((i) -> details.append(i).append("\n"));
    }
    details.append("-----------------\nFehler/Nicht importierbar\n-----------------\n");
    errors.forEach((error) -> details.append(error).append("\n"));
    m.finish();
    if (updatedGtin + newPrices + updatedPrices + updatedContractorPartNo == 0)
        return Reply.failure(summary, details.toString());
    else
        return Reply.success(null, summary, details.toString());
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Matcher(java.util.regex.Matcher) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader)

Example 38 with ReportLine

use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.

the class ReportTest method testRepaymentThreeReports.

@Test
public void testRepaymentThreeReports() {
    Report report1 = new Report("TestReport 1", ALSO, NOW, NOW);
    Report report2 = new Report("TestReport 2", ALSO, NOW, NOW);
    Report report3 = new Report("TestReport 3", ALSO, NOW, NOW);
    ReportLine line1 = ReportLine.builder().documentType(DocumentType.INVOICE).documentId(1).dossierId(1).customerId(1).positionType(PositionType.UNIT).name("Unit-123").refurbishId("123").amount(1).price(100).tax(0.19).build();
    report1.add(line1);
    // Creditmemo unitAnnex.
    ReportLine line2 = ReportLine.builder().documentType(DocumentType.ANNULATION_INVOICE).documentId(2).dossierId(1).customerId(1).positionType(PositionType.UNIT_ANNEX).name("Unit-123").refurbishId("123").amount(1).price(-10).tax(0.19).build();
    line1.add(line2);
    report2.add(line2);
    // Now add A Unit.
    ReportLine line3 = ReportLine.builder().documentType(DocumentType.ANNULATION_INVOICE).documentId(3).dossierId(1).customerId(1).positionType(PositionType.UNIT).name("Unit-123").refurbishId("123").amount(1).price(-90).tax(0.19).build();
    line1.add(line3);
    line2.add(line3);
    report3.add(line3);
    assertTrue("Report1 should only contain line1 of invoice\n" + report1.toMultiLine(false) + report2.toMultiLine(false) + report3.toMultiLine(false), report1.filterInvoiced().size() == 1 && report1.filterInvoiced().contains(line1) && report1.filterInfos().isEmpty() && report1.filterRepayed().isEmpty());
    assertTrue("Report2 should only contaion line2 of partial repayment\n" + report1.toMultiLine(false) + report2.toMultiLine(false) + report3.toMultiLine(false), report2.filterInvoiced().isEmpty() && report2.filterInfos().isEmpty() && report2.filterRepayed().size() == 1 && report2.filterRepayed().contains(line2));
    assertTrue("Report3 should only contaion line3 of full repayment\n" + report1.toMultiLine(false) + report2.toMultiLine(false) + report3.toMultiLine(false), report3.filterInvoiced().isEmpty() && report3.filterInfos().isEmpty() && report3.filterRepayed().size() == 1 && report3.filterRepayed().contains(line3));
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Report(eu.ggnet.dwoss.report.ee.entity.Report) Test(org.junit.Test)

Example 39 with ReportLine

use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.

the class ReportUtilTest method testFilterInvoiceSplit.

@Test
public void testFilterInvoiceSplit() {
    List<ReportLine> lines = new ArrayList<>();
    // One invoice with mfg date today and one with mfg date two years in the past
    lines.add(makeUnitReportLine(now, 0, INVOICE));
    lines.add(makeUnitReportLine(DateUtils.addYears(now, -2), lines.get(0).getDossierId(), INVOICE));
    // Test if the year split is working correctly
    YearSplit split = ReportUtil.filterInvoicedSplit(lines, now);
    assertThat(split.getBefore(), hasItem(lines.get(0)));
    assertTrue("Expect DW0002 to be present but was: " + out(split.getBefore()), split.getBefore().contains(lines.get(0)));
    assertTrue("Expect DW0001 to be present but was: " + out(split.getAfter()), split.getAfter().contains(lines.get(1)));
}
Also used : YearSplit(eu.ggnet.dwoss.report.ee.entity.Report.YearSplit) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Test(org.junit.Test)

Example 40 with ReportLine

use of eu.ggnet.dwoss.report.ee.entity.ReportLine in project dwoss by gg-net.

the class ReportUtilTest method testFilterReportInfo.

@Test
public void testFilterReportInfo() {
    List<ReportLine> lines = new ArrayList<>();
    lines.add(makeUnitReportLine(now, 0, CAPITAL_ASSET));
    lines.add(makeUnitReportLine(now, 1, INVOICE));
    lines.add(makeUnitReportLine(now, 2, COMPLAINT));
    // annulation line wich references a invoice line in another report
    ReportLine invoice = makeUnitReportLine(now, 3, INVOICE);
    lines.add(annulationForInvoice(invoice, false));
    // annulation line wich references a invoice line in the same report
    ReportLine invoice2 = makeUnitReportLine(now, 4, INVOICE);
    lines.add(invoice2);
    lines.add(annulationForInvoice(invoice2, false));
    Set filtered = ReportUtil.filterReportInfo(lines);
    assertTrue("Expect DW0003 and DW0004 twice to be present but was: " + out(filtered), filtered.containsAll(Arrays.asList(lines.get(2), invoice2, invoice2.getSingleReference(ANNULATION_INVOICE))));
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Test(org.junit.Test)

Aggregations

ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)45 Test (org.junit.Test)18 Report (eu.ggnet.dwoss.report.ee.entity.Report)13 ReportParameter (eu.ggnet.dwoss.report.ee.ReportAgent.ReportParameter)5 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)5 SimpleReportLine (eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine)5 ViewReportResult (eu.ggnet.dwoss.report.ee.ReportAgent.ViewReportResult)4 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)3 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)3 ReportAgent (eu.ggnet.dwoss.report.ee.ReportAgent)3 SearchParameter (eu.ggnet.dwoss.report.ee.ReportAgent.SearchParameter)3 YearSplit (eu.ggnet.dwoss.report.ee.entity.Report.YearSplit)3 eu.ggnet.dwoss.rules (eu.ggnet.dwoss.rules)3 Date (java.util.Date)3 JLabel (javax.swing.JLabel)3 AutoLogger (eu.ggnet.dwoss.common.log.AutoLogger)2 RepaymentCustomers (eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers)2 ResolveRepayment (eu.ggnet.dwoss.misc.ee.ResolveRepayment)2 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)2 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)2