Search in sources :

Example 1 with SageExporterEngine

use of eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine in project dwoss by gg-net.

the class SageExporterEngineTest method testExport.

@Test
public void testExport() throws UnsupportedEncodingException {
    UiCustomer cus = new UiCustomer(1, "Herr", "Max", "Müstermann", null, "none", "max@example.com", 0);
    Date date = Date.from(LocalDate.of(2018, 01, 30).atStartOfDay(systemDefault()).toInstant());
    // Prepare some data
    Dossier dos = new Dossier(PaymentMethod.DIRECT_DEBIT, true, 0);
    dos.setIdentifier("DW0001");
    Document doc = new Document(INVOICE, Directive.NONE, new DocumentHistory("Junit", "NoComment"));
    doc.setIdentifier("IN1234");
    doc.setActual(date);
    dos.add(doc);
    doc.append(unit(doc.getTaxType(), new Ledger(1000, "Demo1")));
    doc.append(Position.builder().type(SHIPPING_COST).amount(1).bookingAccount(new Ledger(2000, "Versand")).price(100).tax(doc.getTaxType().getTax()).name("Versandkosten").description("Versandkosten").build());
    Dossier dos2 = new Dossier(PaymentMethod.DIRECT_DEBIT, true, 0);
    dos2.setIdentifier("DW0002");
    Document doc2 = new Document(INVOICE, Directive.NONE, new DocumentHistory("Junit", "NoComment"));
    doc2.setIdentifier("IN4321");
    doc2.setActual(date);
    doc2.setTaxType(REVERSE_CHARGE);
    dos2.add(doc2);
    doc2.append(unit(doc2.getTaxType(), new Ledger(1234, "Demo2")));
    // Comparator is needed for the resulting rowlines. In productive, this is not important, but for an exact string match.
    Map<Document, UiCustomer> content = new TreeMap<>(new Comparator<Document>() {

        @Override
        public int compare(Document t0, Document t1) {
            return t0.getIdentifier().compareTo(t1.getIdentifier());
        }
    });
    content.put(doc, cus);
    content.put(doc2, cus);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SageExporterEngine engine = new SageExporterEngine(out, content, new DefaultSageExporterConfig(666, false));
    engine.execute(null);
    String result = out.toString("ISO-8859-1");
    // Enable for problemhandling
    // System.out.println(result);
    // System.out.println("---------------");
    // System.out.println(VALID);
    // System.out.println("Diff: " + StringUtils.difference(result, VALID));
    // System.out.println("DiffIndex: " + StringUtils.indexOfDifference(result, VALID));
    assertThat(result).isEqualTo(VALID);
}
Also used : SageExporterEngine(eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) DefaultSageExporterConfig(eu.ggnet.dwoss.redtape.ee.sage.DefaultSageExporterConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LocalDate(java.time.LocalDate) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) Test(org.junit.Test)

Example 2 with SageExporterEngine

use of eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine 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)

Aggregations

UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)2 SageExporterEngine (eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 AutoLogger (eu.ggnet.dwoss.common.log.AutoLogger)1 Ledger (eu.ggnet.dwoss.mandator.api.value.Ledger)1 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)1 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 DefaultSageExporterConfig (eu.ggnet.dwoss.redtape.ee.sage.DefaultSageExporterConfig)1 FileJacket (eu.ggnet.dwoss.util.FileJacket)1 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 Test (org.junit.Test)1