Search in sources :

Example 11 with FileJacket

use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.

the class SageExporterOperation method toXml.

/**
 * Exports the all Documents in the Range as the specified XML lines.
 * <p/>
 * @param start the starting date
 * @param end   the ending date
 * @return an Xml document, ready for import in GS Office.
 */
@Override
@AutoLogger
public FileJacket toXml(Date start, Date end) {
    SubMonitor m = monitorFactory.newSubMonitor("GS Buchhalter Export", 100);
    m.start();
    m.message("Loading Invoices");
    DocumentEao documentEao = new DocumentEao(redTapeEm);
    List<Document> documents = new ArrayList<>();
    documents.addAll(documentEao.findDocumentsBetweenDates(start, end, INVOICE, CREDIT_MEMO, ANNULATION_INVOICE));
    L.info("Loaded {} amount of documents", documents.size());
    m.worked(10);
    Map<Document, UiCustomer> customerInvoices = new HashMap<>();
    m.setWorkRemaining(documents.size() * 2);
    for (Document document : documents) {
        m.worked(1, "Handling Invoice " + document.getIdentifier());
        customerInvoices.put(document, customerService.asUiCustomer(document.getDossier().getCustomerId()));
    }
    m.message("Generating Outfile");
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        SageExporterEngine exporter = new SageExporterEngine(out, customerInvoices, config);
        exporter.execute(m);
        m.finish();
        return new FileJacket("Buchungsaetze DW " + mandator.getCompany().getName() + " von " + DATE_FORMAT.format(start) + " bis " + DATE_FORMAT.format(end), ".xml", out.toByteArray());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : SageExporterEngine(eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine) DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) AutoLogger(eu.ggnet.dwoss.common.log.AutoLogger)

Example 12 with FileJacket

use of eu.ggnet.dwoss.util.FileJacket 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 13 with FileJacket

use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.

the class RefurbishmentReporterOperation method toXls.

/**
 * Generates the report between two dates for the contractor.
 *
 * @param contractor the contractor to report about.
 * @param start      the starting date
 * @param end        the end date
 * @return an XLS document as FileJacket
 */
@Override
public FileJacket toXls(TradeName contractor, Date start, Date end) {
    // TODO: Init me from contractor
    double singleRefurbishPrice = 0.;
    // TODO: Init me from contractor.
    double singleRefillPrice = 0.;
    double refurbishedPriceSum = 0.;
    double refilledPriceSum = 0.;
    SubMonitor m = monitorFactory.newSubMonitor("Refurbishment Abrechnung", 100);
    m.message("Loading Units");
    List<Object[]> refurbishedSopoUnits = new ArrayList<>();
    List<Object[]> refilledSopoUnits = new ArrayList<>();
    List<UniqueUnit> units = new UniqueUnitEao(uuem).findBetweenInputDatesAndContractor(start, end, contractor);
    m.worked(10);
    m.setWorkRemaining(units.size() + 10);
    for (UniqueUnit uu : units) {
        if (uu.getInternalComments().contains(StaticInternalComment.REFILLED)) {
            refilledSopoUnits.add(new Object[] { uu.getIdentifier(Identifier.SERIAL), ProductFormater.toName(uu.getProduct()) });
            refilledPriceSum += singleRefillPrice;
        } else if (uu.getInternalComments().contains(StaticInternalComment.RECOVERT)) {
            refurbishedSopoUnits.add(new Object[] { uu.getIdentifier(Identifier.SERIAL), ProductFormater.toName(uu.getProduct()) });
            refurbishedPriceSum += singleRefurbishPrice;
        }
    }
    double tax = (refilledPriceSum + refurbishedPriceSum) * GlobalConfig.DEFAULT_TAX.getTax();
    CSheet summary = new CSheet("Summery", 5, 30, 15, 15, 15);
    SBlock headerAndDate = new SBlock();
    SBlock data = new SBlock();
    SBlock prices = new SBlock();
    headerAndDate.setFormat(new CFormat(BOLD, Color.BLACK, Color.WHITE, LEFT, new CBorder(Color.LIGHT_GRAY, CBorder.LineStyle.HAIR)));
    headerAndDate.add("Report über recoverte und wiederaufgefüllte Geräte");
    headerAndDate.add("Reportzeitraum:", DATE_FORMAT.format(start) + " - " + DATE_FORMAT.format(end));
    summary.addBelow(1, 1, headerAndDate);
    data.add("", "Anzahl", "Einzelpreis", "Summe");
    data.add("Recoverte Geräte", refurbishedSopoUnits.size(), singleRefurbishPrice, EURO_FORMAT, refurbishedPriceSum, EURO_FORMAT);
    data.add("Wiederaufgefüllte Geräte", refilledSopoUnits.size(), singleRefillPrice, EURO_FORMAT, refilledPriceSum, EURO_FORMAT);
    summary.addBelow(1, 1, data);
    prices.add("", "", "netto", refilledPriceSum + refurbishedPriceSum, EURO_FORMAT);
    prices.add("", "", "Mwst", tax, EURO_FORMAT);
    prices.add("", "", "Mwst", refilledPriceSum + refurbishedPriceSum + tax, EURO_FORMAT);
    summary.addBelow(1, 1, prices);
    STable refurbishedTable = new STable();
    refurbishedTable.setHeadlineFormat(new CFormat(BOLD, Color.BLACK, Color.YELLOW, RIGHT, new CBorder(Color.BLACK)));
    refurbishedTable.add(new STableColumn("Seriennummer", 22)).add(new STableColumn("Bezeichnnung", 40));
    refurbishedTable.setModel(new STableModelList(refurbishedSopoUnits));
    STable refilledTable = new STable(refurbishedTable);
    refilledTable.setModel(new STableModelList(refilledSopoUnits));
    CCalcDocument cdoc = new TempCalcDocument("RefurbishedReport_" + contractor);
    cdoc.add(summary);
    cdoc.add(new CSheet("Refurbished", refurbishedTable));
    cdoc.add(new CSheet("Aufgefüllt", refilledTable));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    FileJacket result = new FileJacket("RefurbishedReport_" + contractor, ".xls", file);
    m.finish();
    return result;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) File(java.io.File)

