Skip to content

Commit

Permalink
setIssueDate (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Dec 26, 2024
1 parent 5375130 commit d02705e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ public LocalDate getIssueDateTime() {
return issueDateTime;
}

public abstract void setIssueDateTime(LocalDate value);

public LocalDate getDueDateTime() {
return dueDateTime;
}

public abstract void setDueDateTime(LocalDate value);

public BigDecimal getGrandTotalAmount() {
return grandTotalAmount;
}
Expand Down Expand Up @@ -275,7 +279,7 @@ public Set<Element> findChildNodesByName(Element parent, EInvoiceNS ns, String n

/**
* This helper method returns the first child node by name from a given parent
* node. If no nodes were found the method returns null.
* node. If no nodes were found the method returns creates the elemnt.
*
* See also {@link #findChildNodesByName(Element parent, String nodeName)
* findChildNodesByName}
Expand All @@ -286,26 +290,51 @@ public Set<Element> findChildNodesByName(Element parent, EInvoiceNS ns, String n
* the method returns null
*/
public Element findChildNodeByName(Element parent, EInvoiceNS ns, String nodeName) {
Set<Element> elementList = findChildNodesByName(parent, ns, nodeName);
if (elementList.iterator().hasNext()) {
// return first element
return elementList.iterator().next();
}
// no child elements with the given name found
return null;
}

/**
* This helper method returns the first child node by name from a given parent
* node. If no nodes were found the method returns creates the elemnt.
*
* See also {@link #findChildNodesByName(Element parent, String nodeName)
* findChildNodesByName}
*
* @param parent
* @param nodeName
* @return - Child Element matching the given node name. If no nodes were found,
* the method returns null
*/
public Element findOrCreateChildNodeByName(Element parent, EInvoiceNS ns, String nodeName) {
Set<Element> elementList = findChildNodesByName(parent, ns, nodeName);
if (elementList.iterator().hasNext()) {
// return first element
return elementList.iterator().next();
} else {
// no child elements with the given name found!
return null;
// no child elements with the given name found
// create one
Element element = getDoc().createElement(getPrefix(ns) + nodeName);
parent.appendChild(element);
return element;
}
}

/**
* Helper method to update or create an element with a given value
*/
public void updateElementValue(Element parent, String elementName, String value) {
public void updateElementValue(Element parent, EInvoiceNS nameSpace, String elementName, String value) {
if (value == null) {
return;
}
Element element = findChildNodeByName(parent, EInvoiceNS.RAM, elementName);
Element element = findChildNodeByName(parent, nameSpace, elementName);
if (element == null) {
element = getDoc().createElement(getPrefix(EInvoiceNS.RAM) + elementName);
element = getDoc().createElement(getPrefix(nameSpace) + elementName);
parent.appendChild(element);
}
element.setTextContent(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,43 @@ public void setGrandTotalAmount(BigDecimal value) {
}
}

/**
* Update Duedate
*/
@Override
public void setDueDateTime(LocalDate value) {
Element element = findChildNodeByName(supplyChainTradeTransaction, EInvoiceNS.RAM,
"ApplicableHeaderTradeSettlement");
if (element != null) {
Element specifiedTradePaymentTermsElement = findOrCreateChildNodeByName(element, EInvoiceNS.RAM,
"SpecifiedTradePaymentTerms");
if (specifiedTradePaymentTermsElement != null) {
Element dueDateTimeElement = findOrCreateChildNodeByName(specifiedTradePaymentTermsElement,
EInvoiceNS.RAM,
"DueDateDateTime");
Element dateTimeElement = findOrCreateChildNodeByName(dueDateTimeElement, EInvoiceNS.UDT,
"DateTimeString");
dateTimeElement.setAttribute("format", "102");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
dateTimeElement.setTextContent(formatter.format(value));
}
}
}

/**
* Update Invoice date
*/
@Override
public void setIssueDateTime(LocalDate value) {
Element element = findOrCreateChildNodeByName(exchangedDocument, EInvoiceNS.RAM,
"IssueDateTime");
Element dateTimeElement = findOrCreateChildNodeByName(element, EInvoiceNS.UDT,
"DateTimeString");
dateTimeElement.setAttribute("format", "102");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
dateTimeElement.setTextContent(formatter.format(value));
}

/**
* Updates or creates a trade party in the model and XML structure
*
Expand All @@ -391,6 +428,7 @@ public void setGrandTotalAmount(BigDecimal value) {
*
* @param newParty the trade party to be set
*/
@Override
public void setTradeParty(TradeParty newParty) {
if (newParty == null) {
return;
Expand Down Expand Up @@ -423,7 +461,7 @@ public void setTradeParty(TradeParty newParty) {
}

// Update Name
updateElementValue(tradePartyElement, "Name", newParty.getName());
updateElementValue(tradePartyElement, EInvoiceNS.RAM, "Name", newParty.getName());

// Update PostalTradeAddress
Element postalAddress = findChildNodeByName(tradePartyElement, EInvoiceNS.RAM, "PostalTradeAddress");
Expand All @@ -433,10 +471,10 @@ public void setTradeParty(TradeParty newParty) {
}

// Update address details
updateElementValue(postalAddress, "PostcodeCode", newParty.getPostcodeCode());
updateElementValue(postalAddress, "CityName", newParty.getCityName());
updateElementValue(postalAddress, "CountryID", newParty.getCountryId());
updateElementValue(postalAddress, "LineOne", newParty.getStreetAddress());
updateElementValue(postalAddress, EInvoiceNS.RAM, "PostcodeCode", newParty.getPostcodeCode());
updateElementValue(postalAddress, EInvoiceNS.RAM, "CityName", newParty.getCityName());
updateElementValue(postalAddress, EInvoiceNS.RAM, "CountryID", newParty.getCountryId());
updateElementValue(postalAddress, EInvoiceNS.RAM, "LineOne", newParty.getStreetAddress());

// Update VAT registration if available
if (newParty.getVatNumber() != null && !newParty.getVatNumber().isEmpty()) {
Expand All @@ -446,7 +484,7 @@ public void setTradeParty(TradeParty newParty) {
taxRegistration = getDoc().createElement(getPrefix(EInvoiceNS.RAM) + "SpecifiedTaxRegistration");
tradePartyElement.appendChild(taxRegistration);
}
updateElementValue(taxRegistration, "ID", newParty.getVatNumber());
updateElementValue(taxRegistration, EInvoiceNS.RAM, "ID", newParty.getVatNumber());
}
}
}
Expand All @@ -456,7 +494,13 @@ public void setTradeParty(TradeParty newParty) {
*
* @param item
*/
public void addTradeLineItem(TradeLineItem item) {
@Override
public void setTradeLineItem(TradeLineItem item) {
if (item == null) {
return;
}

super.setTradeLineItem(item);
Element lineItem = getDoc().createElement(getPrefix(EInvoiceNS.RAM) + "IncludedSupplyChainTradeLineItem");

// Document Line with ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,16 @@ public void setGrandTotalAmount(BigDecimal value) {
throw new UnsupportedOperationException("Unimplemented method 'setGrandTotalAmount'");
}

@Override
public void setIssueDateTime(LocalDate value) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'setIssueDateTime'");
}

@Override
public void setDueDateTime(LocalDate value) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'setDueDateTime'");
}

}

0 comments on commit d02705e

Please sign in to comment.