From d923dcb3f05ddebc43c8b0063a769ff34d51755a Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 12 Dec 2024 22:31:21 +0100 Subject: [PATCH] Fixed alpha-2 iso code of North Macedonia --- .../net/codinux/invoicing/model/codes/Country.kt | 2 +- .../parser/excel/ZugferdExcelCodeListsParser.kt | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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 index 8682c10..94499df 100644 --- 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 @@ -165,7 +165,7 @@ enum class Country(val alpha2Code: String, val alpha3Code: String?, val englishN NG("NG", "NGA", "Nigeria"), NU("NU", "NIU", "Niue"), NF("NF", "NFK", "Norfolk Island"), - c("c", "MKD", "North Macedonia"), + MK("MK", "MKD", "North Macedonia"), MP("MP", "MNP", "Northern Mariana Islands (the)"), NO("NO", "NOR", "Norway"), OM("OM", "OMN", "Oman"), 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 95bccbd..751a12b 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 @@ -82,7 +82,7 @@ class ZugferdExcelCodeListsParser { val isFrequentlyUsedValue = cells.all { (it?.cellStyle?.fillForegroundColorColor as? XSSFColor)?.argbHex == "FF4BACC6" || 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()) net.codinux.invoicing.parser.model.Row(values, isFrequentlyUsedValue) }.filterNot { it.values.all { it == null } } // filter out empty rows @@ -125,13 +125,17 @@ class ZugferdExcelCodeListsParser { return Column(cell.columnIndex, name, "String", name) } - private fun getCellValue(cell: Cell?) = when (cell?.cellType) { - CellType.STRING -> cell.stringCellValue.trim().takeUnless { it.isBlank() } + private fun getCellValue(cell: Cell?, type: CodeListType? = null) = when (cell?.cellType) { + CellType.STRING -> cell.stringCellValue.trim().takeUnless { it.isBlank() }?.let { sanitize(it, type) } CellType.NUMERIC -> cell.numericCellValue.toInt() CellType.BLANK -> 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 Iterator.toList(): List = this.asSequence().toList()