Skip to content
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

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

Closed
tavi-cacina opened this issue Aug 5, 2022 · 11 comments
Closed

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

tavi-cacina opened this issue Aug 5, 2022 · 11 comments
Assignees
Milestone

Comments

@tavi-cacina
Copy link

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

@phax
Copy link
Collaborator

phax commented Aug 5, 2022

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

@phax phax added the Format CII label Aug 5, 2022
@tavi-cacina
Copy link
Author

Yes, here you are: data.xml.txt

@MatthiasHainz
Copy link

MatthiasHainz commented Sep 6, 2022

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

@phax
Copy link
Collaborator

phax commented Sep 6, 2022

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
Copy link
Collaborator

phax commented Sep 6, 2022

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

@phax
Copy link
Collaborator

phax commented Sep 6, 2022

<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)" />

@oriol oriol added this to the 1.3.9 milestone Sep 30, 2022
@oriol oriol self-assigned this Sep 30, 2022
@oriol
Copy link
Collaborator

oriol commented Oct 4, 2022

Yes, here you are: data.xml.txt

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

@phax
Copy link
Collaborator

phax commented Oct 4, 2022

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

@oriol oriol assigned tavi-cacina and unassigned oriol Oct 4, 2022
@tavi-cacina
Copy link
Author

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.

@phax phax reopened this Feb 2, 2023
@phax
Copy link
Collaborator

phax commented Feb 2, 2023

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

@oriol oriol modified the milestones: 1.3.9, 1.3.10 Mar 29, 2023
@oriol
Copy link
Collaborator

oriol commented Mar 30, 2023

Added slack

@oriol oriol closed this as completed in d1d04ab Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants