DT-CIUS-PT-173
For each different value of VAT category rate (BT-119) where the VAT category code (BT-118) is "Standard rated", the VAT category taxable amount (BT-116) in a VATBReakdown (BG-23) shall equal the sum of Invoice line net amounts (BT-131) plus the sum of document level charge amounts (BT-99) minus the sum of document level allowance amounts (BT-92) where the VAT category code (BT-151, BT-102, BT-95) is “Standard rated” and the VAT rate (BT-152, BT-103, BT-96) equals the VAT category rate (BT-119), with an acceptance range of 1.00 € (it does not mean that this tolerance is accepted by the customer).
What the rule checks
As the rule set's publisher wrote it. The rule runs on every element the context matches, and fails where the test is false; the validator reports the line of that element.
cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'S' or normalize-space(cbc:ID) = 'NOR']
every $rate in round(cbc:Percent) satisfies ((exists(//cac:InvoiceLine) and ((round((sum(../../../cac:InvoiceLine[normalize-space(cac:Item/cac:ClassifiedTaxCategory/cbc:ID)='S' or normalize-space(cac:Item/cac:ClassifiedTaxCategory/cbc:ID)='NOR'][cac:Item/cac:ClassifiedTaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:LineExtensionAmount)) + sum(../../../cac:AllowanceCharge[cbc:ChargeIndicator='true'][normalize-space(cac:TaxCategory/cbc:ID)='S' or normalize-space(cac:TaxCategory/cbc:ID)='NOR'][cac:TaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:Amount)) - sum(../../../cac:AllowanceCharge[cbc:ChargeIndicator='false'][normalize-space(cac:TaxCategory/cbc:ID)='S' or normalize-space(cac:TaxCategory/cbc:ID)='NOR'][cac:TaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:Amount))) * 100) div 100) <= (xs:decimal(../cbc:TaxableAmount) + 1.00) and (round((sum(../../../cac:InvoiceLine[normalize-space(cac:Item/cac:ClassifiedTaxCategory/cbc:ID)='S' or normalize-space(cac:Item/cac:ClassifiedTaxCategory/cbc:ID)='NOR'][cac:Item/cac:ClassifiedTaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:LineExtensionAmount)) + sum(../../../cac:AllowanceCharge[cbc:ChargeIndicator='true'][normalize-space(cac:TaxCategory/cbc:ID)='S' or normalize-space(cac:TaxCategory/cbc:ID)='NOR'][cac:TaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:Amount)) - sum(../../../cac:AllowanceCharge[cbc:ChargeIndicator='false'][normalize-space(cac:TaxCategory/cbc:ID)='S' or normalize-space(cac:TaxCategory/cbc:ID)='NOR'][cac:TaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:Amount))) * 100) div 100) >=(xs:decimal(../cbc:TaxableAmount) - 1.00))) or (exists(//cac:CreditNoteLine) and ( ((round((sum(../../../cac:CreditNoteLine[normalize-space(cac:Item/cac:ClassifiedTaxCategory/cbc:ID)='S' or normalize-space(cac:Item/cac:ClassifiedTaxCategory/cbc:ID)='NOR'][cac:Item/cac:ClassifiedTaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:LineExtensionAmount)) + sum(../../../cac:AllowanceCharge[cbc:ChargeIndicator='true'][normalize-space(cac:TaxCategory/cbc:ID)='S' or normalize-space(cac:TaxCategory/cbc:ID)='NOR'][cac:TaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:Amount)) - sum(../../../cac:AllowanceCharge[cbc:ChargeIndicator='false'][normalize-space(cac:TaxCategory/cbc:ID)='S' or normalize-space(cac:TaxCategory/cbc:ID)='NOR'][cac:TaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:Amount))) * 100) div 100) <= (xs:decimal(../cbc:TaxableAmount) + 1.00) and (round((sum(../../../cac:CreditNoteLine[normalize-space(cac:Item/cac:ClassifiedTaxCategory/cbc:ID)='S' or normalize-space(cac:Item/cac:ClassifiedTaxCategory/cbc:ID)='NOR'][cac:Item/cac:ClassifiedTaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:LineExtensionAmount)) + sum(../../../cac:AllowanceCharge[cbc:ChargeIndicator='true'][normalize-space(cac:TaxCategory/cbc:ID)='S' or normalize-space(cac:TaxCategory/cbc:ID)='NOR'][cac:TaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:Amount)) - sum(../../../cac:AllowanceCharge[cbc:ChargeIndicator='false'][normalize-space(cac:TaxCategory/cbc:ID)='S' or normalize-space(cac:TaxCategory/cbc:ID)='NOR'][cac:TaxCategory/cbc:Percent=$rate]/xs:decimal(cbc:Amount))) * 100) div 100) >=(xs:decimal(../cbc:TaxableAmount) - 1.00)))))
Checked with Portugal CIUS-PT Invoice (UBL), Portugal CIUS-PT Credit Note (UBL)