Search in sources :

Example 31 with ReportLine

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

the class ReportUtil method partition.

/**
 * Removes all Lines, that only represent active Info (open Complaints).
 * <ol>
 * <li>Sammle alle only Invoice Positions raus → Report</li>
 * <li>Sammle alle Repayment Positions raus → Report</li>
 * <li>Sammle alle Complaint Positionen die mit den Repayment Positionen zusammenhängen raus → Report</li>
 * <li>Sammle alle Compleints die DISCHARDED sind → Report</li>
 * <li>Alles was übrig ist, sollten (offene) Complaints sein → Active Info</li>
 * </ol>
 * <p>
 * It's not allowed to have a null value in the collection.
 * <p>
 * @param allLines   all lines.
 * @param reportType the report type
 * @return
 */
public static PrepareReportPartition partition(Collection<ReportLine> allLines, TradeName reportType) {
    L.debug("filter {}", allLines);
    NavigableSet<ReportLine> reportAble = new TreeSet<>();
    for (ReportLine line : allLines) {
        L.debug("filter processing {}", line.toSimple());
        if (!(line.getDocumentType() == DocumentType.ANNULATION_INVOICE || line.getDocumentType() == DocumentType.CREDIT_MEMO || line.getDocumentType() == DocumentType.CAPITAL_ASSET || (line.getDocumentType() == DocumentType.COMPLAINT && line.getWorkflowStatus() == WorkflowStatus.DISCHARGED) || (line.getDocumentType() == DocumentType.INVOICE && line.hasNoRepayments()) && line.hasNoOpenComplaints()))
            continue;
        L.debug("filter processing, add to reportAble {}", line.toSimple());
        reportAble.add(line);
        Date tomorrow = DateUtils.addDays(line.getReportingDate(), 1);
        for (ReportLine ref : line.getRefrences()) {
            if (ref.getDocumentType() == DocumentType.COMPLAINT && !ref.isInReport(reportType)) {
                L.debug("filter processing referencing complaints, add to reportAble {}", ref.toSimple());
                reportAble.add(ref);
            } else if (ref.getDocumentType() == DocumentType.INVOICE && !ref.isInReport(reportType) && ref.getReportingDate().before(tomorrow)) {
                L.debug("filter processing referencing invoices, add to reportAble {}", ref.toSimple());
                reportAble.add(ref);
            }
        }
    }
    NavigableSet<ReportLine> activeInfo = new TreeSet<>(allLines);
    activeInfo.removeAll(reportAble);
    return new PrepareReportPartition(reportAble, activeInfo);
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine)

Example 32 with ReportLine

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

the class ReportLineGenerator method makeReportLine.

/**
 * Makes one special Reportline
 * <p/>
 * @param contractors  the contractor
 * @param posTypes     the allowed types of positions
 * @param starting     a starting date, this is the earlies date a line will have the reporting date set
 * @param maxDeltaDays this is a max delta for days of the reporting date. The date will be between starting and starting+maxDeltaDays.
 * @param docTypes     documetTypes
 * @return the ReportingLine
 */
public ReportLine makeReportLine(List<TradeName> contractors, Date starting, int maxDeltaDays, List<PositionType> posTypes, List<DocumentType> docTypes) {
    ReportLine line = new ReportLine();
    line.setName("ReportLine-" + getRandomInt());
    line.setDescription("desription-" + getRandomInt());
    line.setDossierId(getRandomLong());
    line.setDocumentIdentifier("dossierIdentifier-" + getRandomInt());
    line.setDocumentId(getRandomLong());
    line.setDocumentIdentifier("documentIdentifier-" + getRandomInt());
    line.setPositionType(posTypes.get(R.nextInt(posTypes.size())));
    line.setDocumentType(docTypes.get(R.nextInt(docTypes.size())));
    line.setCustomerId(getRandomLong());
    line.setContractorPartNo("123.456");
    line.setAmount(getRandomLong());
    double tax = GlobalConfig.DEFAULT_TAX.getTax();
    double price = Math.abs(R.nextDouble() * R.nextInt(1500));
    line.setManufacturerCostPrice(price * 1.10);
    line.setContractorReferencePrice(price * 1.10);
    line.setPrice(price);
    line.setTax(tax);
    line.setBookingAccount(getRandomInt());
    GeneratedAddress makeAddress = new NameGenerator().makeAddress();
    Name makeName = new NameGenerator().makeName();
    String name = makeName.getFirst() + " " + makeName.getLast();
    line.setCustomerName(name);
    String invoiceAdress = name + ", " + makeAddress.getStreet() + " " + makeAddress.getNumber() + ", " + makeAddress.getPostalCode() + " " + makeAddress.getTown();
    line.setCustomerCompany(R.nextInt(10) < 7 ? "" : "TestFirma");
    line.setInvoiceAddress(invoiceAdress);
    line.setRefurbishId("" + R.nextInt(100000));
    line.setUniqueUnitId(getRandomLong());
    line.setSerial("serial" + getRandomInt());
    line.setProductId(getRandomLong());
    line.setPartNo("partNo" + getRandomInt());
    line.setContractor(contractors.size() == 1 ? contractors.get(0) : contractors.get(R.nextInt(contractors.size())));
    line.setProductBrand(brands.get(R.nextInt(brands.size())));
    Date pastFiveYears = DateUtils.setYears(new Date(), 2009);
    line.setMfgDate(DateUtils.addDays(pastFiveYears, R.nextInt(2000)));
    line.setReportingDate(maxDeltaDays > 0 ? DateUtils.addDays(starting, R.nextInt(maxDeltaDays)) : starting);
    return line;
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine)

