# PEPPOL-EN16931-R040

Source: https://xmlvalid.com/rules/PEPPOL-EN16931-R040

> Allowance/charge amount must equal base amount * percentage/100 if base amount and percentage exists

- Level: error
- Rule sets: Peppol BIS Billing 3.0 rules 3.0.21
- Context: `ubl-invoice:Invoice/cac:AllowanceCharge | ubl-invoice:Invoice/cac:InvoiceLine/cac:AllowanceCharge | ubl-creditnote:CreditNote/cac:AllowanceCharge | ubl-creditnote:CreditNote/cac:CreditNoteLine/cac:AllowanceCharge`
- Test: `not(cbc:MultiplierFactorNumeric and cbc:BaseAmount) or u:slack(if (cbc:Amount) then cbc:Amount else 0, (xs:decimal(cbc:BaseAmount) * xs:decimal(cbc:MultiplierFactorNumeric)) div 100, 0.02)`

> Allowance/charge amount must equal base amount * percentage/100 if base amount and percentage exists

- Level: error
- Rule sets: XRechnung 3.0 rules (UBL) 2.6.0
- Context: `ubl-invoice:Invoice/cac:AllowanceCharge | ubl-invoice:Invoice/cac:InvoiceLine/cac:AllowanceCharge | ubl-creditnote:CreditNote/cac:AllowanceCharge | ubl-creditnote:CreditNote/cac:CreditNoteLine/cac:AllowanceCharge`
- Test: `not(cbc:MultiplierFactorNumeric and cbc:BaseAmount) or u:slack(if (cbc:Amount) then cbc:Amount else 0, (xs:decimal(cbc:BaseAmount) * xs:decimal(cbc:MultiplierFactorNumeric)) div 100, $slackValue)`

> Allowance/charge amount must equal base amount * percentage/100 if base amount and percentage exists

- Level: error
- Rule sets: XRechnung 3.0 rules (CII) 2.6.0
- Context: `ram:SpecifiedTradeAllowanceCharge`
- Test: `not(ram:CalculationPercent and ram:BasisAmount) or u:slack(if (ram:ActualAmount) then ram:ActualAmount else 0, (xs:decimal(ram:BasisAmount) * xs:decimal(ram:CalculationPercent)) div 100, $slackValue)`

## Why it fails

- An allowance or charge gives a base amount and a percentage, but its amount is not base amount × percentage ÷ 100.

## How to fix it

- Recalculate `cbc:Amount` from `cbc:BaseAmount` and `cbc:MultiplierFactorNumeric`, or leave the base amount and percentage out. A difference of 0.02 is allowed.

Validate a document against these rules: https://xmlvalid.com/validate
