DT-CIUS-PT-157
The BT-131 must equal the multiplication between the quantity (InvoicedQuantity) and the price (PriceAmount) divided by the base quantity (BaseQuantity) subtracted by the sum of the discounts and added the sum of the charges of the line, 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:InvoiceLine | cac:CreditNoteLine
((not(exists(cac:Price/cbc:BaseQuantity)) or ((exists(cac:Price/cbc:BaseQuantity)) and cac:Price/xs:decimal(cbc:BaseQuantity) = 0 )) and ((exists(cac:AllowanceCharge[cbc:ChargeIndicator='false']) and exists(cac:AllowanceCharge[cbc:ChargeIndicator='true']) and ((round(xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) * 100) div 100) + (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='true']/xs:decimal(cbc:Amount)) * 10 * 10) div 100) - (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='false']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) <= (xs:decimal(cbc:LineExtensionAmount) + 1.00) and ((round(xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) * 100) div 100) + (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='true']/xs:decimal(cbc:Amount)) * 10 * 10) div 100) - (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='false']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) >= (xs:decimal(cbc:LineExtensionAmount) - 1.00)) or (not(exists(cac:AllowanceCharge[cbc:ChargeIndicator='false'])) and exists(cac:AllowanceCharge[cbc:ChargeIndicator='true']) and ((round(xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) * 100) div 100) + (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='true']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) <= (xs:decimal(cbc:LineExtensionAmount) + 1.00) and ((round(xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) * 100) div 100) + (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='true']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) >= (xs:decimal(cbc:LineExtensionAmount) - 1.00)) or (exists(cac:AllowanceCharge[cbc:ChargeIndicator='false']) and not(exists(cac:AllowanceCharge[cbc:ChargeIndicator='true'])) and ((round(xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) * 100) div 100) - (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='false']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) <= (xs:decimal(cbc:LineExtensionAmount) + 1.00) and ((round(xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) * 100) div 100) - (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='false']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) >= (xs:decimal(cbc:LineExtensionAmount) - 1.00)) or (not(exists(cac:AllowanceCharge[cbc:ChargeIndicator='false'])) and not(exists(cac:AllowanceCharge[cbc:ChargeIndicator='true'])) and (round(xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) * 100) div 100) <= (xs:decimal(cbc:LineExtensionAmount) + 1.00) and (round(xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) * 100) div 100) >= (xs:decimal(cbc:LineExtensionAmount) - 1.00)))) or (exists(cac:Price/cbc:BaseQuantity) and (cac:Price/xs:decimal(cbc:BaseQuantity) > 0) and ((exists(cac:AllowanceCharge[cbc:ChargeIndicator='false']) and exists(cac:AllowanceCharge[cbc:ChargeIndicator='true']) and ((round((xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) div cac:Price/xs:decimal(cbc:BaseQuantity)) * 100) div 100) + (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='true']/xs:decimal(cbc:Amount)) * 10 * 10) div 100) - (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='false']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) <= (xs:decimal(cbc:LineExtensionAmount) + 1.00) and ((round((xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) div cac:Price/xs:decimal(cbc:BaseQuantity)) * 100) div 100) + (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='true']/xs:decimal(cbc:Amount)) * 10 * 10) div 100) - (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='false']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) >= (xs:decimal(cbc:LineExtensionAmount) - 1.00)) or (not(exists(cac:AllowanceCharge[cbc:ChargeIndicator='false'])) and exists(cac:AllowanceCharge[cbc:ChargeIndicator='true']) and ((round((xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) div cac:Price/xs:decimal(cbc:BaseQuantity)) * 100) div 100) + (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='true']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) <= (xs:decimal(cbc:LineExtensionAmount) + 1.00) and ((round((xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) div cac:Price/xs:decimal(cbc:BaseQuantity)) * 100) div 100) + (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='true']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) >= (xs:decimal(cbc:LineExtensionAmount) - 1.00)) or (exists(cac:AllowanceCharge[cbc:ChargeIndicator='false']) and not(exists(cac:AllowanceCharge[cbc:ChargeIndicator='true'])) and ((round((xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) div cac:Price/xs:decimal(cbc:BaseQuantity)) * 100) div 100) - (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='false']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) <= (xs:decimal(cbc:LineExtensionAmount) + 1.00) and ((round((xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) div cac:Price/xs:decimal(cbc:BaseQuantity)) * 100) div 100) - (round(sum(cac:AllowanceCharge[cbc:ChargeIndicator='false']/xs:decimal(cbc:Amount)) * 10 * 10) div 100)) >= (xs:decimal(cbc:LineExtensionAmount) - 1.00)) or (not(exists(cac:AllowanceCharge[cbc:ChargeIndicator='false'])) and not(exists(cac:AllowanceCharge[cbc:ChargeIndicator='true'])) and (round((xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) div cac:Price/xs:decimal(cbc:BaseQuantity)) * 100) div 100) <= (xs:decimal(cbc:LineExtensionAmount) + 1.00) and (round((xs:decimal(cbc:InvoicedQuantity | cbc:CreditedQuantity) * cac:Price/xs:decimal(cbc:PriceAmount) div cac:Price/xs:decimal(cbc:BaseQuantity)) * 100) div 100) >= (xs:decimal(cbc:LineExtensionAmount) - 1.00))))
Checked with Portugal CIUS-PT Invoice (UBL), Portugal CIUS-PT Credit Note (UBL)