Issue #458 Allow multiple PaymentTerms for in Invoice
This commit is contained in:
@@ -28,6 +28,7 @@ import org.mustangproject.ZUGFeRD.*;
|
||||
import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
|
||||
/***
|
||||
@@ -56,7 +57,7 @@ public class Invoice implements IExportableTransaction {
|
||||
|
||||
protected ArrayList<IZUGFeRDAllowanceCharge> Allowances = new ArrayList<>(),
|
||||
Charges = new ArrayList<>(), LogisticsServiceCharges = new ArrayList<>();
|
||||
protected IZUGFeRDPaymentTerms paymentTerms = null;
|
||||
protected IZUGFeRDPaymentTerms[] paymentTerms = null;
|
||||
|
||||
protected String invoiceReferencedDocumentID = null;
|
||||
protected Date invoiceReferencedIssueDate;
|
||||
@@ -641,15 +642,22 @@ public class Invoice implements IExportableTransaction {
|
||||
|
||||
|
||||
@Override
|
||||
public IZUGFeRDPaymentTerms getPaymentTerms() {
|
||||
public IZUGFeRDPaymentTerms[] getPaymentTerms() {
|
||||
return paymentTerms;
|
||||
}
|
||||
|
||||
public Invoice setPaymentTerms(IZUGFeRDPaymentTerms paymentTerms) {
|
||||
@JsonProperty
|
||||
public Invoice setPaymentTerms(IZUGFeRDPaymentTerms[] paymentTerms) {
|
||||
this.paymentTerms = paymentTerms;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Invoice setPaymentTerms(IZUGFeRDPaymentTerms paymentTerms) {
|
||||
this.paymentTerms = new IZUGFeRDPaymentTerms[] { paymentTerms };
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TradeParty getDeliveryAddress() {
|
||||
return deliveryAddress;
|
||||
|
||||
@@ -310,7 +310,7 @@ public interface IExportableTransaction {
|
||||
*
|
||||
* @return the IZUGFeRDPaymentTerms of the invoice
|
||||
*/
|
||||
default IZUGFeRDPaymentTerms getPaymentTerms() {
|
||||
default IZUGFeRDPaymentTerms[] getPaymentTerms() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -505,36 +505,44 @@ public class OXPullProvider extends ZUGFeRD2PullProvider {
|
||||
|
||||
private String buildPaymentTermsXml() {
|
||||
|
||||
final IZUGFeRDPaymentTerms paymentTerms = trans.getPaymentTerms();
|
||||
if (paymentTerms == null) {
|
||||
final IZUGFeRDPaymentTerms[] paymentTerms = trans.getPaymentTerms();
|
||||
|
||||
String paymentTermsXml = "";
|
||||
if (paymentTerms == null || paymentTerms.length == 0) {
|
||||
return "";
|
||||
}
|
||||
String paymentTermsXml = "<ram:SpecifiedTradePaymentTerms>";
|
||||
|
||||
final IZUGFeRDPaymentDiscountTerms discountTerms = paymentTerms.getDiscountTerms();
|
||||
paymentTermsXml += "<ram:Description>" + paymentTerms.getDescription() + "</ram:Description>";
|
||||
if (discountTerms != null) {
|
||||
paymentTermsXml += "<ram:ApplicableTradePaymentDiscountTerms>";
|
||||
final String currency = trans.getCurrency();
|
||||
final String basisAmount = currencyFormat(calc.getGrandTotal());
|
||||
paymentTermsXml += "<ram:BasisAmount currencyID=\"" + currency + "\">" + basisAmount + "</ram:BasisAmount>";
|
||||
paymentTermsXml += "<ram:CalculationPercent>" + discountTerms.getCalculationPercentage().toString()
|
||||
for (IZUGFeRDPaymentTerms pt : paymentTerms)
|
||||
{
|
||||
paymentTermsXml += "<ram:SpecifiedTradePaymentTerms>";
|
||||
|
||||
final IZUGFeRDPaymentDiscountTerms discountTerms = pt.getDiscountTerms();
|
||||
paymentTermsXml += "<ram:Description>" + pt.getDescription() + "</ram:Description>";
|
||||
if (discountTerms != null)
|
||||
{
|
||||
paymentTermsXml += "<ram:ApplicableTradePaymentDiscountTerms>";
|
||||
final String currency = trans.getCurrency();
|
||||
final String basisAmount = currencyFormat(calc.getGrandTotal());
|
||||
paymentTermsXml += "<ram:BasisAmount currencyID=\"" + currency + "\">" + basisAmount + "</ram:BasisAmount>";
|
||||
paymentTermsXml += "<ram:CalculationPercent>" + discountTerms.getCalculationPercentage().toString()
|
||||
+ "</ram:CalculationPercent>";
|
||||
|
||||
if (discountTerms.getBaseDate() != null) {
|
||||
final Date baseDate = discountTerms.getBaseDate();
|
||||
paymentTermsXml += "<ram:BasisDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(baseDate);
|
||||
paymentTermsXml += "</ram:BasisDateTime>";
|
||||
if (discountTerms.getBaseDate() != null)
|
||||
{
|
||||
final Date baseDate = discountTerms.getBaseDate();
|
||||
paymentTermsXml += "<ram:BasisDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(baseDate);
|
||||
paymentTermsXml += "</ram:BasisDateTime>";
|
||||
|
||||
paymentTermsXml += "<ram:BasisPeriodMeasure unitCode=\"" + discountTerms.getBasePeriodUnitCode() + "\">"
|
||||
paymentTermsXml += "<ram:BasisPeriodMeasure unitCode=\"" + discountTerms.getBasePeriodUnitCode() + "\">"
|
||||
+ discountTerms.getBasePeriodMeasure() + "</ram:BasisPeriodMeasure>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:ApplicableTradePaymentDiscountTerms>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:ApplicableTradePaymentDiscountTerms>";
|
||||
paymentTermsXml += "</ram:SpecifiedTradePaymentTerms>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:SpecifiedTradePaymentTerms>";
|
||||
return paymentTermsXml;
|
||||
}
|
||||
|
||||
|
||||
@@ -433,44 +433,57 @@ public class ZUGFeRD1PullProvider extends ZUGFeRD2PullProvider {
|
||||
}
|
||||
|
||||
private String buildPaymentTermsXml() {
|
||||
String paymentTermsXml = "<ram:SpecifiedTradePaymentTerms>";
|
||||
final IZUGFeRDPaymentTerms[] paymentTerms = trans.getPaymentTerms();
|
||||
|
||||
final IZUGFeRDPaymentTerms paymentTerms = trans.getPaymentTerms();
|
||||
final IZUGFeRDPaymentDiscountTerms discountTerms = paymentTerms.getDiscountTerms();
|
||||
final Date dueDate = paymentTerms.getDueDate();
|
||||
if (dueDate != null && discountTerms != null && discountTerms.getBaseDate() != null) {
|
||||
throw new IllegalStateException(
|
||||
String paymentTermsXml = "";
|
||||
if (paymentTerms == null || paymentTerms.length == 0) {
|
||||
return paymentTermsXml;
|
||||
}
|
||||
|
||||
for (IZUGFeRDPaymentTerms pt : paymentTerms)
|
||||
{
|
||||
paymentTermsXml += "<ram:SpecifiedTradePaymentTerms>";
|
||||
|
||||
final IZUGFeRDPaymentDiscountTerms discountTerms = pt.getDiscountTerms();
|
||||
final Date dueDate = pt.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 += DATE.udtFormat(dueDate);
|
||||
paymentTermsXml += "</ram:DueDateDateTime>";
|
||||
}
|
||||
|
||||
if (discountTerms != null) {
|
||||
paymentTermsXml += "<ram:ApplicableTradePaymentDiscountTerms>";
|
||||
final String currency = trans.getCurrency();
|
||||
final String basisAmount = currencyFormat(calc.getGrandTotal());
|
||||
paymentTermsXml += "<ram:BasisAmount currencyID=\"" + currency + "\">" + basisAmount + "</ram:BasisAmount>";
|
||||
paymentTermsXml += "<ram:CalculationPercent>" + discountTerms.getCalculationPercentage().toString()
|
||||
+ "</ram:CalculationPercent>";
|
||||
|
||||
if (discountTerms.getBaseDate() != null) {
|
||||
final Date baseDate = discountTerms.getBaseDate();
|
||||
paymentTermsXml += "<ram:BasisDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(baseDate);
|
||||
paymentTermsXml += "</ram:BasisDateTime>";
|
||||
|
||||
paymentTermsXml += "<ram:BasisPeriodMeasure unitCode=\"" + discountTerms.getBasePeriodUnitCode() + "\">"
|
||||
+ discountTerms.getBasePeriodMeasure() + "</ram:BasisPeriodMeasure>";
|
||||
}
|
||||
paymentTermsXml += "<ram:Description>" + pt.getDescription() + "</ram:Description>";
|
||||
if (dueDate != null)
|
||||
{
|
||||
paymentTermsXml += "<ram:DueDateDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(dueDate);
|
||||
paymentTermsXml += "</ram:DueDateDateTime>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:ApplicableTradePaymentDiscountTerms>";
|
||||
}
|
||||
if (discountTerms != null)
|
||||
{
|
||||
paymentTermsXml += "<ram:ApplicableTradePaymentDiscountTerms>";
|
||||
final String currency = trans.getCurrency();
|
||||
final String basisAmount = currencyFormat(calc.getGrandTotal());
|
||||
paymentTermsXml += "<ram:BasisAmount currencyID=\"" + currency + "\">" + basisAmount + "</ram:BasisAmount>";
|
||||
paymentTermsXml += "<ram:CalculationPercent>" + discountTerms.getCalculationPercentage().toString()
|
||||
+ "</ram:CalculationPercent>";
|
||||
|
||||
paymentTermsXml += "</ram:SpecifiedTradePaymentTerms>";
|
||||
if (discountTerms.getBaseDate() != null)
|
||||
{
|
||||
final Date baseDate = discountTerms.getBaseDate();
|
||||
paymentTermsXml += "<ram:BasisDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(baseDate);
|
||||
paymentTermsXml += "</ram:BasisDateTime>";
|
||||
|
||||
paymentTermsXml += "<ram:BasisPeriodMeasure unitCode=\"" + discountTerms.getBasePeriodUnitCode() + "\">"
|
||||
+ discountTerms.getBasePeriodMeasure() + "</ram:BasisPeriodMeasure>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:ApplicableTradePaymentDiscountTerms>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:SpecifiedTradePaymentTerms>";
|
||||
}
|
||||
return paymentTermsXml;
|
||||
}
|
||||
|
||||
|
||||
@@ -963,56 +963,70 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
}
|
||||
|
||||
private String buildPaymentTermsXml() {
|
||||
final IZUGFeRDPaymentTerms paymentTerms = trans.getPaymentTerms();
|
||||
if (paymentTerms == null) {
|
||||
final IZUGFeRDPaymentTerms[] paymentTerms = trans.getPaymentTerms();
|
||||
|
||||
String paymentTermsXml = "";
|
||||
if (paymentTerms == null || paymentTerms.length == 0) {
|
||||
return "";
|
||||
}
|
||||
String paymentTermsXml = "<ram:SpecifiedTradePaymentTerms>";
|
||||
|
||||
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 += "<ram:Description>" + paymentTerms.getDescription() + "</ram:Description>";
|
||||
for (IZUGFeRDPaymentTerms pt : paymentTerms)
|
||||
{
|
||||
|
||||
if (dueDate != null) {
|
||||
paymentTermsXml += "<ram:DueDateDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(dueDate);
|
||||
paymentTermsXml += "</ram:DueDateDateTime>";
|
||||
}
|
||||
paymentTermsXml += "<ram:SpecifiedTradePaymentTerms>";
|
||||
|
||||
if (trans.getTradeSettlement() != null) {
|
||||
for (final IZUGFeRDTradeSettlement payment : trans.getTradeSettlement()) {
|
||||
if ((payment != null) && (payment instanceof IZUGFeRDTradeSettlementDebit)) {
|
||||
paymentTermsXml += payment.getPaymentXML();
|
||||
final IZUGFeRDPaymentDiscountTerms discountTerms = pt.getDiscountTerms();
|
||||
final Date dueDate = pt.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>" + pt.getDescription() + "</ram:Description>";
|
||||
|
||||
if (dueDate != null)
|
||||
{
|
||||
paymentTermsXml += "<ram:DueDateDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(dueDate);
|
||||
paymentTermsXml += "</ram:DueDateDateTime>";
|
||||
}
|
||||
|
||||
if (trans.getTradeSettlement() != null)
|
||||
{
|
||||
for (final IZUGFeRDTradeSettlement payment : trans.getTradeSettlement())
|
||||
{
|
||||
if ((payment != null) && (payment instanceof IZUGFeRDTradeSettlementDebit))
|
||||
{
|
||||
paymentTermsXml += payment.getPaymentXML();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (discountTerms != null) {
|
||||
paymentTermsXml += "<ram:ApplicableTradePaymentDiscountTerms>";
|
||||
final String currency = trans.getCurrency();
|
||||
final String basisAmount = currencyFormat(calc.getGrandTotal());
|
||||
paymentTermsXml += "<ram:BasisAmount currencyID=\"" + currency + "\">" + basisAmount + "</ram:BasisAmount>";
|
||||
paymentTermsXml += "<ram:CalculationPercent>" + discountTerms.getCalculationPercentage().toString()
|
||||
+ "</ram:CalculationPercent>";
|
||||
if (discountTerms != null)
|
||||
{
|
||||
paymentTermsXml += "<ram:ApplicableTradePaymentDiscountTerms>";
|
||||
final String currency = trans.getCurrency();
|
||||
final String basisAmount = currencyFormat(calc.getGrandTotal());
|
||||
paymentTermsXml += "<ram:BasisAmount currencyID=\"" + currency + "\">" + basisAmount + "</ram:BasisAmount>";
|
||||
paymentTermsXml += "<ram:CalculationPercent>" + discountTerms.getCalculationPercentage().toString()
|
||||
+ "</ram:CalculationPercent>";
|
||||
|
||||
if (discountTerms.getBaseDate() != null) {
|
||||
final Date baseDate = discountTerms.getBaseDate();
|
||||
paymentTermsXml += "<ram:BasisDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(baseDate);
|
||||
paymentTermsXml += "</ram:BasisDateTime>";
|
||||
if (discountTerms.getBaseDate() != null)
|
||||
{
|
||||
final Date baseDate = discountTerms.getBaseDate();
|
||||
paymentTermsXml += "<ram:BasisDateTime>";
|
||||
paymentTermsXml += DATE.udtFormat(baseDate);
|
||||
paymentTermsXml += "</ram:BasisDateTime>";
|
||||
|
||||
paymentTermsXml += "<ram:BasisPeriodMeasure unitCode=\"" + discountTerms.getBasePeriodUnitCode() + "\">"
|
||||
+ discountTerms.getBasePeriodMeasure() + "</ram:BasisPeriodMeasure>";
|
||||
paymentTermsXml += "<ram:BasisPeriodMeasure unitCode=\"" + discountTerms.getBasePeriodUnitCode() + "\">"
|
||||
+ discountTerms.getBasePeriodMeasure() + "</ram:BasisPeriodMeasure>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:ApplicableTradePaymentDiscountTerms>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:ApplicableTradePaymentDiscountTerms>";
|
||||
paymentTermsXml += "</ram:SpecifiedTradePaymentTerms>";
|
||||
}
|
||||
|
||||
paymentTermsXml += "</ram:SpecifiedTradePaymentTerms>";
|
||||
return paymentTermsXml;
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ public class ZF2EdgeTest extends MustangReaderTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDPaymentTerms getPaymentTerms() {
|
||||
public IZUGFeRDPaymentTerms[] getPaymentTerms() {
|
||||
PaymentDiscountTerms paymentDiscountTerms =
|
||||
new PaymentDiscountTerms(
|
||||
new BigDecimal(2), // skonto prozent
|
||||
@@ -240,13 +240,13 @@ public class ZF2EdgeTest extends MustangReaderTestCase {
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
return
|
||||
new PaymentTerms(
|
||||
"14 Tage 2% Skonto, 30 Tage rein netto",
|
||||
due,// fälligkeitsdatum
|
||||
paymentDiscountTerms //PaymentDiscountTerms
|
||||
);
|
||||
|
||||
return new IZUGFeRDPaymentTerms[]{
|
||||
new PaymentTerms(
|
||||
"14 Tage 2% Skonto, 30 Tage rein netto",
|
||||
due,// fälligkeitsdatum
|
||||
paymentDiscountTerms //PaymentDiscountTerms
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -243,7 +243,7 @@ public class ZF2Test extends MustangReaderTestCase {
|
||||
try {
|
||||
assertEquals(zi.getVersion(), 2);
|
||||
} catch (final Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
// TCalODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user