eInvoicing-EN16931 icon indicating copy to clipboard operation
eInvoicing-EN16931 copied to clipboard

[CII] VAT breakdown rounding problem, ex BR-Z-08

Open tavi-cacina opened this issue 2 years ago • 2 comments

For some inputs, the rule will wrongly be fired. Ex: VAT BasisAmount: 1046.40 round sum LineTotal : 47212.32 (1) round sum Allowance: 46165.92 (2) (1) - (2) = 1046.4000000000014

The rule should round the whole right side of the equation. So, this:

<param name="BR-Z-08" value="../ram:BasisAmount = (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement[ram:ApplicableTradeTax/ram:CategoryCode = 'Z']/ram:SpecifiedTradeSettlementLineMonetarySummation/xs:decimal(ram:LineTotalAmount))*10*10)div 100) + (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[(ram:ChargeIndicator/udt:Indicator cast as xs:boolean)=true() and ram:CategoryTradeTax/ram:CategoryCode='Z']/xs:decimal(ram:ActualAmount))*10*10)div 100) - (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[(ram:ChargeIndicator/udt:Indicator cast as xs:boolean)=false() and ram:CategoryTradeTax/ram:CategoryCode='Z']/xs:decimal(ram:ActualAmount))*10*10)div 100)"/>

should become:

<param name="BR-Z-08" value="../ram:BasisAmount = round(((round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement[ram:ApplicableTradeTax/ram:CategoryCode = 'Z']/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount)*10*10)div 100) + (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator='true' and ram:CategoryTradeTax/ram:CategoryCode='Z']/ram:ActualAmount)*10*10)div 100) - (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator='false' and ram:CategoryTradeTax/ram:CategoryCode='Z']/ram:ActualAmount)*10*10)div 100)) *10*10)div 100"/>

This may apply to other rules too, it is just that a client encountered it for this BR-Z-08

tavi-cacina avatar Aug 05 '22 10:08 tavi-cacina

Do you eventually have an example instance, in which this rules "misbehaves", so that we can analyze it?

phax avatar Aug 05 '22 11:08 phax

Yes, here you are: data.xml.txt

tavi-cacina avatar Aug 05 '22 12:08 tavi-cacina

There is a similiar rounding problem for this rule (BR-AE-08)

<xsl:when test="../ram:BasisAmount = (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement[ram:ApplicableTradeTax/ram:CategoryCode = 'AE']/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount)*10*10)div 100) + (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator=true() and ram:CategoryTradeTax/ram:CategoryCode='AE']/ram:ActualAmount)*10*10)div 100) - (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator=false() and ram:CategoryTradeTax/ram:CategoryCode='AE']/ram:ActualAmount)*10*10)div 100)" />

Which should be

<xsl:when test="../ram:BasisAmount = (round(xs:decimal(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement[ram:ApplicableTradeTax/ram:CategoryCode = 'AE']/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount))*10*10)div 100) + (round(xs:decimal(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator=true() and ram:CategoryTradeTax/ram:CategoryCode='AE']/ram:ActualAmount))*10*10)div 100) - (round(xs:decimal(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator=false() and ram:CategoryTradeTax/ram:CategoryCode='AE']/ram:ActualAmount))*10*10)div 100)" />

to avoid a false error

An example for a correct file which results in an error is here: data.xml.txt

MatthiasHainz avatar Sep 06 '22 13:09 MatthiasHainz

Please note, in the above example, *10*10 is displayed as 1010 Please always try to use single back apostrophes to display code. Inline code via "`" then the code and end with the same char Code blocks starting with "```" and ending with the same

phax avatar Sep 06 '22 14:09 phax

Code blocks starting with "```xml" even get syntax highlighting but need to end without the "xml"

phax avatar Sep 06 '22 14:09 phax

<xsl:when test="../ram:BasisAmount = (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement[ram:ApplicableTradeTax/ram:CategoryCode = 'AE']/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount)*10*10)div 100) + (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator=true() and ram:CategoryTradeTax/ram:CategoryCode='AE']/ram:ActualAmount)*10*10)div 100) - (round(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator=false() and ram:CategoryTradeTax/ram:CategoryCode='AE']/ram:ActualAmount)*10*10)div 100)" />

Which should be

<xsl:when test="../ram:BasisAmount = (round(xs:decimal(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement[ram:ApplicableTradeTax/ram:CategoryCode = 'AE']/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount))*10*10)div 100) + (round(xs:decimal(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator=true() and ram:CategoryTradeTax/ram:CategoryCode='AE']/ram:ActualAmount))*10*10)div 100) - (round(xs:decimal(sum(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge[ram:ChargeIndicator/udt:Indicator=false() and ram:CategoryTradeTax/ram:CategoryCode='AE']/ram:ActualAmount))*10*10)div 100)" />

phax avatar Sep 06 '22 14:09 phax

Yes, here you are: data.xml.txt

This example does not fail when tested with the current rule. Do you have other examples?

oriol avatar Oct 04 '22 16:10 oriol

@tavi-cacina ping And a quick question: what XSLT processor are you using?

phax avatar Oct 04 '22 16:10 phax

This example does not fail when tested with the current rule.

Yes, you are right, it validates right with the current schema. Was my mistake, I tested accidentally with an old distribution, from itplr-kosit/validator-configuration-xrechnung: validator-configuration-xrechnung_2.0.1_2020-12-31. Current distributions have this rule fixed, is the xs:decimal(ram:ActualAmount) instead of plain ram:ActualAmount that avoids the problem.

And a quick question: what XSLT processor are you using?

here was the second problem, we can not use the XSLT2 directly, it is not realy supported outside java world. We can not take the java runtime as a dependency (is also too slow as we validate interactively after each data-field change). So we changed the xslt so we can use it with an XSLT1 engine. This caused also the different behavior with the rounding, I thought is also a problem in upstream.

tavi-cacina avatar Oct 05 '22 12:10 tavi-cacina

I need to reopen this issue. Please find attached an instance that fails with CII 1.3.9 rules: XR-xrechnung-FEHLER-clean.xml.txt

phax avatar Feb 02 '23 13:02 phax

Added slack

oriol avatar Mar 30 '23 05:03 oriol