Skip to content

Commit

Permalink
closes #343
Browse files Browse the repository at this point in the history
  • Loading branch information
jstaerk committed Dec 23, 2023
1 parent c6173dd commit eba5413
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 232 deletions.
76 changes: 34 additions & 42 deletions library/src/main/java/org/mustangproject/TradeParty.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
protected List<IZUGFeRDTradeSettlementDebit> debitDetails = new ArrayList<>();
protected Contact contact = null;
protected LegalOrganisation legalOrg = null;
protected SchemedID globalId=null;
protected SchemedID uriUniversalCommunicationId=null; //e.g. the email address of the organization
protected SchemedID globalId = null;
protected SchemedID uriUniversalCommunicationId = null; //e.g. the email address of the organization

/**
* Default constructor.
Expand Down Expand Up @@ -153,7 +153,7 @@ protected void parseFromUBL(NodeList nodes) {

if (itemChilds.item(itemChildIndex).getLocalName().equals("GlobalID")) {
if (itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID") != null) {
SchemedID gid=new SchemedID().setScheme(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent());
SchemedID gid = new SchemedID().setScheme(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent());
addGlobalID(gid);
}

Expand Down Expand Up @@ -198,8 +198,7 @@ protected void parseFromUBL(NodeList nodes) {
if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) {
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID") != null) {
Node firstChild = taxChilds.item(taxChildIndex).getFirstChild();
if (firstChild != null)
{
if (firstChild != null) {
if (taxChilds.item(taxChildIndex).getAttributes()
.getNamedItem("schemeID").getNodeValue().equals("VA")) {
setVATID(firstChild.getNodeValue());
Expand Down Expand Up @@ -294,22 +293,19 @@ public TradeParty(NodeList nodes) {
parseFromUBL(nodes);
return;
}

if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) {
setName(itemChilds.item(itemChildIndex).getTextContent());
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("GlobalID")) {
if (itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID") != null) {
SchemedID gid=new SchemedID().setScheme(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent());
SchemedID gid = new SchemedID().setScheme(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent());
addGlobalID(gid);
}

}
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++) {
Expand Down Expand Up @@ -337,6 +333,19 @@ public TradeParty(NodeList nodes) {
}

}
if (itemChilds.item(itemChildIndex).getLocalName().equals("URIUniversalCommunication")) {
NodeList URIchilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int URIChildIndex = 0; URIChildIndex < URIchilds.getLength(); URIChildIndex++) {
Node currentNode = URIchilds.item(URIChildIndex);
if ((currentNode.getLocalName() != null) && (currentNode.getLocalName().equals("URIID")
&&
(currentNode.getAttributes().getNamedItem("schemeID") != null))
&& (URIchilds.item(URIChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("EM"))
) {
setEmail(currentNode.getTextContent());
}
}
}

if (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedTaxRegistration")) {
NodeList taxChilds = itemChilds.item(itemChildIndex).getChildNodes();
Expand All @@ -345,14 +354,13 @@ public TradeParty(NodeList nodes) {
if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) {
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID") != null) {
Node firstChild = taxChilds.item(taxChildIndex).getFirstChild();
if (firstChild != null)
{
if (firstChild != null) {
if (taxChilds.item(taxChildIndex).getAttributes()
.getNamedItem("schemeID").getNodeValue().equals("VA")) {
.getNamedItem("schemeID").getNodeValue().equals("VA")) {
setVATID(firstChild.getNodeValue());
}
if (taxChilds.item(taxChildIndex).getAttributes()
.getNamedItem("schemeID").getNodeValue().equals("FC")) {
.getNamedItem("schemeID").getNodeValue().equals("FC")) {
setTaxID(firstChild.getNodeValue());
}
}
Expand All @@ -374,37 +382,35 @@ public String getID() {

@Override
public String getGlobalID() {
if (globalId!=null) {
if (globalId != null) {
return globalId.getID();
}
return null;
}



@Override
public String getGlobalIDScheme() {
if (globalId!=null) {
if (globalId != null) {
return globalId.getScheme();
}
return null;

}


@Override
public String getUriUniversalCommunicationID() {
if (uriUniversalCommunicationId!=null) {
if (uriUniversalCommunicationId != null) {
return uriUniversalCommunicationId.getID();
}
return null;
}



@Override
public String getUriUniversalCommunicationIDScheme() {
if (uriUniversalCommunicationId!=null) {
if (uriUniversalCommunicationId != null) {
return uriUniversalCommunicationId.getScheme();
}
return null;
Expand All @@ -414,28 +420,15 @@ public String getUriUniversalCommunicationIDScheme() {

/***
* sets the email of the organization (not the one of the contact person)
* (while setEmail has to be defined here getEmail comes from IZUGFeRDExportableTradeParty)
* @return fluent setter
*/
public TradeParty setEmail(String eMail) {
SchemedID theSchemedID=new SchemedID("EM", eMail);
SchemedID theSchemedID = new SchemedID("EM", eMail);
addUriUniversalCommunicationID(theSchemedID);
return this;
}

/***
* gets the email of the organization (not the one of the contact person)
* will return null if not set or if the provided UriUniversalCommunicationID
* is not a email address
*
* @return String the email, or null
*/
public String getEmail() {
if (uriUniversalCommunicationId.getScheme().equals("EM")) {
return uriUniversalCommunicationId.getID();
}
return null;
}


