From c0c9ad1405a6aa0a62e51f5c159fd27ec424fbb5 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Thu, 5 Jun 2025 14:04:37 +0200 Subject: [PATCH] changes for new feature --- .../main/java/org/mustangproject/Product.java | 40 +++++++++++++++++++ .../ZUGFeRD/IZUGFeRDExportableItem.java | 25 +++++++++++- .../ZUGFeRD/IZUGFeRDExportableProduct.java | 19 +++++++++ .../mustangproject/ZUGFeRD/ZF2PushTest.java | 2 +- 4 files changed, 83 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/org/mustangproject/Product.java b/library/src/main/java/org/mustangproject/Product.java index 4f0397ee..93e48a79 100644 --- a/library/src/main/java/org/mustangproject/Product.java +++ b/library/src/main/java/org/mustangproject/Product.java @@ -32,6 +32,8 @@ public class Product implements IZUGFeRDExportableProduct { protected boolean isIntraCommunitySupply = false; protected SchemedID globalId = null; protected String countryOfOrigin = null; + protected ArrayList charges=new ArrayList<>(); + protected ArrayList allowances=new ArrayList<>(); protected HashMap attributes = new HashMap<>(); protected List classifications = new ArrayList<>(); @@ -393,4 +395,42 @@ public class Product implements IZUGFeRDExportableProduct { this.classifications.add(classification); return this; } + + public Product addCharge(Charge e) { + charges.add(e); + return this; + } + + public Product addAllowance(Allowance a) { + allowances.add(a); + return this; + } + + /*** + * returns the AppliedTradeAllowanceCharges of this product which are actually Charges + * @return array of or null, if none + */ + @Override + public Charge[] getCharges() { + if (charges.size()==0) { + return null; + } + Charge[] chargeArr = new Charge[charges.size()]; + return charges.toArray(chargeArr); + } + + @Override + /*** + * returns the AppliedTradeAllowanceCharges of this product which are actually Allowances + * @return array of or null, if none + */ + public Allowance[] getAllowances() { + if (allowances.size()==0) { + return null; + } + Allowance[] allowanceArr = new Allowance[allowances.size()]; + return allowances.toArray(allowanceArr); + } + + } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java index 6d68cdff..1dee20c2 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java @@ -43,7 +43,11 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{ * item level discounts * @return array of the discounts on a single item */ + @Deprecated default IZUGFeRDAllowanceCharge[] getItemAllowances() { + if (getProduct()!=null) { + return getProduct().getAllowances(); + } return null; } @@ -51,10 +55,27 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{ * item level price additions * @return array of the additional charges on the item */ + @Deprecated default IZUGFeRDAllowanceCharge[] getItemCharges() { + if (getProduct()!=null) { + return getProduct().getCharges(); + } return null; } + @Deprecated + default IZUGFeRDAllowanceCharge[] getAllowances() { + return null; + } + + /** + * item level price additions + * @return array of the additional charges on the item + */ + @Deprecated + default IZUGFeRDAllowanceCharge[] getCharges() { + return null; + } /*** * BT 132 (issue https://github.com/ZUGFeRD/mustangproject/issues/247) @@ -147,9 +168,9 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{ } /*** - * specify allowances amount for the line item total + * get all (allowances and charges) SpecifiedTradeAllowanceCharges * - * @return the sum of allowances for this item + * @return the real item lecel SpecifiedTradeAllowanceCharges */ default IZUGFeRDAllowanceCharge[] getItemTotalAllowances() { return null; diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableProduct.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableProduct.java index ae9eb5b8..6ee5f22e 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableProduct.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableProduct.java @@ -166,6 +166,25 @@ public interface IZUGFeRDExportableProduct { return null; } + + /** + * product level discounts (AppliedTradeAllowanceCharge, will change net price) + * @return array of the discounts on a single product + */ + default IZUGFeRDAllowanceCharge[] getAllowances() { + return null; + } + + /** + * product level charges (AppliedTradeAllowanceCharge, will change net price) + * @return array of the additional charges on the product + */ + default IZUGFeRDAllowanceCharge[] getCharges() { + return null; + } + + + /** * Detailed information about the product * diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java index 16a815bb..a9d13a02 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java @@ -628,7 +628,7 @@ public class ZF2PushTest extends TestCase { .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815")) .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")) .setNumber(number) - .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), new BigDecimal(500.0), qty).addAllowance(new Allowance(new BigDecimal(300)).setTaxPercent(new BigDecimal(19)))) + .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)).addAllowance(new Allowance(BigDecimal.ONE)), new BigDecimal(500.0), qty).addAllowance(new Allowance(new BigDecimal(300)).setTaxPercent(new BigDecimal(19)))) .addAllowance(new Allowance(new BigDecimal(600)).setTaxPercent(new BigDecimal(19))) ); String theXML = new String(ze.getProvider().getXML());