ZUGFeRD / mustangproject

Open Source Java e-Invoicing library, validator and tool (Factur-X/ZUGFeRD, UNCEFACT/CII XRechnung)
http://www.mustangproject.org
Apache License 2.0
201 stars 113 forks source link

How to add a discount? #365

Closed razilein closed 5 months ago

razilein commented 6 months ago

Hello,

I'm using ZUGFeRD2PullProvider with the profile XRechnung.

  1. How can I add an itemdiscount?

I have an item with quantity 10, 19% Vat, Gross-Price: 10 EUR and 2 EUR discount. The gross line amount should be 98 EUR (10x10 - 2)

  1. How can I add an discount for the whole invoice?

a) I have an invoice with multiple items with an sum gross amount of 100 EUR and a discount of 20 EUR (80 EUR to pay) b) I have an invoice with multiple items and a percental discount of 10%

jstaerk commented 6 months ago

I will respond more sophisticated in the course of the week and apologies for not documenting it properly in the first place but as a inspiration you might already have a look at the addCharge and addAllowance parts of https://github.com/ZUGFeRD/mustangproject/blob/master/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java: they should work on item and document level. With relative as well as absolute charges/allowances. Please compare the total gross amount with what you expect, everybody should calculate EN16931-compliant but the software should really rather throw an error than generate a invoice whose visual representation does not match the machine readable data.

razilein commented 6 months ago

Thanks I tried that successfully.

It's a bit difficult because I have the gross discount. So I have to calculate the net discount from this. That leads to rounding problems.

Also I have a discount sum for the whole item (for example: quantity 10 and discount 2 EUR). But the API needs the discount for a single item. Maybe this could leed to rounding problems, too, if i divide the net discount with the quantity.

But I think you can't help with this problem. That's how the XML is built.

jstaerk commented 5 months ago

turns out it is already documented where I just wanted to put it (https://www.mustangproject.org/invoice-class/#charges)