From 9cbf93c2767cd26c14d62bb29dd501b929f7ddb2 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Mon, 14 Nov 2022 07:48:16 +0100 Subject: [PATCH] - invoiceimporter to parse BuyerReference - support LineThree in TradeParty (BT-165?) --- History.md | 3 +- .../java/org/mustangproject/TradeParty.java | 46 ++++++++++++++++++- .../ZUGFeRD/IZUGFeRDExportableTradeParty.java | 14 +++++- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 4 ++ .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 11 +++++ .../ZUGFeRD/MustangReaderTestCase.java | 10 ++++ .../org/mustangproject/ZUGFeRD/ZF2Test.java | 4 +- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 3 ++ 8 files changed, 89 insertions(+), 6 deletions(-) diff --git a/History.md b/History.md index 0b179aec..010fa2b0 100644 --- a/History.md +++ b/History.md @@ -1,7 +1,8 @@ 2.5.8 ======= - +- invoiceimporter to parse BuyerReference +- support LineThree in TradeParty (BT-165?) - Corrected forgotten --d CLI shortcut 2.5.7 diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index b20285e0..f92455f7 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -25,6 +25,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { protected String taxID = null, vatID = null; protected String ID = null; protected String additionalAddress = null; + protected String additionalAddressExtension = null; protected List bankDetails = new ArrayList<>(); protected List debitDetails = new ArrayList<>(); protected Contact contact = null; @@ -120,6 +121,9 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if (postal.item(postalChildIndex).getLocalName().equals("LineTwo")) { setAdditionalAddress(postal.item(postalChildIndex).getTextContent()); } + if (postal.item(postalChildIndex).getLocalName().equals("LineThree")) { + setAdditionalAddressExtension(postal.item(postalChildIndex).getTextContent()); + } if (postal.item(postalChildIndex).getLocalName().equals("CityName")) { setLocation(postal.item(postalChildIndex).getTextContent()); } @@ -398,9 +402,11 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } + /*** - * additional parts of the address, e.g. which floor. - * Street address will become "lineOne", this will become "lineTwo" + * additional info of the address, e.g. which building or which floor. + * Street address will become "lineOne", this will become "lineTwo". + * (see setAdditionalAddressExtension for "lineThree") * @param additionalAddress additional address description * @return fluent setter */ @@ -409,5 +415,41 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { return this; } + /*** + * Sets two parts of additional address at once, e.g. which building and which floor + * (if building is not in question which floor can also be set with the first part only :-)) + * + * @param additionalAddress1 first part of additional info, e.g. "Rear building" + * @param additionalAddress2 second part of additional address info, e.g. "2nd floor" + * @return fluent setter + */ + public TradeParty setAdditionalAddress(String additionalAddress1, String additionalAddress2) { + this.additionalAddress = additionalAddress1; + this.additionalAddressExtension = additionalAddress2; + return this; + } + + /*** + * Sets even advanced additional address information, + * e.g. which floor (if LineTwo has already been used e.g. for which building) + * This could sometimes be BT-165? + * + * @param additionalAddress2 + * @return fluent setter + */ + public TradeParty setAdditionalAddressExtension(String additionalAddress2) { + this.additionalAddressExtension = additionalAddress2; + return this; + } + + /*** + * Returns even advanced additional address information, + * e.g. which floor (if LineTwo=setAdditionalAddress has already been used e.g. for which building) + * @return lineThree + */ + public String getAdditionalAddressExtension() { + return this.additionalAddressExtension; + } + } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTradeParty.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTradeParty.java index a32846a0..e76a429e 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTradeParty.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTradeParty.java @@ -119,13 +119,25 @@ public interface IZUGFeRDExportableTradeParty { /** * returns additional address information which is display in xml tag "LineTwo" - * + * e.g. "Rear building" + * * @return additional address information */ default String getAdditionalAddress() { return null; } + /** + * returns additional address information which is display in xml tag "LineThree" + * e.g. "Second floor" if LineTwo is already used, e.g. "Rear Building". + * This attribute could sometimes be BT-165? + * + * @return additional address information + */ + default String getAdditionalAddressExtension() { + return null; + } + /*** * obligatory for sender but not for recipient diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 775c789d..9e561392 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -177,6 +177,10 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { xml += "" + XMLTools.encodeXML(party.getAdditionalAddress()) + ""; } + if (party.getAdditionalAddressExtension() != null) { + xml += "" + XMLTools.encodeXML(party.getAdditionalAddressExtension()) + + ""; + } xml += "" + XMLTools.encodeXML(party.getLocation()) + "" + "" + XMLTools.encodeXML(party.getCountry()) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 7ccf7393..eea28b1b 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -183,6 +183,17 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { .setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number); //.addItem(new Item(new Product("Testprodukt","","C62",BigDecimal.ZERO),amount,new BigDecimal(1.0))) zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]")); + + xpr = xpath.compile("//*[local-name()=\"BuyerReference\"]"); + String buyerReference = null; + totalNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); + if (totalNodes.getLength() > 0) { + buyerReference = totalNodes.item(0).getTextContent(); + } + if (buyerReference!=null) { + zpp.setReferenceNumber(buyerReference); + } + xpr = xpath.compile("//*[local-name()=\"IncludedSupplyChainTradeLineItem\"]"); NodeList nodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderTestCase.java b/library/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderTestCase.java index cb94525c..72c71b24 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderTestCase.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderTestCase.java @@ -76,6 +76,16 @@ public abstract class MustangReaderTestCase extends TestCase implements IExporta return "Bahnstr. 42"; } + @Override + public String getAdditionalAddress() { + return "Hinterhaus"; + } + + @Override + public String getAdditionalAddressExtension() { + return "Zweiter Stock"; + } + @Override public String getVATID() { return "DE999999999"; diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2Test.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2Test.java index 6531bff2..fa1f4db5 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2Test.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2Test.java @@ -215,8 +215,8 @@ public class ZF2Test extends MustangReaderTestCase { assertEquals(zi.getForeignReference(), getNumber()); assertEquals(zi.getBuyerTradePartyAddress().getPostcodeCode(), "88802"); assertEquals(zi.getBuyerTradePartyAddress().getLineOne(), "Bahnstr. 42"); - assertEquals(zi.getBuyerTradePartyAddress().getLineTwo(), null); - assertEquals(zi.getBuyerTradePartyAddress().getLineThree(), null); + assertEquals(zi.getBuyerTradePartyAddress().getLineTwo(), "Hinterhaus"); + assertEquals(zi.getBuyerTradePartyAddress().getLineThree(), "Zweiter Stock"); assertEquals(zi.getBuyerTradePartyAddress().getCountrySubDivisionName(), null); assertEquals(zi.getBuyerTradePartyAddress().getCountryID(), "DE"); assertEquals(zi.getBuyerTradePartyAddress().getCityName(), "Spielkreis"); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index a49d7034..2e7ec10f 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -65,6 +65,7 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { assertEquals(3, invoice.getZFItems().length); assertEquals("400.0000", invoice.getZFItems()[1].getQuantity().toString()); + assertEquals("AB321", invoice.getReferenceNumber()); assertEquals("160.0000", invoice.getZFItems()[0].getPrice().toString()); assertEquals("Heiße Luft pro Liter", invoice.getZFItems()[2].getProduct().getName()); assertEquals("LTR", invoice.getZFItems()[2].getProduct().getUnit()); @@ -77,6 +78,8 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { assertEquals("2017-05-30",sdf.format(invoice.getDueDate())); assertEquals("Bahnstr. 42", invoice.getRecipient().getStreet()); + assertEquals("Hinterhaus", invoice.getRecipient().getAdditionalAddress()); + assertEquals("Zweiter Stock", invoice.getRecipient().getAdditionalAddressExtension()); assertEquals("88802", invoice.getRecipient().getZIP()); assertEquals("DE", invoice.getRecipient().getCountry()); assertEquals("Spielkreis", invoice.getRecipient().getLocation());