Implemented mapping "Invoice"|"Credit Note" to InvoiceTypeUseFor
This commit is contained in:
parent
83963c436f
commit
6874567875
|
@ -1,59 +1,59 @@
|
||||||
package net.codinux.invoicing.model.codes
|
package net.codinux.invoicing.model.codes
|
||||||
|
|
||||||
enum class InvoiceType(val code: String, val meaning: String, val eN16931interpretation: String) {
|
enum class InvoiceType(val code: String, val meaning: String, val useFor: InvoiceTypeUseFor) {
|
||||||
_71("71", "Request for payment", "Invoice"),
|
_71("71", "Request for payment", InvoiceTypeUseFor.Invoice),
|
||||||
_80("80", "Debit note related to goods or services", "Invoice"),
|
_80("80", "Debit note related to goods or services", InvoiceTypeUseFor.Invoice),
|
||||||
_81("81", "Credit note related to goods or services", "Credit Note"),
|
_81("81", "Credit note related to goods or services", InvoiceTypeUseFor.CreditNote),
|
||||||
_82("82", "Metered services invoice", "Invoice"),
|
_82("82", "Metered services invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_83("83", "Credit note related to financial adjustments", "Credit Note"),
|
_83("83", "Credit note related to financial adjustments", InvoiceTypeUseFor.CreditNote),
|
||||||
_84("84", "Debit note related to financial adjustments", "Invoice"),
|
_84("84", "Debit note related to financial adjustments", InvoiceTypeUseFor.Invoice),
|
||||||
_102("102", "Tax notification", "Invoice"),
|
_102("102", "Tax notification", InvoiceTypeUseFor.Invoice),
|
||||||
_130("130", "Invoicing data sheet", "Invoice"),
|
_130("130", "Invoicing data sheet", InvoiceTypeUseFor.Invoice),
|
||||||
_202("202", "Direct payment valuation", "Invoice"),
|
_202("202", "Direct payment valuation", InvoiceTypeUseFor.Invoice),
|
||||||
_203("203", "Provisional payment valuation", "Invoice"),
|
_203("203", "Provisional payment valuation", InvoiceTypeUseFor.Invoice),
|
||||||
_204("204", "Payment valuation", "Invoice"),
|
_204("204", "Payment valuation", InvoiceTypeUseFor.Invoice),
|
||||||
_211("211", "Interim application for payment", "Invoice"),
|
_211("211", "Interim application for payment", InvoiceTypeUseFor.Invoice),
|
||||||
_218("218", "Final payment request based on completion of work", "Invoice"),
|
_218("218", "Final payment request based on completion of work", InvoiceTypeUseFor.Invoice),
|
||||||
_219("219", "Payment request for completed units", "Invoice"),
|
_219("219", "Payment request for completed units", InvoiceTypeUseFor.Invoice),
|
||||||
_261("261", "Self billed credit note", "Credit Note"),
|
_261("261", "Self billed credit note", InvoiceTypeUseFor.CreditNote),
|
||||||
_262("262", "Consolidated credit note - goods and services", "Credit Note"),
|
_262("262", "Consolidated credit note - goods and services", InvoiceTypeUseFor.CreditNote),
|
||||||
_295("295", "Price variation invoice", "Invoice"),
|
_295("295", "Price variation invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_296("296", "Credit note for price variation", "Credit Note"),
|
_296("296", "Credit note for price variation", InvoiceTypeUseFor.CreditNote),
|
||||||
_308("308", "Delcredere credit note", "Credit Note"),
|
_308("308", "Delcredere credit note", InvoiceTypeUseFor.CreditNote),
|
||||||
_325("325", "Proforma invoice", "Invoice"),
|
_325("325", "Proforma invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_326("326", "Partial invoice", "Invoice"),
|
_326("326", "Partial invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_331("331", "Commercial invoice which includes a packing list", "Invoice"),
|
_331("331", "Commercial invoice which includes a packing list", InvoiceTypeUseFor.Invoice),
|
||||||
_380("380", "Commercial invoice", "Invoice"),
|
_380("380", "Commercial invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_381("381", "Credit note", "Credit Note"),
|
_381("381", "Credit note", InvoiceTypeUseFor.CreditNote),
|
||||||
_382("382", "Commission note", "Invoice"),
|
_382("382", "Commission note", InvoiceTypeUseFor.Invoice),
|
||||||
_383("383", "Debit note", "Invoice"),
|
_383("383", "Debit note", InvoiceTypeUseFor.Invoice),
|
||||||
_384("384", "Corrected invoice", "Invoice"),
|
_384("384", "Corrected invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_385("385", "Consolidated invoice", "Invoice"),
|
_385("385", "Consolidated invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_386("386", "Prepayment invoice", "Invoice"),
|
_386("386", "Prepayment invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_387("387", "Hire invoice", "Invoice"),
|
_387("387", "Hire invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_388("388", "Tax invoice", "Invoice"),
|
_388("388", "Tax invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_389("389", "Self-billed invoice", "Invoice"),
|
_389("389", "Self-billed invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_390("390", "Delcredere invoice", "Invoice"),
|
_390("390", "Delcredere invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_393("393", "Factored invoice", "Invoice"),
|
_393("393", "Factored invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_394("394", "Lease invoice", "Invoice"),
|
_394("394", "Lease invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_395("395", "Consignment invoice", "Invoice"),
|
_395("395", "Consignment invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_396("396", "Factored credit note", "Credit Note"),
|
_396("396", "Factored credit note", InvoiceTypeUseFor.CreditNote),
|
||||||
_420("420", "Optical Character Reading (OCR) payment credit note", "Credit Note"),
|
_420("420", "Optical Character Reading (OCR) payment credit note", InvoiceTypeUseFor.CreditNote),
|
||||||
_456("456", "Debit advice", "Invoice"),
|
_456("456", "Debit advice", InvoiceTypeUseFor.Invoice),
|
||||||
_457("457", "Reversal of debit", "Invoice"),
|
_457("457", "Reversal of debit", InvoiceTypeUseFor.Invoice),
|
||||||
_458("458", "Reversal of credit", "Credit Note"),
|
_458("458", "Reversal of credit", InvoiceTypeUseFor.CreditNote),
|
||||||
_527("527", "Self billed debit note", "Invoice"),
|
_527("527", "Self billed debit note", InvoiceTypeUseFor.Invoice),
|
||||||
_532("532", "Forwarder's credit note", "Credit Note"),
|
_532("532", "Forwarder's credit note", InvoiceTypeUseFor.CreditNote),
|
||||||
_553("553", "Forwarder's invoice discrepancy report", "Invoice"),
|
_553("553", "Forwarder's invoice discrepancy report", InvoiceTypeUseFor.Invoice),
|
||||||
_575("575", "Insurer's invoice", "Invoice"),
|
_575("575", "Insurer's invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_623("623", "Forwarder's invoice", "Invoice"),
|
_623("623", "Forwarder's invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_633("633", "Port charges documents", "Invoice"),
|
_633("633", "Port charges documents", InvoiceTypeUseFor.Invoice),
|
||||||
_751("751", "Invoice information for accounting purposes", "Invoice"),
|
_751("751", "Invoice information for accounting purposes", InvoiceTypeUseFor.Invoice),
|
||||||
_780("780", "Freight invoice", "Invoice"),
|
_780("780", "Freight invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_817("817", "Claim notification", "Invoice"),
|
_817("817", "Claim notification", InvoiceTypeUseFor.Invoice),
|
||||||
_870("870", "Consular invoice", "Invoice"),
|
_870("870", "Consular invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_875("875", "Partial construction invoice", "Invoice"),
|
_875("875", "Partial construction invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_876("876", "Partial final construction invoice", "Invoice"),
|
_876("876", "Partial final construction invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_877("877", "Final construction invoice", "Invoice"),
|
_877("877", "Final construction invoice", InvoiceTypeUseFor.Invoice),
|
||||||
_935("935", "Customs invoice", "Invoice"),
|
_935("935", "Customs invoice", InvoiceTypeUseFor.Invoice),
|
||||||
}
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package net.codinux.invoicing.model.codes
|
||||||
|
|
||||||
|
enum class InvoiceTypeUseFor {
|
||||||
|
Invoice,
|
||||||
|
|
||||||
|
CreditNote
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package net.codinux.invoicing.parser
|
package net.codinux.invoicing.parser
|
||||||
|
|
||||||
|
import net.codinux.invoicing.model.codes.InvoiceTypeUseFor
|
||||||
import net.codinux.invoicing.parser.genericode.CodeList
|
import net.codinux.invoicing.parser.genericode.CodeList
|
||||||
import net.codinux.invoicing.parser.model.CodeListType
|
import net.codinux.invoicing.parser.model.CodeListType
|
||||||
import net.codinux.invoicing.parser.model.Column
|
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
|
// 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
|
val (columns, rows) = map(filter(if (codeLists.second != null) codeLists.second!!.columns to codeLists.second!!.rows
|
||||||
else codeLists.first.columns to codeLists.first.rows)
|
else codeLists.first.columns to codeLists.first.rows))
|
||||||
|
|
||||||
File(outputDirectory, type.className + ".kt").bufferedWriter().use { writer ->
|
File(outputDirectory, type.className + ".kt").bufferedWriter().use { writer ->
|
||||||
writer.appendLine("package net.codinux.invoicing.model.codes")
|
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)}" } }) {")
|
writer.appendLine("enum class ${type.className}(${columns.joinToString(", ") { "val ${getPropertyName(it)}: ${getDataType(it, columns, rows)}" } }) {")
|
||||||
|
|
||||||
rows.forEach { row ->
|
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("}")
|
writer.append("}")
|
||||||
}
|
}
|
||||||
|
@ -52,6 +53,27 @@ class CodeGenerator {
|
||||||
return columns.filterIndexed { index, _ -> index != indexToIgnore } to rows.map { it.filterIndexed { index, _ -> index != indexToIgnore } }
|
return columns.filterIndexed { index, _ -> index != indexToIgnore } to rows.map { it.filterIndexed { index, _ -> index != indexToIgnore } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun map(columnsAndRows: Pair<List<Column>, List<List<Any?>>>): Pair<List<Column>, List<List<Any?>>> {
|
||||||
|
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) {
|
private fun getPropertyName(column: Column): String = when (column.name) {
|
||||||
"Unique code" -> "code"
|
"Unique code" -> "code"
|
||||||
|
@ -67,6 +89,18 @@ class CodeGenerator {
|
||||||
else -> column.name.replace(" ", "").let { it[0].lowercase() + it.substring(1) }
|
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<Column>, rows: List<List<Any?>>): String {
|
private fun getDataType(column: Column, columns: List<Column>, rows: List<List<Any?>>): String {
|
||||||
val index = columns.indexOf(column)
|
val index = columns.indexOf(column)
|
||||||
val containsNullValues = rows.any { it[index] == null }
|
val containsNullValues = rows.any { it[index] == null }
|
||||||
|
|
Loading…
Reference in New Issue