allow zf1 reading of line totals
This commit is contained in:
@@ -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)
|
NodeList totalChilds = tradeSettlementChilds.item(tradeSettlementChildIndex)
|
||||||
.getChildNodes();
|
.getChildNodes();
|
||||||
for (int totalChildIndex = 0; totalChildIndex < totalChilds
|
for (int totalChildIndex = 0; totalChildIndex < totalChilds
|
||||||
@@ -255,7 +255,7 @@ public class Item implements IZUGFeRDExportableItem {
|
|||||||
BigDecimal prc = new BigDecimal(price.trim());
|
BigDecimal prc = new BigDecimal(price.trim());
|
||||||
BigDecimal qty = new BigDecimal(quantity.trim());
|
BigDecimal qty = new BigDecimal(quantity.trim());
|
||||||
if ((recalcPrice) && (!qty.equals(BigDecimal.ZERO))) {
|
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,
|
Product p = new Product(name, description, unitCode,
|
||||||
vatPercent == null ? null : new BigDecimal(vatPercent.trim()));
|
vatPercent == null ? null : new BigDecimal(vatPercent.trim()));
|
||||||
|
|||||||
@@ -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
|
* do not raise ParseExceptions even if the reproduced invoice total does not match the given value
|
||||||
|
|||||||
@@ -78,6 +78,14 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ZUGFeRDInvoiceImporter(String pdfFilename) {
|
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)) {
|
try (InputStream bis = Files.newInputStream(Paths.get(pdfFilename), StandardOpenOption.READ)) {
|
||||||
extractLowLevel(bis);
|
extractLowLevel(bis);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
@@ -86,8 +94,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInputStream(InputStream pdfStream) {
|
||||||
public ZUGFeRDInvoiceImporter(InputStream pdfStream) {
|
|
||||||
try {
|
try {
|
||||||
extractLowLevel(pdfStream);
|
extractLowLevel(pdfStream);
|
||||||
} catch (final IOException e) {
|
} 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 {
|
private void extractFiles(Map<String, PDComplexFileSpecification> names) throws IOException {
|
||||||
for (final String alias : names.keySet()) {
|
for (final String alias : names.keySet()) {
|
||||||
|
|
||||||
@@ -209,7 +230,6 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
this.containsMeta = true;
|
this.containsMeta = true;
|
||||||
this.rawXML = rawXML;
|
this.rawXML = rawXML;
|
||||||
this.version = null;
|
this.version = null;
|
||||||
|
|
||||||
parseAutomatically = doParse;
|
parseAutomatically = doParse;
|
||||||
|
|
||||||
try {
|
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));
|
zpp.setDetailedDeliveryPeriod(XMLTools.tryDate(deliveryPeriodStart), XMLTools.tryDate(deliveryPeriodEnd));
|
||||||
} else if (deliveryPeriodStart!=null) {
|
} else if (deliveryPeriodStart != null) {
|
||||||
zpp.setDeliveryDate(XMLTools.tryDate(deliveryPeriodStart));
|
zpp.setDeliveryDate(XMLTools.tryDate(deliveryPeriodStart));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -214,8 +214,9 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
|
|||||||
|
|
||||||
public void testForeignImport() {
|
public void testForeignImport() {
|
||||||
InputStream inputStream = this.getClass().getResourceAsStream("/zugferd_invoice.pdf");
|
InputStream inputStream = this.getClass().getResourceAsStream("/zugferd_invoice.pdf");
|
||||||
ZUGFeRDImporter zi = new ZUGFeRDImporter(inputStream);
|
ZUGFeRDImporter zi = new ZUGFeRDImporter();
|
||||||
|
zi.doRecalculateItemPricesFromLineTotals();
|
||||||
|
zi.setInputStream(inputStream);
|
||||||
// Reading ZUGFeRD
|
// Reading ZUGFeRD
|
||||||
String amount = zi.getAmount();
|
String amount = zi.getAmount();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user