Use ZUGFeRD2PullProvider#buildNotes in inherited classes

This commit is contained in:
Sebastian Sieber
2023-07-13 12:04:01 +02:00
parent 96f26439d4
commit b1bced360b
4 changed files with 33 additions and 65 deletions

View File

@@ -22,6 +22,7 @@ package org.mustangproject;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -679,6 +680,17 @@ public class Invoice implements IExportableTransaction {
return this;
}
public Invoice addNotes(Collection<IncludedNote> notes) {
if (notes == null) {
return this;
}
if (includedNotes == null) {
includedNotes = new ArrayList<>();
}
includedNotes.addAll(notes);
return this;
}
/**
* adds a free text paragraph, which will become an includedNote element with explicit
* subjectCode {@link SubjectCode#AAI}

View File

@@ -45,37 +45,12 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
@Override
public void generateXML(IExportableTransaction trans) {
this.trans = trans;
boolean hasDueDate = false;
final SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy");
final String exemptionReason = "";
String senderReg = "";
if (trans.getOwnOrganisationFullPlaintextInfo() != null) {
senderReg = "<ram:IncludedNote><ram:Content>"
+ XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + "</ram:Content>"
+ "<ram:SubjectCode>REG</ram:SubjectCode></ram:IncludedNote>";
}
String subjectNote = "";
if (trans.getSubjectNote() != null) {
subjectNote = "<ram:IncludedNote><ram:Content>"
+ XMLTools.encodeXML(trans.getSubjectNote()) + "</ram:Content>"
+ "</ram:IncludedNote>";
}
final String typecode = "220";
/*if (trans.getDocumentCode() != null) {
typecode = trans.getDocumentCode();
}*/
String notes = "";
if (trans.getNotes() != null) {
for (final String currentNote : trans.getNotes()) {
notes += "<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
}
}
String testBooleanStr="true";
String xml = "<SCRDMCCBDACIDAMessageStructure\n" +
" xmlns:udt=\"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:25\"\n" +
@@ -99,9 +74,7 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
+ "<ram:TypeCode>" + typecode + "</ram:TypeCode>"
+ "<ram:IssueDateTime>"
+ DATE.udtFormat(trans.getIssueDate()) + "</ram:IssueDateTime>" // date
+ notes
+ subjectNote
+ senderReg
+ buildNotes(trans)
+ "</px:ExchangedDocument>"
+ "<px:SupplyChainTradeTransaction>";
@@ -111,7 +84,7 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
if (currentItem.getProduct().getTaxExemptionReason() != null) {
// exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>";
}
notes = "";
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>";
@@ -308,5 +281,19 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
return profile;
}
@Override
protected String buildNotes(IExportableTransaction exportableTransaction) {
Invoice copyWithoutRebateInfo = new Invoice()
.setOwnOrganisationFullPlaintextInfo(exportableTransaction.getOwnOrganisationFullPlaintextInfo())
.addNotes(exportableTransaction.getNotesWithSubjectCode());
if(exportableTransaction.getNotes() != null) {
for (String note : exportableTransaction.getNotes()) {
copyWithoutRebateInfo.addNote(note);
}
}
if(exportableTransaction.getSubjectNote()!= null) {
copyWithoutRebateInfo.addNote(exportableTransaction.getSubjectNote());
}
return super.buildNotes(copyWithoutRebateInfo);
}
}

View File

@@ -64,39 +64,11 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
}
String senderReg = "";
if (trans.getOwnOrganisationFullPlaintextInfo() != null) {
senderReg = "<ram:IncludedNote><ram:Content>"
+ XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + "</ram:Content>"
+ "<ram:SubjectCode>REG</ram:SubjectCode></ram:IncludedNote>";
}
String rebateAgreement = "";
if (trans.rebateAgreementExists()) {
rebateAgreement = "<ram:IncludedNote><ram:Content>"
+ "Es bestehen Rabatt- und Bonusvereinbarungen.</ram:Content>"
+ "<ram:SubjectCode>AAK</ram:SubjectCode></ram:IncludedNote>";
}
String subjectNote = "";
if (trans.getSubjectNote() != null) {
subjectNote = "<ram:IncludedNote><ram:Content>"
+ XMLTools.encodeXML(trans.getSubjectNote()) + "</ram:Content>"
+ "</ram:IncludedNote>";
}
final String typecode = "220";
/*if (trans.getDocumentCode() != null) {
typecode = trans.getDocumentCode();
}*/
String notes = "";
if (trans.getNotes() != null) {
for (final String currentNote : trans.getNotes()) {
notes += "<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
}
}
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<rsm:SCRDMCCBDACIOMessageStructure\n" +
@@ -126,10 +98,7 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
+ "<ram:TypeCode>" + typecode + "</ram:TypeCode>"
+ "<ram:IssueDateTime>"
+ DATE.udtFormat(trans.getIssueDate()) + "</ram:IssueDateTime>" // date
+ notes
+ subjectNote
+ rebateAgreement
+ senderReg
+ buildNotes(trans)
+ "</rsm:ExchangedDocument>"
+ "<rsm:SupplyChainTradeTransaction>";
@@ -139,7 +108,7 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
if (currentItem.getProduct().getTaxExemptionReason() != null) {
// exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>";
}
notes = "";
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>";

View File

@@ -747,7 +747,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
}
}
private static String buildNotes(IExportableTransaction exportableTransaction) {
protected String buildNotes(IExportableTransaction exportableTransaction) {
final List<IncludedNote> includedNotes = Optional.ofNullable(exportableTransaction.getNotesWithSubjectCode())
.orElse(new ArrayList<>());
if (exportableTransaction.getNotes() != null) {