diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/InvoiceType.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/InvoiceType.kt index 46f991b..1b88b0a 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/InvoiceType.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/InvoiceType.kt @@ -1,59 +1,59 @@ package net.codinux.invoicing.model.codes -enum class InvoiceType(val code: String, val meaning: String, val eN16931interpretation: String) { - _71("71", "Request for payment", "Invoice"), - _80("80", "Debit note related to goods or services", "Invoice"), - _81("81", "Credit note related to goods or services", "Credit Note"), - _82("82", "Metered services invoice", "Invoice"), - _83("83", "Credit note related to financial adjustments", "Credit Note"), - _84("84", "Debit note related to financial adjustments", "Invoice"), - _102("102", "Tax notification", "Invoice"), - _130("130", "Invoicing data sheet", "Invoice"), - _202("202", "Direct payment valuation", "Invoice"), - _203("203", "Provisional payment valuation", "Invoice"), - _204("204", "Payment valuation", "Invoice"), - _211("211", "Interim application for payment", "Invoice"), - _218("218", "Final payment request based on completion of work", "Invoice"), - _219("219", "Payment request for completed units", "Invoice"), - _261("261", "Self billed credit note", "Credit Note"), - _262("262", "Consolidated credit note - goods and services", "Credit Note"), - _295("295", "Price variation invoice", "Invoice"), - _296("296", "Credit note for price variation", "Credit Note"), - _308("308", "Delcredere credit note", "Credit Note"), - _325("325", "Proforma invoice", "Invoice"), - _326("326", "Partial invoice", "Invoice"), - _331("331", "Commercial invoice which includes a packing list", "Invoice"), - _380("380", "Commercial invoice", "Invoice"), - _381("381", "Credit note", "Credit Note"), - _382("382", "Commission note", "Invoice"), - _383("383", "Debit note", "Invoice"), - _384("384", "Corrected invoice", "Invoice"), - _385("385", "Consolidated invoice", "Invoice"), - _386("386", "Prepayment invoice", "Invoice"), - _387("387", "Hire invoice", "Invoice"), - _388("388", "Tax invoice", "Invoice"), - _389("389", "Self-billed invoice", "Invoice"), - _390("390", "Delcredere invoice", "Invoice"), - _393("393", "Factored invoice", "Invoice"), - _394("394", "Lease invoice", "Invoice"), - _395("395", "Consignment invoice", "Invoice"), - _396("396", "Factored credit note", "Credit Note"), - _420("420", "Optical Character Reading (OCR) payment credit note", "Credit Note"), - _456("456", "Debit advice", "Invoice"), - _457("457", "Reversal of debit", "Invoice"), - _458("458", "Reversal of credit", "Credit Note"), - _527("527", "Self billed debit note", "Invoice"), - _532("532", "Forwarder's credit note", "Credit Note"), - _553("553", "Forwarder's invoice discrepancy report", "Invoice"), - _575("575", "Insurer's invoice", "Invoice"), - _623("623", "Forwarder's invoice", "Invoice"), - _633("633", "Port charges documents", "Invoice"), - _751("751", "Invoice information for accounting purposes", "Invoice"), - _780("780", "Freight invoice", "Invoice"), - _817("817", "Claim notification", "Invoice"), - _870("870", "Consular invoice", "Invoice"), - _875("875", "Partial construction invoice", "Invoice"), - _876("876", "Partial final construction invoice", "Invoice"), - _877("877", "Final construction invoice", "Invoice"), - _935("935", "Customs invoice", "Invoice"), +enum class InvoiceType(val code: String, val meaning: String, val useFor: InvoiceTypeUseFor) { + _71("71", "Request for payment", InvoiceTypeUseFor.Invoice), + _80("80", "Debit note related to goods or services", InvoiceTypeUseFor.Invoice), + _81("81", "Credit note related to goods or services", InvoiceTypeUseFor.CreditNote), + _82("82", "Metered services invoice", InvoiceTypeUseFor.Invoice), + _83("83", "Credit note related to financial adjustments", InvoiceTypeUseFor.CreditNote), + _84("84", "Debit note related to financial adjustments", InvoiceTypeUseFor.Invoice), + _102("102", "Tax notification", InvoiceTypeUseFor.Invoice), + _130("130", "Invoicing data sheet", InvoiceTypeUseFor.Invoice), + _202("202", "Direct payment valuation", InvoiceTypeUseFor.Invoice), + _203("203", "Provisional payment valuation", InvoiceTypeUseFor.Invoice), + _204("204", "Payment valuation", InvoiceTypeUseFor.Invoice), + _211("211", "Interim application for payment", InvoiceTypeUseFor.Invoice), + _218("218", "Final payment request based on completion of work", InvoiceTypeUseFor.Invoice), + _219("219", "Payment request for completed units", InvoiceTypeUseFor.Invoice), + _261("261", "Self billed credit note", InvoiceTypeUseFor.CreditNote), + _262("262", "Consolidated credit note - goods and services", InvoiceTypeUseFor.CreditNote), + _295("295", "Price variation invoice", InvoiceTypeUseFor.Invoice), + _296("296", "Credit note for price variation", InvoiceTypeUseFor.CreditNote), + _308("308", "Delcredere credit note", InvoiceTypeUseFor.CreditNote), + _325("325", "Proforma invoice", InvoiceTypeUseFor.Invoice), + _326("326", "Partial invoice", InvoiceTypeUseFor.Invoice), + _331("331", "Commercial invoice which includes a packing list", InvoiceTypeUseFor.Invoice), + _380("380", "Commercial invoice", InvoiceTypeUseFor.Invoice), + _381("381", "Credit note", InvoiceTypeUseFor.CreditNote), + _382("382", "Commission note", InvoiceTypeUseFor.Invoice), + _383("383", "Debit note", InvoiceTypeUseFor.Invoice), + _384("384", "Corrected invoice", InvoiceTypeUseFor.Invoice), + _385("385", "Consolidated invoice", InvoiceTypeUseFor.Invoice), + _386("386", "Prepayment invoice", InvoiceTypeUseFor.Invoice), + _387("387", "Hire invoice", InvoiceTypeUseFor.Invoice), + _388("388", "Tax invoice", InvoiceTypeUseFor.Invoice), + _389("389", "Self-billed invoice", InvoiceTypeUseFor.Invoice), + _390("390", "Delcredere invoice", InvoiceTypeUseFor.Invoice), + _393("393", "Factored invoice", InvoiceTypeUseFor.Invoice), + _394("394", "Lease invoice", InvoiceTypeUseFor.Invoice), + _395("395", "Consignment invoice", InvoiceTypeUseFor.Invoice), + _396("396", "Factored credit note", InvoiceTypeUseFor.CreditNote), + _420("420", "Optical Character Reading (OCR) payment credit note", InvoiceTypeUseFor.CreditNote), + _456("456", "Debit advice", InvoiceTypeUseFor.Invoice), + _457("457", "Reversal of debit", InvoiceTypeUseFor.Invoice), + _458("458", "Reversal of credit", InvoiceTypeUseFor.CreditNote), + _527("527", "Self billed debit note", InvoiceTypeUseFor.Invoice), + _532("532", "Forwarder's credit note", InvoiceTypeUseFor.CreditNote), + _553("553", "Forwarder's invoice discrepancy report", InvoiceTypeUseFor.Invoice), + _575("575", "Insurer's invoice", InvoiceTypeUseFor.Invoice), + _623("623", "Forwarder's invoice", InvoiceTypeUseFor.Invoice), + _633("633", "Port charges documents", InvoiceTypeUseFor.Invoice), + _751("751", "Invoice information for accounting purposes", InvoiceTypeUseFor.Invoice), + _780("780", "Freight invoice", InvoiceTypeUseFor.Invoice), + _817("817", "Claim notification", InvoiceTypeUseFor.Invoice), + _870("870", "Consular invoice", InvoiceTypeUseFor.Invoice), + _875("875", "Partial construction invoice", InvoiceTypeUseFor.Invoice), + _876("876", "Partial final construction invoice", InvoiceTypeUseFor.Invoice), + _877("877", "Final construction invoice", InvoiceTypeUseFor.Invoice), + _935("935", "Customs invoice", InvoiceTypeUseFor.Invoice), } \ No newline at end of file diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/InvoiceTypeUseFor.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/InvoiceTypeUseFor.kt new file mode 100644 index 0000000..fdec042 --- /dev/null +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/codes/InvoiceTypeUseFor.kt @@ -0,0 +1,7 @@ +package net.codinux.invoicing.model.codes + +enum class InvoiceTypeUseFor { + Invoice, + + CreditNote +} \ 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 999507f..40b7f0d 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 @@ -1,5 +1,6 @@ package net.codinux.invoicing.parser +import net.codinux.invoicing.model.codes.InvoiceTypeUseFor import net.codinux.invoicing.parser.genericode.CodeList import net.codinux.invoicing.parser.model.CodeListType import net.codinux.invoicing.parser.model.Column @@ -18,8 +19,8 @@ class CodeGenerator { } // Factur-X has the better column names and often also a Description column - val (columns, rows) = filter(if (codeLists.second != null) codeLists.second!!.columns to codeLists.second!!.rows - else codeLists.first.columns to codeLists.first.rows) + val (columns, rows) = 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") @@ -27,7 +28,7 @@ class CodeGenerator { writer.appendLine("enum class ${type.className}(${columns.joinToString(", ") { "val ${getPropertyName(it)}: ${getDataType(it, columns, rows)}" } }) {") rows.forEach { row -> - writer.appendLine("\t${getEnumName(columns, row)}(${row.joinToString(", ") { it?.let { "\"${it.toString().replace("\n", "").replace('"', '\'')}\"" } ?: "null" } }),") + writer.appendLine("\t${getEnumName(columns, row)}(${row.joinToString(", ") { getPropertyValue(it) } }),") } writer.append("}") } @@ -52,6 +53,27 @@ class CodeGenerator { return columns.filterIndexed { index, _ -> index != indexToIgnore } to rows.map { it.filterIndexed { index, _ -> index != indexToIgnore } } } + private fun map(columnsAndRows: Pair, List>>): Pair, List>> { + val (columns, rows) = columnsAndRows + val useForColumn = columns.firstOrNull { it.name == "EN16931 interpretation" } + + if (useForColumn != null) { + val index = columns.indexOf(useForColumn) + val modifiedColumns = columns.toMutableList().apply { + removeAt(index) + add(Column(columns.last().index + 1, "UseFor", "InvoiceTypeUseFor", "UseFor")) + } + val modifiedRows = rows.map { it.toMutableList().apply { + val useFor = removeAt(index)?.toString() + add(if (useFor == "Credit Note") InvoiceTypeUseFor.CreditNote else InvoiceTypeUseFor.Invoice) + }} + + return modifiedColumns to modifiedRows + } + + return columnsAndRows + } + private fun getPropertyName(column: Column): String = when (column.name) { "Unique code" -> "code" @@ -67,6 +89,18 @@ class CodeGenerator { else -> column.name.replace(" ", "").let { it[0].lowercase() + it.substring(1) } } + private fun getPropertyValue(value: Any?): CharSequence { + if (value == null) { + return "null" + } + + if (value is InvoiceTypeUseFor) { + return "InvoiceTypeUseFor.$value" + } + + return "\"${value.toString().replace("\n", "").replace('"', '\'')}\"" + } + private fun getDataType(column: Column, columns: List, rows: List>): String { val index = columns.indexOf(column) val containsNullValues = rows.any { it[index] == null }