From 35551f0ed3e59673675a62c5b4ed6b3c116d7f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Sta=CC=88rk?= Date: Sat, 9 May 2020 09:28:06 +0200 Subject: [PATCH] zf2pushprovider --- History.md | 3 +- .../org/mustangproject/ZUGFeRD/Contact.java | 85 ++++ .../java/org/mustangproject/ZUGFeRD/Item.java | 58 +++ .../org/mustangproject/ZUGFeRD/Product.java | 59 +++ .../ZUGFeRD/ZUGFeRD2PushProvider.java | 413 ++++++++++++++++++ .../mustangproject/ZUGFeRD/ZF2PushTest.java | 84 ++++ 6 files changed, 701 insertions(+), 1 deletion(-) create mode 100644 libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Contact.java create mode 100644 libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Item.java create mode 100644 libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Product.java create mode 100644 libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PushProvider.java create mode 100644 libraryBasic/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java diff --git a/History.md b/History.md index 0fc45ece..13b3ddd5 100644 --- a/History.md +++ b/History.md @@ -2,6 +2,7 @@ ===== - Refactored comparison operator for ChargeIndicator https://github.com/ZUGFeRD/mustangproject/pull/153 +- ZUGFeRD2PullProvider needs getDueDate() although getPaymentTermDescription() is defined https://github.com/ZUGFeRD/mustangproject/pull/155 - #148 support additional documents for items - #154 german VAT ID may not be used for sellercontact scheme id @@ -191,4 +192,4 @@ ZUGFeRD 1.0 1.0.0 ===== 2014-05-22 -ZUGFeRD 1.0RC Comfort \ No newline at end of file +ZUGFeRD 1.0RC Comfort diff --git a/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Contact.java b/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Contact.java new file mode 100644 index 00000000..5dafc75b --- /dev/null +++ b/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Contact.java @@ -0,0 +1,85 @@ +package org.mustangproject.ZUGFeRD; + +public class Contact implements IZUGFeRDExportableContact { + + protected String name,phone,email,zip,street,location,country; + + public Contact(String name, String phone, String email, String street, String zip, String location, String country) { + this.name = name; + this.phone = phone; + this.email = email; + this.street = street; + this.zip = zip; + this.location = location; + this.country = country; + + } + + @Override + public String getName() { + return name; + } + + public Contact setName(String name) { + this.name = name; + return this; + } + + @Override + public String getPhone() { + return phone; + } + + public Contact setPhone(String phone) { + this.phone = phone; + return this; + } + + public String getEMail() { + return email; + } + + public Contact setEMail(String email) { + this.email = email; + return this; + } + + public String getZIP() { + return zip; + } + + public Contact setZIP(String zip) { + this.zip = zip; + return this; + } + + @Override + public String getStreet() { + return street; + } + + public Contact setStreet(String street) { + this.street = street; + return this; + } + + @Override + public String getLocation() { + return location; + } + + public Contact setLocation(String location) { + this.location = location; + return this; + } + + @Override + public String getCountry() { + return country; + } + + public Contact setCountry(String country) { + this.country = country; + return this; + } +} diff --git a/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Item.java b/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Item.java new file mode 100644 index 00000000..b8c2285c --- /dev/null +++ b/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Item.java @@ -0,0 +1,58 @@ +package org.mustangproject.ZUGFeRD; + +import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge; +import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem; +import org.mustangproject.ZUGFeRD.IZUGFeRDExportableProduct; + +import java.math.BigDecimal; + +public class Item implements IZUGFeRDExportableItem { + protected BigDecimal price, quantity; + protected Product product; + + public Item(Product product, BigDecimal price, BigDecimal quantity) { + this.price = price; + this.quantity = quantity; + this.product = product; + } + + @Override + public BigDecimal getPrice() { + return price; + } + + public Item setPrice(BigDecimal price) { + this.price = price; + return this; + } + + @Override + public BigDecimal getQuantity() { + return quantity; + } + + public Item setQuantity(BigDecimal quantity) { + this.quantity = quantity; + return this; + } + + @Override + public Product getProduct() { + return product; + } + + @Override + public IZUGFeRDAllowanceCharge[] getItemAllowances() { + return null; + } + + @Override + public IZUGFeRDAllowanceCharge[] getItemCharges() { + return null; + } + + public Item setProduct(Product product) { + this.product = product; + return this; + } +} diff --git a/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Product.java b/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Product.java new file mode 100644 index 00000000..d07186b8 --- /dev/null +++ b/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/Product.java @@ -0,0 +1,59 @@ +package org.mustangproject.ZUGFeRD; + +import org.mustangproject.ZUGFeRD.IZUGFeRDExportableProduct; + +import java.math.BigDecimal; + +public class Product implements IZUGFeRDExportableProduct { + protected String unit, name, description; + protected BigDecimal VATPercent; + + + public Product(String name, String description, String unit, BigDecimal VATPercent) { + this.unit = unit; + this.name = name; + this.description = description; + this.VATPercent = VATPercent; + } + + + @Override + public String getUnit() { + return unit; + } + + public Product setUnit(String unit) { + this.unit = unit; + return this; + } + + @Override + public String getName() { + return name; + } + + public Product setName(String name) { + this.name = name; + return this; + } + + @Override + public String getDescription() { + return description; + } + + public Product setDescription(String description) { + this.description = description; + return this; + } + + @Override + public BigDecimal getVATPercent() { + return VATPercent; + } + + public Product setVATPercent(BigDecimal VATPercent) { + this.VATPercent = VATPercent; + return this; + } +} diff --git a/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PushProvider.java b/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PushProvider.java new file mode 100644 index 00000000..4d47c89d --- /dev/null +++ b/libraryBasic/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PushProvider.java @@ -0,0 +1,413 @@ +/** + * ********************************************************************* + *

