From 742fd1df21da6ab57bc98ef4dc1b0c01ec8dcf24 Mon Sep 17 00:00:00 2001 From: Bharti Date: Mon, 20 Oct 2025 22:49:53 +0200 Subject: [PATCH] Reading BT17 based on typecode --- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 8971ecff..623c491b 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -686,6 +686,8 @@ public class ZUGFeRDInvoiceImporter { String sellerOrderIssuerAssignedID = null; String additionalReferencedDocument = null; Date additionalReferencedDocumentDate = null; + int typeC = 0; + for (int i = 0; i < headerTradeAgreementNodes.getLength(); i++) { // XMLTools.trimOrNull(nodes.item(i)))) { Node headerTradeAgreementNode = headerTradeAgreementNodes.item(i); @@ -712,33 +714,41 @@ public class ZUGFeRDInvoiceImporter { } } //Reading BT-17 - if(headerTradeAgreementChilds.item(agreementChildIndex).getLocalName().equals("AdditionalReferencedDocument")) { + if (headerTradeAgreementChilds.item(agreementChildIndex).getLocalName().equals("AdditionalReferencedDocument")) { NodeList additionalChilds = headerTradeAgreementChilds.item(agreementChildIndex).getChildNodes(); - for (int additionalChildIndex = 0; additionalChildIndex < additionalChilds.getLength(); additionalChildIndex++){ - if((additionalChilds.item(additionalChildIndex).getLocalName() != null) - && (additionalChilds.item(additionalChildIndex).getLocalName().equals("IssuerAssignedID"))) { - additionalReferencedDocument = XMLTools.trimOrNull(additionalChilds.item(additionalChildIndex)); + for (int additionalChildIndex = 0; additionalChildIndex < additionalChilds.getLength(); additionalChildIndex++) { + + if ((additionalChilds.item(additionalChildIndex).getLocalName() != null) + && additionalChilds.item(additionalChildIndex).getLocalName().equals("TypeCode")) { + typeC = Integer.parseInt(XMLTools.trimOrNull(additionalChilds.item(additionalChildIndex))); } - if((additionalChilds.item(additionalChildIndex).getLocalName() != null) - && (additionalChilds.item(additionalChildIndex).getLocalName().equals("FormattedIssueDateTime"))) { + if (typeC == 50) { + if ((additionalChilds.item(additionalChildIndex).getLocalName() != null) + && (additionalChilds.item(additionalChildIndex).getLocalName().equals("IssuerAssignedID"))) { + additionalReferencedDocument = XMLTools.trimOrNull(additionalChilds.item(additionalChildIndex)); + } + if ((additionalChilds.item(additionalChildIndex).getLocalName() != null) + && (additionalChilds.item(additionalChildIndex).getLocalName().equals("FormattedIssueDateTime"))) { + + NodeList FormattedIssueDateTimeChilds = additionalChilds.item(additionalChildIndex).getChildNodes(); + for (int dateChildIndex = 0; dateChildIndex < FormattedIssueDateTimeChilds.getLength(); dateChildIndex++) { + if ((FormattedIssueDateTimeChilds.item(dateChildIndex).getLocalName() != null) + && (FormattedIssueDateTimeChilds.item(dateChildIndex).getLocalName().equals("DateTimeString"))) { + additionalReferencedDocumentDate = XMLTools.tryDate(FormattedIssueDateTimeChilds.item(dateChildIndex)); + } - NodeList FormattedIssueDateTimeChilds = additionalChilds.item(additionalChildIndex).getChildNodes(); - for (int dateChildIndex = 0; dateChildIndex < FormattedIssueDateTimeChilds.getLength(); dateChildIndex++){ - if((FormattedIssueDateTimeChilds.item(dateChildIndex).getLocalName() != null) - && (FormattedIssueDateTimeChilds.item(dateChildIndex).getLocalName().equals("DateTimeString"))) { - additionalReferencedDocumentDate = XMLTools.tryDate(FormattedIssueDateTimeChilds.item(dateChildIndex)); } - } } } } } } - } + + String currency = extractString("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]/*[local-name()=\"InvoiceCurrencyCode\"]|//*[local-name()=\"DocumentCurrencyCode\"]"); zpp.setCurrency(currency); @@ -973,6 +983,7 @@ public class ZUGFeRDInvoiceImporter { zpp.setDespatchAdviceReferencedDocumentID(s); } } + if (additionalReferencedDocument != null){ if (additionalReferencedDocumentDate!=null) { zpp.setTenderReferencedDocument(new DatedReference(additionalReferencedDocument, additionalReferencedDocumentDate));