From 6d3ba9657fa42cc71acd912106014271cfc045b2 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 4 Dec 2024 21:47:14 +0100 Subject: [PATCH] Implemented parsing Country codes --- .../codinux/invoicing/model/codes/Country.kt | 255 ++++++++++++++++++ .../codinux/invoicing/parser/CodeGenerator.kt | 9 +- .../excel/ZugferdExcelCodeListsParser.kt | 2 +- 3 files changed, 262 insertions(+), 4 deletions(-) create mode 100644 e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/Country.kt diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/Country.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/Country.kt new file mode 100644 index 0000000..b9dd0e5 --- /dev/null +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/Country.kt @@ -0,0 +1,255 @@ +package net.codinux.invoicing.model.codes + +enum class Country(val englishName: String, val alpha2Code: String, val alpha3Code: String?) { + AF("Afghanistan", "AF", "AFG"), + AX("Åland Islands", "AX", "ALA"), + AL("Albania", "AL", "ALB"), + DZ("Algeria", "DZ", "DZA"), + AS("American Samoa", "AS", "ASM"), + AD("Andorra", "AD", "AND"), + AO("Angola", "AO", "AGO"), + AI("Anguilla", "AI", "AIA"), + AQ("Antarctica", "AQ", "ATA"), + AG("Antigua and Barbuda", "AG", "ATG"), + AR("Argentina", "AR", "ARG"), + AM("Armenia", "AM", "ARM"), + AW("Aruba", "AW", "ABW"), + AU("Australia", "AU", "AUS"), + AT("Austria", "AT", "AUT"), + AZ("Azerbaijan", "AZ", "AZE"), + BS("Bahamas (the)", "BS", "BHS"), + BH("Bahrain", "BH", "BHR"), + BD("Bangladesh", "BD", "BGD"), + BB("Barbados", "BB", "BRB"), + BY("Belarus", "BY", "BLR"), + BE("Belgium", "BE", "BEL"), + BZ("Belize", "BZ", "BLZ"), + BJ("Benin", "BJ", "BEN"), + BM("Bermuda", "BM", "BMU"), + BT("Bhutan", "BT", "BTN"), + BO("Bolivia (Plurinational State of)", "BO", "BOL"), + BQ("Bonaire, Sint Eustatius and Saba", "BQ", "BES"), + BA("Bosnia and Herzegovina", "BA", "BIH"), + BW("Botswana", "BW", "BWA"), + BV("Bouvet Island", "BV", "BVT"), + BR("Brazil", "BR", "BRA"), + IO("British Indian Ocean Territory (the)", "IO", "IOT"), + BN("Brunei Darussalam", "BN", "BRN"), + BG("Bulgaria", "BG", "BGR"), + BF("Burkina Faso", "BF", "BFA"), + BI("Burundi", "BI", "BDI"), + CV("Cabo Verde", "CV", "CPV"), + KH("Cambodia", "KH", "KHM"), + CM("Cameroon", "CM", "CMR"), + CA("Canada", "CA", "CAN"), + KY("Cayman Islands (the)", "KY", "CYM"), + CF("Central African Republic (the)", "CF", "CAF"), + TD("Chad", "TD", "TCD"), + CL("Chile", "CL", "CHL"), + CN("China", "CN", "CHN"), + CX("Christmas Island", "CX", "CXR"), + CC("Cocos (Keeling) Islands (the)", "CC", "CCK"), + CO("Colombia", "CO", "COL"), + KM("Comoros (the)", "KM", "COM"), + CD("Congo (the Democratic Republic of the)", "CD", "COD"), + CG("Congo (the)", "CG", "COG"), + CK("Cook Islands (the)", "CK", "COK"), + CR("Costa Rica", "CR", "CRI"), + CI("Côte d'Ivoire", "CI", "CIV"), + HR("Croatia", "HR", "HRV"), + CU("Cuba", "CU", "CUB"), + CW("Curaçao", "CW", "CUW"), + CY("Cyprus", "CY", "CYP"), + CZ("Czechia", "CZ", "CZE"), + DK("Denmark", "DK", "DNK"), + DJ("Djibouti", "DJ", "DJI"), + DM("Dominica", "DM", "DMA"), + DO("Dominican Republic (the)", "DO", "DOM"), + EC("Ecuador", "EC", "ECU"), + EG("Egypt", "EG", "EGY"), + SV("El Salvador", "SV", "SLV"), + GQ("Equatorial Guinea", "GQ", "GNQ"), + ER("Eritrea", "ER", "ERI"), + EE("Estonia", "EE", "EST"), + SZ("Eswatini", "SZ", "SWZ"), + ET("Ethiopia", "ET", "ETH"), + FK("Falkland Islands (the) [Malvinas]", "FK", "FLK"), + FO("Faroe Islands (the)", "FO", "FRO"), + FJ("Fiji", "FJ", "FJI"), + FI("Finland", "FI", "FIN"), + FR("France", "FR", "FRA"), + GF("French Guiana", "GF", "GUF"), + PF("French Polynesia", "PF", "PYF"), + TF("French Southern Territories (the)", "TF", "ATF"), + GA("Gabon", "GA", "GAB"), + GM("Gambia (the)", "GM", "GMB"), + GE("Georgia", "GE", "GEO"), + DE("Germany", "DE", "DEU"), + GH("Ghana", "GH", "GHA"), + GI("Gibraltar", "GI", "GIB"), + GR("Greece", "GR", "GRC"), + GL("Greenland", "GL", "GRL"), + GD("Grenada", "GD", "GRD"), + GP("Guadeloupe", "GP", "GLP"), + GU("Guam", "GU", "GUM"), + GT("Guatemala", "GT", "GTM"), + GG("Guernsey", "GG", "GGY"), + GN("Guinea", "GN", "GIN"), + GW("Guinea-Bissau", "GW", "GNB"), + GY("Guyana", "GY", "GUY"), + HT("Haiti", "HT", "HTI"), + HM("Heard Island and McDonald Islands", "HM", "HMD"), + VA("Holy See (the)", "VA", "VAT"), + HN("Honduras", "HN", "HND"), + HK("Hong Kong", "HK", "HKG"), + HU("Hungary", "HU", "HUN"), + IS("Iceland", "IS", "ISL"), + IN("India", "IN", "IND"), + ID("Indonesia", "ID", "IDN"), + IR("Iran (Islamic Republic of)", "IR", "IRN"), + IQ("Iraq", "IQ", "IRQ"), + IE("Ireland", "IE", "IRL"), + IM("Isle of Man", "IM", "IMN"), + IL("Israel", "IL", "ISR"), + IT("Italy", "IT", "ITA"), + JM("Jamaica", "JM", "JAM"), + JP("Japan", "JP", "JPN"), + JE("Jersey", "JE", "JEY"), + JO("Jordan", "JO", "JOR"), + KZ("Kazakhstan", "KZ", "KAZ"), + KE("Kenya", "KE", "KEN"), + KI("Kiribati", "KI", "KIR"), + KP("Korea (the Democratic People's Republic of)", "KP", "PRK"), + KR("Korea (the Republic of)", "KR", "KOR"), + KW("Kuwait", "KW", "KWT"), + KG("Kyrgyzstan", "KG", "KGZ"), + LA("Lao People's Democratic Republic (the)", "LA", "LAO"), + LV("Latvia", "LV", "LVA"), + LB("Lebanon", "LB", "LBN"), + LS("Lesotho", "LS", "LSO"), + LR("Liberia", "LR", "LBR"), + LY("Libya", "LY", "LBY"), + LI("Liechtenstein", "LI", "LIE"), + LT("Lithuania", "LT", "LTU"), + LU("Luxembourg", "LU", "LUX"), + MO("Macao", "MO", "MAC"), + MG("Madagascar", "MG", "MDG"), + MW("Malawi", "MW", "MWI"), + MY("Malaysia", "MY", "MYS"), + MV("Maldives", "MV", "MDV"), + ML("Mali", "ML", "MLI"), + MT("Malta", "MT", "MLT"), + MH("Marshall Islands (the)", "MH", "MHL"), + MQ("Martinique", "MQ", "MTQ"), + MR("Mauritania", "MR", "MRT"), + MU("Mauritius", "MU", "MUS"), + YT("Mayotte", "YT", "MYT"), + MX("Mexico", "MX", "MEX"), + FM("Micronesia (Federated States of)", "FM", "FSM"), + MD("Moldova (the Republic of)", "MD", "MDA"), + MC("Monaco", "MC", "MCO"), + MN("Mongolia", "MN", "MNG"), + ME("Montenegro", "ME", "MNE"), + MS("Montserrat", "MS", "MSR"), + MA("Morocco", "MA", "MAR"), + MZ("Mozambique", "MZ", "MOZ"), + MM("Myanmar", "MM", "MMR"), + NA("Namibia", "NA", "NAM"), + NR("Nauru", "NR", "NRU"), + NP("Nepal", "NP", "NPL"), + NL("Netherlands (the)", "NL", "NLD"), + NC("New Caledonia", "NC", "NCL"), + NZ("New Zealand", "NZ", "NZL"), + NI("Nicaragua", "NI", "NIC"), + NE("Niger (the)", "NE", "NER"), + NG("Nigeria", "NG", "NGA"), + NU("Niue", "NU", "NIU"), + NF("Norfolk Island", "NF", "NFK"), + c("North Macedonia", "c", "MKD"), + MP("Northern Mariana Islands (the)", "MP", "MNP"), + NO("Norway", "NO", "NOR"), + OM("Oman", "OM", "OMN"), + PK("Pakistan", "PK", "PAK"), + PW("Palau", "PW", "PLW"), + PS("Palestine, State of", "PS", "PSE"), + PA("Panama", "PA", "PAN"), + PG("Papua New Guinea", "PG", "PNG"), + PY("Paraguay", "PY", "PRY"), + PE("Peru", "PE", "PER"), + PH("Philippines (the)", "PH", "PHL"), + PN("Pitcairn", "PN", "PCN"), + PL("Poland", "PL", "POL"), + PT("Portugal", "PT", "PRT"), + PR("Puerto Rico", "PR", "PRI"), + QA("Qatar", "QA", "QAT"), + RE("Réunion", "RE", "REU"), + RO("Romania", "RO", "ROU"), + RU("Russian Federation (the)", "RU", "RUS"), + RW("Rwanda", "RW", "RWA"), + BL("Saint Barthélemy", "BL", "BLM"), + SH("Saint Helena, Ascension and Tristan da Cunha", "SH", "SHN"), + KN("Saint Kitts and Nevis", "KN", "KNA"), + LC("Saint Lucia", "LC", "LCA"), + MF("Saint Martin (French part)", "MF", "MAF"), + PM("Saint Pierre and Miquelon", "PM", "SPM"), + VC("Saint Vincent and the Grenadines", "VC", "VCT"), + WS("Samoa", "WS", "WSM"), + SM("San Marino", "SM", "SMR"), + ST("Sao Tome and Principe", "ST", "STP"), + SA("Saudi Arabia", "SA", "SAU"), + SN("Senegal", "SN", "SEN"), + RS("Serbia", "RS", "SRB"), + SC("Seychelles", "SC", "SYC"), + SL("Sierra Leone", "SL", "SLE"), + SG("Singapore", "SG", "SGP"), + SX("Sint Maarten (Dutch part)", "SX", "SXM"), + SK("Slovakia", "SK", "SVK"), + SI("Slovenia", "SI", "SVN"), + SB("Solomon Islands", "SB", "SLB"), + SO("Somalia", "SO", "SOM"), + ZA("South Africa", "ZA", "ZAF"), + GS("South Georgia and the South Sandwich Islands", "GS", "SGS"), + SS("South Sudan", "SS", "SSD"), + ES("Spain", "ES", "ESP"), + LK("Sri Lanka", "LK", "LKA"), + SD("Sudan (the)", "SD", "SDN"), + SR("Suriname", "SR", "SUR"), + SJ("Svalbard and Jan Mayen", "SJ", "SJM"), + SE("Sweden", "SE", "SWE"), + CH("Switzerland", "CH", "CHE"), + SY("Syrian Arab Republic (the)", "SY", "SYR"), + TW("Taiwan (Province of China)", "TW", "TWN"), + TJ("Tajikistan", "TJ", "TJK"), + TZ("Tanzania, the United Republic of", "TZ", "TZA"), + TH("Thailand", "TH", "THA"), + TL("Timor-Leste", "TL", "TLS"), + TG("Togo", "TG", "TGO"), + TK("Tokelau", "TK", "TKL"), + TO("Tonga", "TO", "TON"), + TT("Trinidad and Tobago", "TT", "TTO"), + TN("Tunisia", "TN", "TUN"), + TR("Türkiye", "TR", "TUR"), + TM("Turkmenistan", "TM", "TKM"), + TC("Turks and Caicos Islands (the)", "TC", "TCA"), + TV("Tuvalu", "TV", "TUV"), + UG("Uganda", "UG", "UGA"), + UA("Ukraine", "UA", "UKR"), + AE("United Arab Emirates (the)", "AE", "ARE"), + GB("United Kingdom of Great Britain and Northern Ireland (the)", "GB", "GBR"), + UM("United States Minor Outlying Islands (the)", "UM", "UMI"), + US("United States of America (the)", "US", "USA"), + UY("Uruguay", "UY", "URY"), + UZ("Uzbekistan", "UZ", "UZB"), + VU("Vanuatu", "VU", "VUT"), + VE("Venezuela (Bolivarian Republic of)", "VE", "VEN"), + VN("Viet Nam", "VN", "VNM"), + VG("Virgin Islands (British)", "VG", "VGB"), + VI("Virgin Islands (U.S.)", "VI", "VIR"), + WF("Wallis and Futuna", "WF", "WLF"), + EH("Western Sahara*", "EH", "ESH"), + YE("Yemen", "YE", "YEM"), + ZM("Zambia", "ZM", "ZMB"), + ZW("Zimbabwe", "ZW", "ZWE"), + _1A("Kosovo", "1A", null), + XI("United Kingdom (Northern Ireland)", "XI", null), +} \ No newline at end of file diff --git a/e-invoice-spec-parser/src/main/kotlin/net/codinux/invoicing/parser/CodeGenerator.kt b/e-invoice-spec-parser/src/main/kotlin/net/codinux/invoicing/parser/CodeGenerator.kt index 40b7f0d..7c72e07 100644 --- a/e-invoice-spec-parser/src/main/kotlin/net/codinux/invoicing/parser/CodeGenerator.kt +++ b/e-invoice-spec-parser/src/main/kotlin/net/codinux/invoicing/parser/CodeGenerator.kt @@ -14,7 +14,7 @@ class CodeGenerator { matchedCodeLists.forEach { (type, codeLists) -> // ignore Currency and Country for now - if (type == CodeListType.IsoCurrencyCodes || type == CodeListType.IsoCountryCodes) { + if (type == CodeListType.IsoCurrencyCodes) { return@forEach } @@ -43,7 +43,7 @@ class CodeGenerator { // PaymentMeansCodeFacturX: ignore Sens private fun filter(columnsAndRows: Pair, List>>): Pair, List>> { val (columns, rows) = columnsAndRows - val columnToIgnore = columns.firstOrNull { it.name == "Source" || it.name == "Comment" || it.name == "Sens" } + val columnToIgnore = columns.firstOrNull { it.name == "Source" || it.name == "Comment" || it.name == "Sens" || it.name == "French Name" } if (columnToIgnore == null) { return columnsAndRows @@ -112,7 +112,10 @@ class CodeGenerator { } private fun getEnumName(columns: List, row: List): String { - val column = if (columns.first().name == "Scheme ID") row[1] else if (columns.first().name == "Country") row[2] else if (columns.first().name == "English Name") row[3] else row[0] + val column = if (columns.first().name == "Scheme ID") row[1] // ISO 6523 Scheme Identifier codes + else if (columns.first().name == "English Name") row[1] // Country codes + else if (columns.first().name == "Country") row[2] // Currency codes, but does not work yet due to duplicate Keys / Alpha3-Codes + else row[0] // default case: the code is in the first column val name = (column?.toString() ?: "").replace(' ', '_').replace('/', '_').replace('.', '_').replace(',', '_') .replace('-', '_').replace('(', '_').replace(')', '_').replace('[', '_').replace(']', '_') diff --git a/e-invoice-spec-parser/src/main/kotlin/net/codinux/invoicing/parser/excel/ZugferdExcelCodeListsParser.kt b/e-invoice-spec-parser/src/main/kotlin/net/codinux/invoicing/parser/excel/ZugferdExcelCodeListsParser.kt index 3bbd41a..d085618 100644 --- a/e-invoice-spec-parser/src/main/kotlin/net/codinux/invoicing/parser/excel/ZugferdExcelCodeListsParser.kt +++ b/e-invoice-spec-parser/src/main/kotlin/net/codinux/invoicing/parser/excel/ZugferdExcelCodeListsParser.kt @@ -15,7 +15,7 @@ class ZugferdExcelCodeListsParser { private val TableStartColumns = listOf("Code", "English Name", "Country", "Scheme ID") private val CodeListsWithDescription = listOf(CodeListType.UN_5189_AllowanceIdentificationCode, CodeListType.UN_7161_SpecialServiceDescriptionCodes, - CodeListType.IsoCountryCodes, CodeListType.UN_4451_TextSubjectCodeQualifier, CodeListType.UN_7143_ItemTypeIdentificationCode, CodeListType.UN_4461_PaymentCodes, CodeListType.UN_1153_ReferenceCode) + CodeListType.UN_4451_TextSubjectCodeQualifier, CodeListType.UN_7143_ItemTypeIdentificationCode, CodeListType.UN_4461_PaymentCodes, CodeListType.UN_1153_ReferenceCode) }