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
228 stars 124 forks source link

Add Rouning Amount to invoice #480

Closed andyx1975 closed 1 month ago

andyx1975 commented 1 month ago

Hey,

I am currently try to find a way to add a rounding amount to an invoice. Can someone supply a working java example?

I did not found a working method.

Thanks Andy

jstaerk commented 1 month ago

What do you need it for? I have the impression some people try to abuse it to conceil a flawed calculation. I'm not aware where you would need it unless you live in a country like the netherlands where you need to round to the next 5ct.

andyx1975 commented 1 month ago

I am living in Germany... and some softwares are calculating the taxes line by line. The Mustang project is adding the net values and calculates the taxes from the net sum. For Zugferd it often happens that the total amount in the XML is different by 1 cent. Both calculations are valid in Germany. Companies like the German Post or Microsoft are also calculating their bills line by line. This will get a major issue because both calculation variants are accepted by the German tax office. As said not every invoicing software is calculating the same way like Mustangproject.

Can you explain how to add the rounding amount? Or better showing us java code? Thanks!

jstaerk commented 1 month ago

To be honest I dont care too much what "some softwares" do, as far as I know the only correct procedure is add, then apply, which is also the only way allowed and defined defined in EN16931, please have a look at it's example 1. You can get it for free in german at https://www.beuth.de/en/standard/din-en-16931-1/314992770

winnyschuster commented 1 month ago

the only correct procedure... i also did find information about two valid procedures, one called vertical method the other horizontal method, both equally accepted by german authorities(BmF) though differing in their results.

though trusting you more than what i 've found in the net, i'm wondering if that is an answer for the thousends of KMU's that rely on their software since many years. I read your answer as 'sorry, your software is wrong, get a new one' but i hope i'm wrong with that...

andyx1975 commented 1 month ago

Rounding amounts or differences are a standard issues here in Germany. They are accepted by every tax office... this means there is currently no standard way to calculate the amounts. XInvoices are mandatory in Germany very soon. So this issue will come up every couple of weeks very soon. You can ask a tax consultant... they will confirm this issue too and that they are allowed. It's a mandatory feature for some people and I dont uderstand why people from the netherlands are allowed to add rounding amounts and germans not. We can not send Zugferd invoices where the payable gross amount on the PDF and the XML are not the same amount.

So I hacked a solution which make it possible to use this libary without providing a complete own XML. So you can create a vailid XML with mustang and you can add the rounding amount with this small workaround.

private String addRoundingAmount( Invoice invoice, String xml, double grandTotalAmount )
    {
        TransactionCalculator tc = new TransactionCalculator( invoice );
        BigDecimal totalGross = tc.getGrandTotal().setScale( 2, RoundingMode.HALF_EVEN );
        BigDecimal saleTotalGross = new BigDecimal( grandTotalAmount ).setScale( 2, RoundingMode.HALF_EVEN );
        BigDecimal roundingAmount = saleTotalGross.subtract( totalGross ).setScale( 2, RoundingMode.HALF_EVEN );

       if ( roundingAmount.compareTo( BigDecimal.ZERO ) != 0 )
        {
            // Set payable amount
            String duePayableStringOld = "<ram:DuePayableAmount>" + tc.getGrandTotal() + "</ram:DuePayableAmount>";
            String duePayableStringNew = "<ram:DuePayableAmount>"
                + tc.getGrandTotal().add( roundingAmount ).setScale( 2, RoundingMode.HALF_EVEN )
                + "</ram:DuePayableAmount>";
            xml = xml.replace( duePayableStringOld, duePayableStringNew );

            // Add rounding amount
            String grandTotalString = "<ram:GrandTotalAmount>" + tc.getGrandTotal() + "</ram:GrandTotalAmount>\n";
            String roundingString = "\t\t<ram:RoundingAmount>" + roundingAmount + "</ram:RoundingAmount>\n";
            xml = xml.replace( grandTotalString, roundingString + grandTotalString );
        }

        return xml;
    }
jstaerk commented 1 month ago

the only correct procedure... i also did find information about two valid procedures, one called vertical method the other horizontal method, both equally accepted by german authorities(BmF) though differing in their results.

though trusting you more than what i 've found in the net, i'm wondering if that is an answer for the thousends of KMU's that rely on their software since many years. I read your answer as 'sorry, your software is wrong, get a new one' but i hope i'm wrong with that...

You read my answer right. It is an interesting question if EN16931 has been done exclusively or only primarily for B2G, and it is in the process of being updated, but I can only support EN16931 because if I don't stick to it in the writing part of the software the validating part will fail. Which is based on official schematrons. And I have the impression we will see much more validation in the future.

kind regads Jochen

jstaerk commented 1 month ago

Hello

Rounding amounts or differences are a standard issues here in Germany. They are accepted by every tax office...

I have mentioned my source, may you please be as kind as to mention yours?

this means there is currently no standard way to calculate the amounts.

there is, just read EN16931-1

XInvoices are mandatory in Germany very soon.

they are already since 2020 for B2G invoices

You can ask a tax consultant...

I wont why don't you?

It's a mandatory feature for some people

In this case please immediately escalate this and have a change request at the EN16931 folks

and I dont uderstand why people from the netherlands are allowed to add rounding amounts and germans not. Because the currency works different there. They also can't just add any mathematical error.

We can not send Zugferd invoices where the payable gross amount on the PDF and the XML are not the same amount. Which would be a very nice occasion to correct the PDF part :-)

kind regards Jochen