import contacts and tradeparty vat and tax number

This commit is contained in:
jstaerk
2021-10-25 14:54:19 +02:00
parent 032629ab44
commit 41e5689b6a
3 changed files with 135 additions and 34 deletions

View File

@@ -1,6 +1,8 @@
package org.mustangproject;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/***
* a named contact person in an organisation
@@ -9,8 +11,8 @@ import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact;
*/
public class Contact implements IZUGFeRDExportableContact {
protected String name,phone,email,zip,street,location,country;
protected String fax=null;
protected String name, phone, email, zip, street, location, country;
protected String fax = null;
/***
* default constructor.
@@ -46,6 +48,58 @@ public class Contact implements IZUGFeRDExportableContact {
}
/***
* XML parsing constructor
* @param nodes the nodelist returned e.g. from xpath
*
* e.g. sth like
* <ram:DefinedTradeContact>
* <ram:PersonName>Name</ram:PersonName>
* <ram:TelephoneUniversalCommunication>
* <ram:CompleteNumber>069 100-0</ram:CompleteNumber>
* </ram:TelephoneUniversalCommunication>
* <ram:EmailURIUniversalCommunication>
* <ram:URIID>test@example.com</ram:URIID>
* </ram:EmailURIUniversalCommunication>
* </ram:DefinedTradeContact>
*/
public Contact(NodeList nodes) {
if (nodes.getLength() > 0) {
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
//nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(nodeIndex);
if (currentItemNode.getLocalName() != null) {
if (currentItemNode.getLocalName().equals("PersonName")) {
setName(currentItemNode.getFirstChild().getNodeValue());
}
if (currentItemNode.getLocalName().equals("TelephoneUniversalCommunication")) {
NodeList tel = currentItemNode.getChildNodes();
for (int telChildIndex = 0; telChildIndex < tel.getLength(); telChildIndex++) {
if (tel.item(telChildIndex).getLocalName() != null) {
if (tel.item(telChildIndex).getLocalName().equals("CompleteNumber")) {
setPhone(tel.item(telChildIndex).getTextContent());
}
}
}
}
if (currentItemNode.getLocalName().equals("EmailURIUniversalCommunication")) {
NodeList email = currentItemNode.getChildNodes();
for (int emailChildIndex = 0; emailChildIndex < email.getLength(); emailChildIndex++) {
if (email.item(emailChildIndex).getLocalName() != null) {
if (email.item(emailChildIndex).getLocalName().equals("URIID")) {
setEMail(email.item(emailChildIndex).getTextContent());
}
}
}
}
}
}
}
}
@Override
public String getName() {
return name;
@@ -53,6 +107,7 @@ public class Contact implements IZUGFeRDExportableContact {
/**
* the first and last name of the contact
*
* @param name first and last name
* @return fluent setter
*/
@@ -126,6 +181,7 @@ public class Contact implements IZUGFeRDExportableContact {
/**
* street and number, if the address is different to the organisation
*
* @param street street and number of the contact
* @return fluent setter
*/

View File

@@ -78,35 +78,64 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
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:LineTwo")) {
setAdditionalAddress(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());
}
if (itemChilds.item(itemChildIndex).getLocalName() != null) {
if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) {
setName(itemChilds.item(itemChildIndex).getTextContent());
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("DefinedTradeContact")) {
NodeList contact = itemChilds.item(itemChildIndex).getChildNodes();
setContact(new Contact(contact));
}
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("PostalTradeAddress")) {
NodeList postal = itemChilds.item(itemChildIndex).getChildNodes();
for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) {
if (postal.item(postalChildIndex).getLocalName() != null) {
if (postal.item(postalChildIndex).getLocalName().equals("LineOne")) {
setStreet(postal.item(postalChildIndex).getTextContent());
}
if (postal.item(postalChildIndex).getLocalName().equals("LineTwo")) {
setAdditionalAddress(postal.item(postalChildIndex).getTextContent());
}
if (postal.item(postalChildIndex).getLocalName().equals("CityName")) {
setLocation(postal.item(postalChildIndex).getTextContent());
}
if (postal.item(postalChildIndex).getLocalName().equals("PostcodeCode")) {
setZIP(postal.item(postalChildIndex).getTextContent());
}
if (postal.item(postalChildIndex).getLocalName().equals("CountryID")) {
setCountry(postal.item(postalChildIndex).getTextContent());
}
}
}
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedTaxRegistration")) {
NodeList taxChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
if (taxChilds.item(taxChildIndex).getLocalName() != null) {
if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) {
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID")!=null) {
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("VA"))
{
setVATID(taxChilds.item(taxChildIndex).getFirstChild().getNodeValue());
}
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("FC"))
{
setTaxID(taxChilds.item(taxChildIndex).getFirstChild().getNodeValue());
}
}
}
}
}
}
}
}
}
}
}
@Override
@@ -116,6 +145,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
/**
* if it's a customer, this can e.g. be the customer ID
*
* @param ID customer/seller number
* @return fluent setter
*/
@@ -144,14 +174,16 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
bankDetails.add(s);
return this;
}
/**
* (optional)
*
* @param debitDetail
* @return fluent setter
*/
public TradeParty addDebitDetails(IZUGFeRDTradeSettlementDebit debitDetail) {
debitDetails.add(debitDetail);
return this;
debitDetails.add(debitDetail);
return this;
}
public List<BankDetails> getBankDetails() {
@@ -183,11 +215,21 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
return vatID;
}
public TradeParty setVATID(String VATid) {
this.vatID = VATid;
return this;
}
@Override
public String getTaxID() {
return taxID;
}
public TradeParty setTaxID(String tax) {
this.taxID = tax;
return this;
}
public String getName() {
return name;
}
@@ -278,13 +320,13 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
return null;
}
List<IZUGFeRDTradeSettlement> tradeSettlements = Stream.concat(bankDetails.stream(), debitDetails.stream())
.map(IZUGFeRDTradeSettlement.class::cast)
.collect(Collectors.toList());
.map(IZUGFeRDTradeSettlement.class::cast)
.collect(Collectors.toList());
IZUGFeRDTradeSettlement[] result = new IZUGFeRDTradeSettlement[tradeSettlements.size()];
for (int i = 0; i < tradeSettlements.size(); i++) {
IZUGFeRDTradeSettlement izugFeRDTradeSettlement = tradeSettlements.get(i);
result[i]=izugFeRDTradeSettlement;
IZUGFeRDTradeSettlement izugFeRDTradeSettlement = tradeSettlements.get(i);
result[i] = izugFeRDTradeSettlement;
}
return result;
}

View File

@@ -130,8 +130,11 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
xml += " <ram:Name>" + XMLTools.encodeXML(party.getName()) + "</ram:Name>\n";
if ((party.getContact() != null) && (isSender || profile == Profiles.getByName("Extended") || profile == Profiles.getByName("XRechnung"))) {
xml = xml + "<ram:DefinedTradeContact>\n" + " <ram:PersonName>" + XMLTools.encodeXML(party.getContact().getName())
+ "</ram:PersonName>\n";
xml = xml + "<ram:DefinedTradeContact>\n";
if (party.getContact().getPhone() != null) {
xml = xml + "<ram:PersonName>" + XMLTools.encodeXML(party.getContact().getName())
+ "</ram:PersonName>\n";
}
if (party.getContact().getPhone() != null) {
xml = xml + " <ram:TelephoneUniversalCommunication>\n" + " <ram:CompleteNumber>"