/**
* if it's a customer, this can e.g. be the customer ID
Expand All @@ -460,12 +453,12 @@ public TradeParty setContact(Contact c) {
}

public TradeParty addGlobalID(SchemedID schemedID) {
globalId=schemedID;
globalId = schemedID;
return this;
}

public TradeParty addUriUniversalCommunicationID(SchemedID schemedID) {
uriUniversalCommunicationId=schemedID;
uriUniversalCommunicationId = schemedID;
return this;
}

Expand Down Expand Up @@ -496,7 +489,7 @@ public IZUGFeRDLegalOrganisation getLegalOrganisation() {
}

public TradeParty setLegalOrganisation(LegalOrganisation legalOrganisation) {
legalOrg=legalOrganisation;
legalOrg = legalOrganisation;
return this;
}

Expand Down Expand Up @@ -634,8 +627,8 @@ public IZUGFeRDTradeSettlement[] getAsTradeSettlement() {
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++) {
Expand All @@ -651,7 +644,6 @@ public String getAdditionalAddress() {
}



/***
* additional info of the address, e.g. which building or which floor.
* Street address will become "lineOne", this will become "lineTwo".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,36 @@ default String getUriUniversalCommunicationIDScheme() {
return null;
}



/**
* The URIID of URIUniversalCommunicationID
* It is used by some countries, i.e. Luxembourg
* The URIID of URIUniversalCommunicationID (e.g. email address)
* It is used by some countries, i.e. Luxembourg, Peppol
* @return the URI as string
*/
default String getUriUniversalCommunicationID() {
return null;
}


/***
* gets the email of the organization (not the one of the contact person)
* will return null if not set or if the provided UriUniversalCommunicationID
* is not a email address
*
* @return String the email, or null
*/
default String getEmail() {
if ((getUriUniversalCommunicationIDScheme()!=null)&&(getUriUniversalCommunicationIDScheme().equals("EM"))) {
return getUriUniversalCommunicationID();
}
return null;
}

/***
* the named contact person for inquiries
* @return contact
*/
default IZUGFeRDExportableContact getContact() {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void testXREdgeExport() {

FileAttachment fe1=new FileAttachment("one.pdf", "application/pdf", "Alternative", b);
Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSender(new TradeParty(orgname,"teststr","55232","teststadt","DE").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test","+49123456789","test@example.org")).addBankDetails(new BankDetails("DE12500105170648489890","COBADEFXXX")))
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE"))
.setSender(new TradeParty(orgname,"teststr","55232","teststadt","DE").setEmail("sender@example.com").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test","+49123456789","test@example.org")).addBankDetails(new BankDetails("DE12500105170648489890","COBADEFXXX")))
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setEmail("recipient@sample.org"))
.setReferenceNumber("991-01484-64")//leitweg-id
// not using any VAT, this is also a test of zero-rated goods:
.setNumber(number).setPaymentTermDescription("#SKONTO#TAGE=14#PROZENT=2.25#\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ public void testPushEdge() {
ze.setTransaction(new Invoice().setCurrency("CHF").addNote("document level 1/2").addNote("document level 2/2").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSellerOrderReferencedDocumentID("9384").setBuyerOrderReferencedDocumentID("28934")
.setDetailedDeliveryPeriod(new SimpleDateFormat("yyyyMMdd").parse(occurrenceFrom), new SimpleDateFormat("yyyyMMdd").parse(occurrenceTo))
.setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID).setID("0009845"))
.setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID).setEmail("sender@test.org").setID("0009845"))
.setDeliveryAddress(new TradeParty("just the other side of the street", "teststr.12a", "55232", "Entenhausen", "DE").addVATID("DE47110"))
.setContractReferencedDocument(contractID)
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addGlobalID(gln).addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE").setFax("++49555123456")).setAdditionalAddress("Hinterhaus 3"))
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addGlobalID(gln).setEmail("recipient@test.org").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE").setFax("++49555123456")).setAdditionalAddress("Hinterhaus 3"))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(16)).addGlobalID(gtin).setSellerAssignedID("4711"), price, new BigDecimal(1.0)).addReferencedLineID("xxx").addNote("item level 1/1").addAllowance(new Allowance(new BigDecimal(0.02)).setReason("item discount").setTaxPercent(new BigDecimal(16))).setDetailedDeliveryPeriod(sdf.parse("2020-01-13"), sdf.parse("2020-01-15")))
.addCharge(new Charge(new BigDecimal(0.5)).setReason("quick delivery charge").setTaxPercent(new BigDecimal(16)))
.addAllowance(new Allowance(new BigDecimal(0.2)).setReason("discount").setTaxPercent(new BigDecimal(16)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public void testEdgeInvoiceImport() {
// Reading ZUGFeRD
assertEquals("4711", invoice.getZFItems()[0].getProduct().getSellerAssignedID());
assertEquals("9384", invoice.getSellerOrderReferencedDocumentID());
assertEquals("sender@test.org", invoice.getSender().getEmail());
assertEquals("recipient@test.org", invoice.getRecipient().getEmail());
assertEquals("28934", invoice.getBuyerOrderReferencedDocumentID());

}
Expand Down
Loading

0 comments on commit eba5413

Please sign in to comment.