allow zf1 reading of line totals

This commit is contained in:
jstaerk
2024-10-09 13:16:05 +02:00
parent a9a3dce1bd
commit d4e4ed3f2f
4 changed files with 32 additions and 18 deletions

View File

@@ -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()));

View File

@@ -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

View File

@@ -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<String, PDComplexFileSpecification> names) throws IOException {
for (final String alias : names.keySet()) {
@@ -209,7 +230,6 @@ public class ZUGFeRDInvoiceImporter {
this.containsMeta = true;
this.rawXML = rawXML;
this.version = null;
parseAutomatically = doParse;
try {

View File

@@ -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();