VAT place of supply
LegalDecides the VAT treatment before anything is printed: domestic, reverse charge, intra-Community supply, zero-rated export, outside the scope, or the customer's country's rate under the OSS. The EUR 10,000 distance-selling threshold is tested EU-wide on the current and the preceding year, and either one over means destination VAT. A VAT number only counts once it is marked validated, so an unproven business claim is charged VAT, with a note saying why, and a consumer never gets reverse charge. Northern Ireland counts as the EU for goods. Rates come from your data, never from a table that goes stale. The decision is made by a deriver that ships with it, and its treatment and rate are readable as derived values for the totals.
npx dxcl add vat-place-of-supply supply.kind Данные предпросмотра
JSON, на котором построен этот предпросмотр{
"seller": {
"country": "DE",
"ossRegistered": false,
"euDistanceSales": {
"currentYear": 4850000,
"priorYear": 3920000
}
},
"customer": {
"country": "FI",
"isBusiness": true,
"vatNumber": "FI12345678",
"vatNumberValidated": false
},
"supply": {
"kind": "goods",
"shipsFrom": "DE",
"shipsTo": "FI"
},
"vatRates": {
"DE": 19,
"FI": 25.5,
"NL": 21
}
} {
"seller": {
"country": "DE",
"ossRegistered": false,
"euDistanceSales": {
"currentYear": 4850000,
"priorYear": 3920000
}
},
"customer": {
"country": "FI",
"isBusiness": true,
"vatNumber": "FI12345678",
"vatNumberValidated": false
},
"supply": {
"kind": "services",
"shipsFrom": "DE",
"shipsTo": "FI"
},
"vatRates": {
"DE": 19,
"FI": 25.5,
"NL": 21
}
} {
"seller": {
"country": "DE",
"ossRegistered": false,
"euDistanceSales": {
"currentYear": 4850000,
"priorYear": 3920000
}
},
"customer": {
"country": "FI",
"isBusiness": true,
"vatNumber": "FI12345678",
"vatNumberValidated": false
},
"supply": {
"kind": "digital",
"shipsFrom": "DE",
"shipsTo": "FI"
},
"vatRates": {
"DE": 19,
"FI": 25.5,
"NL": 21
}
} Разрешённые узлы
что получает рендерер — узлов: 2vat-place-of-supply paragraph · static VAT charged at 25.5% (Finland) under the Union OSS scheme. vat-place-of-supply-unvalidated paragraph · static VAT has been charged because the customer's VAT number is missing or has not been validated. vat-place-of-supply paragraph · static VAT charged at 19% (Germany). vat-place-of-supply-unvalidated paragraph · static VAT has been charged because the customer's VAT number is missing or has not been validated. vat-place-of-supply paragraph · static VAT charged at 25.5% (Finland) under the Union OSS scheme. vat-place-of-supply-unvalidated paragraph · static VAT has been charged because the customer's VAT number is missing or has not been validated. Файлы
что записывает установка; выбранный файл и есть компонентnodes/vat-place-of-supply.node.tsx import { type Nodes, Paragraph, useDeriver, useState } from "docxcelerate/template";
import vatPlaceOfSupply from "../derivers/vat-place-of-supply.deriver.ts";
/**
* Whose VAT applies to a sale and at what rate, decided before anything is
* printed, as one line saying what was chosen. No section and no heading, so
* it can sit beside the totals on every invoice. The treatment and the rate are
* also readable as `{{derived.vatPlaceOfSupply.treatment}}` and
* `{{derived.vatPlaceOfSupply.rate}}`, so the totals can follow the decision.
*
* Decisions already made for you:
*
* - The EUR 10,000 distance-selling threshold is EU-wide, not per country. It
* is one figure: all of the seller's cross-border B2C sales of goods and
* digital services to other member states, added together. It is tested on
* the current year and on the preceding calendar year, and either one over
* means VAT is due at destination.
* - Over the threshold, or opted in to the Union OSS, means the customer's
* country's rate. Under it, the seller's own rate applies.
* - A VAT number counts only once it is marked validated. A string shaped like
* a VAT number is not proof of business status. A business claim with a
* missing or unvalidated number is charged VAT, never reverse charge, and
* the invoice says why.
* - A consumer never gets reverse charge.
* - Rates come from the document's data, never from a table in the code. A
* hard-coded table goes stale: Finland moved to 25.5% in September 2024,
* Slovakia to 23% in January 2025, Romania to 21% and Estonia to 24% in 2025.
* The component holds the rules and the caller holds the rates.
* - Northern Ireland (`XI`) counts as the EU for goods and as the UK for
* services.
*
* Every comparison here is on request data, so the decision is made by one
* deriver and the node only prints what it returns. Choosing the optional note
* is an ordinary conditional.
*
* Not covered: reduced rates, the special place-of-supply rules for services
* (property, events, transport, catering, hire), imports and the IOSS,
* domestic reverse charges, checking a VAT number, keeping the sales total,
* and calculating amounts. `outside-scope` is not a treatment
* `tax-treatment-notice` knows.
*
* Installed by `dxcl add vat-place-of-supply`, which also installs its deriver.
*/
/** What this component reads. Add these fields to your document data type. */
export interface VatPlaceOfSupplyData {
seller: {
/**
* Where the seller is established: an EU member state, `"GB"`, or `"XI"`
* for Northern Ireland. An ISO 3166-1 alpha-2 code. It is trimmed and
* upper-cased, and `"EL"` is read as Greece (`"GR"`). Required: the
* deriver throws when it is missing, is not two letters, or is outside the
* EU, GB and XI. Sellers established elsewhere are out of scope.
*/
country: string;
/**
* True when the seller has opted to charge destination VAT on every EU
* distance sale by registering for the Union OSS, even under the
* threshold. Missing means false. When true, `euDistanceSales` is not read.
*/
ossRegistered?: boolean;
/**
* The seller's EU-wide total, in euros, of cross-border B2C sales of goods
* and digital services to other member states. It is one figure for the
* whole EU, not one per country. Read only for a cross-border EU sale of
* goods or digital services to a consumer, when `ossRegistered` is not
* true. Missing there throws: the threshold cannot be guessed.
*/
euDistanceSales?: {
/** This calendar year so far, in EUR. Must be a finite number of 0 or more, or the deriver throws. */
currentYear: number;
/** The whole preceding calendar year, in EUR. Must be a finite number of 0 or more, or the deriver throws. */
priorYear: number;
};
};
customer: {
/**
* Where the customer is: who receives a service, or where a consumer
* lives. ISO alpha-2, normalised like `seller.country`. Any country
* outside the EU, GB and XI counts as "outside". Required: the deriver
* throws when it is missing or not two letters.
*/
country: string;
/**
* Whether the customer buys as a business. Missing means a consumer: B2B
* is a claim that has to be made, and a missing claim must not turn into
* a zero rate.
*/
isBusiness: boolean;
/**
* The customer's VAT number. Needed, together with `vatNumberValidated`,
* for reverse charge or an intra-Community supply. Missing, `""` or
* whitespace on a cross-border EU business sale means VAT is charged and
* the "unvalidated" note prints. The number itself is not printed here:
* tax-treatment-notice prints it.
*/
vatNumber?: string;
/**
* True only when the caller has checked the number, for example against
* VIES, and it came back valid. Missing or false is treated like a
* missing number. Only the literal `true` counts.
*/
vatNumberValidated?: boolean;
};
supply: {
/**
* What is being sold. `digital` means telecommunications, broadcasting
* and electronically supplied services (TBE). `services` means any other
* service, under the general rules. Required: anything else throws.
*/
kind: "goods" | "services" | "digital";
/**
* Goods only: the country the goods leave from. Missing means
* `seller.country`. It must be in the EU, GB or XI, or the deriver throws
* (imports are out of scope). If it differs from `seller.country`, the
* distance-selling threshold does not apply.
*/
shipsFrom?: string;
/** Goods only: the country the goods arrive in. Missing means `customer.country`. */
shipsTo?: string;
};
/**
* The current standard VAT rate per country, as a percentage: `{ NL: 21,
* FI: 25.5 }`. Keyed by upper-case ISO alpha-2. Greece is `GR`. Northern
* Ireland uses `GB`. Only the rate the decision needs is read. Throws when
* that rate is missing, not a finite number, below 0, or 100 or more.
* Reduced rates are out of scope.
*/
vatRates: Record<string, number>;
}
/**
* The line saying which VAT applies and at what rate, and, when a business
* claim was charged VAT, the note saying why.
*/
export const VatPlaceOfSupply: Nodes = async () => {
const [{ seller, customer, supply, vatRates }] = useState((data: VatPlaceOfSupplyData) => ({
seller: data.seller,
customer: data.customer,
supply: data.supply,
vatRates: data.vatRates,
}));
// After every other hook.
const pos = await useDeriver(vatPlaceOfSupply, [seller, customer, supply, vatRates]);
return (
<>
<Paragraph id="vat-place-of-supply">{pos.line}</Paragraph>
{pos.note && <Paragraph id="vat-place-of-supply-unvalidated">{pos.note}</Paragraph>}
</>
);
}; derivers/vat-place-of-supply.deriver.ts import { deriver } from "docxcelerate/template";
/**
* Decides whose VAT applies to a sale and at what rate. Installed by
* `dxcl add vat-place-of-supply`.
*
* It is self-contained on purpose: it travels to the engine as source text, so
* a module-level constant or helper would be a ReferenceError there. The EU
* list, the helpers and the formatters are all declared inside `run`.
*/
export default deriver({
name: "vatPlaceOfSupply",
run: (seller: unknown, customer: unknown, supply: unknown, vatRates: unknown) => {
// deno-lint-ignore no-explicit-any
const sel = seller as any;
// deno-lint-ignore no-explicit-any
const cus = customer as any;
// deno-lint-ignore no-explicit-any
const sup = supply as any;
// deno-lint-ignore no-explicit-any
const rates = vatRates as any;
const EU27 = [
"AT", "BE", "BG", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FR", "GR", "HR", "HU",
"IE", "IT", "LT", "LU", "LV", "MT", "NL", "PL", "PT", "RO", "SE", "SI", "SK",
];
const code = (x: unknown, path: string): string => {
if (x == null) throw new Error(path + " is required");
const v = String(x).trim().toUpperCase();
const r = v === "EL" ? "GR" : v;
if (!/^[A-Z]{2}$/.test(r)) throw new Error(path + " must be an ISO 3166-1 alpha-2 country code");
return r;
};
const s = code(sel?.country, "seller.country");
if (!EU27.includes(s) && s !== "GB" && s !== "XI") {
throw new Error("seller.country must be an EU member state, GB or XI");
}
const c = code(cus?.country, "customer.country");
const kind = sup?.kind;
if (kind !== "goods" && kind !== "services" && kind !== "digital") {
throw new Error("supply.kind must be goods, services or digital");
}
const goods = kind === "goods";
const O = goods ? code(sup.shipsFrom ?? sel.country, "supply.shipsFrom") : s;
const D = goods ? code(sup.shipsTo ?? cus.country, "supply.shipsTo") : c;
const jur = (x: string) => (x === "XI" ? "GB" : x);
const area = (x: string) => {
if (EU27.includes(x)) return "EU";
if (x === "XI") return goods ? "EU" : "UK";
return x === "GB" ? "UK" : "outside";
};
if (goods && area(O) === "outside") throw new Error("supply.shipsFrom must be in the EU, GB or XI");
const rateOf = (x: string): number => {
const key = jur(x);
const r = rates?.[key];
if (typeof r !== "number" || !Number.isFinite(r) || r < 0 || r >= 100) {
throw new Error("vatRates." + key + " must be the current standard VAT rate as a percentage");
}
return r;
};
const name = (x: string): string =>
x === "XI" ? "Northern Ireland" : new Intl.DisplayNames("en", { type: "region" }).of(x) ?? x;
const pct = (r: number) => new Intl.NumberFormat("en-GB", { maximumFractionDigits: 2 }).format(r) + "%";
const isBusiness = cus?.isBusiness === true;
const validB2B = isBusiness &&
typeof cus.vatNumber === "string" && cus.vatNumber.trim() !== "" &&
cus.vatNumberValidated === true;
const standard = (at: string, suffix = "") => {
const rate = rateOf(at);
return {
treatment: "standard", rate,
line: "VAT charged at " + pct(rate) + " (" + name(at) + ")" + suffix + ".", note: null as string | null,
};
};
const zero = (treatment: string, line: string) => ({ treatment, rate: 0, line, note: null as string | null });
// 1. Domestic. GB and XI are each other's domestic market.
if (jur(O) === jur(D)) return standard(O);
// 2. Across VAT areas.
if (area(O) !== area(D)) {
if (goods) return zero("zero-rated-export", "Zero-rated: export of goods (" + name(D) + ").");
const outside = zero(
"outside-scope",
"No VAT charged: outside the scope of " + area(O) + " VAT (" + name(D) + ").",
);
if (isBusiness) return outside;
if (kind === "services") return standard(O);
if (area(D) === "EU") return standard(D, " under the non-Union OSS scheme");
return area(D) === "UK" ? standard(D) : outside;
}
// 3. Cross-border inside the EU.
if (validB2B) {
return goods
? zero("intra-community-supply", "No VAT charged: intra-Community supply of goods (" + name(O) + " to " + name(D) + ").")
: zero("reverse-charge-services", "No VAT charged: reverse charge, VAT to be accounted for by the customer (" + name(D) + ").");
}
const note = isBusiness
? "VAT has been charged because the customer's VAT number is missing or has not been validated."
: null;
let result;
if (kind === "services") {
result = standard(O);
} else {
let destination = sel.ossRegistered === true || (goods && jur(O) !== jur(s));
if (!destination) {
const f = sel.euDistanceSales;
const ok = (v: unknown) => typeof v === "number" && Number.isFinite(v) && v >= 0;
if (!ok(f?.currentYear) || !ok(f?.priorYear)) {
throw new Error("seller.euDistanceSales must give currentYear and priorYear as numbers of 0 or more");
}
const cents = (v: number) => Math.round(v * 100) / 100;
destination = cents(f.currentYear) > 10000 || cents(f.priorYear) > 10000;
}
// Northern Ireland VAT is UK VAT, which the Union OSS does not cover.
result = destination ? standard(D, D === "XI" ? "" : " under the Union OSS scheme") : standard(O);
}
return { ...result, note };
},
});