diff --git a/library/src/main/java/org/mustangproject/Charge.java b/library/src/main/java/org/mustangproject/Charge.java index 86cf1638..c87d349a 100644 --- a/library/src/main/java/org/mustangproject/Charge.java +++ b/library/src/main/java/org/mustangproject/Charge.java @@ -1,7 +1,6 @@ package org.mustangproject; import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge; -import org.mustangproject.ZUGFeRD.IZUGFeRDExportableProduct; import java.math.BigDecimal; @@ -40,13 +39,14 @@ public class Charge implements IZUGFeRDAllowanceCharge { return this; } - public Charge setReason(String reason) { - this.reason = reason; - return this; + + @Override + public String getReason() { + return reason; } - public Charge setCategoryCode(String categoryCode) { - this.categoryCode = categoryCode; + public Charge setReason(String reason) { + this.reason = reason; return this; } @@ -56,19 +56,15 @@ public class Charge implements IZUGFeRDAllowanceCharge { return totalAmount; } - @Override - public String getReason() { - return reason; - } @Override public BigDecimal getTaxPercent() { return taxPercent; } - @Override - public String getCategoryCode() { - return categoryCode; - } + public Charge setCategoryCode(String categoryCode) { + this.categoryCode = categoryCode; + return this; + } } diff --git a/library/src/main/java/org/mustangproject/Invoice.java b/library/src/main/java/org/mustangproject/Invoice.java index 59dfd184..22edf6b0 100644 --- a/library/src/main/java/org/mustangproject/Invoice.java +++ b/library/src/main/java/org/mustangproject/Invoice.java @@ -33,8 +33,10 @@ public class Invoice implements IExportableTransaction { protected BigDecimal totalPrepaidAmount = null; protected IZUGFeRDExportableContact ownContact = null, recipient = null, deliveryAddress = null; protected ArrayList ZFItems = null; + protected String contractReferencedDocument = null; - protected IZUGFeRDAllowanceCharge[] ZFAllowances = null, ZFCharges = null, ZFLogisticsServiceCharges = null; + protected ArrayList Allowances = new ArrayList(), + Charges = new ArrayList(), LogisticsServiceCharges = new ArrayList(); protected IZUGFeRDTradeSettlement[] getTradeSettlement = null; protected IZUGFeRDPaymentTerms paymentTerms = null; @@ -49,6 +51,8 @@ public class Invoice implements IExportableTransaction { return documentName; } + public String getContractReferencedDocument() { return contractReferencedDocument; } + public Invoice setDocumentName(String documentName) { this.documentName = documentName; return this; @@ -334,33 +338,30 @@ public class Invoice implements IExportableTransaction { @Override public IZUGFeRDAllowanceCharge[] getZFAllowances() { - return ZFAllowances; + if (Allowances.isEmpty()) { + return null; + } else + return Allowances.toArray(new IZUGFeRDAllowanceCharge[0]); } - public Invoice setZFAllowances(IZUGFeRDAllowanceCharge[] ZFAllowances) { - this.ZFAllowances = ZFAllowances; - return this; - } @Override public IZUGFeRDAllowanceCharge[] getZFCharges() { - return ZFCharges; + if (Charges.isEmpty()) { + return null; + } else + return Charges.toArray(new IZUGFeRDAllowanceCharge[0]); } - public Invoice setZFCharges(IZUGFeRDAllowanceCharge[] ZFCharges) { - this.ZFCharges = ZFCharges; - return this; - } @Override public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() { - return ZFLogisticsServiceCharges; + if (LogisticsServiceCharges.isEmpty()) { + return null; + } else + return LogisticsServiceCharges.toArray(new IZUGFeRDAllowanceCharge[0]); } - public Invoice setZFLogisticsServiceCharges(IZUGFeRDAllowanceCharge[] ZFLogisticsServiceCharges) { - this.ZFLogisticsServiceCharges = ZFLogisticsServiceCharges; - return this; - } public IZUGFeRDTradeSettlement[] getGetTradeSettlement() { return getTradeSettlement; @@ -403,16 +404,6 @@ public class Invoice implements IExportableTransaction { - public Invoice addCharge(IZUGFeRDAllowanceCharge charge) { - //@todo - return this; - } - - public Invoice addAllowance(IZUGFeRDAllowanceCharge allowance) { - //@todo - return this; - } - /*** * checks if all required items are set in order to be able to export it @@ -429,4 +420,17 @@ public class Invoice implements IExportableTransaction { // this.country = country; } + public Invoice addCharge(IZUGFeRDAllowanceCharge izac) { + Charges.add(izac); + return this; + } + public Invoice addAllowance(IZUGFeRDAllowanceCharge izac) { + Allowances.add(izac); + return this; + } + + public Invoice setContractReferencedDocument(String s) { + contractReferencedDocument=s; + return this; + } } diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index 0cbafa05..e14c8d78 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -4,11 +4,14 @@ import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge; import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem; import java.math.BigDecimal; +import java.util.ArrayList; public class Item implements IZUGFeRDExportableItem { protected BigDecimal price, quantity, tax, grossPrice, lineTotalAmount; protected String id; protected Product product; + protected ArrayList Allowances = new ArrayList(), + Charges = new ArrayList(); public Item(Product product, BigDecimal price, BigDecimal quantity) { this.price = price; @@ -25,16 +28,6 @@ public class Item implements IZUGFeRDExportableItem { return this; } - public Item addCharge(IZUGFeRDAllowanceCharge charge) { - //@todo - return this; - } - - public Item addAllowance(IZUGFeRDAllowanceCharge allowance) { - //@todo - return this; - } - public BigDecimal getGrossPrice() { return grossPrice; } @@ -91,16 +84,32 @@ public class Item implements IZUGFeRDExportableItem { @Override public IZUGFeRDAllowanceCharge[] getItemAllowances() { - return null; + if (Allowances.isEmpty()) { + return null; + } else + return Allowances.toArray(new IZUGFeRDAllowanceCharge[0]); } @Override public IZUGFeRDAllowanceCharge[] getItemCharges() { - return null; + if (Charges.isEmpty()) { + return null; + } else + return Charges.toArray(new IZUGFeRDAllowanceCharge[0]); } public Item setProduct(Product product) { this.product = product; return this; } + + + public Item addCharge(IZUGFeRDAllowanceCharge izac) { + Charges.add(izac); + return this; + } + public Item addAllowance(IZUGFeRDAllowanceCharge izac) { + Allowances.add(izac); + 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 e4c89071..37b3970e 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java @@ -95,6 +95,10 @@ public interface IExportableTransaction { return null; } + default String getContractReferencedDocument() { + return null; + } + /** * who processed the order diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java index bb48a4db..82bb2382 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java @@ -208,6 +208,9 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte ensurePDFisUpgraded = false; } + public void attachFile(String filename, byte[] data, String mimetype, String relation) { + //throw new RuntimeException("Not implemented"); + } /*** * Perform the final export to a now ZUGFeRD-enriched PDF file diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java index 39f5e2c4..1163bb3e 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java @@ -51,7 +51,7 @@ public class ZF2PushTest extends TestCase { .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors() .load(SOURCE_PDF)) { - ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOwnOrganisationName(orgname).setOwnStreet("teststr").setOwnZIP("55232").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("DE19990815").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)))); + ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setContractReferencedDocument("0815").setOwnOrganisationName(orgname).setOwnStreet("teststr").setOwnZIP("55232").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("DE19990815").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("