# XV-CZ-12

Source: https://xmlvalid.com/rules/XV-CZ-12

> PayableAmount (…) must equal DifferenceTaxInclusiveAmount + PayableRoundingAmount - PaidDepositsAmount (…); paid advance payments are given as positive amounts (ISDOC 6.0.2, A.6).

- Level: error
- Rule sets: ISDOC amounts and identifiers Standard ISDOC 6.0.2
- Context: `/isdoc:Invoice/isdoc:LegalMonetaryTotal`
- Test: `cz:same(cz:dec(isdoc:DifferenceTaxInclusiveAmount) + cz:dec(isdoc:PayableRoundingAmount) - cz:dec(isdoc:PaidDepositsAmount), cz:dec(isdoc:PayableAmount)) and (not(isdoc:DifferenceTaxInclusiveAmountCurr and isdoc:PaidDepositsAmountCurr and isdoc:PayableAmountCurr) or cz:same(cz:dec(isdoc:DifferenceTaxInclusiveAmountCurr) + cz:dec(isdoc:PayableRoundingAmountCurr) - cz:dec(isdoc:PaidDepositsAmountCurr), cz:dec(isdoc:PayableAmountCurr)))`

## Why it fails

- Paid advance payments (`PaidDepositsAmount`) are given as a negative amount. ISDOC gives them as positive amounts that are subtracted.
- The rounding (`PayableRoundingAmount`) is left out of the sum, or given with the wrong sign.

## How to fix it

- `PayableAmount` = `DifferenceTaxInclusiveAmount` + `PayableRoundingAmount` - `PaidDepositsAmount`, with the advance payments as a positive amount.

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