Add ZUGFeRD2PullProvider#buildItemNotes

This commit is contained in:
Sebastian Sieber
2023-07-13 12:17:46 +02:00
parent b1bced360b
commit 6c968e1b00
3 changed files with 25 additions and 32 deletions

View File

@@ -27,11 +27,14 @@ import static org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants.CATE
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.mustangproject.*; import org.mustangproject.*;
@@ -84,18 +87,11 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
if (currentItem.getProduct().getTaxExemptionReason() != null) { if (currentItem.getProduct().getTaxExemptionReason() != null) {
// exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>"; // exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>";
} }
String notes = ""; final LineCalculator lc = new LineCalculator(currentItem);
if (currentItem.getNotes() != null) {
for (final String currentNote : currentItem.getNotes()) {
notes = notes + "<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
}
}
final LineCalculator lc = new LineCalculator(currentItem);
xml += "<ram:IncludedSupplyChainTradeLineItem>" + xml += "<ram:IncludedSupplyChainTradeLineItem>" +
"<ram:AssociatedDocumentLineDocument>" "<ram:AssociatedDocumentLineDocument>"
+ "<ram:LineID>" + lineID + "</ram:LineID>" + "<ram:LineID>" + lineID + "</ram:LineID>"
+ notes + buildItemNotes(currentItem)
+ "</ram:AssociatedDocumentLineDocument>" + "</ram:AssociatedDocumentLineDocument>"
+ "<ram:SpecifiedTradeProduct>"; + "<ram:SpecifiedTradeProduct>";

View File

@@ -27,14 +27,18 @@ import static org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants.CATE
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.mustangproject.EStandard; import org.mustangproject.EStandard;
import org.mustangproject.FileAttachment; import org.mustangproject.FileAttachment;
import org.mustangproject.IncludedNote;
import org.mustangproject.XMLTools; import org.mustangproject.XMLTools;
public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider { public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider {
@@ -108,18 +112,12 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
if (currentItem.getProduct().getTaxExemptionReason() != null) { if (currentItem.getProduct().getTaxExemptionReason() != null) {
// exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>"; // exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>";
} }
String notes = "";
if (currentItem.getNotes() != null) {
for (final String currentNote : currentItem.getNotes()) {
notes = notes + "<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
}
}
final LineCalculator lc = new LineCalculator(currentItem); final LineCalculator lc = new LineCalculator(currentItem);
xml += "<ram:IncludedSupplyChainTradeLineItem>" + xml += "<ram:IncludedSupplyChainTradeLineItem>" +
"<ram:AssociatedDocumentLineDocument>" "<ram:AssociatedDocumentLineDocument>"
+ "<ram:LineID>" + lineID + "</ram:LineID>" + "<ram:LineID>" + lineID + "</ram:LineID>"
+ notes + buildItemNotes(currentItem)
+ "</ram:AssociatedDocumentLineDocument>" + "</ram:AssociatedDocumentLineDocument>"
+ "<ram:SpecifiedTradeProduct>"; + "<ram:SpecifiedTradeProduct>";

View File

@@ -30,6 +30,7 @@ import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -299,7 +300,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
if (trans.getDocumentCode() != null) { if (trans.getDocumentCode() != null) {
typecode = trans.getDocumentCode(); typecode = trans.getDocumentCode();
} }
String notes;
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<rsm:CrossIndustryInvoice xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:rsm=\"urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100\"" + "<rsm:CrossIndustryInvoice xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:rsm=\"urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100\""
// + " // + "
@@ -334,19 +334,12 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
if (currentItem.getProduct().getTaxExemptionReason() != null) { if (currentItem.getProduct().getTaxExemptionReason() != null) {
exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>"; exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>";
} }
notes = "";
if (currentItem.getNotes() != null) {
for (final String currentNote : currentItem.getNotes()) {
notes = notes + "<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
}
}
final LineCalculator lc = new LineCalculator(currentItem); final LineCalculator lc = new LineCalculator(currentItem);
if ((getProfile() != Profiles.getByName("Minimum")) && (getProfile() != Profiles.getByName("BasicWL"))) { if ((getProfile() != Profiles.getByName("Minimum")) && (getProfile() != Profiles.getByName("BasicWL"))) {
xml += "<ram:IncludedSupplyChainTradeLineItem>" +
xml += "<ram:IncludedSupplyChainTradeLineItem>" +
"<ram:AssociatedDocumentLineDocument>" "<ram:AssociatedDocumentLineDocument>"
+ "<ram:LineID>" + lineID + "</ram:LineID>" + "<ram:LineID>" + lineID + "</ram:LineID>"
+ notes + buildItemNotes(currentItem)
+ "</ram:AssociatedDocumentLineDocument>" + "</ram:AssociatedDocumentLineDocument>"
+ "<ram:SpecifiedTradeProduct>"; + "<ram:SpecifiedTradeProduct>";
@@ -395,16 +388,12 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
"<ram:TypeCode>" + XMLTools.encodeXML(currentReferencedDocument.getTypeCode()) + "</ram:TypeCode>" + "<ram:TypeCode>" + XMLTools.encodeXML(currentReferencedDocument.getTypeCode()) + "</ram:TypeCode>" +
"<ram:ReferenceTypeCode>" + XMLTools.encodeXML(currentReferencedDocument.getReferenceTypeCode()) + "</ram:ReferenceTypeCode>" + "<ram:ReferenceTypeCode>" + XMLTools.encodeXML(currentReferencedDocument.getReferenceTypeCode()) + "</ram:ReferenceTypeCode>" +
"</ram:AdditionalReferencedDocument>"; "</ram:AdditionalReferencedDocument>";
} }
} }
if (currentItem.getBuyerOrderReferencedDocumentLineID() != null) { if (currentItem.getBuyerOrderReferencedDocumentLineID() != null) {
xml += "<ram:BuyerOrderReferencedDocument> " xml += "<ram:BuyerOrderReferencedDocument> "
+ "<ram:LineID>" + XMLTools.encodeXML(currentItem.getBuyerOrderReferencedDocumentLineID()) + "</ram:LineID>" + "<ram:LineID>" + XMLTools.encodeXML(currentItem.getBuyerOrderReferencedDocumentLineID()) + "</ram:LineID>"
+ "</ram:BuyerOrderReferencedDocument>"; + "</ram:BuyerOrderReferencedDocument>";
} }
xml += "<ram:GrossPriceProductTradePrice>" xml += "<ram:GrossPriceProductTradePrice>"
+ "<ram:ChargeAmount>" + priceFormat(lc.getPriceGross()) + "<ram:ChargeAmount>" + priceFormat(lc.getPriceGross())
@@ -747,6 +736,16 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
} }
protected String buildItemNotes(IZUGFeRDExportableItem currentItem) {
if (currentItem.getNotes() == null) {
return "";
}
return Arrays.stream(currentItem.getNotes())
.map(IncludedNote::unspecifiedNote)
.map(IncludedNote::toCiiXml)
.collect(Collectors.joining());
}
protected String buildNotes(IExportableTransaction exportableTransaction) { protected String buildNotes(IExportableTransaction exportableTransaction) {
final List<IncludedNote> includedNotes = Optional.ofNullable(exportableTransaction.getNotesWithSubjectCode()) final List<IncludedNote> includedNotes = Optional.ofNullable(exportableTransaction.getNotesWithSubjectCode())
.orElse(new ArrayList<>()); .orElse(new ArrayList<>());