diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index 321b4723..0e218223 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -237,7 +237,7 @@ public class Item implements IZUGFeRDExportableItem { } } - if (tradeSettlementName.equals("SpecifiedTradeSettlementLineMonetarySummation")) { + if (tradeSettlementName.equals("SpecifiedTradeSettlementLineMonetarySummation") || tradeSettlementName.equals("SpecifiedTradeSettlementMonetarySummation")) { NodeList totalChilds = tradeSettlementChilds.item(tradeSettlementChildIndex) .getChildNodes(); for (int totalChildIndex = 0; totalChildIndex < totalChilds @@ -255,7 +255,7 @@ public class Item implements IZUGFeRDExportableItem { BigDecimal prc = new BigDecimal(price.trim()); BigDecimal qty = new BigDecimal(quantity.trim()); if ((recalcPrice) && (!qty.equals(BigDecimal.ZERO))) { - prc = new BigDecimal(lineTotal.trim()).divide(qty, 4, RoundingMode.HALF_UP); + prc = new BigDecimal(lineTotal.trim()).divide(qty, 18, RoundingMode.HALF_UP); } Product p = new Product(name, description, unitCode, vatPercent == null ? null : new BigDecimal(vatPercent.trim())); diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 2a1ba512..184aefce 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -77,13 +77,6 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { } - /*** - * have the item prices be determined from the line total. - * That's a workaround for some invoices which just put 0 as item price - */ - public void doRecalculateItemPricesFromLineTotals() { - recalcPrice = true; - } /*** * do not raise ParseExceptions even if the reproduced invoice total does not match the given value diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index cfd580f1..344184c4 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -78,6 +78,14 @@ public class ZUGFeRDInvoiceImporter { } public ZUGFeRDInvoiceImporter(String pdfFilename) { + setPDFFilename(pdfFilename); + } + + public ZUGFeRDInvoiceImporter(InputStream pdfStream) { + setInputStream(pdfStream); + } + + public void setPDFFilename(String pdfFilename){ try (InputStream bis = Files.newInputStream(Paths.get(pdfFilename), StandardOpenOption.READ)) { extractLowLevel(bis); } catch (final IOException e) { @@ -86,8 +94,7 @@ public class ZUGFeRDInvoiceImporter { } } - - public ZUGFeRDInvoiceImporter(InputStream pdfStream) { + public void setInputStream(InputStream pdfStream) { try { extractLowLevel(pdfStream); } catch (final IOException e) { @@ -167,6 +174,20 @@ public class ZUGFeRDInvoiceImporter { } + /*** + * have the item prices be determined from the line total. + * That's a workaround for some invoices which just put 0 as item price + */ + public void doRecalculateItemPricesFromLineTotals() { + recalcPrice = true; + } + + + /*** + * sets th pdf attachments, and if a file is recognized (e.g. a factur-x.xml) triggers processing + * @param names the Hashmap of String, PDComplexFileSpecification + * @throws IOException + */ private void extractFiles(Map names) throws IOException { for (final String alias : names.keySet()) { @@ -209,8 +230,7 @@ public class ZUGFeRDInvoiceImporter { this.containsMeta = true; this.rawXML = rawXML; this.version = null; - - parseAutomatically = doParse; + parseAutomatically = doParse; try { setDocument(); @@ -235,7 +255,7 @@ public class ZUGFeRDInvoiceImporter { xmlFact.setNamespaceAware(true); final DocumentBuilder builder = xmlFact.newDocumentBuilder(); final ByteArrayInputStream is = new ByteArrayInputStream(rawXML); - /// is.skip(guessBOMSize(is)); + /// is.skip(guessBOMSize(is)); document = builder.parse(is); if (parseAutomatically) { try { @@ -488,9 +508,9 @@ public class ZUGFeRDInvoiceImporter { } } - if ((deliveryPeriodStart!=null)&&(deliveryPeriodEnd!=null)) { + if ((deliveryPeriodStart != null) && (deliveryPeriodEnd != null)) { zpp.setDetailedDeliveryPeriod(XMLTools.tryDate(deliveryPeriodStart), XMLTools.tryDate(deliveryPeriodEnd)); - } else if (deliveryPeriodStart!=null) { + } else if (deliveryPeriodStart != null) { zpp.setDeliveryDate(XMLTools.tryDate(deliveryPeriodStart)); } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java index 3a767c97..5cec1518 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java @@ -214,8 +214,9 @@ public class MustangReaderWriterTest extends MustangReaderTestCase { public void testForeignImport() { InputStream inputStream = this.getClass().getResourceAsStream("/zugferd_invoice.pdf"); - ZUGFeRDImporter zi = new ZUGFeRDImporter(inputStream); - + ZUGFeRDImporter zi = new ZUGFeRDImporter(); + zi.doRecalculateItemPricesFromLineTotals(); + zi.setInputStream(inputStream); // Reading ZUGFeRD String amount = zi.getAmount();