Möglichkeit in ZUGFeRD 1 <ram:SpecifiedTradePaymentTerms> zu definieren.
Für ZUGFeRD 2 dieselben Klassen wie für ZUGFeRD 1 zur Verfügung gestellt um eine elegantere Möglichkeit zu bieten als von Hand XML in eine Klasse zu tippen
This commit is contained in:
@@ -262,6 +262,16 @@ public interface IZUGFeRDExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get payment terms. if set, getPaymentTermDescription() and getDueDate() are
|
||||
* ignored
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default IZUGFeRDPaymentTerms getPaymentTerms() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get reference document number typically used for Invoice Corrections Will be added as IncludedNote in comfort profile
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public interface IZUGFeRDPaymentDiscountTerms {
|
||||
|
||||
BigDecimal getCalculationPercentage();
|
||||
|
||||
IZUGFeRDDate getBaseDate();
|
||||
|
||||
int getBasePeriodMeasure();
|
||||
|
||||
String getBasePeriodUnitCode();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
public interface IZUGFeRDPaymentTerms {
|
||||
|
||||
String getDescription();
|
||||
|
||||
IZUGFeRDDate getDueDate();
|
||||
|
||||
IZUGFeRDPaymentDiscountTerms getDiscountTerms();
|
||||
}
|
||||
@@ -473,29 +473,30 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
}
|
||||
}
|
||||
|
||||
xml = xml + " <ram:SpecifiedTradePaymentTerms>\n" //$NON-NLS-1$
|
||||
+ " <ram:Description>"+
|
||||
paymentTermsDescription
|
||||
+ "</ram:Description>\n";
|
||||
|
||||
if (trans.getTradeSettlement()!=null) {
|
||||
for (IZUGFeRDTradeSettlement payment : trans.getTradeSettlement()) {
|
||||
if(payment!=null) {
|
||||
xml+=payment.getPaymentXML();
|
||||
if (trans.getPaymentTerms() == null) {
|
||||
xml = xml + " <ram:SpecifiedTradePaymentTerms>\n" //$NON-NLS-1$
|
||||
+ " <ram:Description>" + paymentTermsDescription + "</ram:Description>\n";
|
||||
|
||||
if (trans.getTradeSettlement() != null) {
|
||||
for (IZUGFeRDTradeSettlement payment : trans.getTradeSettlement()) {
|
||||
if (payment != null) {
|
||||
xml += payment.getPaymentXML();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDueDate) {
|
||||
xml = xml + " <ram:DueDateDateTime><udt:DateTimeString format=\"102\">" // $NON-NLS-2$
|
||||
+ zugferdDateFormat.format(trans.getDueDate())
|
||||
+ "</udt:DateTimeString></ram:DueDateDateTime>\n";// 20130704 //$NON-NLS-1$
|
||||
|
||||
}
|
||||
xml = xml + " </ram:SpecifiedTradePaymentTerms>\n"; //$NON-NLS-1$
|
||||
} else {
|
||||
xml = xml + buildPaymentTermsXml();
|
||||
}
|
||||
|
||||
if(hasDueDate) {
|
||||
xml=xml+" <ram:DueDateDateTime><udt:DateTimeString format=\"102\">" //$NON-NLS-2$
|
||||
+ zugferdDateFormat.format(trans.getDueDate()) + "</udt:DateTimeString></ram:DueDateDateTime>\n";// 20130704 //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
xml = xml + " </ram:SpecifiedTradePaymentTerms>\n" //$NON-NLS-1$
|
||||
+ " <ram:SpecifiedTradeSettlementHeaderMonetarySummation>\n" //$NON-NLS-1$
|
||||
xml = xml + " <ram:SpecifiedTradeSettlementHeaderMonetarySummation>\n" //$NON-NLS-1$
|
||||
+ " <ram:LineTotalAmount>" + currencyFormat(getTotal()) + "</ram:LineTotalAmount>\n" //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// currencyID=\"EUR\"
|
||||
+ " <ram:ChargeTotalAmount>0.00</ram:ChargeTotalAmount>\n" //$NON-NLS-1$ currencyID=\"EUR\"
|
||||
@@ -545,4 +546,48 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
} // $NON-NLS-1$
|
||||
}
|
||||
|
||||
private String buildPaymentTermsXml() {
|
||||
String paymentTermsXml = "<ram:SpecifiedTradePaymentTerms>";
|
||||
|
||||
IZUGFeRDPaymentTerms paymentTerms = trans.getPaymentTerms();
|
||||
IZUGFeRDPaymentDiscountTerms discountTerms = paymentTerms.getDiscountTerms();
|
||||
IZUGFeRDDate 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 += "<ram:Description>" + paymentTerms.getDescription() + "</ram:Description>";
|
||||
if (dueDate != null) {
|
||||
paymentTermsXml += "<ram:DueDateDateTime>";
|
||||
paymentTermsXml += "<udt:DateTimeString format=\"" + dueDate.getFormat().getDateTimeType() + "\">"
|
||||
+ dueDate.getFormat().getFormatter().format(dueDate.getDate()) + "</udt:DateTimeString>";
|
||||
paymentTermsXml += "</ram:DueDateDateTime>";
|
||||
}
|
||||
|
||||
if (discountTerms != null) {
|
||||
paymentTermsXml += "<ram:ApplicableTradePaymentDiscountTerms>";
|
||||
String currency = trans.getCurrency();
|
||||
String basisAmount = currencyFormat(getTotalGross());
|
||||
paymentTermsXml += "<ram:BasisAmount currencyID=\"" + currency + "\">" + basisAmount + "</ram:BasisAmount>";
|
||||
paymentTermsXml += "<ram:CalculationPercent>" + discountTerms.getCalculationPercentage().toString()
|
||||
+ "</ram:CalculationPercent>";
|
||||
|
||||
if (discountTerms.getBaseDate() != null) {
|
||||
Date baseDate = discountTerms.getBaseDate().getDate();
|
||||
ZUGFeRDDateFormat baseDateFormat = discountTerms.getBaseDate().getFormat();
|
||||
paymentTermsXml += "<ram:BasisDateTime>";
|
||||
paymentTermsXml += "<udt:DateTimeString format=\"" + baseDateFormat.getDateTimeType() + "\">" + baseDateFormat.getFormatter().format(baseDate) + "</udt:DateTimeString>";
|
||||
paymentTermsXml += "</ram:BasisDateTime>";
|
||||
|
||||
paymentTermsXml += "<ram:BasisPeriodMeasure unitCode=\"" + discountTerms.getBasePeriodUnitCode() + "\">"
|
||||
+ discountTerms.getBasePeriodMeasure() + "</ram:BasisPeriodMeasure>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:ApplicableTradePaymentDiscountTerms>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:SpecifiedTradePaymentTerms>";
|
||||
return paymentTermsXml;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.mustangproject.ZUGFeRD.model.ExchangedDocumentType;
|
||||
import org.mustangproject.ZUGFeRD.model.IDType;
|
||||
import org.mustangproject.ZUGFeRD.model.IndicatorType;
|
||||
import org.mustangproject.ZUGFeRD.model.LogisticsServiceChargeType;
|
||||
import org.mustangproject.ZUGFeRD.model.MeasureType;
|
||||
import org.mustangproject.ZUGFeRD.model.NoteType;
|
||||
import org.mustangproject.ZUGFeRD.model.NoteTypeConstants;
|
||||
import org.mustangproject.ZUGFeRD.model.ObjectFactory;
|
||||
@@ -67,6 +68,7 @@ import org.mustangproject.ZUGFeRD.model.TextType;
|
||||
import org.mustangproject.ZUGFeRD.model.TradeAddressType;
|
||||
import org.mustangproject.ZUGFeRD.model.TradeAllowanceChargeType;
|
||||
import org.mustangproject.ZUGFeRD.model.TradePartyType;
|
||||
import org.mustangproject.ZUGFeRD.model.TradePaymentDiscountTermsType;
|
||||
import org.mustangproject.ZUGFeRD.model.TradePaymentTermsType;
|
||||
import org.mustangproject.ZUGFeRD.model.TradePriceType;
|
||||
import org.mustangproject.ZUGFeRD.model.TradeProductType;
|
||||
@@ -675,6 +677,9 @@ class ZUGFeRDTransactionModelConverter {
|
||||
|
||||
|
||||
private Collection<TradePaymentTermsType> getPaymentTerms() {
|
||||
if (trans.getPaymentTerms() != null) {
|
||||
return handlePaymentTermsObject(trans.getPaymentTerms());
|
||||
}
|
||||
List<TradePaymentTermsType> paymentTerms = new ArrayList<>();
|
||||
|
||||
TradePaymentTermsType paymentTerm = xmlFactory
|
||||
@@ -701,6 +706,69 @@ class ZUGFeRDTransactionModelConverter {
|
||||
return paymentTerms;
|
||||
}
|
||||
|
||||
private Collection<TradePaymentTermsType> handlePaymentTermsObject(IZUGFeRDPaymentTerms paymentTerms) {
|
||||
List<TradePaymentTermsType> xmlPaymentTerms = new ArrayList<>();
|
||||
|
||||
TradePaymentTermsType paymentTerm = xmlFactory.createTradePaymentTermsType();
|
||||
|
||||
TextType paymentTermDescr = xmlFactory.createTextType();
|
||||
|
||||
String paymentTermDescription = paymentTerms.getDescription();
|
||||
if (paymentTermDescription == null) {
|
||||
paymentTermDescription = "";
|
||||
}
|
||||
paymentTermDescr.setValue(paymentTermDescription);
|
||||
paymentTerm.getDescription().add(paymentTermDescr);
|
||||
|
||||
IZUGFeRDPaymentDiscountTerms discountTerms = paymentTerms.getDiscountTerms();
|
||||
if (paymentTerms.getDueDate() != null && discountTerms != null && discountTerms.getBaseDate() != null) {
|
||||
throw new IllegalStateException(
|
||||
"if paymentTerms.dueDate is specified, paymentTerms.discountTerms.baseDate has not to be specified");
|
||||
}
|
||||
|
||||
if (paymentTerms.getDueDate() != null) {
|
||||
DateTimeType dueDate = xmlFactory.createDateTimeType();
|
||||
DateTimeType.DateTimeString dueDateString = xmlFactory.createDateTimeTypeDateTimeString();
|
||||
dueDateString.setFormat(paymentTerms.getDueDate().getFormat().getDateTimeType());
|
||||
dueDateString.setValue(
|
||||
paymentTerms.getDueDate().getFormat().getFormatter().format(paymentTerms.getDueDate().getDate()));
|
||||
dueDate.setDateTimeString(dueDateString);
|
||||
paymentTerm.setDueDateDateTime(dueDate);
|
||||
}
|
||||
|
||||
if (discountTerms != null) {
|
||||
TradePaymentDiscountTermsType tradePaymentDiscountTerms = xmlFactory.createTradePaymentDiscountTermsType();
|
||||
|
||||
PercentType calculationPercent = xmlFactory.createPercentType();
|
||||
calculationPercent.setValue(discountTerms.getCalculationPercentage());
|
||||
tradePaymentDiscountTerms.setCalculationPercent(calculationPercent);
|
||||
|
||||
AmountType basisAmount = xmlFactory.createAmountType();
|
||||
basisAmount.setCurrencyID(currency);
|
||||
basisAmount.setValue(currencyFormat(totals.totalGrossAmount));
|
||||
tradePaymentDiscountTerms.getBasisAmount().add(basisAmount);
|
||||
|
||||
if (discountTerms.getBaseDate() != null) {
|
||||
DateTimeType baseDate = xmlFactory.createDateTimeType();
|
||||
DateTimeType.DateTimeString baseDateString = xmlFactory.createDateTimeTypeDateTimeString();
|
||||
baseDateString.setFormat(discountTerms.getBaseDate().getFormat().getDateTimeType());
|
||||
baseDateString.setValue(discountTerms.getBaseDate().getFormat().getFormatter()
|
||||
.format(discountTerms.getBaseDate().getDate()));
|
||||
baseDate.setDateTimeString(baseDateString);
|
||||
tradePaymentDiscountTerms.setBasisDateTime(baseDate);
|
||||
|
||||
MeasureType basisPeriodMeasure = xmlFactory.createMeasureType();
|
||||
basisPeriodMeasure.setUnitCode(discountTerms.getBasePeriodUnitCode());
|
||||
basisPeriodMeasure.setValue(new BigDecimal(discountTerms.getBasePeriodMeasure()));
|
||||
tradePaymentDiscountTerms.setBasisPeriodMeasure(basisPeriodMeasure);
|
||||
}
|
||||
paymentTerm.getApplicableTradePaymentDiscountTerms().add(tradePaymentDiscountTerms);
|
||||
}
|
||||
xmlPaymentTerms.add(paymentTerm);
|
||||
|
||||
return xmlPaymentTerms;
|
||||
}
|
||||
|
||||
|
||||
private TradeSettlementMonetarySummationType getMonetarySummation() {
|
||||
TradeSettlementMonetarySummationType monetarySummation = xmlFactory
|
||||
|
||||
Reference in New Issue
Block a user