josemmo / einvoicing

Library for reading and creating European-compliant electronic invoices (EN 16931)
https://josemmo.github.io/einvoicing/
MIT License
110 stars 29 forks source link

Bug on Allowance and Invoice Totals #58

Open liviubirleanu opened 2 months ago

liviubirleanu commented 2 months ago

Hello,

If we have 2 allowances for the same invoice line, one with positive amount and the other with negative amount, invoices totals are buggy, as total calculations does not take into account both.

Valid XML attached however totals shown by the library are completely wrong 3514844377.zip

netAmount 2642.16 correct 3265.20 vatAmount 502.01 correct 620.39 taxInclusiveAmount 3144.17 correct 3885.59

What is worth to be mentioned, is that original invoice is not issued with same library, but with other commercial software www.oblio.eu

However, its a valid invoice confirmed by our local authorities and I want to correctly read & import it in our systems.

Looking forward to your feedback here

Best Liviu

josemmo commented 1 month ago

Hello @liviubirleanu,

The invoice you sent doesn't seem to have the right amounts. Take invoice line 1:

<cac:InvoiceLine>
    <cbc:ID>1</cbc:ID>
    <cbc:InvoicedQuantity unitCode="H87">177</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount currencyID="RON">3115.2</cbc:LineExtensionAmount>
    <cac:AllowanceCharge>
        <cbc:ChargeIndicator>false</cbc:ChargeIndicator>
        <cbc:AllowanceChargeReason>Discount produse</cbc:AllowanceChargeReason>
        <cbc:MultiplierFactorNumeric>20</cbc:MultiplierFactorNumeric>
        <cbc:Amount currencyID="RON">778.8</cbc:Amount>
    </cac:AllowanceCharge>
    <!-- [...] -->
</cac:InvoiceLine>

It has a charge of 20%, which the library calculates to be 3115.2 × 0.2 = 623.04. However, the value from <cbc:Amount /> is 778.8, which is not correct.