Implemented mapping Currency codes

This commit is contained in:
dankito 2024-12-04 22:47:07 +01:00
parent 0fee651114
commit df9e554d3e
2 changed files with 215 additions and 6 deletions

View File

@ -0,0 +1,184 @@
package net.codinux.invoicing.model.codes
enum class Currency(val alpha3Code: String, val currencySymbol: String?, val englishName: String, val countries: Set<String>) {
AED("AED", "AED", "UAE Dirham", setOf("UNITED ARAB EMIRATES (THE)")),
AFN("AFN", "AFN", "Afghani", setOf("AFGHANISTAN")),
ALL("ALL", "ALL", "Lek", setOf("ALBANIA")),
AMD("AMD", "AMD", "Armenian Dram", setOf("ARMENIA")),
ANG("ANG", "ANG", "Netherlands Antillean Guilder", setOf("CURAÇAO", "SINT MAARTEN (DUTCH PART)")),
AOA("AOA", "AOA", "Kwanza", setOf("ANGOLA")),
ARS("ARS", "ARS", "Argentine Peso", setOf("ARGENTINA")),
AUD("AUD", "A$", "Australian Dollar", setOf("AUSTRALIA", "CHRISTMAS ISLAND", "COCOS (KEELING) ISLANDS (THE)", "HEARD ISLAND AND McDONALD ISLANDS", "KIRIBATI", "NAURU", "NORFOLK ISLAND", "TUVALU")),
AWG("AWG", "AWG", "Aruban Florin", setOf("ARUBA")),
AZN("AZN", "AZN", "Azerbaijan Manat", setOf("AZERBAIJAN")),
BAM("BAM", "BAM", "Convertible Mark", setOf("BOSNIA AND HERZEGOVINA")),
BBD("BBD", "BBD", "Barbados Dollar", setOf("BARBADOS")),
BDT("BDT", "BDT", "Taka", setOf("BANGLADESH")),
BGN("BGN", "BGN", "Bulgarian Lev", setOf("BULGARIA")),
BHD("BHD", "BHD", "Bahraini Dinar", setOf("BAHRAIN")),
BIF("BIF", "BIF", "Burundi Franc", setOf("BURUNDI")),
BMD("BMD", "BMD", "Bermudian Dollar", setOf("BERMUDA")),
BND("BND", "BND", "Brunei Dollar", setOf("BRUNEI DARUSSALAM")),
BOB("BOB", "BOB", "Boliviano", setOf("BOLIVIA (PLURINATIONAL STATE OF)")),
BOV("BOV", "BOV", "Mvdol", setOf("BOLIVIA (PLURINATIONAL STATE OF)")),
BRL("BRL", "R$", "Brazilian Real", setOf("BRAZIL")),
BSD("BSD", "BSD", "Bahamian Dollar", setOf("BAHAMAS (THE)")),
BTN("BTN", "BTN", "Ngultrum", setOf("BHUTAN")),
BWP("BWP", "BWP", "Pula", setOf("BOTSWANA")),
BYN("BYN", "BYN", "Belarusian Ruble", setOf("BELARUS")),
BZD("BZD", "BZD", "Belize Dollar", setOf("BELIZE")),
CAD("CAD", "CA$", "Canadian Dollar", setOf("CANADA")),
CDF("CDF", "CDF", "Congolese Franc", setOf("CONGO (THE DEMOCRATIC REPUBLIC OF THE)")),
CHE("CHE", "CHE", "WIR Euro", setOf("SWITZERLAND")),
CHF("CHF", "CHF", "Swiss Franc", setOf("LIECHTENSTEIN", "SWITZERLAND")),
CHW("CHW", "CHW", "WIR Franc", setOf("SWITZERLAND")),
CLF("CLF", "CLF", "Unidad de Fomento", setOf("CHILE")),
CLP("CLP", "CLP", "Chilean Peso", setOf("CHILE")),
CNY("CNY", "CN¥", "Yuan Renminbi", setOf("CHINA")),
COP("COP", "COP", "Colombian Peso", setOf("COLOMBIA")),
COU("COU", "COU", "Unidad de Valor Real", setOf("COLOMBIA")),
CRC("CRC", "CRC", "Costa Rican Colon", setOf("COSTA RICA")),
CUC("CUC", "CUC", "Peso Convertible", setOf("CUBA")),
CUP("CUP", "CUP", "Cuban Peso", setOf("CUBA")),
CVE("CVE", "CVE", "Cabo Verde Escudo", setOf("CABO VERDE")),
CZK("CZK", "CZK", "Czech Koruna", setOf("CZECHIA")),
DJF("DJF", "DJF", "Djibouti Franc", setOf("DJIBOUTI")),
DKK("DKK", "DKK", "Danish Krone", setOf("DENMARK", "FAROE ISLANDS (THE)", "GREENLAND")),
DOP("DOP", "DOP", "Dominican Peso", setOf("DOMINICAN REPUBLIC (THE)")),
DZD("DZD", "DZD", "Algerian Dinar", setOf("ALGERIA")),
EGP("EGP", "EGP", "Egyptian Pound", setOf("EGYPT")),
ERN("ERN", "ERN", "Nakfa", setOf("ERITREA")),
ETB("ETB", "ETB", "Ethiopian Birr", setOf("ETHIOPIA")),
EUR("EUR", "", "Euro", setOf("ÅLAND ISLANDS", "ANDORRA", "AUSTRIA", "BELGIUM", "CYPRUS", "ESTONIA", "EUROPEAN UNION", "FINLAND", "FRANCE", "FRENCH GUIANA", "FRENCH SOUTHERN TERRITORIES (THE)", "GERMANY", "GREECE", "GUADELOUPE", "HOLY SEE (THE)", "IRELAND", "ITALY", "LATVIA", "LITHUANIA", "LUXEMBOURG", "MALTA", "MARTINIQUE", "MAYOTTE", "MONACO", "MONTENEGRO", "NETHERLANDS (THE)", "PORTUGAL", "RÉUNION", "SAINT BARTHÉLEMY", "SAINT MARTIN (FRENCH PART)", "SAINT PIERRE AND MIQUELON", "SAN MARINO", "SLOVAKIA", "SLOVENIA", "SPAIN")),
FJD("FJD", "FJD", "Fiji Dollar", setOf("FIJI")),
FKP("FKP", "FKP", "Falkland Islands Pound", setOf("FALKLAND ISLANDS (THE) [MALVINAS]")),
GBP("GBP", "£", "Pound Sterling", setOf("GUERNSEY", "ISLE OF MAN", "JERSEY", "UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN IRELAND (THE)")),
GEL("GEL", "GEL", "Lari", setOf("GEORGIA")),
GHS("GHS", "GHS", "Ghana Cedi", setOf("GHANA")),
GIP("GIP", "GIP", "Gibraltar Pound", setOf("GIBRALTAR")),
GMD("GMD", "GMD", "Dalasi", setOf("GAMBIA (THE)")),
GNF("GNF", "GNF", "Guinean Franc", setOf("GUINEA")),
GTQ("GTQ", "GTQ", "Quetzal", setOf("GUATEMALA")),
GYD("GYD", "GYD", "Guyana Dollar", setOf("GUYANA")),
HKD("HKD", "HK$", "Hong Kong Dollar", setOf("HONG KONG")),
HNL("HNL", "HNL", "Lempira", setOf("HONDURAS")),
HTG("HTG", "HTG", "Gourde", setOf("HAITI")),
HUF("HUF", "HUF", "Forint", setOf("HUNGARY")),
IDR("IDR", "IDR", "Rupiah", setOf("INDONESIA")),
ILS("ILS", "", "New Israeli Sheqel", setOf("ISRAEL")),
INR("INR", "", "Indian Rupee", setOf("BHUTAN", "INDIA")),
IQD("IQD", "IQD", "Iraqi Dinar", setOf("IRAQ")),
IRR("IRR", "IRR", "Iranian Rial", setOf("IRAN (ISLAMIC REPUBLIC OF)")),
ISK("ISK", "ISK", "Iceland Krona", setOf("ICELAND")),
JMD("JMD", "JMD", "Jamaican Dollar", setOf("JAMAICA")),
JOD("JOD", "JOD", "Jordanian Dinar", setOf("JORDAN")),
JPY("JPY", "¥", "Yen", setOf("JAPAN")),
KES("KES", "KES", "Kenyan Shilling", setOf("KENYA")),
KGS("KGS", "KGS", "Som", setOf("KYRGYZSTAN")),
KHR("KHR", "KHR", "Riel", setOf("CAMBODIA")),
KMF("KMF", "KMF", "Comorian Franc", setOf("COMOROS (THE)")),
KPW("KPW", "KPW", "North Korean Won", setOf("KOREA (THE DEMOCRATIC PEOPLES REPUBLIC OF)")),
KRW("KRW", "", "Won", setOf("KOREA (THE REPUBLIC OF)")),
KWD("KWD", "KWD", "Kuwaiti Dinar", setOf("KUWAIT")),
KYD("KYD", "KYD", "Cayman Islands Dollar", setOf("CAYMAN ISLANDS (THE)")),
KZT("KZT", "KZT", "Tenge", setOf("KAZAKHSTAN")),
LAK("LAK", "LAK", "Lao Kip", setOf("LAO PEOPLES DEMOCRATIC REPUBLIC (THE)")),
LBP("LBP", "LBP", "Lebanese Pound", setOf("LEBANON")),
LKR("LKR", "LKR", "Sri Lanka Rupee", setOf("SRI LANKA")),
LRD("LRD", "LRD", "Liberian Dollar", setOf("LIBERIA")),
LSL("LSL", "LSL", "Loti", setOf("LESOTHO")),
LYD("LYD", "LYD", "Libyan Dinar", setOf("LIBYA")),
MAD("MAD", "MAD", "Moroccan Dirham", setOf("MOROCCO", "WESTERN SAHARA")),
MDL("MDL", "MDL", "Moldovan Leu", setOf("MOLDOVA (THE REPUBLIC OF)")),
MGA("MGA", "MGA", "Malagasy Ariary", setOf("MADAGASCAR")),
MKD("MKD", "MKD", "Denar", setOf("MACEDONIA (THE FORMER YUGOSLAV REPUBLIC OF)")),
MMK("MMK", "MMK", "Kyat", setOf("MYANMAR")),
MNT("MNT", "MNT", "Tugrik", setOf("MONGOLIA")),
MOP("MOP", "MOP", "Pataca", setOf("MACAO")),
MRU("MRU", "MRU", "Ouguiya", setOf("MAURITANIA")),
MUR("MUR", "MUR", "Mauritius Rupee", setOf("MAURITIUS")),
MVR("MVR", "MVR", "Rufiyaa", setOf("MALDIVES")),
MWK("MWK", "MWK", "Malawi Kwacha", setOf("MALAWI")),
MXN("MXN", "MX$", "Mexican Peso", setOf("MEXICO")),
MXV("MXV", "MXV", "Mexican Unidad de Inversion (UDI)", setOf("MEXICO")),
MYR("MYR", "MYR", "Malaysian Ringgit", setOf("MALAYSIA")),
MZN("MZN", "MZN", "Mozambique Metical", setOf("MOZAMBIQUE")),
NAD("NAD", "NAD", "Namibia Dollar", setOf("NAMIBIA")),
NGN("NGN", "NGN", "Naira", setOf("NIGERIA")),
NIO("NIO", "NIO", "Cordoba Oro", setOf("NICARAGUA")),
NOK("NOK", "NOK", "Norwegian Krone", setOf("BOUVET ISLAND", "NORWAY", "SVALBARD AND JAN MAYEN")),
NPR("NPR", "NPR", "Nepalese Rupee", setOf("NEPAL")),
NZD("NZD", "NZ$", "New Zealand Dollar", setOf("COOK ISLANDS (THE)", "NEW ZEALAND", "NIUE", "PITCAIRN", "TOKELAU")),
OMR("OMR", "OMR", "Rial Omani", setOf("OMAN")),
PAB("PAB", "PAB", "Balboa", setOf("PANAMA")),
PEN("PEN", "PEN", "Sol", setOf("PERU")),
PGK("PGK", "PGK", "Kina", setOf("PAPUA NEW GUINEA")),
PHP("PHP", "", "Philippine Peso", setOf("PHILIPPINES (THE)")),
PKR("PKR", "PKR", "Pakistan Rupee", setOf("PAKISTAN")),
PLN("PLN", "PLN", "Zloty", setOf("POLAND")),
PYG("PYG", "PYG", "Guarani", setOf("PARAGUAY")),
QAR("QAR", "QAR", "Qatari Rial", setOf("QATAR")),
RON("RON", "RON", "Romanian Leu", setOf("ROMANIA")),
RSD("RSD", "RSD", "Serbian Dinar", setOf("SERBIA")),
RUB("RUB", "RUB", "Russian Ruble", setOf("RUSSIAN FEDERATION (THE)")),
RWF("RWF", "RWF", "Rwanda Franc", setOf("RWANDA")),
SAR("SAR", "SAR", "Saudi Riyal", setOf("SAUDI ARABIA")),
SBD("SBD", "SBD", "Solomon Islands Dollar", setOf("SOLOMON ISLANDS")),
SCR("SCR", "SCR", "Seychelles Rupee", setOf("SEYCHELLES")),
SDG("SDG", "SDG", "Sudanese Pound", setOf("SUDAN (THE)")),
SEK("SEK", "SEK", "Swedish Krona", setOf("SWEDEN")),
SGD("SGD", "SGD", "Singapore Dollar", setOf("SINGAPORE")),
SHP("SHP", "SHP", "Saint Helena Pound", setOf("SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA")),
SLE("SLE", "SLE", "Sierra Leone (new valuation 2022)", setOf("SIERRA LEONE (new valuation 2022)")),
SOS("SOS", "SOS", "Somali Shilling", setOf("SOMALIA")),
SRD("SRD", "SRD", "Surinam Dollar", setOf("SURINAME")),
SSP("SSP", "SSP", "South Sudanese Pound", setOf("SOUTH SUDAN")),
STN("STN", "STN", "Dobra", setOf("SAO TOME AND PRINCIPE")),
SVC("SVC", "SVC", "El Salvador Colon", setOf("EL SALVADOR")),
SYP("SYP", "SYP", "Syrian Pound", setOf("SYRIAN ARAB REPUBLIC")),
SZL("SZL", "SZL", "Lilangeni", setOf("ESWATINI")),
THB("THB", "THB", "Baht", setOf("THAILAND")),
TJS("TJS", "TJS", "Somoni", setOf("TAJIKISTAN")),
TMT("TMT", "TMT", "Turkmenistan New Manat", setOf("TURKMENISTAN")),
TND("TND", "TND", "Tunisian Dinar", setOf("TUNISIA")),
TOP("TOP", "TOP", "Paanga", setOf("TONGA")),
TRY("TRY", "TRY", "Turkish Lira", setOf("TURKEY")),
TTD("TTD", "TTD", "Trinidad and Tobago Dollar", setOf("TRINIDAD AND TOBAGO")),
TWD("TWD", "NT$", "New Taiwan Dollar", setOf("TAIWAN (PROVINCE OF CHINA)")),
TZS("TZS", "TZS", "Tanzanian Shilling", setOf("TANZANIA, UNITED REPUBLIC OF")),
UAH("UAH", "UAH", "Hryvnia", setOf("UKRAINE")),
UGX("UGX", "UGX", "Uganda Shilling", setOf("UGANDA")),
USD("USD", "$", "US Dollar", setOf("AMERICAN SAMOA", "BONAIRE, SINT EUSTATIUS AND SABA", "BRITISH INDIAN OCEAN TERRITORY (THE)", "ECUADOR", "EL SALVADOR", "GUAM", "HAITI", "MARSHALL ISLANDS (THE)", "MICRONESIA (FEDERATED STATES OF)", "NORTHERN MARIANA ISLANDS (THE)", "PALAU", "PANAMA", "PUERTO RICO", "TIMOR-LESTE", "TURKS AND CAICOS ISLANDS (THE)", "UNITED STATES MINOR OUTLYING ISLANDS (THE)", "UNITED STATES OF AMERICA (THE)", "VIRGIN ISLANDS (BRITISH)", "VIRGIN ISLANDS (U.S.)")),
USN("USN", "USN", "US Dollar (Next day)", setOf("UNITED STATES OF AMERICA (THE)")),
UYI("UYI", "UYI", "Uruguay Peso en Unidades Indexadas (UI)", setOf("URUGUAY")),
UYU("UYU", "UYU", "Peso Uruguayo", setOf("URUGUAY")),
UYW("UYW", null, "Unidad Previsional", setOf("URUGUAY")),
UZS("UZS", "UZS", "Uzbekistan Sum", setOf("UZBEKISTAN")),
VED("VED", "VED", "Bolívar Soberano, new valuation", emptySet()),
VES("VES", "VES", "Bolívar Soberano", setOf("VENEZUELA (BOLIVARIAN REPUBLIC OF)")),
VND("VND", "", "Dong", setOf("VIET NAM")),
VUV("VUV", "VUV", "Vatu", setOf("VANUATU")),
WST("WST", "WST", "Tala", setOf("SAMOA")),
XAF("XAF", "FCFA", "CFA Franc BEAC", setOf("CAMEROON", "CENTRAL AFRICAN REPUBLIC (THE)", "CHAD", "CONGO (THE)", "EQUATORIAL GUINEA", "GABON")),
XAG("XAG", "XAG", "Silver", setOf("ZZ11_Silver")),
XAU("XAU", "XAU", "Gold", setOf("ZZ08_Gold")),
XBA("XBA", "XBA", "Bond Markets Unit European Composite Unit (EURCO)", setOf("ZZ01_Bond Markets Unit European_EURCO")),
XBB("XBB", "XBB", "Bond Markets Unit European Monetary Unit (E.M.U.-6)", setOf("ZZ02_Bond Markets Unit European_EMU-6")),
XBC("XBC", "XBC", "Bond Markets Unit European Unit of Account 9 (E.U.A.-9)", setOf("ZZ03_Bond Markets Unit European_EUA-9")),
XBD("XBD", "XBD", "Bond Markets Unit European Unit of Account 17 (E.U.A.-17)", setOf("ZZ04_Bond Markets Unit European_EUA-17")),
XCD("XCD", "EC$", "East Caribbean Dollar", setOf("ANGUILLA", "ANTIGUA AND BARBUDA", "DOMINICA", "GRENADA", "MONTSERRAT", "SAINT KITTS AND NEVIS", "SAINT LUCIA", "SAINT VINCENT AND THE GRENADINES")),
XDR("XDR", "XDR", "SDR (Special Drawing Right)", setOf("INTERNATIONAL MONETARY FUND (IMF)")),
XOF("XOF", "FCFA", "CFA Franc BCEAO", setOf("BENIN", "BURKINA FASO", "CÔTE D'IVOIRE", "GUINEA-BISSAU", "MALI", "NIGER (THE)", "SENEGAL", "TOGO")),
XPD("XPD", "XPD", "Palladium", setOf("ZZ09_Palladium")),
XPF("XPF", "CFPF", "CFP Franc", setOf("FRENCH POLYNESIA", "NEW CALEDONIA", "WALLIS AND FUTUNA")),
XPT("XPT", "XPT", "Platinum", setOf("ZZ10_Platinum")),
XSU("XSU", "XSU", "Sucre", setOf("SISTEMA UNITARIO DE COMPENSACION REGIONAL DE PAGOS 'SUCRE'")),
XTS("XTS", "XTS", "Codes specifically reserved for testing purposes", setOf("ZZ06_Testing_Code")),
XUA("XUA", "XUA", "ADB Unit of Account", setOf("MEMBER COUNTRIES OF THE AFRICAN DEVELOPMENT BANK GROUP")),
XXX("XXX", "¤", "The codes assigned for transactions where no currency is involved", setOf("ZZ07_No_Currency")),
YER("YER", "YER", "Yemeni Rial", setOf("YEMEN")),
ZAR("ZAR", "ZAR", "Rand", setOf("LESOTHO", "NAMIBIA", "SOUTH AFRICA")),
ZMW("ZMW", "ZMW", "Zambian Kwacha", setOf("ZAMBIA")),
ZWG("ZWG", null, "Zimbabwe Gold", emptySet()),
ZWL("ZWL", "ZWL", "Zimbabwe Dollar", setOf("ZIMBABWE")),
}

