Fixed alpha-2 iso code of North Macedonia

This commit is contained in:
dankito 2024-12-12 22:31:21 +01:00
parent cef6565053
commit d923dcb3f0
2 changed files with 8 additions and 4 deletions

View File

@ -165,7 +165,7 @@ enum class Country(val alpha2Code: String, val alpha3Code: String?, val englishN
NG("NG", "NGA", "Nigeria"), NG("NG", "NGA", "Nigeria"),
NU("NU", "NIU", "Niue"), NU("NU", "NIU", "Niue"),
NF("NF", "NFK", "Norfolk Island"), NF("NF", "NFK", "Norfolk Island"),
c("c", "MKD", "North Macedonia"), MK("MK", "MKD", "North Macedonia"),
MP("MP", "MNP", "Northern Mariana Islands (the)"), MP("MP", "MNP", "Northern Mariana Islands (the)"),
NO("NO", "NOR", "Norway"), NO("NO", "NOR", "Norway"),
OM("OM", "OMN", "Oman"), OM("OM", "OMN", "Oman"),

View File

@ -82,7 +82,7 @@ class ZugferdExcelCodeListsParser {
val isFrequentlyUsedValue = cells.all { (it?.cellStyle?.fillForegroundColorColor as? XSSFColor)?.argbHex == "FF4BACC6" val isFrequentlyUsedValue = cells.all { (it?.cellStyle?.fillForegroundColorColor as? XSSFColor)?.argbHex == "FF4BACC6"
|| it?.columnIndex == sourceColumn?.columnIndex } // only the source column never has a background color || it?.columnIndex == sourceColumn?.columnIndex } // only the source column never has a background color
val values = cells.map { getCellValue(it) } + val values = cells.map { getCellValue(it, type) } +
( if (isTypeWithDescription) listOf(getCellValue(allRows.get(row.rowNum + 1).getCell(descriptionColumnIndex))) else emptyList()) ( if (isTypeWithDescription) listOf(getCellValue(allRows.get(row.rowNum + 1).getCell(descriptionColumnIndex))) else emptyList())
net.codinux.invoicing.parser.model.Row(values, isFrequentlyUsedValue) net.codinux.invoicing.parser.model.Row(values, isFrequentlyUsedValue)
}.filterNot { it.values.all { it == null } } // filter out empty rows }.filterNot { it.values.all { it == null } } // filter out empty rows
@ -125,13 +125,17 @@ class ZugferdExcelCodeListsParser {
return Column(cell.columnIndex, name, "String", name) return Column(cell.columnIndex, name, "String", name)
} }
private fun getCellValue(cell: Cell?) = when (cell?.cellType) { private fun getCellValue(cell: Cell?, type: CodeListType? = null) = when (cell?.cellType) {
CellType.STRING -> cell.stringCellValue.trim().takeUnless { it.isBlank() } CellType.STRING -> cell.stringCellValue.trim().takeUnless { it.isBlank() }?.let { sanitize(it, type) }
CellType.NUMERIC -> cell.numericCellValue.toInt() CellType.NUMERIC -> cell.numericCellValue.toInt()
CellType.BLANK -> null CellType.BLANK -> null
else -> null else -> null
} }
private fun sanitize(value: String, type: CodeListType?): String =
if (type == CodeListType.IsoCountryCodes && value == "c") "MK" // bug in Zugferd list, country code of NorthMacedonia is stated as "c" instead of "MK"
else value
private fun <T> Iterator<T>.toList(): List<T> = private fun <T> Iterator<T>.toList(): List<T> =
this.asSequence().toList() this.asSequence().toList()