diff --git a/History.md b/History.md index 798ac64e..080769d7 100644 --- a/History.md +++ b/History.md @@ -1,8 +1,9 @@ -1. +1.7.5 ===== -2019- +2019-10- - support Sepa Direct Debit +- closes #134 ZUGFeRD2PullProvider uses NetPrice for GrossPrice 1.7.4 ===== diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableProduct.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableProduct.java index ea41877f..091591a8 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableProduct.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableProduct.java @@ -81,5 +81,10 @@ public interface IZUGFeRDExportableProduct { * @return VAT percent of the product */ BigDecimal getVATPercent(); + + default String getTaxCategoryCode() { + return "S"; + } + } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index a744da0a..53fcebab 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -319,7 +319,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " VAT\n" //$NON-NLS-1$ - + " S\n" //$NON-NLS-1$ + + " "+currentItem.getProduct().getTaxCategoryCode()+"\n" //$NON-NLS-1$ + " " //$NON-NLS-1$ + vatFormat(currentItem.getProduct().getVATPercent()) + "\n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ diff --git a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderTestCase.java b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderTestCase.java index 9b74f570..099a70f5 100644 --- a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderTestCase.java +++ b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderTestCase.java @@ -125,7 +125,7 @@ public abstract class MustangReaderTestCase extends TestCase implements IZUGFeRD protected class Item implements IZUGFeRDExportableItem { - public Item(BigDecimal price, BigDecimal quantity, Product product) { + public Item(BigDecimal price, BigDecimal quantity, IZUGFeRDExportableProduct product) { super(); this.price = price; this.quantity = quantity; @@ -133,7 +133,7 @@ public abstract class MustangReaderTestCase extends TestCase implements IZUGFeRD } private BigDecimal price, quantity; - private Product product; + private IZUGFeRDExportableProduct product; @Override public BigDecimal getPrice() { @@ -154,11 +154,11 @@ public abstract class MustangReaderTestCase extends TestCase implements IZUGFeRD } @Override - public Product getProduct() { + public IZUGFeRDExportableProduct getProduct() { return product; } - public void setProduct(Product product) { + public void setProduct(IZUGFeRDExportableProduct product) { this.product = product; } diff --git a/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java b/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java index 2bd13c2d..10870c3b 100644 --- a/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java +++ b/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java @@ -1,279 +1,322 @@ -/** ********************************************************************** - * - * Copyright 2019 Jochen Staerk - * - * Use is subject to license terms. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - * - *********************************************************************** */ -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; -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ZF2EdgeTest extends MustangReaderTestCase { - final String TARGET_PDF = "./target/testout-ZF2newEdge.pdf"; +/** ********************************************************************** + * + * Copyright 2019 Jochen Staerk + * + * Use is subject to license terms. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *********************************************************************** */ +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; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ZF2EdgeTest extends MustangReaderTestCase implements IZUGFeRDExportableTransaction { + final String TARGET_PDF = "./target/testout-ZF2newEdge.pdf"; + + protected class EdgeProduct implements IZUGFeRDExportableProduct { + private String description, name, unit; + + public EdgeProduct(String description, String name, String unit) { + super(); + this.description = description; + this.name = name; + this.unit = unit; + } + + @Override + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + @Override + public BigDecimal getVATPercent() { + return BigDecimal.ZERO; + } + + @Override + public String getTaxCategoryCode() { + return "K"; // simulate intra community supply + } + } protected class DebitPayment implements IZUGFeRDTradeSettlementDebit { - @Override public String getIBAN() { return "DE540815"; } - @Override public String getMandate() { return "DE99XX12345"; } - + } - @Override public IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() { return null; } - + @Override - public IZUGFeRDTradeSettlement[] getTradeSettlement() { + public IZUGFeRDTradeSettlement[] getTradeSettlement() { IZUGFeRDTradeSettlement[] payments = new DebitPayment[1]; payments[0] = new DebitPayment(); return payments; } - - @Override - public Date getDeliveryDate() { - return new GregorianCalendar(2017, Calendar.MAY, 7).getTime(); - } - - @Override - public Date getDueDate() { - return new GregorianCalendar(2017, Calendar.MAY, 30).getTime(); - } - - @Override - public Date getIssueDate() { - return new GregorianCalendar(2017, Calendar.MAY, 9).getTime(); - } - - @Override - public String getNumber() { - return "RE-20170509/505"; - } - - @Override - public String getOwnCountry() { - return "DE"; - } - - @Override - public String getOwnLocation() { - return "Stadthausen"; - } - - @Override - public String getOwnOrganisationName() { - return "Bei Spiel GmbH"; - } - - @Override - public String getOwnStreet() { - return "Ecke 12"; - } - - @Override - public IZUGFeRDExportableContact getOwnContact() { - return new SenderContact(); - - } - - @Override - public String getOwnTaxID() { - return "22/815/0815/4"; - } - - @Override - public String getOwnVATID() { - return "DE136695976"; - } - - @Override - public String getOwnZIP() { - return "12345"; - } - - @Override - public IZUGFeRDExportableContact getRecipient() { - return new RecipientContact(); - } - - @Override - public String getOwnOrganisationFullPlaintextInfo() { - return null; - } - - @Override - public String getCurrency() { - return "EUR"; - } - - @Override - public IZUGFeRDExportableItem[] getZFItems() { - Item[] allItems = new Item[3]; - Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR", - new BigDecimal("7.000000")); - Product balloonProduct = new Product("", "Bestellerweiterung für E&F Umbau", "C62", - new BigDecimal("19.000000"));// test for issue 103 - Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000")); - - allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("1"), designProduct); - allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("400"), balloonProduct); - allItems[2] = new Item(new BigDecimal("0.10"), new BigDecimal("200"), airProduct); - return allItems; - } - - @Override - public String getPaymentTermDescription() { - SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy"); - return "Zahlbar ohne Abzug bis zum " + germanDateFormat.format(getDueDate()); - } - - @Override - public IZUGFeRDAllowanceCharge[] getZFAllowances() { - return null; - } - - @Override - public IZUGFeRDAllowanceCharge[] getZFCharges() { - return null; - } - - @Override - public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() { - return null; - } - - @Override - public String getReferenceNumber() { - return "AB321"; - } - - /** - * Create the test case - * - * @param testName name of the test case - */ - public ZF2EdgeTest(String testName) { - super(testName); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() { - return new TestSuite(ZF2EdgeTest.class); - } - - // //////// TESTS - // ////////////////////////////////////////////////////////////////////////////////////////// - - /** - * The exporter test bases on @{code - * ./src/test/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf}, adds - * metadata, writes to @{code ./target/testout-*} and then imports to check the - * values. - */ - public void testEdgeExport() { - - // the writing part - - try (InputStream SOURCE_PDF = this.getClass() - .getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf"); - - ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory().setProducer("My Application") - .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors() - .load(SOURCE_PDF)) { - ze.PDFattachZugferdFile(this); - String theXML = new String(ze.getProvider().getXML()); - assertTrue(theXML.contains("59")); - assertTrue(zi.getUTF8().contains("DE540815")); + assertTrue(zi.getUTF8().contains("DE540815")); assertTrue(zi.getUTF8().contains("DE99XX12345")); assertFalse(zi.getUTF8().contains("")); - - // Reading ZUGFeRD - assertEquals(zi.getAmount(), "571.04"); - assertEquals(zi.getHolder(), getOwnOrganisationName()); - assertEquals(zi.getForeignReference(), getNumber()); - try { - assertEquals(zi.getVersion(), 2); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - /** - * The exporter test bases on @{code - * ./src/test/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf}, adds - * metadata, writes to @{code ./target/testout-*} and then imports to check the - * values. - */ - public void testOutputStreamExport() { - - // the writing part - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - try (InputStream SOURCE_PDF = this.getClass() - .getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf"); - - ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory().setProducer("My Application") - .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors() - .load(SOURCE_PDF)) { - ze.PDFattachZugferdFile(this); - String theXML = new String(ze.getProvider().getXML()); - assertTrue(theXML.contains("