View File

@ -5,6 +5,7 @@ import net.codinux.invoicing.parser.genericode.CodeList
import net.codinux.invoicing.parser.model.CodeListType
import net.codinux.invoicing.parser.model.Column
import java.io.File
import java.util.Currency
class CodeGenerator {
@ -13,14 +14,14 @@ class CodeGenerator {
val matchedCodeLists = cefCodeLists.associateBy { it.type }.mapValues { it.value to zugferdCodeListsByType[it.key] }
matchedCodeLists.forEach { (type, codeLists) ->
// ignore Currency and Country for now
if (type == CodeListType.IsoCurrencyCodes) {
return@forEach
val (columns, rows) = if (type == CodeListType.IsoCurrencyCodes) mergeCurrencyData(codeLists.first, codeLists.second!!) else {
// Factur-X has the better column names and often also a Description column
reorder(map(filter(
if (codeLists.second != null) codeLists.second!!.columns to codeLists.second!!.rows
else codeLists.first.columns to codeLists.first.rows
)))
}
// Factur-X has the better column names and often also a Description column
val (columns, rows) = reorder(map(filter(if (codeLists.second != null) codeLists.second!!.columns to codeLists.second!!.rows
else codeLists.first.columns to codeLists.first.rows)))
File(outputDirectory, type.className + ".kt").bufferedWriter().use { writer ->
writer.appendLine("package net.codinux.invoicing.model.codes")
@ -99,6 +100,26 @@ class CodeGenerator {
return columnsAndRows
}
private fun mergeCurrencyData(cefCodeList: CodeList, zugferdCodeList: net.codinux.invoicing.parser.excel.CodeList): Pair<List<Column>, List<List<Any?>>> {
val columns = listOf(
Column(0, "alpha3Code", "String", "alpha3Code"),
Column(1, "currencySymbol", "String", "currencySymbol"),
Column(2, "englishName", "String", "englishName"),
Column(3, "countries", "Set<String>", "countries")
)
val cefByIsoCode = cefCodeList.rows.associateBy { it[0] }
val zugferdByIsoCode = zugferdCodeList.rows.groupBy { it[2] }
val availableCurrencies = Currency.getAvailableCurrencies().associateBy { it.currencyCode } // TODO: there are 52 currencies in availableCurrencies that are not in CEF and Zugferd list
val rows = cefByIsoCode.map { (isoCode, cefRow) ->
val zugferdRows = zugferdByIsoCode[isoCode] ?: emptyList()
listOf(isoCode, availableCurrencies[isoCode]?.symbol, cefRow[1], zugferdRows.map { it[0] }.toSet())
}
return columns to rows
}
private fun getPropertyName(column: Column): String = when (column.name) {
"Unique code" -> "code"
@ -123,6 +144,10 @@ class CodeGenerator {
return "InvoiceTypeUseFor.$value"
}
if (value is Set<*>) {
return if (value.isEmpty()) "emptySet()" else "setOf(${value.joinToString(", ") { getPropertyValue(it) } })"
}
return "\"${value.toString().replace("\n", "").replace('"', '\'')}\""
}