corrected document level period start/end
This commit is contained in:
@@ -4,13 +4,12 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.AbstractList;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.RandomAccess;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.dom4j.io.XMLWriter;
|
import org.dom4j.io.XMLWriter;
|
||||||
|
import org.mustangproject.ZUGFeRD.ZUGFeRDDateFormat;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
@@ -70,7 +69,85 @@ public class XMLTools extends XMLWriter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the value of an node
|
||||||
|
*
|
||||||
|
* @param node the Node to get the value from
|
||||||
|
* @return A String or empty String, if no value was found
|
||||||
|
*/
|
||||||
|
public static String getNodeValue(Node node) {
|
||||||
|
if (node != null && node.getFirstChild() != null) {
|
||||||
|
return node.getFirstChild().getNodeValue();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tries to convert a String to BigDecimal.
|
||||||
|
*
|
||||||
|
* @param nodeValue The value as String
|
||||||
|
* @return a BigDecimal with the value provides as String or a BigDecimal with value 0.00 if an error occurs
|
||||||
|
*/
|
||||||
|
public static BigDecimal tryBigDecimal(String nodeValue) {
|
||||||
|
try {
|
||||||
|
return new BigDecimal(nodeValue);
|
||||||
|
} catch (final Exception e) {
|
||||||
|
try {
|
||||||
|
return BigDecimal.valueOf(Float.valueOf(nodeValue));
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
return new BigDecimal("0.00");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tries to convert a Node to a BigDecimal.
|
||||||
|
*
|
||||||
|
* @param node The value as String
|
||||||
|
* @return a BigDecimal with the value provides as String or a BigDecimal with value 0.00 if an error occurs
|
||||||
|
*/
|
||||||
|
public static BigDecimal tryBigDecimal(Node node) {
|
||||||
|
final String nodeValue = XMLTools.getNodeValue(node);
|
||||||
|
if (nodeValue.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return XMLTools.tryBigDecimal(nodeValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* returns a util.Date from a 102 String yyyymmdd in a node
|
||||||
|
* @param node the node
|
||||||
|
* @return a util.Date, or null, if not parseable
|
||||||
|
*/
|
||||||
|
public static Date tryDate(Node node) {
|
||||||
|
final String nodeValue = XMLTools.getNodeValue(node);
|
||||||
|
if (nodeValue.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return tryDate(nodeValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* returns a util.Date from a 102 String yyyymmdd
|
||||||
|
* @param toParse the string
|
||||||
|
* @return a util.Date, or null, if not parseable
|
||||||
|
*/
|
||||||
|
public static Date tryDate(String toParse) {
|
||||||
|
final SimpleDateFormat formatter = ZUGFeRDDateFormat.DATE.getFormatter();
|
||||||
|
try {
|
||||||
|
return formatter.parse(toParse);
|
||||||
|
} catch (final Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* relplaces some entities like < , > and & with their escaped pendant like <
|
||||||
|
* @param s the string
|
||||||
|
* @return the "safe" string
|
||||||
|
*/
|
||||||
public static String encodeXML(CharSequence s) {
|
public static String encodeXML(CharSequence s) {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import javax.xml.xpath.XPathExpressionException;
|
|||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.fop.util.XMLUtil;
|
||||||
import org.apache.pdfbox.Loader;
|
import org.apache.pdfbox.Loader;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
|
import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
|
||||||
@@ -702,7 +703,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
|||||||
if (node != null) {
|
if (node != null) {
|
||||||
final NodeList tradeAgreementChildren = node.getChildNodes();
|
final NodeList tradeAgreementChildren = node.getChildNodes();
|
||||||
node = getNodeByName(tradeAgreementChildren, "ChargeAmount");
|
node = getNodeByName(tradeAgreementChildren, "ChargeAmount");
|
||||||
lineItem.setPrice(tryBigDecimal(getNodeValue(node)));
|
lineItem.setPrice(XMLTools.tryBigDecimal(node));
|
||||||
node = getNodeByName(tradeAgreementChildren, "BasisQuantity");
|
node = getNodeByName(tradeAgreementChildren, "BasisQuantity");
|
||||||
if (node != null && node.getAttributes() != null) {
|
if (node != null && node.getAttributes() != null) {
|
||||||
final Node unitCodeAttribute = node.getAttributes().getNamedItem("unitCode");
|
final Node unitCodeAttribute = node.getAttributes().getNamedItem("unitCode");
|
||||||
@@ -715,48 +716,48 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
|||||||
node = getNodeByName(nn.getChildNodes(), "GrossPriceProductTradePrice");
|
node = getNodeByName(nn.getChildNodes(), "GrossPriceProductTradePrice");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node = getNodeByName(node.getChildNodes(), "ChargeAmount");
|
node = getNodeByName(node.getChildNodes(), "ChargeAmount");
|
||||||
lineItem.setGrossPrice(tryBigDecimal(getNodeValue(node)));
|
lineItem.setGrossPrice(XMLTools.tryBigDecimal(node));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "AssociatedDocumentLineDocument":
|
case "AssociatedDocumentLineDocument":
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "LineID");
|
node = getNodeByName(nn.getChildNodes(), "LineID");
|
||||||
lineItem.setId(getNodeValue(node));
|
lineItem.setId(XMLTools.getNodeValue(node));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SpecifiedTradeProduct":
|
case "SpecifiedTradeProduct":
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "SellerAssignedID");
|
node = getNodeByName(nn.getChildNodes(), "SellerAssignedID");
|
||||||
lineItem.getProduct().setSellerAssignedID(getNodeValue(node));
|
lineItem.getProduct().setSellerAssignedID(XMLTools.getNodeValue(node));
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "BuyerAssignedID");
|
node = getNodeByName(nn.getChildNodes(), "BuyerAssignedID");
|
||||||
lineItem.getProduct().setBuyerAssignedID(getNodeValue(node));
|
lineItem.getProduct().setBuyerAssignedID(XMLTools.getNodeValue(node));
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "Name");
|
node = getNodeByName(nn.getChildNodes(), "Name");
|
||||||
lineItem.getProduct().setName(getNodeValue(node));
|
lineItem.getProduct().setName(XMLTools.getNodeValue(node));
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "Description");
|
node = getNodeByName(nn.getChildNodes(), "Description");
|
||||||
lineItem.getProduct().setDescription(getNodeValue(node));
|
lineItem.getProduct().setDescription(XMLTools.getNodeValue(node));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SpecifiedLineTradeDelivery":
|
case "SpecifiedLineTradeDelivery":
|
||||||
case "SpecifiedSupplyChainTradeDelivery":
|
case "SpecifiedSupplyChainTradeDelivery":
|
||||||
node = getNodeByName(nn.getChildNodes(), "BilledQuantity");
|
node = getNodeByName(nn.getChildNodes(), "BilledQuantity");
|
||||||
lineItem.setQuantity(tryBigDecimal(getNodeValue(node)));
|
lineItem.setQuantity(XMLTools.tryBigDecimal(node));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SpecifiedLineTradeSettlement":
|
case "SpecifiedLineTradeSettlement":
|
||||||
node = getNodeByName(nn.getChildNodes(), "ApplicableTradeTax");
|
node = getNodeByName(nn.getChildNodes(), "ApplicableTradeTax");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node = getNodeByName(node.getChildNodes(), "RateApplicablePercent");
|
node = getNodeByName(node.getChildNodes(), "RateApplicablePercent");
|
||||||
lineItem.getProduct().setVATPercent(tryBigDecimal(getNodeValue(node)));
|
lineItem.getProduct().setVATPercent(XMLTools.tryBigDecimal(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "ApplicableTradeTax");
|
node = getNodeByName(nn.getChildNodes(), "ApplicableTradeTax");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node = getNodeByName(node.getChildNodes(), "CalculatedAmount");
|
node = getNodeByName(node.getChildNodes(), "CalculatedAmount");
|
||||||
lineItem.setTax(tryBigDecimal(getNodeValue(node)));
|
lineItem.setTax(XMLTools.tryBigDecimal(node));
|
||||||
}
|
}
|
||||||
node = getNodeByName(nn.getChildNodes(), "BillingSpecifiedPeriod");
|
node = getNodeByName(nn.getChildNodes(), "BillingSpecifiedPeriod");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
@@ -770,13 +771,13 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
|||||||
if (end != null) {
|
if (end != null) {
|
||||||
dateTimeEnd = getNodeByName(end.getChildNodes(), "DateTimeString");
|
dateTimeEnd = getNodeByName(end.getChildNodes(), "DateTimeString");
|
||||||
}
|
}
|
||||||
lineItem.setDetailedDeliveryPeriod(tryDate(dateTimeStart), tryDate(dateTimeEnd));
|
lineItem.setDetailedDeliveryPeriod(XMLTools.tryDate(dateTimeStart), XMLTools.tryDate(dateTimeEnd));
|
||||||
}
|
}
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "SpecifiedTradeSettlementLineMonetarySummation");
|
node = getNodeByName(nn.getChildNodes(), "SpecifiedTradeSettlementLineMonetarySummation");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node = getNodeByName(node.getChildNodes(), "LineTotalAmount");
|
node = getNodeByName(node.getChildNodes(), "LineTotalAmount");
|
||||||
lineItem.setLineTotalAmount(tryBigDecimal(getNodeValue(node)));
|
lineItem.setLineTotalAmount(XMLTools.tryBigDecimal(node));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "SpecifiedSupplyChainTradeSettlement":
|
case "SpecifiedSupplyChainTradeSettlement":
|
||||||
@@ -785,19 +786,19 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
|||||||
node = getNodeByName(nn.getChildNodes(), "ApplicableTradeTax");
|
node = getNodeByName(nn.getChildNodes(), "ApplicableTradeTax");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node = getNodeByName(node.getChildNodes(), "ApplicablePercent");
|
node = getNodeByName(node.getChildNodes(), "ApplicablePercent");
|
||||||
lineItem.getProduct().setVATPercent(tryBigDecimal(getNodeValue(node)));
|
lineItem.getProduct().setVATPercent(XMLTools.tryBigDecimal(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "ApplicableTradeTax");
|
node = getNodeByName(nn.getChildNodes(), "ApplicableTradeTax");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node = getNodeByName(node.getChildNodes(), "CalculatedAmount");
|
node = getNodeByName(node.getChildNodes(), "CalculatedAmount");
|
||||||
lineItem.setTax(tryBigDecimal(getNodeValue(node)));
|
lineItem.setTax(XMLTools.tryBigDecimal(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
node = getNodeByName(nn.getChildNodes(), "SpecifiedTradeSettlementMonetarySummation");
|
node = getNodeByName(nn.getChildNodes(), "SpecifiedTradeSettlementMonetarySummation");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node = getNodeByName(node.getChildNodes(), "LineTotalAmount");
|
node = getNodeByName(node.getChildNodes(), "LineTotalAmount");
|
||||||
lineItem.setLineTotalAmount(tryBigDecimal(getNodeValue(node)));
|
lineItem.setLineTotalAmount(XMLTools.tryBigDecimal(node));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -872,51 +873,4 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the value of an node
|
|
||||||
*
|
|
||||||
* @param node the Node to get the value from
|
|
||||||
* @return A String or empty String, if no value was found
|
|
||||||
*/
|
|
||||||
private String getNodeValue(Node node) {
|
|
||||||
if (node != null && node.getFirstChild() != null) {
|
|
||||||
return node.getFirstChild().getNodeValue();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* tries to convert an String to BigDecimal.
|
|
||||||
*
|
|
||||||
* @param nodeValue The value as String
|
|
||||||
* @return a BigDecimal with the value provides as String or a BigDecimal with value 0.00 if an error occurs
|
|
||||||
*/
|
|
||||||
private BigDecimal tryBigDecimal(String nodeValue) {
|
|
||||||
try {
|
|
||||||
return new BigDecimal(nodeValue);
|
|
||||||
} catch (final Exception e) {
|
|
||||||
try {
|
|
||||||
return BigDecimal.valueOf(Float.valueOf(nodeValue));
|
|
||||||
} catch (final Exception ex) {
|
|
||||||
return new BigDecimal("0.00");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Date tryDate(Node node) {
|
|
||||||
final String nodeValue = getNodeValue(node);
|
|
||||||
if (nodeValue.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return tryDate(nodeValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Date tryDate(String toParse) {
|
|
||||||
final SimpleDateFormat formatter = ZUGFeRDDateFormat.DATE.getFormatter();
|
|
||||||
try {
|
|
||||||
return formatter.parse(toParse);
|
|
||||||
} catch (final Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,6 +261,8 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
|
|
||||||
String number = "";
|
String number = "";
|
||||||
String typeCode = null;
|
String typeCode = null;
|
||||||
|
String deliveryPeriodStart = null;
|
||||||
|
String deliveryPeriodEnd = null;
|
||||||
/*
|
/*
|
||||||
* dummywerte sind derzeit noch setDueDate setIssueDate setDeliveryDate
|
* dummywerte sind derzeit noch setDueDate setIssueDate setDeliveryDate
|
||||||
* setSender setRecipient setnumber bspw. due date
|
* setSender setRecipient setnumber bspw. due date
|
||||||
@@ -460,9 +462,37 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((headerTradeSettlementChilds.item(settlementChildIndex).getLocalName() != null)
|
||||||
|
&& (headerTradeSettlementChilds.item(settlementChildIndex).getLocalName().equals("BillingSpecifiedPeriod"))) {
|
||||||
|
NodeList periodChilds = headerTradeSettlementChilds.item(settlementChildIndex).getChildNodes();
|
||||||
|
for (int periodChildIndex = 0; periodChildIndex < periodChilds.getLength(); periodChildIndex++) {
|
||||||
|
if ((periodChilds.item(periodChildIndex).getLocalName() != null) && (periodChilds.item(periodChildIndex).getLocalName().equals("StartDateTime"))) {
|
||||||
|
|
||||||
|
NodeList startPeriodChilds = periodChilds.item(periodChildIndex).getChildNodes();
|
||||||
|
for (int startPeriodIndex = 0; startPeriodIndex < startPeriodChilds.getLength(); startPeriodIndex++) {
|
||||||
|
if ((startPeriodChilds.item(startPeriodIndex).getLocalName() != null) && (startPeriodChilds.item(startPeriodIndex).getLocalName().equals("DateTimeString"))) {//CII
|
||||||
|
deliveryPeriodStart = startPeriodChilds.item(startPeriodIndex).getTextContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((periodChilds.item(periodChildIndex).getLocalName() != null) && (periodChilds.item(periodChildIndex).getLocalName().equals("EndDateTime"))) {
|
||||||
|
NodeList endPeriodChilds = periodChilds.item(periodChildIndex).getChildNodes();
|
||||||
|
for (int endPeriodIndex = 0; endPeriodIndex < endPeriodChilds.getLength(); endPeriodIndex++) {
|
||||||
|
if ((endPeriodChilds.item(endPeriodIndex).getLocalName() != null) && (endPeriodChilds.item(endPeriodIndex).getLocalName().equals("DateTimeString"))) {//CII
|
||||||
|
deliveryPeriodEnd = endPeriodChilds.item(endPeriodIndex).getTextContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((deliveryPeriodStart!=null)&&(deliveryPeriodEnd!=null)) {
|
||||||
|
zpp.setDetailedDeliveryPeriod(XMLTools.tryDate(deliveryPeriodStart), XMLTools.tryDate(deliveryPeriodEnd));
|
||||||
|
} else if (deliveryPeriodStart!=null) {
|
||||||
|
zpp.setDeliveryDate(XMLTools.tryDate(deliveryPeriodStart));
|
||||||
|
}
|
||||||
|
|
||||||
xpr = xpath.compile("//*[local-name()=\"PaymentMeans\"]"); //UBL only
|
xpr = xpath.compile("//*[local-name()=\"PaymentMeans\"]"); //UBL only
|
||||||
NodeList paymentMeansNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
NodeList paymentMeansNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
||||||
|
|||||||
Reference in New Issue
Block a user