- Added possibility to specify delivery date in "week of year" or "month of year" format, through introduction of new IZUGFeRDDate interface. Keeping backward compatibility by providing both methods in IZUGFeRDExportableTransaction

- Added possibility to specify "LineTwo" in Recipient Address
- Limited pdfbox version to maximum 2.0.17 because otherwise 3.0.0-SNAPSHOT was pulled in which was broken because of missing ByteArrayDataSource
This commit is contained in:
Christian Schwerdtfeger
2019-10-14 17:31:32 +02:00
parent 191debf7e4
commit 3015de02a5
11 changed files with 254 additions and 19 deletions

View File

@@ -0,0 +1,30 @@
package org.mustangproject.ZUGFeRD;
import java.util.Date;
public class IZUGFeRDDateImpl implements IZUGFeRDDate {
private Date date;
private ZUGFeRDDateFormat format = ZUGFeRDDateFormat.DATE;
public IZUGFeRDDateImpl setDate(Date date) {
this.date = date;
return this;
}
public IZUGFeRDDateImpl setFormat(ZUGFeRDDateFormat format) {
this.format = format;
return this;
}
@Override
public Date getDate() {
return date;
}
@Override
public ZUGFeRDDateFormat getFormat() {
return format;
}
}

View File

@@ -32,6 +32,7 @@ public class IZUGFeRDExportableTransactionImpl implements IZUGFeRDExportableTran
private IZUGFeRDExportableItem[] zFItems;
private IZUGFeRDExportableContact recipient;
private IZUGFeRDTradeSettlementPayment[] settlementPayments;
private IZUGFeRDDate zfDeliveryDate;
private String ownTaxID;
private String ownVATID;
private String ownOrganisationName;
@@ -149,6 +150,11 @@ public class IZUGFeRDExportableTransactionImpl implements IZUGFeRDExportableTran
return referenceNumber;
}
@Override
public IZUGFeRDDate getZFDeliveryDate() {
return zfDeliveryDate;
}
public IZUGFeRDExportableTransactionImpl setNumber(String number) {
this.number = number;
return this;
@@ -234,6 +240,11 @@ public class IZUGFeRDExportableTransactionImpl implements IZUGFeRDExportableTran
return this;
}
public IZUGFeRDExportableTransactionImpl setZfDeliveryDate(IZUGFeRDDate zfDeliveryDate) {
this.zfDeliveryDate = zfDeliveryDate;
return this;
}
public IZUGFeRDExportableTransactionImpl setCurrency(String currency) {
this.currency = currency;
return this;

View File

@@ -19,11 +19,6 @@
*********************************************************************** */
package org.mustangproject.ZUGFeRD;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -33,6 +28,12 @@ import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import junit.framework.Test;
import junit.framework.TestSuite;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ZF2EdgeTest extends MustangReaderTestCase implements IZUGFeRDExportableTransaction {
final String TARGET_PDF = "./target/testout-ZF2newEdge.pdf";
@@ -286,7 +287,6 @@ public class ZF2EdgeTest extends MustangReaderTestCase implements IZUGFeRDExport
try {
assertEquals(zi.getVersion(), 2);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

View File

@@ -18,14 +18,15 @@
*********************************************************************** */
package org.mustangproject.ZUGFeRD;
import org.junit.Test;
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
import javax.xml.bind.JAXBElement;
import java.math.BigDecimal;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.bind.JAXBElement;
import org.junit.Test;
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
public class ZUGFeRDTransactionModelConverterTest {
@Test
public void convertToModel_convertsMinimalTransactionToValidXml() throws Exception {
@@ -65,10 +66,108 @@ public class ZUGFeRDTransactionModelConverterTest {
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
@Test
public void convertToModel_convertsWithDateFormatToValidXml() throws Exception {
// setup
IZUGFeRDExportableTransaction transaction = new IZUGFeRDExportableTransactionImpl()
.setIssueDate(createDate(2000, 1, 1))
.setZfDeliveryDate(createZfDate(2000, 1, 2, ZUGFeRDDateFormat.DATE)).setDueDate(createDate(2000, 1, 3))
.setNumber("num")
.setRecipient(new IZUGFeRDExportableContactImpl().setName("recipient name")
.setStreet("recipient street").setLocation("recipient city").setCountry("recipient country"))
.setOwnOrganisationName("own org").setOwnStreet("own street").setOwnCountry("own country")
.setOwnLocation("own city")
.setTradeSettlementPayment(new IZUGFeRDTradeSettlementPaymentImpl().setOwnBankName("own bank"))
.setZFItems(new IZUGFeRDExportableItemImpl()
.setProduct(new IZUGFeRDExportableProductImpl().setVatPercent(new BigDecimal("1.19"))
.setName("product name").setDescription("product description").setUnit("product unit"))
.setQuantity(BigDecimal.ONE).setPrice(BigDecimal.TEN));
// execution
final JAXBElement<CrossIndustryDocumentType> actual = new ZUGFeRDTransactionModelConverter(transaction)
.convertToModel();
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
@Test
public void convertToModel_convertsWithWeekFormatToValidXml() throws Exception {
// setup
IZUGFeRDExportableTransaction transaction = new IZUGFeRDExportableTransactionImpl()
.setIssueDate(createDate(2000, 1, 1))
.setZfDeliveryDate(createZfDate(2000, 1, 2, ZUGFeRDDateFormat.WEEK_OF_YEAR))
.setDueDate(createDate(2000, 1, 3)).setNumber("num")
.setRecipient(new IZUGFeRDExportableContactImpl().setName("recipient name")
.setStreet("recipient street").setLocation("recipient city").setCountry("recipient country"))
.setOwnOrganisationName("own org").setOwnStreet("own street").setOwnCountry("own country")
.setOwnLocation("own city")
.setTradeSettlementPayment(new IZUGFeRDTradeSettlementPaymentImpl().setOwnBankName("own bank"))
.setZFItems(new IZUGFeRDExportableItemImpl()
.setProduct(new IZUGFeRDExportableProductImpl().setVatPercent(new BigDecimal("1.19"))
.setName("product name").setDescription("product description").setUnit("product unit"))
.setQuantity(BigDecimal.ONE).setPrice(BigDecimal.TEN));
// execution
final JAXBElement<CrossIndustryDocumentType> actual = new ZUGFeRDTransactionModelConverter(transaction)
.convertToModel();
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
@Test
public void convertToModel_convertsWithMonthFormatToValidXml() throws Exception {
// setup
IZUGFeRDExportableTransaction transaction = new IZUGFeRDExportableTransactionImpl()
.setIssueDate(createDate(2000, 1, 1))
.setZfDeliveryDate(createZfDate(2000, 1, 2, ZUGFeRDDateFormat.MONTH_OF_YEAR))
.setDueDate(createDate(2000, 1, 3))
.setNumber("num")
.setRecipient(new IZUGFeRDExportableContactImpl()
.setName("recipient name")
.setStreet("recipient street")
.setLocation("recipient city")
.setCountry("recipient country")
)
.setOwnOrganisationName("own org")
.setOwnStreet("own street")
.setOwnCountry("own country")
.setOwnLocation("own city")
.setTradeSettlementPayment(new IZUGFeRDTradeSettlementPaymentImpl().setOwnBankName("own bank"))
.setZFItems(
new IZUGFeRDExportableItemImpl()
.setProduct(new IZUGFeRDExportableProductImpl()
.setVatPercent(new BigDecimal("1.19"))
.setName("product name")
.setDescription("product description")
.setUnit("product unit")
)
.setQuantity(BigDecimal.ONE)
.setPrice(BigDecimal.TEN)
);
// execution
final JAXBElement<CrossIndustryDocumentType> actual =
new ZUGFeRDTransactionModelConverter(transaction).convertToModel();
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
private static Date createDate(int year, int month, int day) {
final GregorianCalendar calendar = new GregorianCalendar();
calendar.set(year, month - 1, day);
return calendar.getTime();
}
private static IZUGFeRDDate createZfDate(int year, int month, int day, ZUGFeRDDateFormat format) {
final GregorianCalendar calendar = new GregorianCalendar();
calendar.set(year, month - 1, day);
IZUGFeRDDateImpl date = new IZUGFeRDDateImpl();
date.setDate(calendar.getTime());
date.setFormat(format);
return date;
}
}