correct date format, make it possible to *not* initially parse docs

This commit is contained in:
jstaerk
2024-10-02 13:54:16 +02:00
parent b21b095c1a
commit a15267272b
3 changed files with 46 additions and 23 deletions

View File

@@ -374,6 +374,9 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
if (settlement instanceof IZUGFeRDTradeSettlementDebit) {
return ((IZUGFeRDTradeSettlementDebit) settlement).getIBAN();
}
if (settlement instanceof IZUGFeRDTradeSettlementPayment) {
return ((IZUGFeRDTradeSettlementPayment) settlement).getOwnIBAN();
}
}
return null;
}
@@ -401,7 +404,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
* @return when the payment is due
*/
public String getDueDate() {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
return sdf.format(importedInvoice.getDueDate());
}

View File

@@ -62,6 +62,10 @@ public class ZUGFeRDInvoiceImporter {
* parsed Document
*/
protected Document document;
/***
* automatically parse into importedInvoice
*/
protected boolean parseAutomatically = true;
protected Integer version;
protected Invoice importedInvoice = null;
protected boolean recalcPrice = false;
@@ -93,7 +97,6 @@ public class ZUGFeRDInvoiceImporter {
}
/***
* return the file names of all files embedded into the PDF
* @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.
*
@@ -165,8 +167,6 @@ public class ZUGFeRDInvoiceImporter {
}
private void extractFiles(Map<String, PDComplexFileSpecification> names) throws IOException {
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.rawXML = rawXML;
this.version = null;
parseAutomatically = doParse;
try {
setDocument();
} catch (ParserConfigurationException | SAXException e) {
LOGGER.error("Failed to parse XML", 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 {
@@ -218,6 +237,7 @@ public class ZUGFeRDInvoiceImporter {
final ByteArrayInputStream is = new ByteArrayInputStream(rawXML);
/// is.skip(guessBOMSize(is));
document = builder.parse(is);
if (parseAutomatically) {
try {
importedInvoice = new Invoice();
extractInto(importedInvoice);
@@ -227,7 +247,7 @@ public class ZUGFeRDInvoiceImporter {
throw new RuntimeException(e);
}
}
}
/***
@@ -581,6 +601,7 @@ public class ZUGFeRDInvoiceImporter {
}
TransactionCalculator tc = new TransactionCalculator(zpp);
String expectedStringTotalGross = tc.getGrandTotal().toPlainString();
EStandard whichType;
try {
@@ -600,12 +621,12 @@ public class ZUGFeRDInvoiceImporter {
return zpp;
}
protected Document getDocument() {
return document;
}
protected String extractString(String xpathStr) {
if (!containsMeta) {
throw new ZUGFeRDExportException("No suitable data/ZUGFeRD file could be found.");

View File

@@ -125,13 +125,12 @@ public class XRTest extends TestCase {
Invoice readInvoice = new Invoice();
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter();
try {
zii.setRawXML(zf2p.getXML());
zii.setRawXML(zf2p.getXML(), false);
zii.extractInto(readInvoice);
} catch (ParseException | XPathExpressionException xp) {
fail("Exception not expected");
fail("ParseException not expected");
} catch (IOException e) {
throw new RuntimeException(e);
fail("IOException not expected");
}
List<FileAttachment> attachedFiles=zii.getFileAttachmentsXML();
assertNotNull(attachedFiles);