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; package org.mustangproject;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact; import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/*** /***
* a named contact person in an organisation * a named contact person in an organisation
@@ -9,8 +11,8 @@ import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact;
*/ */
public class Contact implements IZUGFeRDExportableContact { public class Contact implements IZUGFeRDExportableContact {
protected String name,phone,email,zip,street,location,country; protected String name, phone, email, zip, street, location, country;
protected String fax=null; protected String fax = null;
/*** /***
* default constructor. * 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 @Override
public String getName() { public String getName() {
return name; return name;
@@ -53,6 +107,7 @@ public class Contact implements IZUGFeRDExportableContact {
/** /**
* the first and last name of the contact * the first and last name of the contact
*
* @param name first and last name * @param name first and last name
* @return fluent setter * @return fluent setter
*/ */
@@ -126,6 +181,7 @@ public class Contact implements IZUGFeRDExportableContact {
/** /**
* street and number, if the address is different to the organisation * street and number, if the address is different to the organisation
*
* @param street street and number of the contact * @param street street and number of the contact
* @return fluent setter * @return fluent setter
*/ */

View File

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

View File

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