VRBL-INV-MY-1p0-75

Basic Info

Rule The Delivery Location Country Subentity Code must be provided, if the Delivery Location Country Identification Code is 'MY', and follow the VRBL Country Subentity Code List, or the ISO 3166-2 Code List.
Context /ubl:Invoice/cac:Delivery/cac:DeliveryLocation/cac:Address
Pattern vrbl-invoice-my-1p0
Severity fatal

Implementation

not(boolean(cac:Country/cbc:IdentificationCode))
or
(
	cac:Country/cbc:IdentificationCode = 'MY'
	and
	(
		not(boolean(cbc:CountrySubentityCode))
		or
		(
			starts-with(cbc:CountrySubentityCode, $VRBL-MY-Prefix)
			and
			contains(
				$VRBL-CL-MY-VRBL-CountrySubentityCode,
				concat(
					substring($VRBL-CL-MY-VRBL-CountrySubentityCode, 1, 1),
					substring(cbc:CountrySubentityCode, string-length($VRBL-MY-Prefix) + 1),
					substring($VRBL-CL-MY-VRBL-CountrySubentityCode, 1, 1)
				)
			)
		)
		or
		(
			contains(
				$VRBL-CL-MY-ISO-CountrySubentityCode,
				concat(
					substring($VRBL-CL-MY-ISO-CountrySubentityCode, 1, 1),
					cbc:CountrySubentityCode,
					substring($VRBL-CL-MY-ISO-CountrySubentityCode, 1, 1)
				)
			)
		)
	)
)
or
(
	not(cac:Country/cbc:IdentificationCode = 'MY')
	and
	(
		not(boolean(cbc:CountrySubentityCode))
		or
		cbc:CountrySubentityCode = concat($VRBL-MY-Prefix, '00') or cbc:CountrySubentityCode = '_N/A_'
		or
		cbc:CountrySubentityCode = concat($VRBL-MY-Prefix, '17') or cbc:CountrySubentityCode = '_N/A_'
	)
)