-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Having two items with different VATs and adding a charge/allowance will generate an invalid or wrong XML #640
Comments
I looked into the code and I think the problem is related to the fact, that the In the method
First confusing part is, that the charges needs to have set the taxPercent. where as all VATs can be get from the keys of the Second, if percent are set inside the
This code is problematic, because Setting the totalAmount to the calculated charge will work as expected. In case it is a bug, I can create a PR. |
Hi, |
Hi, |
puts a charge of 10€ while I believe
adds a 10% charge, each on 19% VAT items. Maybe you were missing the setTaxPercent part? |
That's the way I am doing it:
this is working as long as all items have the same VAT. Having items with different VATs fail. I'll check it again and try to set up a test case in case I don't find an issue in my code. |
This bug gets more and more interesting! I'll created two invoices. Both have 2 items:
and a charge of 10 %. Inside the first invoice both items have a VAT of 19 % and in opposite to the first one, the second invoice has a second item with a VAT of 7 %; I attached both invoices as JSON: the only difference is the VAT of the second item. These JSONs can be used as an input for a test case. Let's say, that The invoice 01 looks like that: Everything is fine and valid. The correct version of Invoice 02 looks like that: The Grand total of the invoice is 142.67 €, which is right. This is a pdf, where the generated XML of invoice 02 is used for creating a PDF for visualization: RechnungV2Issue640-fail-pdf-generated-from-xml.pdf This one has a grand total of 154.56 €, which is wrong (it should be 142.67 €) due to a bug in the charge and VAT calculation, I think. Funny thing is, that all XMLs & PDfs are valid! |
v2.16.0 does not fix it. |
Thanks, I'll have a look tonight |
Unfortunately I cant reproduce the XML from your JSON (wrong date format, and then other problems), and the source code is not complete but when I try it myself with the following java
the following XML is produced
which has the correct 142,67 and is valid: what precisely was/is the issue? |
Yeah, the class model of the invoice class can't be used with Gson. In your code example you are adding the charge on item level. To reproduce the issue, add a charge on document level. Something like that:
BTW, in both examples I have to set the tax percent. Which seams to be is not necessary, bc on line charges (allowance) the VAT from the item can be used and on document level, the projects needs to create the sums for each items with the same VATs, to calculate the netto sum, to add the charge (allowance) to it and to calculate the VAT correctly. In both cases, the project knows the VAT. Or, do I miss something? |
Please use this class to reproduce the issue (I had to add a reason to generate a valid XML):
which will generate the following XML:
which delivers the incorrect 154,56. The generated xml is validated successfully. The visualized XML: invoice-123.pdf The validation report (as txt): validation-report-xml.txt |
@jstaerk Did you test the code with charges of document level to recreate the error?? |
It looks like that there is an issue when having an invoice with two items and different VAT. Adding a charge/allowance will generate an invalid XML or has a wrong calculation. A n invoice where all items have the same VAT works as expected.
Generate an invoice with the following two items:
item 1: quantity: 10, price: 10, VAT 19 %
item 2: quantity: 1, price: 10, VAT: 19 %
invoice with two items and same VAT without a charge/allowance -> works (XML is valid)
invoice with two items and same VAT with a charge/allowance -> works (XML is valid)
invoice with two items (one item 19% VAT, second 7 % VAT) without a charge/allowance -> works (XML is valid)
invoice with two items (one item 19% VAT, second 7 % VAT) with a charge/allowance -> works (XML is invalid or calculation is wrong depending on the input)
In the first case the XML for the charges look like this:
The XML is invalid due to the fact that the tax percents are missing/is by default BigDEcimal.ZERO.
In the second case adding two charges (one for VAT 19% and a second one for 7 %) generates the following XML:
Now, the XML is valid, but the totalamount is now the amount of all items and not the sum of items with VAT 19 % or VAT 7%.
Expected behavior
Setting up a charge using
should result in the following XML:
macOS, Java 17 & version 2.15.2
The text was updated successfully, but these errors were encountered: