How the Portugal iva (vat) calculator is verified

Inputs

InputFieldType
Amountamountnumber
Directiondirectionstring
What is being suppliedcategorystring
Turnover last calendar yearannualTurnovernumber
B2B reverse charge appliesreverseChargeboolean

The formula

Each derived value below is computed by the Valem engine from the expression shown, in this order. Nothing else runs — there is no hidden code path.

Derived valueFieldFormula (JSONata)
Rateratecategory = 'reduced1' ? $const.reducedRate1 : category = 'reduced2' ? $const.reducedRate2 : $const.standardRate
Effective RateeffectiveRatereverseCharge ? 0 : rate
Net AmountnetAmountdirection = 'remove' ? $round(amount / (1 + effectiveRate), 2) : $round(amount, 2)
Vat AmountvatAmount$round(netAmount * effectiveRate, 2)
Gross AmountgrossAmount$round(netAmount + vatAmount, 2)
Must RegistermustRegisterannualTurnover > $const.registrationThreshold

Rates and thresholds

The expressions above read these as $const. They are the figures the annual refresh replaces, so they live as data rather than being written into the formulas — which is what makes a year-on-year change a one-line diff instead of an edit to arithmetic.

ConstantValue
standardRate0.23
reducedRate10.06
reducedRate20.13
registrationThreshold15000

Test vectors (6)

Every case is executed against this model on each build, by the Java engine and independently by a JavaScript one. A mismatch of a single cent fails the build, so the page cannot ship advertising a figure the model no longer produces.

Case 1 — S1 100.00 EUR net at the normal rate

given amount100
given directionadd
given categorystandard
given reverseChargeno
given annualTurnover0
expect vatAmount23
expect grossAmount123
expect netAmount100

Case 2 — S2 123.00 EUR gross back to net at the normal rate

given amount123
given directionremove
given categorystandard
given reverseChargeno
given annualTurnover0
expect netAmount100
expect vatAmount23

Case 3 — S3 100.00 EUR net at the 6% reduced rate

given amount100
given directionadd
given categoryreduced1
given reverseChargeno
given annualTurnover0
expect vatAmount6
expect grossAmount106

Case 4 — S4 100.00 EUR net at the 13% intermediate rate

given amount100
given directionadd
given categoryreduced2
given reverseChargeno
given annualTurnover0
expect vatAmount13
expect grossAmount113

Case 5 — S5 last year over 15 000 EUR: the exemption does not apply

given amount100
given directionadd
given categorystandard
given reverseChargeno
given annualTurnover20000
expect mustRegistertrue

Case 6 — S6 last year at or under the limit: exempt

given amount100
given directionadd
given categorystandard
given reverseChargeno
given annualTurnover12000
expect mustRegisterfalse

Sources

Check it yourself — and reuse it

The whole model as JSON — inputs, outputs, formulas, vectors and sources in one re-runnable document.

This model is published under CC BY 4.0: use it, adapt it, build on it, with attribution. The licence covers the model — the expression of each rule and the arrangement of the catalog. The rates and thresholds are law, and nobody licenses those; the sources above are where they come from.

← Back to the Portugal iva (vat) calculator

Built with Valem — a live, verifiable calculator you can fork and embed.