diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index ee0d5a89..53f4562b 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -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())); } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 3323c168..12cef115 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -20,10 +20,8 @@ */ package org.mustangproject.ZUGFeRD; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.codec.binary.StringUtils; import org.junit.jupiter.api.Test; import org.mustangproject.*; @@ -66,7 +64,7 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } assertFalse(hasExceptions); // Reading ZUGFeRD - assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName()); + assertEquals("Bei Spiel GmbH", invoice.getSender().getName()); assertEquals(3, invoice.getZFItems().length); assertEquals("400.0000", invoice.getZFItems()[1].getQuantity().toString()); @@ -124,7 +122,7 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } assertFalse(hasExceptions); // Reading ZUGFeRD - assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName()); + assertEquals("Bei Spiel GmbH", invoice.getSender().getName()); assertEquals(3, invoice.getZFItems().length); assertEquals(invoice.getZFItems()[0].getNotesWithSubjectCode().get(0).getContent(),"Something"); assertEquals(invoice.getZFItems()[0].getNotesWithSubjectCode().size(),1); @@ -200,7 +198,7 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } assertFalse(hasExceptions); // Reading ZUGFeRD - assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName()); + assertEquals("Bei Spiel GmbH", invoice.getSender().getName()); assertEquals(3, invoice.getZFItems().length); assertEquals("400.0000", invoice.getZFItems()[1].getQuantity().toString()); @@ -617,4 +615,22 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { assertEquals(3, invoice.getZFItems().length); assertEquals("BUYER_ACCOUNTING_REF", invoice.getZFItems()[0].getAccountingReference()); } + + @Test + public void testImportExport() throws FileNotFoundException, XPathExpressionException, ParseException { + File inputFile = getResourceAsFile("cii/Factur-X_basic.xml"); + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(); + zii.setInputStream(new FileInputStream(inputFile)); + + Invoice invoice = zii.extractInvoice(); + assertTrue(invoice.isValid()); + + assertNull(invoice.getDeliveryAddress()); + assertNull(invoice.getPayee()); + + assertNull(invoice.getBuyerOrderReferencedDocumentID()); + assertNull(invoice.getSellerOrderReferencedDocumentID()); + assertNull(invoice.getDespatchAdviceReferencedDocumentID()); + assertNull(invoice.getInvoiceReferencedDocumentID()); + } } diff --git a/library/src/test/resources/cii/Factur-X_basic.xml b/library/src/test/resources/cii/Factur-X_basic.xml new file mode 100644 index 00000000..268c19df --- /dev/null +++ b/library/src/test/resources/cii/Factur-X_basic.xml @@ -0,0 +1,130 @@ + + + + + + + + urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic + + + + 471102 + 380 + + 20241115 + + + Rechnung gemäß Bestellung vom 01.11.2024. + + + Lieferant GmbH + Lieferantenstraße 20 + 80333 München + Deutschland + Geschäftsführer: Hans Muster + Handelsregisternummer: H A 123 + + + Unsere GLN: 4000001123452 + Ihre GLN: 4000001987658 + Ihre Kundennummer: GE2020211 + + + Zahlbar innerhalb 30 Tagen netto bis 25.12.2024, 3% Skonto innerhalb 10 Tagen bis 25.11.2024. + + + + + + 1 + + + 4012345001235 + GTIN: 4012345001235 + Unsere Art.-Nr.: TB100A4 + Trennblätter A4 + + + + + 9.9000 + 1.0000 + + + + 20.0000 + + + + VAT + S + 19.00 + + + 198.00 + + + + + + Lieferant GmbH + + 80333 + Lieferantenstraße 20 + München + DE + + + DE123456789 + + + 201/113/40209 + + + + Kunden AG Mitte + + 69876 + Hans Muster + Kundenstraße 15 + Frankfurt + DE + + + + + + + 20241114 + + + + + EUR + + 37.62 + VAT + 198.00 + S + 19.00 + + + Zahlbar innerhalb 30 Tagen netto bis 25.12.2024, 3% Skonto innerhalb 10 Tagen bis 25.11.2024. + + 20241215 + + + + 198.00 + 0.00 + 0.00 + 198.00 + 37.62 + 235.62 + 0.00 + 235.62 + + + +