Skip to content

Commit

Permalink
first attempt to parse tradeparties from XML
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Stärk authored and Jochen Stärk committed Oct 15, 2020
1 parent 3780cdb commit 47146ad
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
1 change: 1 addition & 0 deletions library/src/main/java/org/mustangproject/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ public Contact setCountry(String country) {
this.country = country;
return this;
}

}
68 changes: 67 additions & 1 deletion library/src/main/java/org/mustangproject/TradeParty.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableTradeParty;
import org.mustangproject.ZUGFeRD.IZUGFeRDTradeSettlement;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.xpath.XPathConstants;
import java.util.ArrayList;

public class TradeParty implements IZUGFeRDExportableTradeParty {
Expand All @@ -22,17 +25,80 @@ public TradeParty(String name, String street, String zip, String location, Strin

}

public TradeParty(NodeList nodes) {
/**
* <ram:SellerTradeParty>
* <ram:ID>LIEF-987654321</ram:ID>
* <ram:Name>Max Mustermann IT GmbH</ram:Name>
* <ram:DefinedTradeContact>
* <ram:PersonName>Herr Treudiener</ram:PersonName>
* <ram:TelephoneUniversalCommunication>
* <ram:CompleteNumber>+49 1234-98765-12</ram:CompleteNumber>
* </ram:TelephoneUniversalCommunication>
* <ram:EmailURIUniversalCommunication>
* <ram:URIID>treudiener@max-mustermann-it.de</ram:URIID>
* </ram:EmailURIUniversalCommunication>
* </ram:DefinedTradeContact>
* <ram:PostalTradeAddress>
* <ram:PostcodeCode>12345</ram:PostcodeCode>
* <ram:LineOne>Musterstraße 1</ram:LineOne>
* <ram:CityName>Musterstadt</ram:CityName>
* <ram:CountryID>DE</ram:CountryID>
* </ram:PostalTradeAddress>
* <ram:SpecifiedTaxRegistration>
* <ram:ID schemeID="VA">DE123456789</ram:ID>
* </ram:SpecifiedTaxRegistration>
* </ram:SellerTradeParty>
*/
if (nodes.getLength() > 0) {

for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
//nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(nodeIndex);
NodeList itemChilds = currentItemNode.getChildNodes();
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
if (itemChilds.item(itemChildIndex).getNodeName().equals("ram:Name")) {
setName(itemChilds.item(itemChildIndex).getTextContent());
}
if (itemChilds.item(itemChildIndex).getNodeName().equals("ram:PostalTradeAddress")) {
NodeList postal = itemChilds.item(itemChildIndex).getChildNodes();
for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) {
if (postal.item(postalChildIndex).getNodeName().equals("ram:LineOne")) {
setStreet(postal.item(postalChildIndex).getTextContent());
}
if (postal.item(postalChildIndex).getNodeName().equals("ram:CityName")) {
setLocation(postal.item(postalChildIndex).getTextContent());
}
if (postal.item(postalChildIndex).getNodeName().equals("ram:PostcodeCode")) {
setZIP(postal.item(postalChildIndex).getTextContent());
}
if (postal.item(postalChildIndex).getNodeName().equals("ram:CountryID")) {
setCountry(postal.item(postalChildIndex).getTextContent());
}
}

}

}
}
}

}

public TradeParty setContact(Contact c) {
this.contact = c;
return this;
}

public TradeParty addBankDetails(BankDetails s) {
bankDetails.add(s);
return this;
}

public ArrayList<BankDetails> getBankDetails() {
return bankDetails;
}

public TradeParty addTaxID(String taxID) {
this.taxID = taxID;
return this;
Expand Down Expand Up @@ -117,7 +183,7 @@ public IZUGFeRDExportableContact getContact() {
}

public IZUGFeRDTradeSettlement[] getAsTradeSettlement() {
if (bankDetails.size()==0) {
if (bankDetails.size() == 0) {
return null;
}
return bankDetails.toArray(new IZUGFeRDTradeSettlement[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ public Invoice extractInvoice() {
* dummywerte sind derzeit noch setDueDate setIssueDate setDeliveryDate setSender setRecipient setnumber
* bspw. due date //ExchangedDocument//IssueDateTime//DateTimeString : due date optional
*/
Invoice zpp = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty("company", "teststr", "55232", "teststadt", "DE")).setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number);
//.addItem(new Item(new Product("Testprodukt","","C62",new BigDecimal(0)),amount,new BigDecimal(1.0)))
zpp.setOwnOrganisationName(extractString("//SellerTradeParty/Name"));

XPathFactory xpathFact = XPathFactory.newInstance();
XPath xpath = xpathFact.newXPath();
Invoice zpp = null;
try {

XPathExpression xpr = xpath.compile(
"//SellerTradeParty");
NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
xpr = xpath.compile(
"//BuyerTradeParty");
NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);

zpp= new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number);
//.addItem(new Item(new Product("Testprodukt","","C62",new BigDecimal(0)),amount,new BigDecimal(1.0)))
zpp.setOwnOrganisationName(extractString("//SellerTradeParty/Name"));

xpr = xpath.compile(
"//*[local-name()=\"IncludedSupplyChainTradeLineItem\"]");
NodeList nodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);

Expand Down

0 comments on commit 47146ad

Please sign in to comment.