invoiceninja / invoiceninja

Invoices, Expenses and Tasks built with Laravel, Flutter and React

Home Page:https://invoiceninja.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

xInvoice ApplicableTradeTax wrong when using discount on article

support-tt opened this issue · comments

Setup

  • Version: v5.8.55
  • Environment: Docker

Interface

  • Flutter: []
  • React: []
  • Both: []

Checklist

no errors just a Bug

Describe the bug

XML Values are wrong. Here is an example:
image
image

In the XML I got:

      <ram:SpecifiedLineTradeSettlement>
        <ram:ApplicableTradeTax>
          <ram:TypeCode>VAT</ram:TypeCode>
          <ram:CategoryCode>S</ram:CategoryCode>
          <ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>
        </ram:ApplicableTradeTax>
        <ram:SpecifiedTradeSettlementLineMonetarySummation>
          <ram:LineTotalAmount>1113.69</ram:LineTotalAmount>
        </ram:SpecifiedTradeSettlementLineMonetarySummation>
      </ram:SpecifiedLineTradeSettlement>

The tax is correct but the LineTotalAmount is 1113.69 I dont know where this number is coming from.
Then

      <ram:ApplicableTradeTax>
        <ram:CalculatedAmount>211.60</ram:CalculatedAmount>
        <ram:TypeCode>VAT</ram:TypeCode>
        <ram:BasisAmount>1113.69</ram:BasisAmount>
        <ram:CategoryCode>S</ram:CategoryCode>
        <ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>
      </ram:ApplicableTradeTax>

Also here the 1113.69 is wrong and because of that the tax here is 211.66 instead of the 222.74 from the PDF invoice.
The last Part

      <ram:SpecifiedTradeSettlementHeaderMonetarySummation>
        <ram:LineTotalAmount>1172.30</ram:LineTotalAmount>
        <ram:ChargeTotalAmount>0.00</ram:ChargeTotalAmount>
        <ram:AllowanceTotalAmount>0.00</ram:AllowanceTotalAmount>
        <ram:TaxBasisTotalAmount>1172.30</ram:TaxBasisTotalAmount>
        <ram:TaxTotalAmount currencyID="EUR">222.74</ram:TaxTotalAmount>
        <ram:RoundingAmount>0.00</ram:RoundingAmount>
        <ram:GrandTotalAmount>1395.04</ram:GrandTotalAmount>
        <ram:TotalPrepaidAmount>1395.04</ram:TotalPrepaidAmount>
        <ram:DuePayableAmount>0.00</ram:DuePayableAmount>
      </ram:SpecifiedTradeSettlementHeaderMonetarySummation>

Here is everything correct.

Steps To Reproduce

1.Under Settings --> Product Settings --> enable Productdiscount
2. Create a Inovice with an productdiscount
3. Send Invoice with a line discount with XML (xInvoice 3.0 in my test)

Expected Behavior

The discount must be used in the calculation for the XML. Otherwise the taxes and line values are wrong.

@LarsK1 are we factoring in discounts with the calculations?

@turbo124 yes we we're, but in x invoice 3.0 the schema changed. The fix is already available in #9523

@support-tt please check, once the next release is ready.

@LarsK1 I will do that thanks

@LarsK1
Hello I tested this today sorry for the delay I was ill and then had some stress. The fields are now correct but there is a new issue.
The field:
Version v5.8.55
GrossPriceProductTradePrice was correct in version 5.8.55

        <ram:GrossPriceProductTradePrice>
          <ram:ChargeAmount>1000.00</ram:ChargeAmount>
									
        </ram:GrossPriceProductTradePrice>

In the new Version v5.10 (with 5% discount):

        <ram:GrossPriceProductTradePrice>
          <ram:ChargeAmount>1005.00</ram:ChargeAmount>
          <ram:AppliedTradeAllowanceCharge>
            <ram:ChargeIndicator>
              <udt:Indicator>false</udt:Indicator>
            </ram:ChargeIndicator>
            <ram:ActualAmount>100.0</ram:ActualAmount>
          </ram:AppliedTradeAllowanceCharge>
        </ram:GrossPriceProductTradePrice>

we tested this the ChargeAmount actuelly adds +5€ to the invoice. So our invoice is 1000 and the field is 1005 (instead of 5% discount the price here is higher then the whole invoice without tax).

