correct date format, make it possible to *not* initially parse docs
This commit is contained in:
@@ -374,6 +374,9 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
|||||||
if (settlement instanceof IZUGFeRDTradeSettlementDebit) {
|
if (settlement instanceof IZUGFeRDTradeSettlementDebit) {
|
||||||
return ((IZUGFeRDTradeSettlementDebit) settlement).getIBAN();
|
return ((IZUGFeRDTradeSettlementDebit) settlement).getIBAN();
|
||||||
}
|
}
|
||||||
|
if (settlement instanceof IZUGFeRDTradeSettlementPayment) {
|
||||||
|
return ((IZUGFeRDTradeSettlementPayment) settlement).getOwnIBAN();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -401,7 +404,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
|||||||
* @return when the payment is due
|
* @return when the payment is due
|
||||||
*/
|
*/
|
||||||
public String getDueDate() {
|
public String getDueDate() {
|
||||||
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
|
||||||
return sdf.format(importedInvoice.getDueDate());
|
return sdf.format(importedInvoice.getDueDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,11 +62,15 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
* parsed Document
|
* parsed Document
|
||||||
*/
|
*/
|
||||||
protected Document document;
|
protected Document document;
|
||||||
|
/***
|
||||||
|
* automatically parse into importedInvoice
|
||||||
|
*/
|
||||||
|
protected boolean parseAutomatically = true;
|
||||||
protected Integer version;
|
protected Integer version;
|
||||||
protected Invoice importedInvoice=null;
|
protected Invoice importedInvoice = null;
|
||||||
protected boolean recalcPrice = false;
|
protected boolean recalcPrice = false;
|
||||||
protected boolean ignoreCalculationErrors = false;
|
protected boolean ignoreCalculationErrors = false;
|
||||||
protected ArrayList<FileAttachment> fileAttachments=new ArrayList<>();
|
protected ArrayList<FileAttachment> fileAttachments = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
protected ZUGFeRDInvoiceImporter() {
|
protected ZUGFeRDInvoiceImporter() {
|
||||||
@@ -93,7 +97,6 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* return the file names of all files embedded into the PDF
|
* return the file names of all files embedded into the PDF
|
||||||
* @see for XML embedded files please use ZUGFeRDInvoiceImporter.getFileAttachmentsXML
|
* @see for XML embedded files please use ZUGFeRDInvoiceImporter.getFileAttachmentsXML
|
||||||
@@ -104,7 +107,6 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts a ZUGFeRD invoice from a PDF document represented by an input stream. Errors are reported via exception handling.
|
* Extracts a ZUGFeRD invoice from a PDF document represented by an input stream. Errors are reported via exception handling.
|
||||||
*
|
*
|
||||||
@@ -165,8 +167,6 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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()) {
|
||||||
|
|
||||||
@@ -199,16 +199,35 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRawXML(byte[] rawXML) throws IOException {
|
/***
|
||||||
|
* set the xml of a CII invoice
|
||||||
|
* @param rawXML the xml string
|
||||||
|
* @param doParse automatically parse input for zugferdImporter (not ZUGFeRDInvoiceImporter)
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void setRawXML(byte[] rawXML, boolean doParse) throws IOException {
|
||||||
this.containsMeta = true;
|
this.containsMeta = true;
|
||||||
this.rawXML = rawXML;
|
this.rawXML = rawXML;
|
||||||
this.version = null;
|
this.version = null;
|
||||||
|
|
||||||
|
parseAutomatically = doParse;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setDocument();
|
setDocument();
|
||||||
} catch (ParserConfigurationException | SAXException e) {
|
} catch (ParserConfigurationException | SAXException e) {
|
||||||
LOGGER.error("Failed to parse XML", e);
|
LOGGER.error("Failed to parse XML", e);
|
||||||
throw new ZUGFeRDExportException(e);
|
throw new ZUGFeRDExportException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* set the xml of a CII invoice, simple version
|
||||||
|
* @param rawXML the cii(?) as a string
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void setRawXML(byte[] rawXML) throws IOException {
|
||||||
|
setRawXML(rawXML, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDocument() throws ParserConfigurationException, IOException, SAXException {
|
private void setDocument() throws ParserConfigurationException, IOException, SAXException {
|
||||||
@@ -218,8 +237,9 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
final ByteArrayInputStream is = new ByteArrayInputStream(rawXML);
|
final ByteArrayInputStream is = new ByteArrayInputStream(rawXML);
|
||||||
/// is.skip(guessBOMSize(is));
|
/// is.skip(guessBOMSize(is));
|
||||||
document = builder.parse(is);
|
document = builder.parse(is);
|
||||||
|
if (parseAutomatically) {
|
||||||
try {
|
try {
|
||||||
importedInvoice=new Invoice();
|
importedInvoice = new Invoice();
|
||||||
extractInto(importedInvoice);
|
extractInto(importedInvoice);
|
||||||
} catch (XPathExpressionException e) {
|
} catch (XPathExpressionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -227,7 +247,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@@ -377,7 +397,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String currency= extractString("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]/*[local-name()=\"InvoiceCurrencyCode\"]|*[local-name()=\"DocumentCurrencyCode\"]");
|
String currency = extractString("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]/*[local-name()=\"InvoiceCurrencyCode\"]|*[local-name()=\"DocumentCurrencyCode\"]");
|
||||||
zpp.setCurrency(currency);
|
zpp.setCurrency(currency);
|
||||||
|
|
||||||
xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]|//*[local-name()=\"ApplicableSupplyChainTradeSettlement\"]");
|
xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]|//*[local-name()=\"ApplicableSupplyChainTradeSettlement\"]");
|
||||||
@@ -503,7 +523,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
xpr = xpath.compile("//*[local-name()=\"AttachmentBinaryObject\"]|//*[local-name()=\"EmbeddedDocumentBinaryObject\"]");
|
xpr = xpath.compile("//*[local-name()=\"AttachmentBinaryObject\"]|//*[local-name()=\"EmbeddedDocumentBinaryObject\"]");
|
||||||
NodeList attachmentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
NodeList attachmentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
||||||
for (int i = 0; i < attachmentNodes.getLength(); i++) {
|
for (int i = 0; i < attachmentNodes.getLength(); i++) {
|
||||||
FileAttachment fa=new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(),attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(),"Data", Base64.getDecoder().decode(attachmentNodes.item(i).getTextContent()));
|
FileAttachment fa = new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(), attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(), "Data", Base64.getDecoder().decode(attachmentNodes.item(i).getTextContent()));
|
||||||
fileAttachments.add(fa);
|
fileAttachments.add(fa);
|
||||||
// filename = "Aufmass.png" mimeCode = "image/png"
|
// filename = "Aufmass.png" mimeCode = "image/png"
|
||||||
//EmbeddedDocumentBinaryObject cbc:EmbeddedDocumentBinaryObject mimeCode="image/png" filename="Aufmass.png"
|
//EmbeddedDocumentBinaryObject cbc:EmbeddedDocumentBinaryObject mimeCode="image/png" filename="Aufmass.png"
|
||||||
@@ -581,6 +601,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TransactionCalculator tc = new TransactionCalculator(zpp);
|
TransactionCalculator tc = new TransactionCalculator(zpp);
|
||||||
|
|
||||||
String expectedStringTotalGross = tc.getGrandTotal().toPlainString();
|
String expectedStringTotalGross = tc.getGrandTotal().toPlainString();
|
||||||
EStandard whichType;
|
EStandard whichType;
|
||||||
try {
|
try {
|
||||||
@@ -600,12 +621,12 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
return zpp;
|
return zpp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Document getDocument() {
|
protected Document getDocument() {
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected String extractString(String xpathStr) {
|
protected String extractString(String xpathStr) {
|
||||||
if (!containsMeta) {
|
if (!containsMeta) {
|
||||||
throw new ZUGFeRDExportException("No suitable data/ZUGFeRD file could be found.");
|
throw new ZUGFeRDExportException("No suitable data/ZUGFeRD file could be found.");
|
||||||
|
|||||||
@@ -125,13 +125,12 @@ public class XRTest extends TestCase {
|
|||||||
Invoice readInvoice = new Invoice();
|
Invoice readInvoice = new Invoice();
|
||||||
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter();
|
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter();
|
||||||
try {
|
try {
|
||||||
|
zii.setRawXML(zf2p.getXML(), false);
|
||||||
zii.setRawXML(zf2p.getXML());
|
|
||||||
zii.extractInto(readInvoice);
|
zii.extractInto(readInvoice);
|
||||||
} catch (ParseException | XPathExpressionException xp) {
|
} catch (ParseException | XPathExpressionException xp) {
|
||||||
fail("Exception not expected");
|
fail("ParseException not expected");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
fail("IOException not expected");
|
||||||
}
|
}
|
||||||
List<FileAttachment> attachedFiles=zii.getFileAttachmentsXML();
|
List<FileAttachment> attachedFiles=zii.getFileAttachmentsXML();
|
||||||
assertNotNull(attachedFiles);
|
assertNotNull(attachedFiles);
|
||||||
|
|||||||
Reference in New Issue
Block a user