# DT-CIUS-PT-163

Source: https://xmlvalid.com/rules/DT-CIUS-PT-163

> Invoice total amount without VAT (BT-109) = Σ Invoice line net amount (BT-131) - Sum of allowances on document level (BT-107) + Sum of charges on document level (BT-108), with an acceptance range of 1.00 € (it does not mean that this tolerance is accepted by the customer).

- Level: error
- Rule sets: CIUS-PT rules (Portugal, UBL) 2.1.1
- Context: `cac:LegalMonetaryTotal`
- Test: `(exists(../cac:InvoiceLine) and ((cbc:ChargeTotalAmount) and (cbc:AllowanceTotalAmount) and (round((sum(../cac:InvoiceLine/xs:decimal(cbc:LineExtensionAmount)) + xs:decimal(cbc:ChargeTotalAmount) - xs:decimal(cbc:AllowanceTotalAmount)) * 10 * 10) div 100 ) <= (xs:decimal(cbc:TaxExclusiveAmount) + 1.00) and (round((sum(../cac:InvoiceLine/xs:decimal(cbc:LineExtensionAmount)) + xs:decimal(cbc:ChargeTotalAmount) - xs:decimal(cbc:AllowanceTotalAmount)) * 10 * 10) div 100 ) >= (xs:decimal(cbc:TaxExclusiveAmount) - 1.00)) or ( not(cbc:ChargeTotalAmount) and (cbc:AllowanceTotalAmount) and (round((sum(../cac:InvoiceLine/xs:decimal(cbc:LineExtensionAmount)) - xs:decimal(cbc:AllowanceTotalAmount)) * 10 * 10 ) div 100) <= (xs:decimal(cbc:TaxExclusiveAmount) + 1.00) and (round((sum(../cac:InvoiceLine/xs:decimal(cbc:LineExtensionAmount)) - xs:decimal(cbc:AllowanceTotalAmount)) * 10 * 10 ) div 100) >= (xs:decimal(cbc:TaxExclusiveAmount) - 1.00) ) or ( (cbc:ChargeTotalAmount) and not(cbc:AllowanceTotalAmount) and (round((sum(../cac:InvoiceLine/xs:decimal(cbc:LineExtensionAmount)) + xs:decimal(cbc:ChargeTotalAmount)) * 10 * 10 ) div 100) <= (xs:decimal(cbc:TaxExclusiveAmount) + 1.00) and (round((sum(../cac:InvoiceLine/xs:decimal(cbc:LineExtensionAmount)) + xs:decimal(cbc:ChargeTotalAmount)) * 10 * 10 ) div 100) >= (xs:decimal(cbc:TaxExclusiveAmount) - 1.00)) or ( not(cbc:ChargeTotalAmount) and not(cbc:AllowanceTotalAmount) and sum(../cac:InvoiceLine/xs:decimal(cbc:LineExtensionAmount)) <= (xs:decimal(cbc:TaxExclusiveAmount) + 1.00) and sum(../cac:InvoiceLine/xs:decimal(cbc:LineExtensionAmount)) >= (xs:decimal(cbc:TaxExclusiveAmount) - 1.00))) or (exists(../cac:CreditNoteLine) and ((cbc:ChargeTotalAmount) and (cbc:AllowanceTotalAmount) and (round((sum(../cac:CreditNoteLine/xs:decimal(cbc:LineExtensionAmount)) + xs:decimal(cbc:ChargeTotalAmount) - xs:decimal(cbc:AllowanceTotalAmount)) * 10 * 10) div 100 ) <= (xs:decimal(cbc:TaxExclusiveAmount) + 1.00) and (round((sum(../cac:CreditNoteLine/xs:decimal(cbc:LineExtensionAmount)) + xs:decimal(cbc:ChargeTotalAmount) - xs:decimal(cbc:AllowanceTotalAmount)) * 10 * 10) div 100 ) >= (xs:decimal(cbc:TaxExclusiveAmount) - 1.00)) or ( not(cbc:ChargeTotalAmount) and (cbc:AllowanceTotalAmount) and (round((sum(../cac:CreditNoteLine/xs:decimal(cbc:LineExtensionAmount)) - xs:decimal(cbc:AllowanceTotalAmount)) * 10 * 10 ) div 100) <= (xs:decimal(cbc:TaxExclusiveAmount) + 1.00) and (round((sum(../cac:CreditNoteLine/xs:decimal(cbc:LineExtensionAmount)) - xs:decimal(cbc:AllowanceTotalAmount)) * 10 * 10 ) div 100) >= (xs:decimal(cbc:TaxExclusiveAmount) - 1.00) ) or ( (cbc:ChargeTotalAmount) and not(cbc:AllowanceTotalAmount) and (round((sum(../cac:CreditNoteLine/xs:decimal(cbc:LineExtensionAmount)) + xs:decimal(cbc:ChargeTotalAmount)) * 10 * 10 ) div 100) <= (xs:decimal(cbc:TaxExclusiveAmount) + 1.00) and (round((sum(../cac:CreditNoteLine/xs:decimal(cbc:LineExtensionAmount)) + xs:decimal(cbc:ChargeTotalAmount)) * 10 * 10 ) div 100) >= (xs:decimal(cbc:TaxExclusiveAmount) - 1.00)) or ( not(cbc:ChargeTotalAmount) and not(cbc:AllowanceTotalAmount) and sum(../cac:CreditNoteLine/xs:decimal(cbc:LineExtensionAmount)) <= (xs:decimal(cbc:TaxExclusiveAmount) + 1.00) and sum(../cac:CreditNoteLine/xs:decimal(cbc:LineExtensionAmount)) >= (xs:decimal(cbc:TaxExclusiveAmount) - 1.00)))`

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