- be able to extract data into existing invoice objects
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
- #317 (support conversion towards peppol #282)
|
||||||
|
- #313
|
||||||
|
- https://github.com/ZUGFeRD/mustangproject/pull/315 invoiceimporter constructor for InputStream
|
||||||
|
- be able to extract data into existing invoice objects
|
||||||
|
|
||||||
2.7.0
|
2.7.0
|
||||||
=======
|
=======
|
||||||
2023-04-17
|
2023-04-17
|
||||||
|
|||||||
@@ -57,12 +57,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseException {
|
||||||
* This will parse a XML into a invoice object
|
|
||||||
*
|
|
||||||
* @return the parsed invoice object
|
|
||||||
*/
|
|
||||||
public Invoice extractInvoice() throws XPathExpressionException, ParseException {
|
|
||||||
|
|
||||||
String number = "";
|
String number = "";
|
||||||
/*
|
/*
|
||||||
@@ -72,7 +67,6 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
*/
|
*/
|
||||||
XPathFactory xpathFact = XPathFactory.newInstance();
|
XPathFactory xpathFact = XPathFactory.newInstance();
|
||||||
XPath xpath = xpathFact.newXPath();
|
XPath xpath = xpathFact.newXPath();
|
||||||
Invoice zpp = null;
|
|
||||||
XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]");
|
XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]");
|
||||||
NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
||||||
|
|
||||||
@@ -108,7 +102,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
.getLength(); issueDateChildIndex++) {
|
.getLength(); issueDateChildIndex++) {
|
||||||
if ((issueDateTimeChilds.item(issueDateChildIndex).getLocalName() != null)
|
if ((issueDateTimeChilds.item(issueDateChildIndex).getLocalName() != null)
|
||||||
&& (issueDateTimeChilds.item(issueDateChildIndex).getLocalName()
|
&& (issueDateTimeChilds.item(issueDateChildIndex).getLocalName()
|
||||||
.equals("DateTimeString"))) {
|
.equals("DateTimeString"))) {
|
||||||
issueDate = new SimpleDateFormat("yyyyMMdd")
|
issueDate = new SimpleDateFormat("yyyyMMdd")
|
||||||
.parse(issueDateTimeChilds.item(issueDateChildIndex).getTextContent());
|
.parse(issueDateTimeChilds.item(issueDateChildIndex).getTextContent());
|
||||||
}
|
}
|
||||||
@@ -128,20 +122,20 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
.getLength(); deliveryChildIndex++) {
|
.getLength(); deliveryChildIndex++) {
|
||||||
if ((headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName() != null)
|
if ((headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName() != null)
|
||||||
&& (headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName()
|
&& (headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName()
|
||||||
.equals("ActualDeliverySupplyChainEvent"))) {
|
.equals("ActualDeliverySupplyChainEvent"))) {
|
||||||
NodeList actualDeliveryChilds = headerTradeDeliveryChilds.item(deliveryChildIndex).getChildNodes();
|
NodeList actualDeliveryChilds = headerTradeDeliveryChilds.item(deliveryChildIndex).getChildNodes();
|
||||||
for (int actualDeliveryChildIndex = 0; actualDeliveryChildIndex < actualDeliveryChilds
|
for (int actualDeliveryChildIndex = 0; actualDeliveryChildIndex < actualDeliveryChilds
|
||||||
.getLength(); actualDeliveryChildIndex++) {
|
.getLength(); actualDeliveryChildIndex++) {
|
||||||
if ((actualDeliveryChilds.item(actualDeliveryChildIndex).getLocalName() != null)
|
if ((actualDeliveryChilds.item(actualDeliveryChildIndex).getLocalName() != null)
|
||||||
&& (actualDeliveryChilds.item(actualDeliveryChildIndex).getLocalName()
|
&& (actualDeliveryChilds.item(actualDeliveryChildIndex).getLocalName()
|
||||||
.equals("OccurrenceDateTime"))) {
|
.equals("OccurrenceDateTime"))) {
|
||||||
NodeList occurenceChilds = actualDeliveryChilds.item(actualDeliveryChildIndex)
|
NodeList occurenceChilds = actualDeliveryChilds.item(actualDeliveryChildIndex)
|
||||||
.getChildNodes();
|
.getChildNodes();
|
||||||
for (int occurenceChildIndex = 0; occurenceChildIndex < occurenceChilds
|
for (int occurenceChildIndex = 0; occurenceChildIndex < occurenceChilds
|
||||||
.getLength(); occurenceChildIndex++) {
|
.getLength(); occurenceChildIndex++) {
|
||||||
if ((occurenceChilds.item(occurenceChildIndex).getLocalName() != null)
|
if ((occurenceChilds.item(occurenceChildIndex).getLocalName() != null)
|
||||||
&& (occurenceChilds.item(occurenceChildIndex).getLocalName()
|
&& (occurenceChilds.item(occurenceChildIndex).getLocalName()
|
||||||
.equals("DateTimeString"))) {
|
.equals("DateTimeString"))) {
|
||||||
deliveryDate = new SimpleDateFormat("yyyyMMdd")
|
deliveryDate = new SimpleDateFormat("yyyyMMdd")
|
||||||
.parse(occurenceChilds.item(occurenceChildIndex).getTextContent());
|
.parse(occurenceChilds.item(occurenceChildIndex).getTextContent());
|
||||||
}
|
}
|
||||||
@@ -163,7 +157,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
.getLength(); settlementChildIndex++) {
|
.getLength(); settlementChildIndex++) {
|
||||||
if ((headerTradeSettlementChilds.item(settlementChildIndex).getLocalName() != null)
|
if ((headerTradeSettlementChilds.item(settlementChildIndex).getLocalName() != null)
|
||||||
&& (headerTradeSettlementChilds.item(settlementChildIndex).getLocalName()
|
&& (headerTradeSettlementChilds.item(settlementChildIndex).getLocalName()
|
||||||
.equals("SpecifiedTradePaymentTerms"))) {
|
.equals("SpecifiedTradePaymentTerms"))) {
|
||||||
NodeList paymentTermChilds = headerTradeSettlementChilds.item(settlementChildIndex).getChildNodes();
|
NodeList paymentTermChilds = headerTradeSettlementChilds.item(settlementChildIndex).getChildNodes();
|
||||||
for (int paymentTermChildIndex = 0; paymentTermChildIndex < paymentTermChilds
|
for (int paymentTermChildIndex = 0; paymentTermChildIndex < paymentTermChilds
|
||||||
.getLength(); paymentTermChildIndex++) {
|
.getLength(); paymentTermChildIndex++) {
|
||||||
@@ -184,7 +178,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zpp = new Invoice().setDueDate(dueDate).setDeliveryDate(deliveryDate).setIssueDate(issueDate)
|
zpp.setDueDate(dueDate).setDeliveryDate(deliveryDate).setIssueDate(issueDate)
|
||||||
.setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number);
|
.setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number);
|
||||||
//.addItem(new Item(new Product("Testprodukt","","C62",BigDecimal.ZERO),amount,new BigDecimal(1.0)))
|
//.addItem(new Item(new Product("Testprodukt","","C62",BigDecimal.ZERO),amount,new BigDecimal(1.0)))
|
||||||
zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]"));
|
zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]"));
|
||||||
@@ -195,7 +189,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
if (totalNodes.getLength() > 0) {
|
if (totalNodes.getLength() > 0) {
|
||||||
buyerReference = totalNodes.item(0).getTextContent();
|
buyerReference = totalNodes.item(0).getTextContent();
|
||||||
}
|
}
|
||||||
if (buyerReference!=null) {
|
if (buyerReference != null) {
|
||||||
zpp.setReferenceNumber(buyerReference);
|
zpp.setReferenceNumber(buyerReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +272,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
String tradeName = tradeLineChilds.item(tradeLineChildIndex).getLocalName();
|
String tradeName = tradeLineChilds.item(tradeLineChildIndex).getLocalName();
|
||||||
if ((tradeName != null)
|
if ((tradeName != null)
|
||||||
&& (tradeName.equals("BilledQuantity") || tradeName.equals("RequestedQuantity")
|
&& (tradeName.equals("BilledQuantity") || tradeName.equals("RequestedQuantity")
|
||||||
|| tradeName.equals("DespatchedQuantity"))) {
|
|| tradeName.equals("DespatchedQuantity"))) {
|
||||||
// RequestedQuantity is for Order-X, BilledQuantity for FX and ZF
|
// RequestedQuantity is for Order-X, BilledQuantity for FX and ZF
|
||||||
quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent();
|
quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent();
|
||||||
unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes()
|
unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes()
|
||||||
@@ -292,12 +286,12 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
.getLength(); tradeProductChildIndex++) {
|
.getLength(); tradeProductChildIndex++) {
|
||||||
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
|
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
|
||||||
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
|
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
|
||||||
.equals("Name"))) {
|
.equals("Name"))) {
|
||||||
name = tradeProductChilds.item(tradeProductChildIndex).getTextContent();
|
name = tradeProductChilds.item(tradeProductChildIndex).getTextContent();
|
||||||
}
|
}
|
||||||
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
|
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
|
||||||
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
|
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
|
||||||
.equals("GlobalID"))) {
|
.equals("GlobalID"))) {
|
||||||
if (tradeProductChilds.item(tradeProductChildIndex).getAttributes()
|
if (tradeProductChilds.item(tradeProductChildIndex).getAttributes()
|
||||||
.getNamedItem("schemeID") != null) {
|
.getNamedItem("schemeID") != null) {
|
||||||
gid = new SchemedID()
|
gid = new SchemedID()
|
||||||
@@ -388,7 +382,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
.getLength(); indicatorChildIndex++) {
|
.getLength(); indicatorChildIndex++) {
|
||||||
if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null)
|
if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null)
|
||||||
&& (indicatorChilds.item(indicatorChildIndex).getLocalName()
|
&& (indicatorChilds.item(indicatorChildIndex).getLocalName()
|
||||||
.equals("Indicator"))) {
|
.equals("Indicator"))) {
|
||||||
isCharge = indicatorChilds.item(indicatorChildIndex).getTextContent()
|
isCharge = indicatorChilds.item(indicatorChildIndex).getTextContent()
|
||||||
.equalsIgnoreCase("true");
|
.equalsIgnoreCase("true");
|
||||||
}
|
}
|
||||||
@@ -445,7 +439,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
|
|
||||||
if ((whichType != EStandard.despatchadvice)
|
if ((whichType != EStandard.despatchadvice)
|
||||||
&& ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2)))
|
&& ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2)))
|
||||||
&& (!ignoreCalculationErrors))) {
|
&& (!ignoreCalculationErrors))) {
|
||||||
throw new ParseException(
|
throw new ParseException(
|
||||||
"Could not reproduce the invoice, this could mean that it could not be read properly", 0);
|
"Could not reproduce the invoice, this could mean that it could not be read properly", 0);
|
||||||
}
|
}
|
||||||
@@ -454,6 +448,18 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* This will parse a XML into a invoice object
|
||||||
|
*
|
||||||
|
* @return the parsed invoice object
|
||||||
|
*/
|
||||||
|
public Invoice extractInvoice() throws XPathExpressionException, ParseException {
|
||||||
|
Invoice i=new Invoice();
|
||||||
|
return extractInto(i);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void doRecalculateItemPricesFromLineTotals() {
|
public void doRecalculateItemPricesFromLineTotals() {
|
||||||
recalcPrice = true;
|
recalcPrice = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user