<?php
namespace ModulesAbstract\ElectronicInvoice\UBL21Config;

abstract class View_Index extends \ModulesAbstract\PluginReports\Config\View_Index
{
    /**
	 * Get the possible values of payment associations
	 * @see https://docs.peppol.eu/poacc/billing/3.0/codelist/UNCL4461/
	 *
	 * @return string[]
	 */
	protected function generatePaymentAssociationsFieldset_getPossibleValues()
	{
		return [
			'1' =>      '[1] Instrument not defined',
			'2' =>      '[2] Automated clearing house credit',
			'3' =>      '[3] Automated clearing house debit',
			'4' =>      '[4] ACH demand debit reversal',
			'5' =>      '[5] ACH demand credit reversal',
			'6' =>      '[6] ACH demand credit',
			'7' =>      '[7] ACH demand debit',
			'8' =>      '[8] Hold',
			'9' =>      '[9] National or regional clearing',
			'10' =>     '[10] In cash',
			'11' =>     '[11] ACH savings credit reversal',
			'12' =>     '[12] ACH savings debit reversal',
			'13' =>     '[13] ACH savings credit',
			'14' =>     '[14] ACH savings debit',
			'15' =>     '[15] Bookentry credit',
			'16' =>     '[16] Bookentry debit',
			'17' =>     '[17] ACH demand cash concentration/disbursement (CCD) credit',
			'18' =>     '[18] ACH demand cash concentration/disbursement (CCD) debit',
			'19' =>     '[19] ACH demand corporate trade payment (CTP) credit',
			'20' =>     '[20] Cheque',
			'21' =>     '[21] Banker\'s draft',
			'22' =>     '[22] Certified banker\'s draft',
			'23' =>     '[23] Bank cheque (issued by a banking or similar establishment)',
			'24' =>     '[24] Bill of exchange awaiting acceptance',
			'25' =>     '[25] Certified cheque',
			'26' =>     '[26] Local cheque',
			'27' =>     '[27] ACH demand corporate trade payment (CTP) debit',
			'28' =>     '[28] ACH demand corporate trade exchange (CTX) credit',
			'29' =>     '[29] ACH demand corporate trade exchange (CTX) debit',
			'30' =>     '[30] Credit transfer',
			'31' =>     '[31] Debit transfer',
			'32' =>     '[32] ACH demand cash concentration/disbursement plus (CCD+) credit',
			'33' =>     '[33] ACH demand cash concentration/disbursement plus (CCD+) debit',
			'34' =>     '[34] ACH prearranged payment and deposit (PPD)',
			'35' =>     '[35] ACH savings cash concentration/disbursement (CCD) credit',
			'36' =>     '[36] ACH savings cash concentration/disbursement (CCD) debit',
			'37' =>     '[37] ACH savings corporate trade payment (CTP) credit',
			'38' =>     '[38] ACH savings corporate trade payment (CTP) debit',
			'39' =>     '[39] ACH savings corporate trade exchange (CTX) credit',
			'40' =>     '[40] ACH savings corporate trade exchange (CTX) debit',
			'41' =>     '[41] ACH savings cash concentration/disbursement plus (CCD+) credit',
			'42' =>     '[42] Payment to bank account',
			'43' =>     '[43] ACH savings cash concentration/disbursement plus (CCD+) debit',
			'44' =>     '[44] Accepted bill of exchange',
			'45' =>     '[45] Referenced home-banking credit transfer',
			'46' =>     '[46] Interbank debit transfer',
			'47' =>     '[47] Home-banking debit transfer',
			'48' =>     '[48] Bank card',
			'49' =>     '[49] Direct debit',
			'50' =>     '[50] Payment by postgiro',
			'51' =>     '[51] FR, norme 6 97-Telereglement CFONB (French Organisation for Banking Standards)  - Option A',
			'52' =>     '[52] Urgent commercial payment',
			'53' =>     '[53] Urgent Treasury Payment',
			'54' =>     '[54] Credit card',
			'55' =>     '[55] Debit card',
			'56' =>     '[56] Bankgiro',
			'57' =>     '[57] Standing agreement',
			'58' =>     '[58] SEPA credit transfer',
			'59' =>     '[59] SEPA direct debit',
			'60' =>     '[60] Promissory note',
			'61' =>     '[61] Promissory note signed by the debtor',
			'62' =>     '[62] Promissory note signed by the debtor and endorsed by a bank',
			'63' =>     '[63] Promissory note signed by the debtor and endorsed by a third party',
			'64' =>     '[64] Promissory note signed by a bank',
			'65' =>     '[65] Promissory note signed by a bank and endorsed by another bank',
			'66' =>     '[66] Promissory note signed by a third party',
			'67' =>     '[67] Promissory note signed by a third party and endorsed by a bank',
			'68' =>     '[68] Online payment service',
			'70' =>     '[70] Bill drawn by the creditor on the debtor',
			'74' =>     '[74] Bill drawn by the creditor on a bank',
			'75' =>     '[75] Bill drawn by the creditor, endorsed by another bank',
			'76' =>     '[76] Bill drawn by the creditor on a bank and endorsed by a third party',
			'77' =>     '[77] Bill drawn by the creditor on a third party',
			'78' =>     '[78] Bill drawn by creditor on third party, accepted and endorsed by bank',
			'91' =>     '[91] Not transferable banker\'s draft',
			'92' =>     '[92] Not transferable local cheque',
			'93' =>     '[93] Reference giro',
			'94' =>     '[94] Urgent giro',
			'95' =>     '[95] Free format giro',
			'96' =>     '[96] Requested method for payment was not used',
			'97' =>     '[97] Clearing between partners',
			'ZZZ' =>    '[ZZZ] Mutually defined',
		];
	}

