Merge branch 'master' of github.com:ZUGFeRD/mustangproject

This commit is contained in:
jstaerk
2025-05-27 17:34:36 +02:00
5 changed files with 215 additions and 27 deletions

View File

@@ -320,7 +320,7 @@ public class ZUGFeRDInvoiceImporter {
NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
XPathExpression shipEx = xpath.compile("//*[local-name()=\"ShipToTradeParty\"]");
NodeList deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET);
if (deliveryNodes != null) {
if (deliveryNodes.getLength() > 0) {
zpp.setDeliveryAddress(new TradeParty(deliveryNodes));
}
@@ -329,7 +329,7 @@ public class ZUGFeRDInvoiceImporter {
//UBL...
XPathExpression UBLNotesEx = xpath.compile("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"Note\"]");
NodeList UBLNotesNd = (NodeList) UBLNotesEx.evaluate(getDocument(), XPathConstants.NODESET);
if ((UBLNotesNd != null) && (UBLNotesNd.getLength() > 0)) {
if (UBLNotesNd.getLength() > 0) {
for (int nodeIndex = 0; nodeIndex < UBLNotesNd.getLength(); nodeIndex++) {
includedNotes.add(IncludedNote.generalNote(UBLNotesNd.item(nodeIndex).getTextContent()));
}
@@ -429,7 +429,9 @@ public class ZUGFeRDInvoiceImporter {
// });
// }
//NodeList UBLpayeeNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
zpp.setPayee(new TradeParty(ublPayeeNodes));
if (ublPayeeNodes.getLength() > 0) {
zpp.setPayee(new TradeParty(ublPayeeNodes));
}
// TradeParty payee =new TradeParty();
// NodeMap payeeID = new NodeMap(UBLpayeeNodes).getAsNodeMap("PartyIdentification").get();
// if (payeeID !=null) {
@@ -583,15 +585,15 @@ public class ZUGFeRDInvoiceImporter {
number = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"ID\"]").trim();
typeCode = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"InvoiceTypeCode\"]").trim();
String issueDateStr = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"IssueDate\"]").trim();
if (issueDateStr.length() > 0) {
if (!issueDateStr.isEmpty()) {
issueDate = new SimpleDateFormat("yyyy-MM-dd").parse(issueDateStr);
}
String dueDt = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"DueDate\"]").trim();
if (dueDt.length() > 0) {
if (!dueDt.isEmpty()) {
dueDate = new SimpleDateFormat("yyyy-MM-dd").parse(dueDt);
}
String deliveryDt = extractString("//*[local-name()=\"Delivery\"]/*[local-name()=\"ActualDeliveryDate\"]").trim();
if (deliveryDt.length() > 0) {
if (!deliveryDt.isEmpty()) {
deliveryDate = new SimpleDateFormat("yyyy-MM-dd").parse(deliveryDt);
}
}
@@ -672,7 +674,7 @@ public class ZUGFeRDInvoiceImporter {
zpp.setCurrency(currency);
String paymentTermsDescription = extractString("//*[local-name()=\"SpecifiedTradePaymentTerms\"]/*[local-name()=\"Description\"]|//*[local-name()=\"PaymentTerms\"]/*[local-name()=\"Note\"]");
if ((paymentTermsDescription != null) && (!paymentTermsDescription.isEmpty())) {
if (!paymentTermsDescription.isEmpty()) {
zpp.setPaymentTermDescription(paymentTermsDescription);
}
@@ -883,19 +885,31 @@ public class ZUGFeRDInvoiceImporter {
if (buyerOrderIssuerAssignedID != null) {
zpp.setBuyerOrderReferencedDocumentID(buyerOrderIssuerAssignedID);
} else {
zpp.setBuyerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"ID\"]"));
String s = extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"ID\"]");
if (!s.isEmpty()) {
zpp.setBuyerOrderReferencedDocumentID(s);
}
}
if (sellerOrderIssuerAssignedID != null) {
zpp.setSellerOrderReferencedDocumentID(sellerOrderIssuerAssignedID);
} else {
zpp.setSellerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"SalesOrderID\"]"));
String s = extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"SalesOrderID\"]");
if (!s.isEmpty()) {
zpp.setSellerOrderReferencedDocumentID(s);
}
}
if (despatchAdviceReferencedDocument != null) {
zpp.setDespatchAdviceReferencedDocumentID(despatchAdviceReferencedDocument);
} else {
zpp.setDespatchAdviceReferencedDocumentID(extractString("//*[local-name()=\"DespatchDocumentReference\"]/*[local-name()=\"ID\"]"));
String s = extractString("//*[local-name()=\"DespatchDocumentReference\"]/*[local-name()=\"ID\"]");
if (!s.isEmpty()) {
zpp.setDespatchAdviceReferencedDocumentID(s);
}
}
String invoiceReferencedDocumentID = extractString("//*[local-name()=\"InvoiceReferencedDocument\"]/*[local-name()=\"IssuerAssignedID\"]|//*[local-name()=\"BillingReference\"]/*[local-name()=\"InvoiceDocumentReference\"]/*[local-name()=\"ID\"]");
if (!invoiceReferencedDocumentID.isEmpty()) {
zpp.setInvoiceReferencedDocumentID(invoiceReferencedDocumentID);
}
zpp.setInvoiceReferencedDocumentID(extractString("//*[local-name()=\"InvoiceReferencedDocument\"]/*[local-name()=\"IssuerAssignedID\"]|//*[local-name()=\"BillingReference\"]/*[local-name()=\"InvoiceDocumentReference\"]/*[local-name()=\"ID\"]"));
xpr = xpath.compile("//*[local-name()=\"InvoiceReferencedDocument\"]");
NodeList nodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
@@ -913,10 +927,8 @@ public class ZUGFeRDInvoiceImporter {
}
}
zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]|//*[local-name()=\"AccountingSupplierParty\"]/*[local-name()=\"Party\"]/*[local-name()=\"PartyName\"]").trim());
String rounding = extractString("//*[local-name()=\"SpecifiedTradeSettlementHeaderMonetarySummation\"]/*[local-name()=\"RoundingAmount\"]|//*[local-name()=\"LegalMonetaryTotal\"]/*[local-name()=\"Party\"]/*[local-name()=\"PayableRoundingAmount\"]");
if ((rounding != null) && (!rounding.isEmpty())) {
if (!rounding.isEmpty()) {
zpp.setRoundingAmount(new BigDecimal(rounding.trim()));
}

View File

@@ -46,6 +46,8 @@ import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
@@ -77,7 +79,7 @@ public class ZUGFeRDVisualizer {
private Templates mXsltXRTemplate = null;
private Templates mXsltUBLTemplate = null;
private Templates mXsltCIOTemplate = null;
private Templates mXsltHTMLTemplate = null;
private Map<Language, Templates> mXsltHTMLTemplates = null;
private Templates mXsltPDFTemplate = null;
private Templates mXsltZF1HTMLTemplate = null;
@@ -179,7 +181,7 @@ public class ZUGFeRDVisualizer {
Optional<InputStream> in = copyStream(htmlOutput);
ByteArrayOutputStream htmlOutStream = new ByteArrayOutputStream();
if (in.isPresent()) {
applyXSLTToHTML(in.get(), htmlOutStream);
applyXSLTToHTML(in.get(), htmlOutStream, lang);
}
return htmlOutStream.toString(StandardCharsets.UTF_8);
@@ -222,9 +224,12 @@ public class ZUGFeRDVisualizer {
new StreamSource(CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + "stylesheets/cii-xr.xsl")));
}
if (mXsltHTMLTemplate == null) {
mXsltHTMLTemplate = mFactory.newTemplates(new StreamSource(
CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + "stylesheets/xrechnung-html." + lang.name().toLowerCase() + ".xsl")));
if (mXsltHTMLTemplates == null) {
mXsltHTMLTemplates = new HashMap<>();
if (mXsltHTMLTemplates.get(lang) == null) {
Templates mXsltHTMLTemplate = mFactory.newTemplates(new StreamSource(CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + "stylesheets/xrechnung-html." + lang.name().toLowerCase() + ".xsl")));
mXsltHTMLTemplates.put(lang, mXsltHTMLTemplate);
}
}
if (mXsltZF1HTMLTemplate == null) {
mXsltZF1HTMLTemplate = mFactory.newTemplates(new StreamSource(
@@ -442,9 +447,9 @@ public class ZUGFeRDVisualizer {
transformer.transform(new StreamSource(xmlFile), new StreamResult(htmlOutStream));
}
protected void applyXSLTToHTML(final InputStream xmlFile, final OutputStream htmlOutStream)
protected void applyXSLTToHTML(final InputStream xmlFile, final OutputStream htmlOutStream, Language lang)
throws TransformerException, IOException {
Transformer transformer = mXsltHTMLTemplate.newTransformer();
Transformer transformer = mXsltHTMLTemplates.get(lang).newTransformer();
transformer.transform(new StreamSource(xmlFile), new StreamResult(htmlOutStream));
xmlFile.close();

View File

@@ -276,7 +276,9 @@
<fo:block color="{$msg_color}"
margin="0mm"
padding="1mm">
<xsl:value-of select="$msg_text"/>
<xsl:call-template name="IntersperseWithZeroSpaces">
<xsl:with-param name="str" select="$msg_text"/>
</xsl:call-template>
</fo:block>
</fo:table-cell>
</fo:table-row>
@@ -349,4 +351,27 @@
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="IntersperseWithZeroSpaces">
<xsl:param name="str"/>
<xsl:variable name="spacechars">
&#x9;&#xA;
&#x2000;&#x2001;&#x2002;&#x2003;&#x2004;&#x2005;
&#x2006;&#x2007;&#x2008;&#x2009;&#x200A;&#x200B;
</xsl:variable>
<xsl:if test="string-length($str) &gt; 0">
<xsl:variable name="c1" select="substring($str, 1, 1)"/>
<xsl:variable name="c2" select="substring($str, 2, 1)"/>
<xsl:value-of select="$c1"/>
<xsl:if test="$c2 != '' and
not(contains($spacechars, $c1) or
contains($spacechars, $c2))">
<xsl:text>&#x200B;</xsl:text>
</xsl:if>
<xsl:call-template name="IntersperseWithZeroSpaces">
<xsl:with-param name="str" select="substring($str, 2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>