import doc level allowance charges

This commit is contained in:
jstaerk
2024-11-23 16:39:58 +01:00
parent a1dc8e5b31
commit 5d0e342144
2 changed files with 25 additions and 18 deletions

View File

@@ -304,7 +304,7 @@ public class ZUGFeRDInvoiceImporter {
//UBL... //UBL...
shipEx = xpath.compile("//*[local-name()=\"DeliveryLocation\"]"); shipEx = xpath.compile("//*[local-name()=\"DeliveryLocation\"]");
deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET);
if (deliveryNodes!=null) { if (deliveryNodes != null) {
String street, name, additionalStreet, city, postal, countrySubentity, line, country = null; String street, name, additionalStreet, city, postal, countrySubentity, line, country = null;
street = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"StreetName\"]"); street = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"StreetName\"]");
additionalStreet = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"AdditionalStreetName\"]"); additionalStreet = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"AdditionalStreetName\"]");
@@ -321,7 +321,6 @@ public class ZUGFeRDInvoiceImporter {
} }
xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]/*"); xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]/*");
NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
@@ -463,7 +462,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\"]");
@@ -600,20 +599,17 @@ public class ZUGFeRDInvoiceImporter {
if (buyerOrderIssuerAssignedID != null) { if (buyerOrderIssuerAssignedID != null) {
zpp.setBuyerOrderReferencedDocumentID(buyerOrderIssuerAssignedID); zpp.setBuyerOrderReferencedDocumentID(buyerOrderIssuerAssignedID);
} } else {
else {
zpp.setBuyerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"ID\"]")); zpp.setBuyerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"ID\"]"));
} }
if (sellerOrderIssuerAssignedID != null) { if (sellerOrderIssuerAssignedID != null) {
zpp.setSellerOrderReferencedDocumentID(sellerOrderIssuerAssignedID); zpp.setSellerOrderReferencedDocumentID(sellerOrderIssuerAssignedID);
} } else {
else {
zpp.setSellerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"SalesOrderID\"]")); zpp.setSellerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"SalesOrderID\"]"));
} }
if (despatchAdviceReferencedDocument != null) { if (despatchAdviceReferencedDocument != null) {
zpp.setDespatchAdviceReferencedDocumentID(despatchAdviceReferencedDocument); zpp.setDespatchAdviceReferencedDocumentID(despatchAdviceReferencedDocument);
} } else {
else {
zpp.setDespatchAdviceReferencedDocumentID(extractString("//*[local-name()=\"DespatchDocumentReference\"]/*[local-name()=\"ID\"]")); zpp.setDespatchAdviceReferencedDocumentID(extractString("//*[local-name()=\"DespatchDocumentReference\"]/*[local-name()=\"ID\"]"));
} }
@@ -655,7 +651,7 @@ public class ZUGFeRDInvoiceImporter {
// be read, // be read,
// so the invoice remains arithmetically correct // so the invoice remains arithmetically correct
// -> parse document level charges+allowances // -> parse document level charges+allowances
xpr = xpath.compile("//*[local-name()=\"SpecifiedTradeAllowanceCharge\"]"); xpr = xpath.compile("//*[local-name()=\"SpecifiedTradeAllowanceCharge\"]|/*[local-name()=\"Invoice\"]/*[local-name()=\"AllowanceCharge\"]");//CII and UBL
NodeList chargeNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); NodeList chargeNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
for (int i = 0; i < chargeNodes.getLength(); i++) { for (int i = 0; i < chargeNodes.getLength(); i++) {
NodeList chargeNodeChilds = chargeNodes.item(i).getChildNodes(); NodeList chargeNodeChilds = chargeNodes.item(i).getChildNodes();
@@ -669,18 +665,28 @@ public class ZUGFeRDInvoiceImporter {
if (chargeChildName != null) { if (chargeChildName != null) {
if (chargeChildName.equals("ChargeIndicator")) { if (chargeChildName.equals("ChargeIndicator")) {
NodeList indicatorChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); if (chargeNodeChilds.item(chargeChildIndex).getTextContent().trim().equalsIgnoreCase("false")) {
for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds.getLength(); indicatorChildIndex++) { // UBL
if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null) isCharge = false;
&& (indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) { } else if (chargeNodeChilds.item(chargeChildIndex).getTextContent().trim().equalsIgnoreCase("true")) {
isCharge = XMLTools.trimOrNull(indicatorChilds.item(indicatorChildIndex)).equalsIgnoreCase("true"); // still UBL
isCharge = true;
} else {
//CII
NodeList indicatorChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes();
for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds.getLength(); indicatorChildIndex++) {
if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null)
&& (indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) {
isCharge = XMLTools.trimOrNull(indicatorChilds.item(indicatorChildIndex)).equalsIgnoreCase("true");
}
} }
} }
} else if (chargeChildName.equals("ActualAmount")) {
} else if (chargeChildName.equals("ActualAmount") || chargeChildName.equals("Amount")) {
chargeAmount = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex)); chargeAmount = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex));
} else if (chargeChildName.equals("Reason")) { } else if (chargeChildName.equals("Reason") || chargeChildName.equals("AllowanceChargeReason")) {
reason = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex)); reason = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex));
} else if (chargeChildName.equals("ReasonCode")) { } else if (chargeChildName.equals("ReasonCode") || chargeChildName.equals("AllowanceChargeReasonCode")) {
reasonCode = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex)); reasonCode = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex));
} else if (chargeChildName.equals("CategoryTradeTax")) { } else if (chargeChildName.equals("CategoryTradeTax")) {
NodeList taxChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); NodeList taxChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes();

View File

@@ -407,6 +407,7 @@ this would test if for all elements/attributes
invoiceUBL = zii.extractInvoice(); invoiceUBL = zii.extractInvoice();
try { try {
zii.ignoreCalculationErrors=true;
zii.fromXML(new String(Files.readAllBytes(inputUBL.toPath()), StandardCharsets.UTF_8)); zii.fromXML(new String(Files.readAllBytes(inputUBL.toPath()), StandardCharsets.UTF_8));
} catch (IOException e) { } catch (IOException e) {