From 124386336865a083ca8720f8c8811e9fbb6af682 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Wed, 4 Nov 2020 20:51:22 +0100 Subject: [PATCH] support included notes --- History.md | 2 ++ .../main/java/org/mustangproject/Invoice.java | 22 +++++++++++++ .../main/java/org/mustangproject/Item.java | 22 +++++++++++++ .../ZUGFeRD/IExportableTransaction.java | 27 +++++++++++++++ .../ZUGFeRD/IZUGFeRDExportableItem.java | 22 ++++++++++++- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 21 +++++++++--- .../mustangproject/ZUGFeRD/ZF2PushTest.java | 33 +++++++++++++++++++ 7 files changed, 144 insertions(+), 5 deletions(-) diff --git a/History.md b/History.md index 8571a94b..6d1d624e 100644 --- a/History.md +++ b/History.md @@ -38,6 +38,8 @@ switch - new tradeparty class, Contact getOwnContact superseded by TradeParty getSender - new invoicecorrection class - order-x xml read support +- support included notes on document and item level +- occurence periods setOccurrencePeriod(Date start, Date end) - automated tests zuv/verapdf validate created library test files - trans.getTradeSettlementPayment() removed in favor of trans.getTradeSettlement() - commandline option for no notices diff --git a/library/src/main/java/org/mustangproject/Invoice.java b/library/src/main/java/org/mustangproject/Invoice.java index 2be259e8..78b8b856 100644 --- a/library/src/main/java/org/mustangproject/Invoice.java +++ b/library/src/main/java/org/mustangproject/Invoice.java @@ -27,6 +27,10 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; +/*** + * An invoice, with fluent setters + * @see IExportableTransaction if you want to implement an interface instead + */ public class Invoice implements IExportableTransaction { 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, ownForeignOrganisationID = null, ownOrganisationName = null, currency = null, paymentTermDescription = null; @@ -34,6 +38,7 @@ public class Invoice implements IExportableTransaction { protected BigDecimal totalPrepaidAmount = null; protected TradeParty sender=null, recipient = null, deliveryAddress = null; protected ArrayList ZFItems = null; + protected ArrayList notes = null; protected String contractReferencedDocument = null; protected Date occurrenceDateFrom = null; @@ -266,6 +271,14 @@ public class Invoice implements IExportableTransaction { } + @Override + public String[] getNotes() { + if (notes==null) { + return null; + } + return notes.toArray(new String[0]); + } + @Override public String getCurrency() { return currency; @@ -492,4 +505,13 @@ public class Invoice implements IExportableTransaction { } } + + public Invoice addNote(String text) { + if (notes==null) { + notes=new ArrayList(); + } + notes.add(text); + return this; + } + } diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index e14c8d78..90f7bec9 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -10,6 +10,7 @@ public class Item implements IZUGFeRDExportableItem { protected BigDecimal price, quantity, tax, grossPrice, lineTotalAmount; protected String id; protected Product product; + protected ArrayList notes = null; protected ArrayList Allowances = new ArrayList(), Charges = new ArrayList(); @@ -98,6 +99,16 @@ public class Item implements IZUGFeRDExportableItem { return Charges.toArray(new IZUGFeRDAllowanceCharge[0]); } + + + @Override + public String[] getNotes() { + if (notes==null) { + return null; + } + return notes.toArray(new String[0]); + } + public Item setProduct(Product product) { this.product = product; return this; @@ -108,8 +119,19 @@ public class Item implements IZUGFeRDExportableItem { Charges.add(izac); return this; } + public Item addAllowance(IZUGFeRDAllowanceCharge izac) { Allowances.add(izac); return this; } + + public Item addNote(String text) { + if (notes==null) { + notes=new ArrayList(); + } + notes.add(text); + return this; + } + + } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java index 16ad9eb7..60a1e6c5 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java @@ -33,6 +33,11 @@ import java.util.Date; import org.mustangproject.FileAttachment; import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; +/*** + * the interface of an transaction, e.g. an invoice, you want to create xml (potentially to be added to a PDF) + * for + * @see Invoice if you want to use an object rather than an interface + */ public interface IExportableTransaction { /** @@ -426,13 +431,26 @@ public interface IExportableTransaction { return null; } + /*** + * specify delivery date + * @return the delivery date + */ default Date getOccurrenceDate() { return null; } + /*** + * specify delivery period + * @return the beginning of the delivery period + */ default Date getOccurrencePeriodFrom() { return null; } + + /*** + * specify delivery period + * @return the end of the delivery period + */ default Date getOccurrencePeriodTo() { return null; } @@ -446,4 +464,13 @@ public interface IExportableTransaction { default FileAttachment[] getAdditionalReferencedDocuments() { return null; } + + + /*** + * additional text description + * @return an array of strings of document wide "includedNotes" (descriptive text values) + */ + default String[] getNotes() { + return null; + } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java index 9f7cbcf7..0522b2c7 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java @@ -34,8 +34,16 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{ IZUGFeRDExportableProduct getProduct(); + /** + * item level discounts + * @return array of the discounts on a single item + */ IZUGFeRDAllowanceCharge[] getItemAllowances(); + /** + * item level price additions + * @return array of the additional charges on the item + */ IZUGFeRDAllowanceCharge[] getItemCharges(); @@ -69,9 +77,21 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{ default String getCategoryCode() { return TaxCategoryCodeTypeConstants.STANDARDRATE; } - + + /*** + * the ID of an additionally referenced document for this item + * @return the id as string + */ default String getAdditionalReferencedDocumentID() { return null; } + /*** + * descriptive texts + * @return an array of strings of item specific "includedNotes", text values + */ + default String[] getNotes() { + return null; + } + } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 9dc9b68d..f72964d1 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -236,6 +236,13 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { if (trans.getDocumentCode() != null) { typecode = trans.getDocumentCode(); } + String notes=""; + if (trans.getNotes()!=null) { + for (String currentNote:trans.getNotes()) { + notes=notes+"" + XMLTools.encodeXML(currentNote) + ""; + + } + } String xml = "\n" + "" + typecode + "\n" + " " + zugferdDateFormat.format(trans.getIssueDate()) + "\n" // date - // format - // was - // 20130605 + + notes + subjectNote + rebateAgreement + senderReg @@ -275,13 +280,21 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { if (currentItem.getProduct().getTaxExemptionReason() != null) { exemptionReason = "" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + ""; } + notes=""; + if (currentItem.getNotes()!=null) { + for (String currentNote:currentItem.getNotes()) { + notes=notes+"" + XMLTools.encodeXML(currentNote) + ""; + } + } LineCalculator lc = new LineCalculator(currentItem); xml = xml + " \n" + " \n" + " " + lineID + "\n" //$NON-NLS-2$ + + notes + " \n" - + " \n"; + + + " \n"; // + " 4012345001235\n" if (currentItem.getProduct().getSellerAssignedID() != null) { xml = xml + " " diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java index 7b9e0f22..5062f4ff 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java @@ -44,6 +44,7 @@ public class ZF2PushTest extends TestCase { final String TARGET_CHARGESALLOWANCESPDF = "./target/testout-ZF2PushChargesAllowances.pdf"; final String TARGET_RELATIVECHARGESALLOWANCESPDF = "./target/testout-ZF2PushRelativeChargesAllowances.pdf"; final String TARGET_ATTACHMENTSPDF = "./target/testout-ZF2PushAttachments.pdf"; + final String TARGET_PUSHEDGE = "./target/testout-ZF2PushEdge.pdf"; public void testPushExport() { @@ -241,6 +242,38 @@ public class ZF2PushTest extends TestCase { } + public void testPushEdge() { + + String orgname = "Test company"; + String number = "123"; + String priceStr = "1.00"; + String taxID = "9990815"; + BigDecimal price = new BigDecimal(priceStr); + try (InputStream SOURCE_PDF = this.getClass() + .getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf"); + + ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1().setProducer("My Application") + .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors() + .load(SOURCE_PDF)) { + + ze.setTransaction(new Invoice().addNote("document level 1/2").addNote("document level 2/2").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID)).setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)).addNote("item level 1/1")) + + ); + String theXML = new String(ze.getProvider().getXML()); + assertTrue(theXML.contains("