Example 33 with ReportLine

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

the class ReportAgentBean method store.

/**
 * Stores a new report, persisting the report and merging the lines.
 * <p/>
 * @param report    the report to persist.
 * @param storables the lines to merge, only the id is considered and a new instance is used from the EntityManager.
 * @return the persisted report.
 */
@Override
@AutoLogger
public Report store(Report report, Collection<ReportLine.Storeable> storables) {
    for (ReportLine.Storeable storable : storables) {
        ReportLine line = reportEm.find(ReportLine.class, storable.getId());
        line.setMarginPercentage(storable.getMarginPercentage());
        line.setPurchasePrice(storable.getPurchasePrice());
        report.add(line);
        L.debug("Report Line {} was anded to report. ", line);
    }
    reportEm.persist(report);
    return optionalFetchEager(report);
}
Also used : SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) AutoLogger(eu.ggnet.dwoss.common.log.AutoLogger)

Example 34 with ReportLine

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

the class UnitOverseerBean method toDetailedHtmlUnit.

private String toDetailedHtmlUnit(UniqueUnit uniqueUnit, boolean showPrices) {
    SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyy");
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    List<ReportLine> reportLines = new ReportLineEao(reportEm).findByUniqueUnitId(uniqueUnit.getId());
    String re = UniqueUnitFormater.toHtmlDetailed(uniqueUnit);
    TreeSet<Dossier> dossiers = new TreeSet<>(Dossier.ORDER_INVERSE_ACTIVE_ACTUAL);
    for (Position pos : new PositionEao(redTapeEm).findByUniqueUnitId(uniqueUnit.getId())) {
        // For now we ignore all Dossiers which just had the unit in the history
        if (!pos.getDocument().isActive())
            continue;
        dossiers.add(pos.getDocument().getDossier());
    }
    re += "<hr />";
    re += "<b>Vorgänge:</b><ul>";
    if (dossiers.isEmpty())
        re += "<li>Keine Vorgänge vorhanden</li>";
    for (Dossier dossier : dossiers) {
        re += "<li>";
        re += customerService.asUiCustomer(dossier.getCustomerId()).toNameCompanyLine();
        re += DossierFormater.toHtmlSimpleWithDocument(dossier) + "<br /></li>";
    }
    re += "</ul>";
    re += "<hr />";
    if (uniqueUnit.getHistory() != null && !uniqueUnit.getHistory().isEmpty()) {
        re += "<b>Unit History:</b><ul>";
        for (UniqueUnitHistory history : new TreeSet<>(uniqueUnit.getHistory())) {
            re += "<li>" + df.format(history.getOccurence()) + " - " + history.getComment() + "</li>";
        }
        re += "</ul>";
    }
    re += "<hr />";
    re += "<p><b>Lagerinformationen</b><br />";
    if (stockUnit == null)
        re += "Kein Lagergerät vorhanden<br />";
    else
        re += StockUnitFormater.toHtml(stockUnit);
    re += "</p>";
    re += "<hr />";
    re += "<b>Reporting-Informationen</b>";
    if (reportLines == null || reportLines.isEmpty())
        re += "Keine Reporting-Informationen vorhanden<br />";
    else {
        re += "<table border=\"1\"><tr>";
        re += wrap("<th>", "</th>", "Id", "ReportDate", "Kid", "SopoNr", "Type", "Dossier", "Report");
        re += "</tr>";
        for (ReportLine l : reportLines) {
            re += "<tr>";
            re += wrap("<td>", "</td>", l.getId(), DateFormats.ISO.format(l.getReportingDate()), l.getCustomerId(), l.getRefurbishId(), l.getPositionType() == PRODUCT_BATCH && l.getReference(WARRANTY) != null ? "Garantieerweiterung" : l.getPositionType().getName(), l.getDossierIdentifier() + ", " + l.getDocumentType().getName() + l.getWorkflowStatus().getSign() + (l.getDocumentIdentifier() == null ? "" : ", " + l.getDocumentIdentifier()), l.getReports().stream().map(Report::getName).collect(Collectors.joining(",")));
        }
        re += "</table><br />";
    }
    if (!showPrices)
        return re;
    re += "<hr />";
    re += "<b>Geräte Preis-Informationen</b>";
    re += UniqueUnitFormater.toHtmlPriceInformation(uniqueUnit.getPrices(), uniqueUnit.getPriceHistory());
    re += "<b>Artikel Preis-Informationen</b>";
    re += UniqueUnitFormater.toHtmlPriceInformation(uniqueUnit.getProduct().getPrices(), uniqueUnit.getProduct().getPriceHistory());
    return Css.toHtml5WithStyle(re);
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) SimpleDateFormat(java.text.SimpleDateFormat) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitHistory(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnitHistory)