	/**
	 * Generate the payment associations fieldset
	 * @see generatePaymentAssociationsFieldset_getPossibleValues()
	 *
	 * @param string $name
	 * @param array $formFields
	 * @return \Engine\Form\Container\Fieldset
	 * @throws \Exception
	 */
	protected function generatePaymentAssociationsFieldset($name, $formFields)
	{
		// Quantity mapping
		$quantityAssociationsFieldset = \Engine\Form\Container\Fieldset::create($this->lang['form']["{$name}_fieldset"]);
		$quantityAssociationsFieldset
			->setCollapsible(true)
			->setCollapsed(false);

		foreach (\App\Config\FormsOfPayment::getInstance()->getAll() as $type=>$label) {
			$fld = new \Engine\Form\Input\Select($label, "{$name}[{$type}]", $formFields[$type]);
			$fld->showDefaultOption();
			$fld->setPossibleValues($this->generatePaymentAssociationsFieldset_getPossibleValues());
			$quantityAssociationsFieldset->addElement($fld);
		}

		return $quantityAssociationsFieldset;
	}


	/**
	 * Get the possible values of VAT associations
	 * Data was scraped from https://docs.peppol.eu/poacc/billing/3.0/codelist/UNCL5305/ at 2022-12-09
	 *
	 * @return array
	 */
	protected function generateVATAssociationsFieldset_getPossibleValues()
	{
		$rawData = [
			[
				"code" =>        'S',
				"label" =>       'Standard rate',
				"description" => 'Code specifying the standard rate',
			],
			[
				"code" =>        'AE',
				"label" =>       'Vat Reverse Charge',
				"description" => 'Code specifying that the standard VAT rate is levied from the invoicee',
			],
			[
				"code" =>        'E',
				"label" =>       'Exempt from Tax',
				"description" => 'Code specifying that taxes are not applicable',
			],
			[
				"code" =>        'Z',
				"label" =>       'Zero rated goods',
				"description" => 'Code specifying that the goods are at a zero rate',
			],
			[
				"code" =>        'G',
				"label" =>       'Free export item, VAT not charged',
				"description" => 'Code specifying that the item is free export and taxes are not charged',
			],
			[
				"code" =>        'O',
				"label" =>       'Services outside scope of tax',
				"description" => 'Code specifying that taxes are not applicable to the services',
			],
			[
				"code" =>        'K',
				"label" =>       'VAT exempt for EEA intra-community supply of goods and services',
				"description" => 'A tax category code indicating the item is VAT exempt due to an intra-community supply in the European Economic Area',
			],
			[
				"code" =>        'L',
				"label" =>       'Canary Islands general indirect tax',
				"description" => 'Impuesto General Indirecto Canario (IGIC) is an indirect tax levied on goods and services supplied in the Canary Islands (Spain) by traders and professionals, as well as on import of goods',
			],
			[
				"code" =>        'M',
				"label" =>       'Tax for production, services and importation in Ceuta and Melilla',
				"description" => 'Impuesto sobre la Producción, los Servicios y la Importación (IPSI) is an indirect municipal tax, levied on the production, processing and import of all kinds of movable tangible property, the supply of services and the transfer of immovable property located in the cities of Ceuta and Melilla',
			],
			[
				"code" =>        'B',
				"label" =>       'Transferred (VAT), In Italy',
				"description" => 'VAT not to be paid to the issuer of the invoice but directly to relevant tax authority. This code is allowed in the EN 16931 for Italy only based on the Italian A-deviation',
			],
		];

		$possibleValues = [];
		foreach ($rawData as $value) {
			$possibleValues[$value['code']] = sprintf("[%s] %s", $value['code'], $value['label']);
		}

		return $possibleValues;
	}

