VRBL-INV-CH-YELLOWBILL-3p0-39

Basic Info

Rule When the Delivery Tax Company ID is used as a VAT ID, the Delivery Tax Company ID must be a valid VAT ID from Switzerland or an EU country.
Context /ubl:Invoice/cac:Delivery/cac:DeliveryParty/cac:PartyTaxScheme/cbc:CompanyID
Pattern vrbl-ch-yellowbill-3p0
Severity fatal

Used Template: VRBL-CH-TaxID-Format

Parameter Value
probe = .

Implementation

(
	not(../cac:TaxScheme/cbc:ID = 'VAT')
)
or
(
		not(boolean(.))
		or
		(
			string-length(normalize-space(.)) = 10
			and
			translate(substring(normalize-space(.), 3), $Numerics, '') = ''
			and
			contains(' CZ DK FI HU LU MT SI ', concat(' ', substring(normalize-space(.), 1, 2), ' '))
		)
		or
		(
			string-length(normalize-space(.)) = 11
			and
			translate(substring(normalize-space(.), 3), $Numerics, '') = ''
			and
			contains(' BG CZ DE EE EL LT PT ', concat(' ', substring(normalize-space(.), 1, 2), ' '))
		)
		or
		(
			string-length(normalize-space(.)) = 12
			and
			translate(substring(normalize-space(.), 3), $Numerics, '') = ''
			and
			contains(' BG CZ PL SK ', concat(' ', substring(normalize-space(.), 1, 2), ' '))
		)
		or
		(
			string-length(normalize-space(.)) = 13
			and
			translate(substring(normalize-space(.), 3), $Numerics, '') = ''
			and
			contains(' HR IT LV ', concat(' ', substring(normalize-space(.), 1, 2), ' '))
		)
		or
		(
			string-length(normalize-space(.)) = 14
			and
			translate(substring(normalize-space(.), 3), $Numerics, '') = ''
			and
			contains(' LT SE ', concat(' ', substring(normalize-space(.), 1, 2), ' '))
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'AT'
			and
			string-length(normalize-space(.)) = 11
			and
			substring(normalize-space(.), 3, 1) =  'U'
			and
			translate(substring(normalize-space(.), 4), $Numerics, '') = ''
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'BE'
			and
			translate(substring(normalize-space(.), 3), $Numerics, '') = ''
			and
			(
				string-length(normalize-space(.)) = 11
				or
				(
					string-length(normalize-space(.)) = 12
					and
					(
						substring(normalize-space(.), 3, 1) = '0'
						or
						substring(normalize-space(.), 3, 1) = '1'
					)
				)
			)
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'CY'
			and
			string-length(normalize-space(.)) = 11
			and
			translate(substring(normalize-space(.), 3, 8), $Numerics, '') = ''
			and
			translate(substring(normalize-space(.), 11, 1), $AlphabetUpperCase, '') = ''
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'ES'
			and
			string-length(normalize-space(.)) = 11
			and
			(
				(
					translate(substring(normalize-space(.), 3, 1), $AlphabetUpperCase, '') = ''
					and
					translate(substring(normalize-space(.), 4, 7), $Numerics, '') = ''
					and
					translate(substring(normalize-space(.), 11, 1), $AlphabetUpperCase, '') = ''
				)
				or
				(
					translate(substring(normalize-space(.), 3, 8), $Numerics, '') = ''
					and
					translate(substring(normalize-space(.), 11, 1), $AlphabetUpperCase, '') = ''
				)
				or
				(
					translate(substring(normalize-space(.), 3, 1), $AlphabetUpperCase, '') = ''
					and
					translate(substring(normalize-space(.), 4, 8), $Numerics, '') = ''
				)
			)
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'FR'
			and
			string-length(normalize-space(.)) = 13
			and
			translate(substring(normalize-space(.), 3, 2), concat($AlphabetUpperCase, $Numerics), '') = ''
			and
			translate(substring(normalize-space(.), 5), $Numerics, '') = ''
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'IE'
			and
			(
				(
					string-length(normalize-space(.)) = 10
					and
					translate(substring(normalize-space(.), 3, 1), $Numerics, '') = ''
					and
					translate(substring(normalize-space(.), 4, 1), concat($AlphabetUpperCase, $Numerics), '') = ''
					and
					translate(substring(normalize-space(.), 5, 5), $Numerics, '') = ''
					and
					translate(substring(normalize-space(.), 10, 1), $AlphabetUpperCase, '') = ''
				)
				or
				(
					string-length(normalize-space(.)) >= 10
					and
					string-length(normalize-space(.)) <= 11
					and
					translate(substring(normalize-space(.), 3, 7), $Numerics, '') = ''
					and
					translate(substring(normalize-space(.), 10), $AlphabetUpperCase, '') = ''
				)
			)
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'NL'
			and
			string-length(normalize-space(.)) = 14
			and
			translate(substring(normalize-space(.), 3, 9), $Numerics, '') = ''
			and
			substring(normalize-space(.), 12, 1) = 'B'
			and
			translate(substring(normalize-space(.), 13, 2), $Numerics, '') = ''
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'RO'
			and
			(
				string-length(normalize-space(.)) >= 4
				and
				string-length(normalize-space(.)) <= 12
			)
			and
			translate(substring(normalize-space(.), 3), $Numerics, '') = ''
		)
		or
		(
			substring(normalize-space(.), 1, 2) = 'CH'
			and
			substring(normalize-space(.), 3, 1) = 'E'
			and
			string-length(translate(substring(normalize-space(.), 4), concat($AlphabetUpperCase, ' -.'), '')) = 9
			and
			translate(substring(translate(normalize-space(.), ' -.', ''), 4, 9), $Numerics, '') = ''
			and
			contains(' MWST TVA IVA VAT  ', concat(' ', substring(translate(normalize-space(.), ' -.', ''), 13), ' '))
		)
)