+ * Copyright 2018 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 java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; + +public class ZUGFeRD2PushProvider implements IZUGFeRDExportableTransaction { + + protected String documentName = null, documentCode = null, number = null, ownOrganisationFullPlaintextInfo = null, referenceNumber = null, shipToOrganisationID = null, shipToOrganisationName = null, shipToStreet = null, shipToZIP = null, shipToLocation = null, shipToCountry = null, buyerOrderReferencedDocumentID = null, buyerOrderReferencedDocumentIssueDateTime = null, ownTaxID = null, ownVATID = null, ownForeignOrganisationID = null, ownOrganisationName = null, ownStreet = null, ownZIP = null, ownLocation = null, ownCountry = null, currency = null, paymentTermDescription = null; + protected Date issueDate = null, dueDate = null, deliveryDate = null; + protected BigDecimal totalPrepaidAmount = null; + protected IZUGFeRDExportableContact ownContact = null, recipient = null, deliveryAddress = null; + protected ArrayList ZFItems = null; + + protected IZUGFeRDAllowanceCharge[] ZFAllowances = null, ZFCharges = null, ZFLogisticsServiceCharges = null; + protected IZUGFeRDTradeSettlement[] getTradeSettlement = null; + protected IZUGFeRDPaymentTerms paymentTerms = null; + + + public ZUGFeRD2PushProvider() { + ZFItems = new ArrayList(); + } + + @Override + public String getDocumentName() { + return documentName; + } + + public ZUGFeRD2PushProvider setDocumentName(String documentName) { + this.documentName = documentName; + return this; + } + + @Override + public String getDocumentCode() { + return documentCode; + } + + public ZUGFeRD2PushProvider setDocumentCode(String documentCode) { + this.documentCode = documentCode; + return this; + } + + @Override + public String getNumber() { + return number; + } + + public ZUGFeRD2PushProvider setNumber(String number) { + this.number = number; + return this; + } + + @Override + public String getOwnOrganisationFullPlaintextInfo() { + return ownOrganisationFullPlaintextInfo; + } + + public ZUGFeRD2PushProvider setOwnOrganisationFullPlaintextInfo(String ownOrganisationFullPlaintextInfo) { + this.ownOrganisationFullPlaintextInfo = ownOrganisationFullPlaintextInfo; + return this; + } + + @Override + public String getReferenceNumber() { + return referenceNumber; + } + + public ZUGFeRD2PushProvider setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + return this; + } + + @Override + public String getShipToOrganisationID() { + return shipToOrganisationID; + } + + public ZUGFeRD2PushProvider setShipToOrganisationID(String shipToOrganisationID) { + this.shipToOrganisationID = shipToOrganisationID; + return this; + } + + @Override + public String getShipToOrganisationName() { + return shipToOrganisationName; + } + + public ZUGFeRD2PushProvider setShipToOrganisationName(String shipToOrganisationName) { + this.shipToOrganisationName = shipToOrganisationName; + return this; + } + + @Override + public String getShipToStreet() { + return shipToStreet; + } + + public ZUGFeRD2PushProvider setShipToStreet(String shipToStreet) { + this.shipToStreet = shipToStreet; + return this; + } + + @Override + public String getShipToZIP() { + return shipToZIP; + } + + public ZUGFeRD2PushProvider setShipToZIP(String shipToZIP) { + this.shipToZIP = shipToZIP; + return this; + } + + @Override + public String getShipToLocation() { + return shipToLocation; + } + + public ZUGFeRD2PushProvider setShipToLocation(String shipToLocation) { + this.shipToLocation = shipToLocation; + return this; + } + + @Override + public String getShipToCountry() { + return shipToCountry; + } + + public ZUGFeRD2PushProvider setShipToCountry(String shipToCountry) { + this.shipToCountry = shipToCountry; + return this; + } + + @Override + public String getBuyerOrderReferencedDocumentID() { + return buyerOrderReferencedDocumentID; + } + + public ZUGFeRD2PushProvider setBuyerOrderReferencedDocumentID(String buyerOrderReferencedDocumentID) { + this.buyerOrderReferencedDocumentID = buyerOrderReferencedDocumentID; + return this; + } + + @Override + public String getBuyerOrderReferencedDocumentIssueDateTime() { + return buyerOrderReferencedDocumentIssueDateTime; + } + + public ZUGFeRD2PushProvider setBuyerOrderReferencedDocumentIssueDateTime(String buyerOrderReferencedDocumentIssueDateTime) { + this.buyerOrderReferencedDocumentIssueDateTime = buyerOrderReferencedDocumentIssueDateTime; + return this; + } + + @Override + public String getOwnTaxID() { + return ownTaxID; + } + + public ZUGFeRD2PushProvider setOwnTaxID(String ownTaxID) { + this.ownTaxID = ownTaxID; + return this; + } + + @Override + public String getOwnVATID() { + return ownVATID; + } + + public ZUGFeRD2PushProvider setOwnVATID(String ownVATID) { + this.ownVATID = ownVATID; + return this; + } + + @Override + public String getOwnForeignOrganisationID() { + return ownForeignOrganisationID; + } + + public ZUGFeRD2PushProvider setOwnForeignOrganisationID(String ownForeignOrganisationID) { + this.ownForeignOrganisationID = ownForeignOrganisationID; + return this; + } + + @Override + public String getOwnOrganisationName() { + return ownOrganisationName; + } + + public ZUGFeRD2PushProvider setOwnOrganisationName(String ownOrganisationName) { + this.ownOrganisationName = ownOrganisationName; + return this; + } + + @Override + public String getOwnStreet() { + return ownStreet; + } + + public ZUGFeRD2PushProvider setOwnStreet(String ownStreet) { + this.ownStreet = ownStreet; + return this; + } + + @Override + public String getOwnZIP() { + return ownZIP; + } + + public ZUGFeRD2PushProvider setOwnZIP(String ownZIP) { + this.ownZIP = ownZIP; + return this; + } + + public String getOwnLocation() { + return ownLocation; + } + + public ZUGFeRD2PushProvider setOwnLocation(String getOwnLocation) { + this.ownLocation = getOwnLocation; + return this; + } + + public String getOwnCountry() { + return ownCountry; + } + + public ZUGFeRD2PushProvider setOwnCountry(String getOwnCountry) { + this.ownCountry = getOwnCountry; + return this; + } + + @Override + public String getCurrency() { + return currency; + } + + public ZUGFeRD2PushProvider setCurrency(String currency) { + this.currency = currency; + return this; + } + + @Override + public String getPaymentTermDescription() { + return paymentTermDescription; + } + + public ZUGFeRD2PushProvider setPaymentTermDescription(String paymentTermDescription) { + this.paymentTermDescription = paymentTermDescription; + return this; + } + + @Override + public Date getIssueDate() { + return issueDate; + } + + public ZUGFeRD2PushProvider setIssueDate(Date issueDate) { + this.issueDate = issueDate; + return this; + } + + @Override + public Date getDueDate() { + return dueDate; + } + + public ZUGFeRD2PushProvider setDueDate(Date dueDate) { + this.dueDate = dueDate; + return this; + } + + @Override + public Date getDeliveryDate() { + return deliveryDate; + } + + public ZUGFeRD2PushProvider setDeliveryDate(Date deliveryDate) { + this.deliveryDate = deliveryDate; + return this; + } + + @Override + public BigDecimal getTotalPrepaidAmount() { + return totalPrepaidAmount; + } + + public ZUGFeRD2PushProvider setTotalPrepaidAmount(BigDecimal totalPrepaidAmount) { + this.totalPrepaidAmount = totalPrepaidAmount; + return this; + } + + @Override + public IZUGFeRDExportableContact getOwnContact() { + return ownContact; + } + + public ZUGFeRD2PushProvider setOwnContact(IZUGFeRDExportableContact ownContact) { + this.ownContact = ownContact; + return this; + } + + @Override + public IZUGFeRDExportableContact getRecipient() { + return recipient; + } + + public ZUGFeRD2PushProvider setRecipient(IZUGFeRDExportableContact recipient) { + this.recipient = recipient; + return this; + } + + @Override + public IZUGFeRDAllowanceCharge[] getZFAllowances() { + return ZFAllowances; + } + + public ZUGFeRD2PushProvider setZFAllowances(IZUGFeRDAllowanceCharge[] ZFAllowances) { + this.ZFAllowances = ZFAllowances; + return this; + } + + @Override + public IZUGFeRDAllowanceCharge[] getZFCharges() { + return ZFCharges; + } + + public ZUGFeRD2PushProvider setZFCharges(IZUGFeRDAllowanceCharge[] ZFCharges) { + this.ZFCharges = ZFCharges; + return this; + } + + @Override + public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() { + return ZFLogisticsServiceCharges; + } + + public ZUGFeRD2PushProvider setZFLogisticsServiceCharges(IZUGFeRDAllowanceCharge[] ZFLogisticsServiceCharges) { + this.ZFLogisticsServiceCharges = ZFLogisticsServiceCharges; + return this; + } + + public IZUGFeRDTradeSettlement[] getGetTradeSettlement() { + return getTradeSettlement; + } + + public ZUGFeRD2PushProvider setGetTradeSettlement(IZUGFeRDTradeSettlement[] getTradeSettlement) { + this.getTradeSettlement = getTradeSettlement; + return this; + } + + @Override + public IZUGFeRDPaymentTerms getPaymentTerms() { + return paymentTerms; + } + + public ZUGFeRD2PushProvider setPaymentTerms(IZUGFeRDPaymentTerms paymentTerms) { + this.paymentTerms = paymentTerms; + return this; + } + + @Override + public IZUGFeRDExportableContact getDeliveryAddress() { + return deliveryAddress; + } + + public ZUGFeRD2PushProvider setDeliveryAddress(IZUGFeRDExportableContact deliveryAddress) { + this.deliveryAddress = deliveryAddress; + return this; + } + + @Override + public IZUGFeRDExportableItem[] getZFItems() { + return ZFItems.toArray(new IZUGFeRDExportableItem[0]); + } + + public ZUGFeRD2PushProvider addItem(IZUGFeRDExportableItem item) { + ZFItems.add(item); + return this; + } + + + public boolean isValid() { + return (dueDate != null) && (ownZIP != null) && (ownStreet != null) && (ownLocation != null) && (ownCountry != null) && (ownTaxID != null) && (ownVATID != null) && (recipient != null); + //contact + // this.phone = phone; + // this.email = email; + // this.street = street; + // this.zip = zip; + // this.location = location; + // this.country = country; + } + +} diff --git a/libraryBasic/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java b/libraryBasic/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java new file mode 100644 index 00000000..eb7e0597 --- /dev/null +++ b/libraryBasic/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java @@ -0,0 +1,84 @@ + +/** ********************************************************************** + * + * 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 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; + +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import junit.framework.TestCase; +import junit.framework.Test; +import junit.framework.TestSuite; + + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ZF2PushTest extends TestCase { + final String TARGET_PDF = "./target/testout-ZF2Push.pdf"; + + public void testPushExport() { + + // the writing part + + String orgname="Test company"; + String number="123"; + String amountStr="1.00"; + BigDecimal amount=new BigDecimal(amountStr); + 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(new ZUGFeRD2PushProvider().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOwnOrganisationName(orgname).setOwnStreet("teststr").setOwnZIP("55232").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new Contact("Franz Müller", "0177123456", "fmueller@test.com", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number).addItem(new Item(new Product("Testprodukt","","C62",new BigDecimal(0)),amount,new BigDecimal(1.0)))); + String theXML = new String(ze.getProvider().getXML()); + assertTrue(theXML.contains("