	/**
	 * Get the possible values of VAT associations exemtions list
	 * Data was scraped from https://docs.peppol.eu/poacc/billing/3.0/codelist/vatex/ at 2022-12-09
	 *
	 * @return array
	 */
	protected function generateVATAssociationsFieldset_getPossibleValues_exemptionsList()
	{
		$rawData = [
			[
				"code" =>        'VATEX-EU-79-C',
				"label" =>       'Exempt based on article 79, point c of Council Directive 2006/112/EC',
				"description" => 'Exemptions relating to repayment of expenditures. Remark, Repayment of expenditure is not an exemption in the sense of the VAT Directive but may be handled as such in the context of the EN16931',
			],
			[
				"code" =>        'VATEX-EU-132',
				"label" =>       'Exempt based on article 132 of Council Directive 2006/112/EC',
				"description" => 'Exemptions for certain activities in public interest',
			],
			[
				"code" =>        'VATEX-EU-132-1A',
				"label" =>       'Exempt based on article 132, section 1 (a) of Council Directive 2006/112/EC',
				"description" => 'The supply by the public postal services of services other than passenger transport and telecommunications services, and the supply of goods incidental thereto',
			],
			[
				"code" =>        'VATEX-EU-132-1B',
				"label" =>       'Exempt based on article 132, section 1 (b) of Council Directive 2006/112/EC',
				"description" => 'Hospital and medical care and closely related activities undertaken by bodies governed by public law or, under social conditions comparable with those applicable to bodies governed by public law, by hospitals, centres for medical treatment or diagnosis and other duly recognised establishments of a similar nature',
			],
			[
				"code" =>        'VATEX-EU-132-1C',
				"label" =>       'Exempt based on article 132, section 1 (c) of Council Directive 2006/112/EC',
				"description" => 'The provision of medical care in the exercise of the medical and paramedical professions as defined by the Member State concerned',
			],
			[
				"code" =>        'VATEX-EU-132-1D',
				"label" =>       'Exempt based on article 132, section 1 (d) of Council Directive 2006/112/EC',
				"description" => 'The supply of human organs, blood and milk',
			],
			[
				"code" =>        'VATEX-EU-132-1E',
				"label" =>       'Exempt based on article 132, section 1 (e) of Council Directive 2006/112/EC',
				"description" => 'The supply of services by dental technicians in their professional capacity and the supply of dental prostheses by dentists and dental technicians',
			],
			[
				"code" =>        'VATEX-EU-132-1F',
				"label" =>       'Exempt based on article 132, section 1 (f) of Council Directive 2006/112/EC',
				"description" => 'The supply of services by independent groups of persons, who are carrying on an activity which is exempt from VAT or in relation to which they are not taxable persons, for the purpose of rendering their members the services directly necessary for the exercise of that activity, where those groups merely claim from their members exact reimbursement of their share of the joint expenses, provided that such exemption is not likely to cause distortion of competition',
			],
			[
				"code" =>        'VATEX-EU-132-1G',
				"label" =>       'Exempt based on article 132, section 1 (g) of Council Directive 2006/112/EC',
				"description" => 'The supply of services and of goods closely linked to welfare and social security work, including those supplied by old people\'s homes, by bodies governed by public law or by other bodies recognised by the Member State concerned as being devoted to social wellbeing',
			],
			[
				"code" =>        'VATEX-EU-132-1H',
				"label" =>       'Exempt based on article 132, section 1 (h) of Council Directive 2006/112/EC',
				"description" => '"The supply of services and of goods closely linked to the protection of children and young persons by bodies governed by public law or by other organisations recognised by the Member State concerned as being devoted to social wellbeing"',
			],
			[
				"code" =>        'VATEX-EU-132-1I',
				"label" =>       'Exempt based on article 132, section 1 (i) of Council Directive 2006/112/EC',
				"description" => '" The provision of children\'s or young people\'s education, school or university education, vocational training or retraining, including the supply of services and of goods closely related thereto, by bodies governed by public law having such as their aim or by other organisations recognised by the Member State concerned as having similar objects."',
			],
			[
				"code" =>        'VATEX-EU-132-1J',
				"label" =>       'Exempt based on article 132, section 1 (j) of Council Directive 2006/112/EC',
				"description" => 'Tuition given privately by teachers and covering school or university education',
			],
			[
				"code" =>        'VATEX-EU-132-1K',
				"label" =>       'Exempt based on article 132, section 1 (k) of Council Directive 2006/112/EC',
				"description" => 'The supply of staff by religious or philosophical institutions for the purpose of the activities referred to in points (b), (g), (h) and (i) and with a view to spiritual welfare',
			],
			[
				"code" =>        'VATEX-EU-132-1L',
				"label" =>       'Exempt based on article 132, section 1 (l) of Council Directive 2006/112/EC',
				"description" => 'The supply of services, and the supply of goods closely linked thereto, to their members in their common interest in return for a subscription fixed in accordance with their rules by non-profitmaking organisations with aims of a political, trade-union, religious, patriotic, philosophical, philanthropic or civic nature, provided that this exemption is not likely to cause distortion of competition',
			],
			[
				"code" =>        'VATEX-EU-132-1M',
				"label" =>       'Exempt based on article 132, section 1 (m) of Council Directive 2006/112/EC',
				"description" => 'The supply of certain services closely linked to sport or physical education by non-profit-making organisations to persons taking part in sport or physical education',
			],
			[
				"code" =>        'VATEX-EU-132-1N',
				"label" =>       'Exempt based on article 132, section 1 (n) of Council Directive 2006/112/EC',
				"description" => 'The supply of certain cultural services, and the supply of goods closely linked thereto, by bodies governed by public law or by other cultural bodies recognised by the Member State concerned',
			],
			[
				"code" =>        'VATEX-EU-132-1O',
				"label" =>       'Exempt based on article 132, section 1 (o) of Council Directive 2006/112/EC',
				"description" => '"The supply of services and goods, by organisations whose activities are exempt pursuant to points (b), (g), (h), (i), (l), (m) and (n), in connection with fund-raising events organised exclusively for their own benefit, provided that exemption is not likely to cause distortion of competition."',
			],
			[
				"code" =>        'VATEX-EU-132-1P',
				"label" =>       'Exempt based on article 132, section 1 (p) of Council Directive 2006/112/EC',
				"description" => 'The supply of transport services for sick or injured persons in vehicles specially designed for the purpose, by duly authorised bodies',
			],
			[
				"code" =>        'VATEX-EU-132-1Q',
				"label" =>       'Exempt based on article 132, section 1 (q) of Council Directive 2006/112/EC',
				"description" => 'The activities, other than those of a commercial nature, carried out by public radio and television bodies',
			],
			[
				"code" =>        'VATEX-EU-143',
				"label" =>       'Exempt based on article 143 of Council Directive 2006/112/EC',
				"description" => 'Exemptions on importation',
			],
			[
				"code" =>        'VATEX-EU-143-1A',
				"label" =>       'Exempt based on article 143, section 1 (a) of Council Directive 2006/112/EC',
				"description" => 'The final importation of goods of which the supply by a taxable person would in all circumstances be exempt within their respective territory',
			],
			[
				"code" =>        'VATEX-EU-143-1B',
				"label" =>       'Exempt based on article 143, section 1 (b) of Council Directive 2006/112/EC',
				"description" => 'The final importation of goods governed by Council Directives 69/169/EEC (1), 83/181/EEC (2) and 2006/79/EC (3)',
			],
			[
				"code" =>        'VATEX-EU-143-1C',
				"label" =>       'Exempt based on article 143, section 1 (c) of Council Directive 2006/112/EC',
				"description" => 'The final importation of goods, in free circulation from a third territory forming part of the Community customs territory, which would be entitled to exemption under point (b) if they had been imported within the meaning of the first paragraph of Article 30',
			],
			[
				"code" =>        'VATEX-EU-143-1D',
				"label" =>       'Exempt based on article 143, section 1 (d) of Council Directive 2006/112/EC',
				"description" => 'The importation of goods dispatched or transported from a third territory or a third country into a Member State other than that in which the dispatch or transport of the goods ends, where the supply of such goods by the importer designated or recognised under Article 201 as liable for payment of VAT is exempt under Article 138',
			],
			[
				"code" =>        'VATEX-EU-143-1E',
				"label" =>       'Exempt based on article 143, section 1 (e) of Council Directive 2006/112/EC',
				"description" => 'The reimportation, by the person who exported them, of goods in the state in which they were exported, where those goods are exempt from customs duties',
			],
			[
				"code" =>        'VATEX-EU-143-1F',
				"label" =>       'Exempt based on article 143, section 1 (f) of Council Directive 2006/112/EC',
				"description" => 'The importation, under diplomatic and consular arrangements, of goods which are exempt from customs duties',
			],
			[
				"code" =>        'VATEX-EU-143-1FA',
				"label" =>       'Exempt based on article 143, section 1 (fa) of Council Directive 2006/112/EC',
				"description" => '"The importation of goods by the European Community, the European Atomic Energy Community, the European Central Bank or the European Investment Bank, or by the bodies set up by the Communities to which the Protocol of 8 April 1965 on the privileges and immunities of the European Communities applies, within the limits and under the conditions of that Protocol and the agreements for its implementation or the headquarters agreements, in so far as it does not lead to distortion of competition"',
			],
			[
				"code" =>        'VATEX-EU-143-1G',
				"label" =>       'Exempt based on article 143, section 1 (g) of Council Directive 2006/112/EC',
				"description" => '" The importation of goods by international bodies, other than those referred to in point (fa), recognised as such by the public authorities of the host Member State, or by members of such bodies, within the limits and under the conditions laid down by the international conventions establishing the bodies or by headquarters agreements"',
			],
			[
				"code" =>        'VATEX-EU-143-1H',
				"label" =>       'Exempt based on article 143, section 1 (h) of Council Directive 2006/112/EC',
				"description" => 'The importation of goods, into Member States party to the North Atlantic Treaty, by the armed forces of other States party to that Treaty for the use of those forces or the civilian staff accompanying them or for supplying their messes or canteens where such forces take part in the common defence effort',
			],
			[
				"code" =>        'VATEX-EU-143-1I',
				"label" =>       'Exempt based on article 143, section 1 (i) of Council Directive 2006/112/EC',
				"description" => 'The importation of goods by the armed forces of the United Kingdom stationed in the island of Cyprus pursuant to the Treaty of Establishment concerning the Republic of Cyprus, dated 16 August 1960, which are for the use of those forces or the civilian staff accompanying them or for supplying their messes or canteens',
			],
			[
				"code" =>        'VATEX-EU-143-1J',
				"label" =>       'Exempt based on article 143, section 1 (j) of Council Directive 2006/112/EC',
				"description" => 'The importation into ports, by sea fishing undertakings, of their catches, unprocessed or after undergoing preservation for marketing but before being supplied',
			],
			[
				"code" =>        'VATEX-EU-143-1K',
				"label" =>       'Exempt based on article 143, section 1 (k) of Council Directive 2006/112/EC',
				"description" => 'The importation of gold by central banks',
			],
			[
				"code" =>        'VATEX-EU-143-1L',
				"label" =>       'Exempt based on article 143, section 1 (l) of Council Directive 2006/112/EC',
				"description" => 'The importation of gas through a natural gas system or any network connected to such a system or fed in from a vessel transporting gas into a natural gas system or any upstream pipeline network, of electricity or of heat or cooling energy through heating or cooling networks',
			],
			[
				"code" =>        'VATEX-EU-148',
				"label" =>       'Exempt based on article 148 of Council Directive 2006/112/EC',
				"description" => 'Exemptions related to international transport',
			],
			[
				"code" =>        'VATEX-EU-148-A',
				"label" =>       'Exempt based on article 148, section (a) of Council Directive 2006/112/EC',
				"description" => 'Fuel supplies for commercial international transport vessels',
			],
			[
				"code" =>        'VATEX-EU-148-B',
				"label" =>       'Exempt based on article 148, section (b) of Council Directive 2006/112/EC',
				"description" => 'Fuel supplies for fighting ships in international transport',
			],
			[
				"code" =>        'VATEX-EU-148-C',
				"label" =>       'Exempt based on article 148, section (c) of Council Directive 2006/112/EC',
				"description" => 'Maintenance, modification, chartering and hiring of international transport vessels',
			],
			[
				"code" =>        'VATEX-EU-148-D',
				"label" =>       'Exempt based on article 148, section (d) of Council Directive 2006/112/EC',
				"description" => 'Supply to of other services to commercial international transport vessels',
			],
			[
				"code" =>        'VATEX-EU-148-E',
				"label" =>       'Exempt based on article 148, section (e) of Council Directive 2006/112/EC',
				"description" => 'Fuel supplies for aircraft on international routes',
			],
			[
				"code" =>        'VATEX-EU-148-F',
				"label" =>       'Exempt based on article 148, section (f) of Council Directive 2006/112/EC',
				"description" => 'Maintenance, modification, chartering and hiring of aircraft on international routes',
			],
			[
				"code" =>        'VATEX-EU-148-G',
				"label" =>       'Exempt based on article 148, section (g) of Council Directive 2006/112/EC',
				"description" => 'Supply to of other services to aircraft on international routes',
			],
			[
				"code" =>        'VATEX-EU-151',
				"label" =>       'Exempt based on article 151 of Council Directive 2006/112/EC',
				"description" => 'Exemptions relating to certain Transactions treated as exports',
			],
			[
				"code" =>        'VATEX-EU-151-1A',
				"label" =>       'Exempt based on article 151, section 1 (a) of Council Directive 2006/112/EC',
				"description" => 'The supply of goods or services under diplomatic and consular arrangements',
			],
			[
				"code" =>        'VATEX-EU-151-1AA',
				"label" =>       'Exempt based on article 151, section 1 (aa) of Council Directive 2006/112/EC',
				"description" => 'The supply of goods or services to the European Community, the European Atomic Energy Community, the European Central Bank or the European Investment Bank, or to the bodies set up by the Communities to which the Protocol of 8 April 1965 on the privileges and immunities of the European Communities applies, within the limits and under the conditions of that Protocol and the agreements for its implementation or the headquarters agreements, in so far as it does not lead to distortion of competition',
			],
			[
				"code" =>        'VATEX-EU-151-1B',
				"label" =>       'Exempt based on article 151, section 1 (b) of Council Directive 2006/112/EC',
				"description" => 'The supply of goods or services to international bodies, other than those referred to in point (aa), recognised as such by the public authorities of the host Member States, and to members of such bodies, within the limits and under the conditions laid down by the international conventions establishing the bodies or by headquarters agreements',
			],
			[
				"code" =>        'VATEX-EU-151-1C',
				"label" =>       'Exempt based on article 151, section 1 (c) of Council Directive 2006/112/EC',
				"description" => 'The supply of goods or services within a Member State which is a party to the North Atlantic Treaty, intended either for the armed forces of other States party to that Treaty for the use of those forces, or of the civilian staff accompanying them, or for supplying their messes or canteens when such forces take part in the common defence effort',
			],
			[
				"code" =>        'VATEX-EU-151-1D',
				"label" =>       'Exempt based on article 151, section 1 (d) of Council Directive 2006/112/EC',
				"description" => 'The supply of goods or services to another Member State, intended for the armed forces of any State which is a party to the North Atlantic Treaty, other than the Member State of destination itself, for the use of those forces, or of the civilian staff accompanying them, or for supplying their messes or canteens when such forces take part in the common defence effort',
			],
			[
				"code" =>        'VATEX-EU-151-1E',
				"label" =>       'Exempt based on article 151, section 1 (e) of Council Directive 2006/112/EC',
				"description" => 'The supply of goods or services to the armed forces of the United Kingdom stationed in the island of Cyprus pursuant to the Treaty of Establishment concerning the Republic of Cyprus, dated 16 August 1960, which are for the use of those forces, or of the civilian staff accompanying them, or for supplying their messes or canteens',
			],
			[
				"code" =>        'VATEX-EU-309',
				"label" =>       'Exempt based on article 309 of Council Directive 2006/112/EC',
				"description" => 'Travel agents performed outside of EU',
			],
			[
				"code" =>        'VATEX-EU-AE',
				"label" =>       'Reverse charge',
				"description" => 'Supports EN 16931-1 rule BR-AE-10 - Only use with VAT category code AE',
			],
			[
				"code" =>        'VATEX-EU-D',
				"label" =>       'Intra-Community acquisition from second hand means of transport',
				"description" => 'Second-hand means of transport - Indication that VAT has been paid according to the relevant transitional arrangements - Only use with VAT category code E',
			],
			[
				"code" =>        'VATEX-EU-F',
				"label" =>       'Intra-Community acquisition of second hand goods',
				"description" => 'Second-hand goods - Indication that the VAT margin scheme for second-hand goods has been applied. - Only use with VAT category code E',
			],
			[
				"code" =>        'VATEX-EU-G',
				"label" =>       'Export outside the EU',
				"description" => 'Supports EN 16931-1 rule BR-G-10 - Only use with VAT category code G',
			],
			[
				"code" =>        'VATEX-EU-I',
				"label" =>       'Intra-Community acquisition of works of art',
				"description" => 'Works of art - Indication that the VAT margin scheme for works of art has been applied. - Only use with VAT category code E',
			],
			[
				"code" =>        'VATEX-EU-IC',
				"label" =>       'Intra-Community supply',
				"description" => 'Supports EN 16931-1 rule BR-IC-10 - Only use with VAT category code K',
			],
			[
				"code" =>        'VATEX-EU-O',
				"label" =>       'Not subject to VAT',
				"description" => 'Supports EN 16931-1 rule BR-O-10 - Only use with VAT category code O',
			],
			[
				"code" =>        'VATEX-EU-J',
				"label" =>       'Intra-Community acquisition of collectors items and antiques',
				"description" => 'Collectors\' items and antiques - Indication that the VAT margin scheme for collector’s items and antiques has been applied. - Only use with VAT category code E',
			],
		];


		$possibleValues = [];
		foreach ($rawData as $value) {
			$possibleValues[$value['code']] = sprintf("[%s] %s", $value['code'], $value['label']);
		}

		return $possibleValues;
	}

