From 80fe0391f02e371fd69e8bd99c0d28de654e9e08 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 09:33:42 +0200 Subject: [PATCH 01/11] Remove unused method --- .../ZUGFeRD/DAPullProvider.java | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java index 8fbaf975..81d5e8aa 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java @@ -308,51 +308,5 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider return profile; } - private String buildPaymentTermsXml() { - - final IZUGFeRDPaymentTerms paymentTerms = trans.getPaymentTerms(); - if (paymentTerms == null) { - return ""; - } - String paymentTermsXml = ""; - - final IZUGFeRDPaymentDiscountTerms discountTerms = paymentTerms.getDiscountTerms(); - final Date dueDate = paymentTerms.getDueDate(); - if (dueDate != null && discountTerms != null && discountTerms.getBaseDate() != null) { - throw new IllegalStateException( - "if paymentTerms.dueDate is specified, paymentTerms.discountTerms.baseDate has not to be specified"); - } - paymentTermsXml += "" + paymentTerms.getDescription() + ""; - if (dueDate != null) { - paymentTermsXml += ""; - paymentTermsXml += DATE.udtFormat(dueDate); - paymentTermsXml += ""; - } - - if (discountTerms != null) { - paymentTermsXml += ""; - final String currency = trans.getCurrency(); - final String basisAmount = currencyFormat(calc.getGrandTotal()); - paymentTermsXml += "" + basisAmount + ""; - paymentTermsXml += "" + discountTerms.getCalculationPercentage().toString() - + ""; - - if (discountTerms.getBaseDate() != null) { - final Date baseDate = discountTerms.getBaseDate(); - paymentTermsXml += ""; - paymentTermsXml += DATE.udtFormat(baseDate); - paymentTermsXml += ""; - - paymentTermsXml += "" - + discountTerms.getBasePeriodMeasure() + ""; - } - - paymentTermsXml += ""; - } - - paymentTermsXml += ""; - return paymentTermsXml; - } - } From 6d3951413c5d70e4ebb3f7f622ef758fb857fe55 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 09:55:33 +0200 Subject: [PATCH 02/11] Merge all includedNotes to one string --- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 72 ++++++++----------- 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 912e35e1..30da37cd 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -277,7 +277,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { boolean hasDueDate = false; final SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy"); - + String exemptionReason = ""; if (trans.getPaymentTermDescription() != null) { @@ -288,42 +288,13 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { paymentTermsDescription = "Zahlbar ohne Abzug bis " + germanDateFormat.format(trans.getDueDate()); } - - String senderReg = ""; - if (trans.getOwnOrganisationFullPlaintextInfo() != null) { - senderReg = "" - + XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + "" - + "REG"; - - } - - String rebateAgreement = ""; - if (trans.rebateAgreementExists()) { - rebateAgreement = "" - + "Es bestehen Rabatt- und Bonusvereinbarungen." - + "AAK"; - } - - String subjectNote = ""; - if (trans.getSubjectNote() != null) { - subjectNote = "" - + XMLTools.encodeXML(trans.getSubjectNote()) + "" - + ""; - } - + String typecode = "380"; if (trans.getDocumentCode() != null) { typecode = trans.getDocumentCode(); } - String notes = ""; - if (trans.getNotes() != null) { - for (final String currentNote : trans.getNotes()) { - notes = notes + "" + XMLTools.encodeXML(currentNote) + ""; - - } - } - String xml = "" - + String notes; + String xml = "" + "" + typecode + "" + "" + DATE.udtFormat(trans.getIssueDate()) + "" // date - + notes - + subjectNote - + rebateAgreement - + senderReg + + buildNotes(trans) + "" + ""; @@ -364,7 +332,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { if (currentItem.getNotes() != null) { for (final String currentNote : currentItem.getNotes()) { notes = notes + "" + XMLTools.encodeXML(currentNote) + ""; - } } final LineCalculator lc = new LineCalculator(currentItem); @@ -647,8 +614,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { xml += "" + DATE.udtFormat(trans.getDetailedDeliveryPeriodTo()) + ""; } xml += ""; - - } if ((trans.getZFCharges() != null) && (trans.getZFCharges().length > 0)) { @@ -776,7 +741,32 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { } } - @Override + private static String buildNotes(IExportableTransaction trans) { + String notes = ""; + if (trans.getNotes() != null) { + for (final String currentNote : trans.getNotes()) { + notes += "" + XMLTools.encodeXML(currentNote) + ""; + } + } + if (trans.rebateAgreementExists()) { + notes += "" + + "Es bestehen Rabatt- und Bonusvereinbarungen." + + "AAK"; + } + if (trans.getOwnOrganisationFullPlaintextInfo() != null) { + notes += "" + + XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + "" + + "REG"; + } + if (trans.getSubjectNote() != null) { + notes += "" + + XMLTools.encodeXML(trans.getSubjectNote()) + "" + + ""; + } + return notes; + } + + @Override public void setProfile(Profile p) { profile = p; } From 11bbcbaf5c302692ba883e9756fe3a137602a8a1 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 09:59:11 +0200 Subject: [PATCH 03/11] Use StringBuilder --- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 30da37cd..c45d628a 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -742,28 +742,32 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { } private static String buildNotes(IExportableTransaction trans) { - String notes = ""; + StringBuilder notes = new StringBuilder(); if (trans.getNotes() != null) { for (final String currentNote : trans.getNotes()) { - notes += "" + XMLTools.encodeXML(currentNote) + ""; + notes.append("") + .append(XMLTools.encodeXML(currentNote)) + .append(""); } } if (trans.rebateAgreementExists()) { - notes += "" - + "Es bestehen Rabatt- und Bonusvereinbarungen." - + "AAK"; + notes.append("") + .append("Es bestehen Rabatt- und Bonusvereinbarungen.") + .append("AAK"); } if (trans.getOwnOrganisationFullPlaintextInfo() != null) { - notes += "" - + XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + "" - + "REG"; + notes.append("") + .append(XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo())) + .append("") + .append("REG"); } if (trans.getSubjectNote() != null) { - notes += "" - + XMLTools.encodeXML(trans.getSubjectNote()) + "" - + ""; + notes.append("") + .append(XMLTools.encodeXML(trans.getSubjectNote())) + .append("") + .append(""); } - return notes; + return notes.toString(); } @Override From 83f51ecda948a53c9bed9cc17345bdacd5791b12 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 10:47:09 +0200 Subject: [PATCH 04/11] Add new getter and classes IExportableTransaction#getNotesWithSubjectCode IncludedNote SubjectCode --- .../java/org/mustangproject/IncludedNote.java | 42 +++++++++++++++++++ .../java/org/mustangproject/SubjectCode.java | 31 ++++++++++++++ .../ZUGFeRD/IExportableTransaction.java | 14 ++++++- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/org/mustangproject/IncludedNote.java create mode 100644 library/src/main/java/org/mustangproject/SubjectCode.java diff --git a/library/src/main/java/org/mustangproject/IncludedNote.java b/library/src/main/java/org/mustangproject/IncludedNote.java new file mode 100644 index 00000000..219f9e20 --- /dev/null +++ b/library/src/main/java/org/mustangproject/IncludedNote.java @@ -0,0 +1,42 @@ +package org.mustangproject; + +/** + * A grouping of business terms to indicate accounting-relevant free texts including a qualification of these. + */ +public class IncludedNote { + private final String content; + private final SubjectCode subjectCode; + + private IncludedNote(String content, SubjectCode subjectCode) { + this.content = content; + this.subjectCode = subjectCode; + } + + public static IncludedNote generalNote(String content) { + return new IncludedNote(content, SubjectCode.AAI); + } + public static IncludedNote regulatoryNote(String content) { + return new IncludedNote(content, SubjectCode.REG); + } + public static IncludedNote legalNote(String content) { + return new IncludedNote(content, SubjectCode.ABL); + } + public static IncludedNote customsNote(String content) { + return new IncludedNote(content, SubjectCode.CUS); + } + public static IncludedNote sellerNote(String content) { + return new IncludedNote(content, SubjectCode.SUR); + } + public static IncludedNote taxNote(String content) { + return new IncludedNote(content, SubjectCode.TXD); + } + + public String getContent() { + return content; + } + + public SubjectCode getSubjectCode() { + return subjectCode; + } + +} diff --git a/library/src/main/java/org/mustangproject/SubjectCode.java b/library/src/main/java/org/mustangproject/SubjectCode.java new file mode 100644 index 00000000..fb388c1f --- /dev/null +++ b/library/src/main/java/org/mustangproject/SubjectCode.java @@ -0,0 +1,31 @@ +package org.mustangproject; + +/** + * the qualification of the free text on the invoice from BT-22 + */ +public enum SubjectCode { + /** + * general information + */ + AAI, + /** + * seller notes + */ + SUR, + /** + * regulatory information + */ + REG, + /** + * legal information + */ + ABL, + /** + * tax information + */ + TXD, + /** + * Customs information + */ + CUS +} diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java index fb8fa602..bd778d78 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java @@ -29,8 +29,10 @@ package org.mustangproject.ZUGFeRD; import java.math.BigDecimal; import java.util.Date; +import java.util.List; import org.mustangproject.FileAttachment; +import org.mustangproject.IncludedNote; import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; /*** @@ -80,10 +82,13 @@ public interface IExportableTransaction { /** * this should be the full sender institution name, details, manager and tax * registration. It is one of the few functions which may return null. e.g. - *

+ *

* Lieferant GmbH Lieferantenstraße 20 80333 München Deutschland * Geschäftsführer: Hans Muster Handelsregisternummer: H A 123 + *

* + * It is written as an includedNode with subjectCode {@link org.mustangproject.SubjectCode#REG}. See also + * {@link #getNotesWithSubjectCode()} * @return null or full sender institution name, details, manager and tax * registration */ @@ -489,6 +494,13 @@ public interface IExportableTransaction { return null; } + /** + * A grouping of business terms to indicate accounting-relevant free texts including a qualification of these.

+ * The information are written to the same xml nodes like {@link #getNotes()} but with explicit subjectCode. + */ + default List getNotesWithSubjectCode(){ + return null; + } default String getSpecifiedProcuringProjectName() { return null; } From afffa93d8907174d92fd25dfca9054bd1c4004d1 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 10:58:37 +0200 Subject: [PATCH 05/11] Implement Invoice#getNotesWithSubjectCode and convenient setter methods. --- .../main/java/org/mustangproject/Invoice.java | 97 ++++++++++++++++++- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/org/mustangproject/Invoice.java b/library/src/main/java/org/mustangproject/Invoice.java index 3622b041..2f63578b 100644 --- a/library/src/main/java/org/mustangproject/Invoice.java +++ b/library/src/main/java/org/mustangproject/Invoice.java @@ -23,6 +23,7 @@ package org.mustangproject; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; +import java.util.List; import org.mustangproject.ZUGFeRD.IExportableTransaction; import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge; @@ -48,6 +49,7 @@ public class Invoice implements IExportableTransaction { @JsonDeserialize(contentAs=Item.class) protected ArrayList ZFItems = null; protected ArrayList notes = null; + private List includedNotes = null; protected String sellerOrderReferencedDocumentID; protected String contractReferencedDocument = null; protected ArrayList xmlEmbeddedFiles=null; @@ -396,7 +398,12 @@ public class Invoice implements IExportableTransaction { return notes.toArray(new String[0]); } - @Override + @Override + public List getNotesWithSubjectCode() { + return includedNotes; + } + + @Override public String getCurrency() { return currency; } @@ -659,8 +666,8 @@ public class Invoice implements IExportableTransaction { } - /*** - * adds a free text paragraph, which will become a includedNote element + /** + * adds a free text paragraph, which will become an includedNote element * @param text freeform UTF8 plain text * @return fluent setter */ @@ -671,7 +678,91 @@ public class Invoice implements IExportableTransaction { notes.add(text); return this; } + + /** + * adds a free text paragraph, which will become an includedNote element with explicit + * subjectCode {@link SubjectCode#AAI} + * @param content freeform UTF8 plain text + * @return fluent setter + */ + public Invoice addGeneralNote(String content) { + if (includedNotes == null) { + includedNotes = new ArrayList<>(); + } + includedNotes.add(IncludedNote.generalNote(content)); + return this; + } + /** + * adds a free text paragraph, which will become an includedNote element with explicit + * subjectCode {@link SubjectCode#REG} + * @param content freeform UTF8 plain text + * @return fluent setter + */ + public Invoice regulatoryNote(String content) { + if (includedNotes == null) { + includedNotes = new ArrayList<>(); + } + includedNotes.add(IncludedNote.regulatoryNote(content)); + return this; + } + + /** + * adds a free text paragraph, which will become an includedNote element with explicit + * subjectCode {@link SubjectCode#ABL} + * @param content freeform UTF8 plain text + * @return fluent setter + */ + public Invoice legalNote(String content) { + if (includedNotes == null) { + includedNotes = new ArrayList<>(); + } + includedNotes.add(IncludedNote.legalNote(content)); + return this; + } + + /** + * adds a free text paragraph, which will become an includedNote element with explicit + * subjectCode {@link SubjectCode#CUS} + * @param content freeform UTF8 plain text + * @return fluent setter + */ + public Invoice customsNote(String content) { + if (includedNotes == null) { + includedNotes = new ArrayList<>(); + } + includedNotes.add(IncludedNote.customsNote(content)); + return this; + } + + /** + * adds a free text paragraph, which will become an includedNote element with explicit + * subjectCode {@link SubjectCode#SUR} + * @param content freeform UTF8 plain text + * @return fluent setter + */ + public Invoice sellerNote(String content) { + if (includedNotes == null) { + includedNotes = new ArrayList<>(); + } + includedNotes.add(IncludedNote.sellerNote(content)); + return this; + } + + /** + * adds a free text paragraph, which will become an includedNote element with explicit + * subjectCode {@link SubjectCode#TXD} + * @param content freeform UTF8 plain text + * @return fluent setter + */ + public Invoice taxNote(String content) { + if (includedNotes == null) { + includedNotes = new ArrayList<>(); + } + includedNotes.add(IncludedNote.taxNote(content)); + return this; + } + @Override public String getSpecifiedProcuringProjectID() { return specifiedProcuringProjectID; From 7fd3c18547fc447e482654d17cdbdb4fab83ab02 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 11:22:56 +0200 Subject: [PATCH 06/11] Add more setter for notes --- .../java/org/mustangproject/IncludedNote.java | 6 +++ .../main/java/org/mustangproject/Invoice.java | 37 ++++++++++++++++--- .../java/org/mustangproject/SubjectCode.java | 10 ++++- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 9 ++++- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/org/mustangproject/IncludedNote.java b/library/src/main/java/org/mustangproject/IncludedNote.java index 219f9e20..5eeea22e 100644 --- a/library/src/main/java/org/mustangproject/IncludedNote.java +++ b/library/src/main/java/org/mustangproject/IncludedNote.java @@ -30,6 +30,12 @@ public class IncludedNote { public static IncludedNote taxNote(String content) { return new IncludedNote(content, SubjectCode.TXD); } + public static IncludedNote introductionNote(String content) { + return new IncludedNote(content, SubjectCode.ACY); + } + public static IncludedNote discountBonusNote(String content) { + return new IncludedNote(content, SubjectCode.AAK); + } public String getContent() { return content; diff --git a/library/src/main/java/org/mustangproject/Invoice.java b/library/src/main/java/org/mustangproject/Invoice.java index 2f63578b..606d19ba 100644 --- a/library/src/main/java/org/mustangproject/Invoice.java +++ b/library/src/main/java/org/mustangproject/Invoice.java @@ -699,7 +699,7 @@ public class Invoice implements IExportableTransaction { * @param content freeform UTF8 plain text * @return fluent setter */ - public Invoice regulatoryNote(String content) { + public Invoice addRegulatoryNote(String content) { if (includedNotes == null) { includedNotes = new ArrayList<>(); } @@ -713,7 +713,7 @@ public class Invoice implements IExportableTransaction { * @param content freeform UTF8 plain text * @return fluent setter */ - public Invoice legalNote(String content) { + public Invoice addLegalNote(String content) { if (includedNotes == null) { includedNotes = new ArrayList<>(); } @@ -727,7 +727,7 @@ public class Invoice implements IExportableTransaction { * @param content freeform UTF8 plain text * @return fluent setter */ - public Invoice customsNote(String content) { + public Invoice addCustomsNote(String content) { if (includedNotes == null) { includedNotes = new ArrayList<>(); } @@ -741,7 +741,7 @@ public class Invoice implements IExportableTransaction { * @param content freeform UTF8 plain text * @return fluent setter */ - public Invoice sellerNote(String content) { + public Invoice addSellerNote(String content) { if (includedNotes == null) { includedNotes = new ArrayList<>(); } @@ -755,7 +755,7 @@ public class Invoice implements IExportableTransaction { * @param content freeform UTF8 plain text * @return fluent setter */ - public Invoice taxNote(String content) { + public Invoice addTaxNote(String content) { if (includedNotes == null) { includedNotes = new ArrayList<>(); } @@ -763,6 +763,33 @@ public class Invoice implements IExportableTransaction { return this; } + /** + * adds a free text paragraph, which will become an includedNote element with explicit + * subjectCode {@link SubjectCode#ACY} + * @param content freeform UTF8 plain text + * @return fluent setter + */ + public Invoice addIntroductionNote(String content) { + if (includedNotes == null) { + includedNotes = new ArrayList<>(); + } + includedNotes.add(IncludedNote.introductionNote(content)); + return this; + } + /** + * adds a free text paragraph, which will become an includedNote element with explicit + * subjectCode {@link SubjectCode#AAK} + * @param content freeform UTF8 plain text + * @return fluent setter + */ + public Invoice addDiscountBonusNote(String content) { + if (includedNotes == null) { + includedNotes = new ArrayList<>(); + } + includedNotes.add(IncludedNote.discountBonusNote(content)); + return this; + } + @Override public String getSpecifiedProcuringProjectID() { return specifiedProcuringProjectID; diff --git a/library/src/main/java/org/mustangproject/SubjectCode.java b/library/src/main/java/org/mustangproject/SubjectCode.java index fb388c1f..52cc698a 100644 --- a/library/src/main/java/org/mustangproject/SubjectCode.java +++ b/library/src/main/java/org/mustangproject/SubjectCode.java @@ -27,5 +27,13 @@ public enum SubjectCode { /** * Customs information */ - CUS + CUS, + /** + * introduction + */ + ACY, + /** + * Discount and bonus agreements + */ + AAK } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index c45d628a..4c632db1 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -41,6 +41,7 @@ import org.dom4j.DocumentHelper; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.mustangproject.FileAttachment; +import org.mustangproject.SubjectCode; import org.mustangproject.XMLTools; import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; @@ -753,13 +754,17 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { if (trans.rebateAgreementExists()) { notes.append("") .append("Es bestehen Rabatt- und Bonusvereinbarungen.") - .append("AAK"); + .append("") + .append(SubjectCode.AAK) + .append(""); } if (trans.getOwnOrganisationFullPlaintextInfo() != null) { notes.append("") .append(XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo())) .append("") - .append("REG"); + .append("") + .append(SubjectCode.REG) + .append(""); } if (trans.getSubjectNote() != null) { notes.append("") From 96f26439d4ca7fa2162f4f23ddb4664f19ee912f Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 11:42:42 +0200 Subject: [PATCH 07/11] Move xml conversion to IncludedNote --- .../java/org/mustangproject/IncludedNote.java | 20 +++++++++ .../ZUGFeRD/ZUGFeRD2PullProvider.java | 44 ++++++++----------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/library/src/main/java/org/mustangproject/IncludedNote.java b/library/src/main/java/org/mustangproject/IncludedNote.java index 5eeea22e..95536afb 100644 --- a/library/src/main/java/org/mustangproject/IncludedNote.java +++ b/library/src/main/java/org/mustangproject/IncludedNote.java @@ -7,6 +7,13 @@ public class IncludedNote { private final String content; private final SubjectCode subjectCode; + private static final String INCLUDE_START = ""; + private static final String INCLUDE_END = ""; + private static final String CONTENT_START = ""; + private static final String CONTENT_END = ""; + private static final String SUBJECT_CODE_START = ""; + private static final String SUBJECT_CODE_END = ""; + private IncludedNote(String content, SubjectCode subjectCode) { this.content = content; this.subjectCode = subjectCode; @@ -37,6 +44,10 @@ public class IncludedNote { return new IncludedNote(content, SubjectCode.AAK); } + public static IncludedNote unspecifiedNote(String content) { + return new IncludedNote(content, null); + } + public String getContent() { return content; } @@ -45,4 +56,13 @@ public class IncludedNote { return subjectCode; } + public String toCiiXml(){ + String result = INCLUDE_START + CONTENT_START + + XMLTools.encodeXML(getContent() )+ CONTENT_END; + if (getSubjectCode() != null) { + result += SUBJECT_CODE_START + getSubjectCode() + SUBJECT_CODE_END; + } + return result + INCLUDE_END; + } + } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 4c632db1..b48446e9 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -29,11 +29,15 @@ import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Base64; import java.util.Date; +import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -41,6 +45,7 @@ import org.dom4j.DocumentHelper; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.mustangproject.FileAttachment; +import org.mustangproject.IncludedNote; import org.mustangproject.SubjectCode; import org.mustangproject.XMLTools; import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; @@ -742,37 +747,24 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { } } - private static String buildNotes(IExportableTransaction trans) { - StringBuilder notes = new StringBuilder(); - if (trans.getNotes() != null) { - for (final String currentNote : trans.getNotes()) { - notes.append("") - .append(XMLTools.encodeXML(currentNote)) - .append(""); + private static String buildNotes(IExportableTransaction exportableTransaction) { + final List includedNotes = Optional.ofNullable(exportableTransaction.getNotesWithSubjectCode()) + .orElse(new ArrayList<>()); + if (exportableTransaction.getNotes() != null) { + for (final String currentNote : exportableTransaction.getNotes()) { + includedNotes.add(IncludedNote.unspecifiedNote(currentNote)); } } - if (trans.rebateAgreementExists()) { - notes.append("") - .append("Es bestehen Rabatt- und Bonusvereinbarungen.") - .append("") - .append(SubjectCode.AAK) - .append(""); + if (exportableTransaction.rebateAgreementExists()) { + includedNotes.add(IncludedNote.discountBonusNote("Es bestehen Rabatt- und Bonusvereinbarungen.")); } - if (trans.getOwnOrganisationFullPlaintextInfo() != null) { - notes.append("") - .append(XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo())) - .append("") - .append("") - .append(SubjectCode.REG) - .append(""); + if (exportableTransaction.getOwnOrganisationFullPlaintextInfo() != null) { + includedNotes.add(IncludedNote.regulatoryNote(exportableTransaction.getOwnOrganisationFullPlaintextInfo())); } - if (trans.getSubjectNote() != null) { - notes.append("") - .append(XMLTools.encodeXML(trans.getSubjectNote())) - .append("") - .append(""); + if (exportableTransaction.getSubjectNote() != null) { + includedNotes.add(IncludedNote.unspecifiedNote(exportableTransaction.getSubjectNote())); } - return notes.toString(); + return includedNotes.stream().map(IncludedNote::toCiiXml).collect(Collectors.joining("")); } @Override From b1bced360b34f93a0e56537313af95df29785223 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 12:04:01 +0200 Subject: [PATCH 08/11] Use ZUGFeRD2PullProvider#buildNotes in inherited classes --- .../main/java/org/mustangproject/Invoice.java | 12 +++++ .../ZUGFeRD/DAPullProvider.java | 47 +++++++------------ .../ZUGFeRD/OXPullProvider.java | 37 ++------------- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 2 +- 4 files changed, 33 insertions(+), 65 deletions(-) diff --git a/library/src/main/java/org/mustangproject/Invoice.java b/library/src/main/java/org/mustangproject/Invoice.java index 606d19ba..da43eaeb 100644 --- a/library/src/main/java/org/mustangproject/Invoice.java +++ b/library/src/main/java/org/mustangproject/Invoice.java @@ -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 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} diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java index 81d5e8aa..5a050c7c 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java @@ -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 = "" - + XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + "" - + "REG"; - - } - - String subjectNote = ""; - if (trans.getSubjectNote() != null) { - subjectNote = "" - + XMLTools.encodeXML(trans.getSubjectNote()) + "" - + ""; - } final String typecode = "220"; /*if (trans.getDocumentCode() != null) { typecode = trans.getDocumentCode(); }*/ - String notes = ""; - if (trans.getNotes() != null) { - for (final String currentNote : trans.getNotes()) { - notes += "" + XMLTools.encodeXML(currentNote) + ""; - } - } String testBooleanStr="true"; String xml = "" + typecode + "" + "" + DATE.udtFormat(trans.getIssueDate()) + "" // date - + notes - + subjectNote - + senderReg + + buildNotes(trans) + "" + ""; @@ -111,7 +84,7 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider if (currentItem.getProduct().getTaxExemptionReason() != null) { // exemptionReason = "" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + ""; } - notes = ""; + String notes = ""; if (currentItem.getNotes() != null) { for (final String currentNote : currentItem.getNotes()) { notes = notes + "" + XMLTools.encodeXML(currentNote) + ""; @@ -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); + } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/OXPullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/OXPullProvider.java index 10b4b498..1394e2b0 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/OXPullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/OXPullProvider.java @@ -64,39 +64,11 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider } - String senderReg = ""; - if (trans.getOwnOrganisationFullPlaintextInfo() != null) { - senderReg = "" - + XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + "" - + "REG"; - - } - - String rebateAgreement = ""; - if (trans.rebateAgreementExists()) { - rebateAgreement = "" - + "Es bestehen Rabatt- und Bonusvereinbarungen." - + "AAK"; - } - - String subjectNote = ""; - if (trans.getSubjectNote() != null) { - subjectNote = "" - + XMLTools.encodeXML(trans.getSubjectNote()) + "" - + ""; - } - final String typecode = "220"; /*if (trans.getDocumentCode() != null) { typecode = trans.getDocumentCode(); }*/ - String notes = ""; - if (trans.getNotes() != null) { - for (final String currentNote : trans.getNotes()) { - notes += "" + XMLTools.encodeXML(currentNote) + ""; - - } - } + String xml = "" + "" + typecode + "" + "" + DATE.udtFormat(trans.getIssueDate()) + "" // date - + notes - + subjectNote - + rebateAgreement - + senderReg + + buildNotes(trans) + "" + ""; @@ -139,7 +108,7 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider if (currentItem.getProduct().getTaxExemptionReason() != null) { // exemptionReason = "" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + ""; } - notes = ""; + String notes = ""; if (currentItem.getNotes() != null) { for (final String currentNote : currentItem.getNotes()) { notes = notes + "" + XMLTools.encodeXML(currentNote) + ""; diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index b48446e9..d79d6042 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -747,7 +747,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { } } - private static String buildNotes(IExportableTransaction exportableTransaction) { + protected String buildNotes(IExportableTransaction exportableTransaction) { final List includedNotes = Optional.ofNullable(exportableTransaction.getNotesWithSubjectCode()) .orElse(new ArrayList<>()); if (exportableTransaction.getNotes() != null) { From 6c968e1b006c80ef66039ca13a2184617c1a2a08 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 12:17:46 +0200 Subject: [PATCH 09/11] Add ZUGFeRD2PullProvider#buildItemNotes --- .../ZUGFeRD/DAPullProvider.java | 14 ++++----- .../ZUGFeRD/OXPullProvider.java | 14 ++++----- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 29 +++++++++---------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java index 5a050c7c..93ae5b37 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java @@ -27,11 +27,14 @@ import static org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants.CATE import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Base64; import java.util.Date; +import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import org.mustangproject.*; @@ -84,18 +87,11 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider if (currentItem.getProduct().getTaxExemptionReason() != null) { // exemptionReason = "" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + ""; } - String notes = ""; - if (currentItem.getNotes() != null) { - for (final String currentNote : currentItem.getNotes()) { - notes = notes + "" + XMLTools.encodeXML(currentNote) + ""; - - } - } - final LineCalculator lc = new LineCalculator(currentItem); + final LineCalculator lc = new LineCalculator(currentItem); xml += "" + "" + "" + lineID + "" - + notes + + buildItemNotes(currentItem) + "" + ""; diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/OXPullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/OXPullProvider.java index 1394e2b0..9ea90e19 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/OXPullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/OXPullProvider.java @@ -27,14 +27,18 @@ import static org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants.CATE import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Base64; import java.util.Date; +import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import org.mustangproject.EStandard; import org.mustangproject.FileAttachment; +import org.mustangproject.IncludedNote; import org.mustangproject.XMLTools; public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider { @@ -108,18 +112,12 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider if (currentItem.getProduct().getTaxExemptionReason() != null) { // exemptionReason = "" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + ""; } - String notes = ""; - if (currentItem.getNotes() != null) { - for (final String currentNote : currentItem.getNotes()) { - notes = notes + "" + XMLTools.encodeXML(currentNote) + ""; - - } - } + final LineCalculator lc = new LineCalculator(currentItem); xml += "" + "" + "" + lineID + "" - + notes + + buildItemNotes(currentItem) + "" + ""; diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index d79d6042..753a43de 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -30,6 +30,7 @@ import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Base64; import java.util.Date; import java.util.List; @@ -299,7 +300,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { if (trans.getDocumentCode() != null) { typecode = trans.getDocumentCode(); } - String notes; String xml = "" + ""; } - notes = ""; - if (currentItem.getNotes() != null) { - for (final String currentNote : currentItem.getNotes()) { - notes = notes + "" + XMLTools.encodeXML(currentNote) + ""; - } - } final LineCalculator lc = new LineCalculator(currentItem); - if ((getProfile() != Profiles.getByName("Minimum")) && (getProfile() != Profiles.getByName("BasicWL"))) { - - xml += "" + + if ((getProfile() != Profiles.getByName("Minimum")) && (getProfile() != Profiles.getByName("BasicWL"))) { + xml += "" + "" + "" + lineID + "" - + notes + + buildItemNotes(currentItem) + "" + ""; @@ -395,16 +388,12 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { "" + XMLTools.encodeXML(currentReferencedDocument.getTypeCode()) + "" + "" + XMLTools.encodeXML(currentReferencedDocument.getReferenceTypeCode()) + "" + ""; - - } - } if (currentItem.getBuyerOrderReferencedDocumentLineID() != null) { xml += " " + "" + XMLTools.encodeXML(currentItem.getBuyerOrderReferencedDocumentLineID()) + "" + ""; - } xml += "" + "" + 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) { final List includedNotes = Optional.ofNullable(exportableTransaction.getNotesWithSubjectCode()) .orElse(new ArrayList<>()); From d660e79af46ba8edd2fe32d6b8047fb1c8338c8f Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 13:31:07 +0200 Subject: [PATCH 10/11] Replace if statements with Optional#ifPresent --- .../org/mustangproject/ZUGFeRD/DAPullProvider.java | 14 ++------------ .../ZUGFeRD/ZUGFeRD2PullProvider.java | 13 ++++++------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java index 93ae5b37..36a564bc 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/DAPullProvider.java @@ -21,20 +21,12 @@ package org.mustangproject.ZUGFeRD; import static org.mustangproject.ZUGFeRD.ZUGFeRDDateFormat.DATE; -import static org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants.CORRECTEDINVOICE; -import static org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants.CATEGORY_CODES_WITH_EXEMPTION_REASON; import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Base64; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.mustangproject.*; @@ -287,9 +279,7 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider copyWithoutRebateInfo.addNote(note); } } - if(exportableTransaction.getSubjectNote()!= null) { - copyWithoutRebateInfo.addNote(exportableTransaction.getSubjectNote()); - } + Optional.ofNullable(exportableTransaction.getSubjectNote()).ifPresent(copyWithoutRebateInfo::addNote); return super.buildNotes(copyWithoutRebateInfo); } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 753a43de..dd7eb3d3 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -47,7 +47,6 @@ import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.mustangproject.FileAttachment; import org.mustangproject.IncludedNote; -import org.mustangproject.SubjectCode; import org.mustangproject.XMLTools; import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; @@ -757,12 +756,12 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { if (exportableTransaction.rebateAgreementExists()) { includedNotes.add(IncludedNote.discountBonusNote("Es bestehen Rabatt- und Bonusvereinbarungen.")); } - if (exportableTransaction.getOwnOrganisationFullPlaintextInfo() != null) { - includedNotes.add(IncludedNote.regulatoryNote(exportableTransaction.getOwnOrganisationFullPlaintextInfo())); - } - if (exportableTransaction.getSubjectNote() != null) { - includedNotes.add(IncludedNote.unspecifiedNote(exportableTransaction.getSubjectNote())); - } + Optional.ofNullable(exportableTransaction.getOwnOrganisationFullPlaintextInfo()) + .ifPresent(info -> includedNotes.add(IncludedNote.regulatoryNote(info))); + + Optional.ofNullable(exportableTransaction.getSubjectNote()) + .ifPresent(note -> includedNotes.add(IncludedNote.unspecifiedNote(note))); + return includedNotes.stream().map(IncludedNote::toCiiXml).collect(Collectors.joining("")); } From fbe9c4d13c670e2aa36c500f40100bbfc0f86102 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Thu, 13 Jul 2023 11:22:56 +0200 Subject: [PATCH 11/11] Add java doc --- library/src/main/java/org/mustangproject/SubjectCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/org/mustangproject/SubjectCode.java b/library/src/main/java/org/mustangproject/SubjectCode.java index 52cc698a..99208128 100644 --- a/library/src/main/java/org/mustangproject/SubjectCode.java +++ b/library/src/main/java/org/mustangproject/SubjectCode.java @@ -1,7 +1,8 @@ package org.mustangproject; /** - * the qualification of the free text on the invoice from BT-22 + * EN16931-ID: BT-21 - the qualification of the free text on the invoice from BT-22
+ * In the first step only the recommended codes are implemented. */ public enum SubjectCode { /**