Hi @support-tt ,
can you please send me an example invoice, so that I can clearly test your case.

Rechnung_R0031.pdf
Rechnung_R0032.pdf

Attached are 2 PDF with embedded XML (xinvoice 2.2). Unfornetetely I cant upload XML here. In both example we got 5€ and 20 € discount (with percentage discount its the same so when you got 5% discount the XML adds 5€ to ChargeAmount ) and this discound got added to the ChargeAmount in GrossPriceProductTradePrice

Thanks @LarsK1

edit: here is an example with percent discount.
Rechnung_R0031_Percent.pdf

Hi @support-tt,
I took the same data as you provided in your examples. And generated the both attached xinvoice files. There the calculcation is absolutly correct. You can also validate any invoice (using XInvoice 3.0.1) here: https://e-rechnung.bayern.de/app/#/upload
My demo files:
Invoice_PtPWT.zip

Can you please try to set your profile to the latest XInvoice, then regenerate these files and then recheck? (It migth be an issue with older profiles)

Hello @LarsK1 ,

we switched to XInvoice 2.2 because we need the XML embedded in the PDF (german goverment needs).
So I tested with 2.2. Can I change the minor version like 2.2.1 ?

Hi @support-tt ,
ZUGFeRD ist auch in Version 3.0.1 unterstützt. Alle andern Versionen sind eh rechtlich gesehen nicht (mehr) gültig. Die anderen Versionen werden auch bald entsprechend entfernt...

Hi @LarsK1

wie wähle ich denn Version 3.0.1 aus ?
image

Wenn ich 3.0 auswähle bekomme ich in der Mail das XML und PDF einzeln. Leider wurde uns gesagt, dass wir nur 1 Anhang schicken dürfen und dieser muss PDF mit XML embedded sein oder nur XML.
Da wir Kunden haben die natürlich das PDF haben wollen war 2.2 mit PDF embedded die ideale Lösung.

Habe ich hier etwas übersehen ?
Also mit dem Haken Merge E-Invoice bekomme ich das PDF mit XML aber auch das XML nochmal einzeln. Das wird leider von unseren Staatskunden abgelehnt da nur 1 anhang zugelassen ist -,-

Wir haben aber gerade mit der Invoice 3.0 Version nochmal geprüft und der Wert "ChargeAmount in GrossPriceProductTradePrice" ist bei uns leider immer noch Falsch in der neuesten Version. Wir benutzen die Stock Docker Version ohne Anpassungen. Er Addiert hier den Rabat als Wert auf.
Hier ein Beispiel mit Invoice 3.0
Rechnung_R0032.pdf

Die Rechnung ist 1710 mit 10 % Rabat im XML steht
<ram:GrossPriceProductTradePrice> <ram:ChargeAmount>1720.00</ram:ChargeAmount>
Zusatz:
Hattest du mal mit prozentualen Rabatten getestet ?

Ah, jetzt verstehe ich wo der Fehler liegt. Die Option für nur PDF ohne XML ist heute in's Repo gemergt worden. Sollte also im nächsten Release verfügbar sein. Das andere schaue ich mir bald an.

@support-tt ,
bitte probiere mal diese Änderung in: app/Services/EDocument/Standards/ZugferdEDokument.php in Zeile 147:
von:

$this->xdocument->addNewPosition($index)
                ->setDocumentPositionGrossPrice($item->gross_line_total + $item->discount)
                ->setDocumentPositionNetPrice($item->line_total);

auf

$this->xdocument->addNewPosition($index)
                ->setDocumentPositionGrossPrice($item->gross_line_total)
                ->setDocumentPositionNetPrice($item->line_total);

Danach die Datei speichern und die E-Rechnung erneut herunterladen.

Let me know, how it goes.

@LarsK1
Mit dieser Änderung ist die Rechnung mit Invoice3.0 richtig.
Mit der Änderung das nur das PDF geschickt wird ist es dann perfekt :)

Alles klar. Danke für das Feedback. Die Änderungen sind im PR #9777, sobald der Release dazu da ist, sollte dieser Fehler auch weg sein.....

Dann schließe ich dieses Problem mal da alle Probleme bereits in Merges bearbeitet werden.
Vielen Dank @LarsK1