Example 35 with ReportLine

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

the class ResolveRepaymentBeanIT method testResolve.

@Test
public void testResolve() throws UserInfoException {
    List<Stock> allStocks = stockGenerator.makeStocksAndLocations(2);
    assertThat(allStocks).isNotEmpty().hasSize(2);
    Stock activeStock = allStocks.get(0);
    assertThat(customerGenerator.makeCustomers(10)).isNotEmpty();
    assertThat(receiptGenerator.makeUniqueUnits(200, true, true)).isNotEmpty();
    assertThat(redTapeGenerator.makeSalesDossiers(30)).isNotEmpty();
    final TradeName TRADE_NAME = ACER;
    assertThat(TRADE_NAME.isManufacturer()).isTrue();
    long customerId = customerGenerator.makeCustomer();
    List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(1, true, true);
    UniqueUnit uu = uus.get(0);
    uu = helper.changeContractors(uu.getId(), TRADE_NAME);
    String refurbishId = uu.getRefurbishId();
    Dossier dos = redTapeWorker.create(customerId, true, "Me");
    // order oder direct invoice
    Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    // Create Positions
    doc.append(Position.builder().type(UNIT).amount(1).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).price(uu.getPrice(CUSTOMER)).tax(doc.getSingleTax()).name(uu.getProduct().getName() + " | SN:" + uu.getSerial()).description(uu.getProduct().getDescription()).refurbishedId(refurbishId).build());
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos.getId(), uu.getRefurbishId());
    doc.add(Document.Condition.PAID);
    doc.add(Document.Condition.PICKED_UP);
    doc.setType(DocumentType.INVOICE);
    doc = redTapeWorker.update(doc, null, "JUnit");
    // Now create an annulation Invoice
    doc.setType(ANNULATION_INVOICE);
    // ArrayList<Position> positions = new ArrayList<>();
    for (Position value : doc.getPositions().values()) {
        // if ( value.getType() == UNIT ) positions.add(value);
        value.setPrice(value.getPrice() * -1);
    }
    redTapeWorker.update(doc, activeStock.getId(), "JUnit Test");
    // Closing the Day. Creating report lines.
    redTapeCloser.executeManual("JUnitTest");
    // Ensure, that we have a Mirror Dossier on the repaymentcustomers.
    List<Dossier> repaymentDossiers = redTapeAgent.findDossiersOpenByCustomerIdEager(repaymentCustomers.get(TRADE_NAME).get());
    assertThat(repaymentDossiers).as("RepaymentDossiers").isNotEmpty();
    Dossier repaymentDossier = repaymentDossiers.get(0);
    List<Document> activeDocuments = repaymentDossier.getActiveDocuments(BLOCK);
    assertThat(activeDocuments).isNotEmpty();
    assertThat(activeDocuments.get(0).getPositions(UNIT)).isNotEmpty();
    Report report = new Report("Test", TRADE_NAME, new Date(), new Date());
    List<ReportLine> reportLines = reportLineEao.findAll();
    List<Storeable> arrayList = new ArrayList<>();
    reportLines.stream().filter((line) -> (line.getDocumentType() == INVOICE)).forEach((line) -> {
        arrayList.add(line.toStorable());
    });
    report = reportAgent.store(report, arrayList);
    assertThat(report).isNotNull();
    assertThat(report.getLines()).isNotEmpty();
    List<ReportLine> notReported = report.getLines().stream().filter((l) -> reportLines.contains(l)).collect(Collectors.toList());
    final int uuId = uu.getId();
    ReportLine lineToUniqueUnit = notReported.stream().filter((line) -> line.getUniqueUnitId() == uuId).collect(Collectors.toList()).get(0);
    assertThat(lineToUniqueUnit).isNotNull();
    List<ReportLine> repaymentLines = bean.getRepaymentLines(lineToUniqueUnit.getContractor());
    ReportLine repaymentLine = repaymentLines.stream().filter((l) -> l.getRefurbishId().equals(refurbishId)).collect(Collectors.toList()).get(0);
    assertThat(stockAgent.findStockUnitsByRefurbishIdEager(Arrays.asList(refurbishId))).isNotEmpty();
    // Resolving of the Unit.
    bean.resolveUnit(refurbishId, TRADE_NAME, "JUnit", "JUnit");
    List<Report> reports = reportAgent.findAll(Report.class);
    assertThat(reports).hasSize(2);
    Report repaymentReport = null;
    // Try to get Report with the Name that is generated in a Static method inside the ResolveRepaymentBean.
    if (reports.get(0).getName().equals(ResolveRepaymentBean.toReportName(TRADE_NAME)))
        repaymentReport = reports.get(0);
    else
        repaymentReport = reports.get(1);
    repaymentReport = reportAgent.findByIdEager(Report.class, repaymentReport.getId());
    assertThat(repaymentReport.getLines()).hasSize(1);
    assertThat(repaymentLines).contains(repaymentLine);
    // Ensure, that we the mirror Dossier has be cleared of the unit
    repaymentDossiers = redTapeAgent.findDossiersOpenByCustomerIdEager(repaymentCustomers.get(TRADE_NAME).get());
    assertThat(repaymentDossiers).isNotEmpty();
    repaymentDossier = repaymentDossiers.get(0);
    activeDocuments = repaymentDossier.getActiveDocuments(BLOCK);
    assertThat(activeDocuments).isNotEmpty();
    assertThat(activeDocuments.get(0).getPositions(UNIT)).isEmpty();
    // We still should have comments there.
    assertThat(activeDocuments.get(0).getPositions(PositionType.COMMENT)).isNotEmpty();
    assertThat(stockAgent.findStockUnitsByRefurbishIdEager(Arrays.asList(refurbishId))).isNullOrEmpty();
}
Also used : java.util(java.util) StockGeneratorOperation(eu.ggnet.dwoss.stock.ee.assist.gen.StockGeneratorOperation) Arquillian(org.jboss.arquillian.junit.Arquillian) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) 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) eu.ggnet.dwoss.rules(eu.ggnet.dwoss.rules) UnitOverseer(eu.ggnet.dwoss.redtapext.ee.UnitOverseer) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) CUSTOMER(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.CUSTOMER) RedTapeCloser(eu.ggnet.dwoss.redtapext.ee.reporting.RedTapeCloser) Inject(javax.inject.Inject) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) ResolveRepayment(eu.ggnet.dwoss.misc.ee.ResolveRepayment) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) DocumentType(eu.ggnet.dwoss.rules.DocumentType) Report(eu.ggnet.dwoss.report.ee.entity.Report) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) RedTapeGeneratorOperation(eu.ggnet.dwoss.redtapext.ee.gen.RedTapeGeneratorOperation) EJB(javax.ejb.EJB) Storeable(eu.ggnet.dwoss.report.ee.entity.ReportLine.Storeable) RepaymentCustomers(eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ReportAgent(eu.ggnet.dwoss.report.ee.ReportAgent) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UNIT(eu.ggnet.dwoss.rules.PositionType.UNIT) ACER(eu.ggnet.dwoss.rules.TradeName.ACER) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) RedTapeAgent(eu.ggnet.dwoss.redtape.ee.RedTapeAgent) ResolveRepaymentBean(eu.ggnet.dwoss.misc.ee.ResolveRepaymentBean) ReceiptGeneratorOperation(eu.ggnet.dwoss.receipt.ee.gen.ReceiptGeneratorOperation) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Report(eu.ggnet.dwoss.report.ee.entity.Report) Storeable(eu.ggnet.dwoss.report.ee.entity.ReportLine.Storeable) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) 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