	/**
	 * Generate the VAT associations and exemptions fieldset
	 * @see generatePaymentAssociationsFieldset_getPossibleValues()
	 *
	 * @param string $name
	 * @param array $formFields
	 * @return \Engine\Form\Container\Fieldset
	 * @throws \Exception
	 */
	protected function generateVATAssociationsFieldset($name, $formFields)
	{
		// Quantity mapping
		$VATAssociationsFieldset = \Engine\Form\Container\Fieldset::create($this->lang['form']["{$name}_fieldset"]);
		$VATAssociationsFieldset
			->setCollapsible(true)
			->setCollapsed(false);

		// @see https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-invoice/cac-TaxTotal/cac-TaxSubtotal/cac-TaxCategory/cbc-TaxExemptionReasonCode/
		// @see https://docs.peppol.eu/poacc/billing/3.0/codelist/vatex/

		// VAT's mapping, group by service and vat quota
		$serviceCodeLabelAssociations = \App\Config\Services_Basic::getInstance()->getListLinearSimple();
		$calculationsArray = [];
		foreach (\App\Config\Services_Calculations_InvoiceVat::getInstance()->getAll() as $k=>$values) {
			list($k1, , ) = explode('_', $k);
			if (!$calculationsArray[$k1]) {
				$calculationsArray[$k1] = [];
			}
			foreach ($values as $rowCfg) {
				$calculationsArray[$k1][$rowCfg['vatText']] = $rowCfg['vatText'];
			}
		}
		// cleanup & sort the final array
		foreach ($calculationsArray as $k=>$v) {
			$calculationsArray[$k] = array_values(array_unique(array_filter($v)));
			natcasesort($calculationsArray[$k]);

			if (!$calculationsArray[$k]) {
				unset($calculationsArray[$k]);
			}
		}

		$possibleValuesForVATCode = $this->generateVATAssociationsFieldset_getPossibleValues();
		$possibleValuesForVATExemption = $this->generateVATAssociationsFieldset_getPossibleValues_exemptionsList();

		foreach ($calculationsArray as $serviceCode=>$vatQuotas) {
			$VATAssociationsFieldsetChild = \Engine\Form\Container\Fieldset::create($serviceCodeLabelAssociations[$serviceCode]);
			$VATAssociationsFieldsetChild
				->setCollapsible(true)
				->setCollapsed(false);
			$VATAssociationsFieldset->addContainer($VATAssociationsFieldsetChild);

			foreach ($vatQuotas as $vatQuotaStr) {
				$fldBT151 = new \Engine\Form\Input\Select(null, "VATAssociations[{$serviceCode}][{$vatQuotaStr}][BT-151]", $formFields[$serviceCode][$vatQuotaStr]['BT-151']);
				$fldBT151->showDefaultOption();
				$fldBT151->setPossibleValues($possibleValuesForVATCode);

				$fldBT121 = new \Engine\Form\Input\Select(null, "VATAssociations[{$serviceCode}][{$vatQuotaStr}][BT-121]", $formFields[$serviceCode][$vatQuotaStr]['BT-121']);
				$fldBT121->showDefaultOption();
				$fldBT121->setPossibleValues($possibleValuesForVATExemption);

				$fld = new \Engine\Form\Input\ElementWithElements($vatQuotaStr, 'VATAssociations[{$serviceCode}][{$vatQuotaStr}]', null);
				$fld->addElement($fldBT151, 'main');
				$fld->addElement($fldBT121, 'post');
				$fld->setStyle('renderMode', 'inline');
				$VATAssociationsFieldsetChild->addElement($fld);
			}
		}

		return $VATAssociationsFieldset;
	}

}