Example 14 with FileJacket

use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.

the class ExporterOperation method toXls.

/**
 * Creates a price compare sheet, expects a list of partNos and returns a xls File with last sales and estimated generated price
 *
 * @param partNos the partNos to inspect
 * @return the xls file with informations
 */
private FileJacket toXls(String... partNos) {
    // Create a Produkt with the part no;
    SubMonitor m = monitorFactory.newSubMonitor("Auswertung über PartNos", partNos.length + 10);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    StockUnitEao suEao = new StockUnitEao(stockEm);
    DocumentEao documentEao = new DocumentEao(redTapeEm);
    List<List<Object>> model = new ArrayList<>();
    for (String partNo : partNos) {
        m.worked(1, "loading: " + partNo);
        List<Object> line = new ArrayList<>();
        model.add(line);
        partNo = partNo.trim();
        line.add(partNo);
        List<UniqueUnit> uus = uniqueUnitEao.findByProductPartNo(partNo);
        if (uus.isEmpty()) {
            line.add("Keine Geräte oder Produkte im System.");
            for (int i = 0; i < 14; i++) line.add(null);
            continue;
        }
        Product product = uus.get(0).getProduct();
        line.add(ProductFormater.toName(product));
        line.add(uus.size());
        line.add(maxPrice(uus, PriceType.CUSTOMER));
        line.add(minPrice(uus, PriceType.RETAILER));
        List<Document> documents = documentEao.findInvoiceWithProdcutId(product.getId());
        for (int i = 0; i < 3; i++) {
            if (documents.size() > i) {
                // TODO: Was balancingId
                line.add(documents.get(i).getActual());
                line.add(priceByProductId(documents.get(i), product.getId()));
            } else {
                line.add(null);
                line.add(null);
            }
        }
        PriceEngineResult per = priceEngine.estimate(uus.get(0), productSpecEao.findByProductId(product.getId()), suEao.findByUniqueUnitId(uus.get(0).getId()).getStock().getName());
        line.add(per.getCostPrice());
        line.add(per.getRetailerPrice());
        line.add(per.getCustomerPrice());
        line.add(per.getRulesLog());
    }
    m.message("creating File");
    STable table = new STable();
    CFormat euro = new CFormat(RIGHT, CURRENCY_EURO);
    CFormat date = new CFormat(CENTER, SHORT_DATE);
    table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, WHITE, BLUE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("PartNo", 15)).add(new STableColumn("Name", 30));
    table.add(new STableColumn("Menge im System", 12));
    table.add(new STableColumn("VP(Min)", 12, euro)).add(new STableColumn("VP(Max)", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Cp", 12, euro)).add(new STableColumn("Hp", 12, euro)).add(new STableColumn("Ep", 12, euro));
    table.add(new STableColumn("Rules", 40));
    table.setModel(new STableModelList(model));
    CCalcDocument cdoc = new TempCalcDocument("PartNoPrice_");
    cdoc.add(new CSheet("PartNoPrice", table));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    FileJacket result = new FileJacket("PartNoPrice", ".xls", file);
    m.finish();
    return result;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) File(java.io.File)

Example 15 with FileJacket

use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.

the class ContractorPricePartNoExporterOperation method toManufacturerMissingXls.

@Override
public FileJacket toManufacturerMissingXls(TradeName contractorManufacturer) {
    if (!contractorManufacturer.isManufacturer())
        throw new RuntimeException(contractorManufacturer + " is not a Manufacturer, wrong exporter");
    SubMonitor m = monitorFactory.newSubMonitor("Lieferanten und Hersteller Exporter");
    m.message("Loading Units").start();
    List<Object[]> rows = productEao.findByTradeNames(contractorManufacturer.getBrands()).stream().filter(p -> p.getPrice(MANUFACTURER_COST) <= 0.01).sorted().map(p -> new Object[] { p.getPartNo(), 0.0, ProductFormater.toName(p) }).collect(Collectors.toList());
    m.setWorkRemaining(rows.size() + 10).message("Filtering");
    m.message("Generating Document");
    STable table = new STable();
    table.setTableFormat(new CFormat(BLACK, WHITE));
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC));
    table.add(new STableColumn("Artikelnummer", 18)).add(new STableColumn("Kostpreis", 12, new CFormat(CURRENCY_EURO))).add(new STableColumn("Name", 45));
    table.setModel(new STableModelList(rows));
    CCalcDocument cdoc = new TempCalcDocument();
    cdoc.add(new CSheet("Kostpreise", table));
    FileJacket result = new FileJacket("Fehlende " + contractorManufacturer.getName() + " Kostpreise vom " + ISO.format(new Date()), ".xls", new JExcelLucidCalcWriter().write(cdoc));
    m.finish();
    return result;
}
Also used : Stateless(javax.ejb.Stateless) CURRENCY_EURO(eu.ggnet.lucidcalc.CFormat.Representation.CURRENCY_EURO) TradeName(eu.ggnet.dwoss.rules.TradeName) ProductFormater(eu.ggnet.dwoss.uniqueunit.ee.format.ProductFormater) Date(java.util.Date) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) FileJacket(eu.ggnet.dwoss.util.FileJacket) WHITE(java.awt.Color.WHITE) Collectors(java.util.stream.Collectors) ISO(eu.ggnet.dwoss.util.DateFormats.ISO) CONTRACTOR_REFERENCE(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.CONTRACTOR_REFERENCE) Inject(javax.inject.Inject) BLACK(java.awt.Color.BLACK) List(java.util.List) MANUFACTURER_COST(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType.MANUFACTURER_COST) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) eu.ggnet.lucidcalc(eu.ggnet.lucidcalc) MonitorFactory(eu.ggnet.dwoss.progress.MonitorFactory) BOLD_ITALIC(eu.ggnet.lucidcalc.CFormat.FontStyle.BOLD_ITALIC) JExcelLucidCalcWriter(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcWriter) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) FileJacket(eu.ggnet.dwoss.util.FileJacket) Date(java.util.Date) JExcelLucidCalcWriter(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcWriter)

Aggregations

FileJacket (eu.ggnet.dwoss.util.FileJacket)27 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)18 File (java.io.File)14 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)11 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)8 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)7 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)7 CSheet (eu.ggnet.lucidcalc.CSheet)7 STable (eu.ggnet.lucidcalc.STable)7 STableColumn (eu.ggnet.lucidcalc.STableColumn)7 STableModelList (eu.ggnet.lucidcalc.STableModelList)7 TempCalcDocument (eu.ggnet.lucidcalc.TempCalcDocument)7 CFormat (eu.ggnet.lucidcalc.CFormat)6 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)5 CBorder (eu.ggnet.lucidcalc.CBorder)5 JExcelLucidCalcWriter (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcWriter)4 ArrayList (java.util.ArrayList)4 Inject (javax.inject.Inject)4 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)3