From d8f707e5eb0224324acac7b0afda96d8e5ae5249 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 2 Dec 2024 04:08:07 +0100 Subject: [PATCH] Extracted InvoiceDetails --- .../invoicing/api/InvoicingResource.kt | 2 +- .../codinux/invoicing/mapper/MustangMapper.kt | 22 ++++++++----------- .../net/codinux/invoicing/model/Invoice.kt | 10 ++------- .../codinux/invoicing/model/InvoiceDetails.kt | 13 +++++++++++ .../net/codinux/invoicing/Demonstration.kt | 8 ++----- .../codinux/invoicing/test/DataGenerator.kt | 7 ++---- .../codinux/invoicing/test/InvoiceAsserter.kt | 4 ++-- 7 files changed, 31 insertions(+), 35 deletions(-) create mode 100644 e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceDetails.kt diff --git a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt index a973045..20f624d 100644 --- a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt +++ b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt @@ -94,7 +94,7 @@ class InvoicingResource( private fun createPdfFileResponse(pdfFile: java.nio.file.Path, invoice: Invoice): Response = Response.ok(pdfFile) - .header("Content-Disposition", "attachment;filename=\"${invoice.invoiceDate.toString().replace('-', '.')} ${invoice.customer.name} ${invoice.invoiceNumber}.pdf\"") + .header("Content-Disposition", "attachment;filename=\"${invoice.details.invoiceDate.toString().replace('-', '.')} ${invoice.customer.name} ${invoice.details.invoiceNumber}.pdf\"") .build() } \ No newline at end of file diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/mapper/MustangMapper.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/mapper/MustangMapper.kt index 8b1f1f2..946e65a 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/mapper/MustangMapper.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/mapper/MustangMapper.kt @@ -1,11 +1,10 @@ package net.codinux.invoicing.mapper import net.codinux.invoicing.calculator.AmountsCalculator -import net.codinux.invoicing.model.AmountAdjustments -import net.codinux.invoicing.model.ChargeOrAllowance -import net.codinux.invoicing.model.InvoiceItem -import net.codinux.invoicing.model.Party +import net.codinux.invoicing.model.* import org.mustangproject.* +import org.mustangproject.BankDetails +import org.mustangproject.Invoice import org.mustangproject.ZUGFeRD.IExportableTransaction import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem import java.math.BigDecimal @@ -19,15 +18,15 @@ open class MustangMapper( ) { open fun mapToTransaction(invoice: net.codinux.invoicing.model.Invoice): IExportableTransaction = Invoice().apply { - this.number = invoice.invoiceNumber - this.issueDate = map(invoice.invoiceDate) + this.number = invoice.details.invoiceNumber + this.issueDate = map(invoice.details.invoiceDate) this.sender = mapParty(invoice.supplier) this.recipient = mapParty(invoice.customer) this.setZFItems(ArrayList(invoice.items.map { mapLineItem(it) })) - this.dueDate = map(invoice.dueDate) - this.paymentTermDescription = invoice.paymentDescription + this.dueDate = map(invoice.details.dueDate) + this.paymentTermDescription = invoice.details.paymentDescription this.referenceNumber = invoice.customerReference @@ -92,15 +91,12 @@ open class MustangMapper( open fun mapToInvoice(invoice: Invoice) = net.codinux.invoicing.model.Invoice( - invoiceNumber = invoice.number, - invoiceDate = map(invoice.issueDate), + details = InvoiceDetails(invoice.number, map(invoice.issueDate), map(invoice.dueDate ?: invoice.paymentTerms?.dueDate), invoice.paymentTermDescription ?: invoice.paymentTerms?.description), + supplier = mapParty(invoice.sender), customer = mapParty(invoice.recipient), items = invoice.zfItems.map { mapLineItem(it) }, - dueDate = map(invoice.dueDate ?: invoice.paymentTerms?.dueDate), - paymentDescription = invoice.paymentTermDescription ?: invoice.paymentTerms?.description, - customerReference = invoice.referenceNumber, amountAdjustments = mapAmountAdjustments(invoice), diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/Invoice.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/Invoice.kt index 41ee555..00cfa7f 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/Invoice.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/Invoice.kt @@ -1,17 +1,11 @@ package net.codinux.invoicing.model -import java.time.LocalDate - class Invoice( - val invoiceNumber: String, - val invoiceDate: LocalDate, + val details: InvoiceDetails, val supplier: Party, val customer: Party, val items: List, - val dueDate: LocalDate? = null, - val paymentDescription: String? = null, - /** * Unique reference number of the customer, e.g. the Leitweg-ID required by German authorities (Behörden) */ @@ -27,5 +21,5 @@ class Invoice( */ var totalAmounts: TotalAmounts? = null ) { - override fun toString() = "$invoiceDate $invoiceNumber to $customer ${totalAmounts?.duePayableAmount?.let { " (${it.toPlainString()})" } ?: ""}" + override fun toString() = "$details to $customer ${totalAmounts?.duePayableAmount?.let { " (${it.toPlainString()})" } ?: ""}" } \ No newline at end of file diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceDetails.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceDetails.kt new file mode 100644 index 0000000..98dbfc3 --- /dev/null +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceDetails.kt @@ -0,0 +1,13 @@ +package net.codinux.invoicing.model + +import java.time.LocalDate + +class InvoiceDetails( + val invoiceNumber: String, + val invoiceDate: LocalDate, + + val dueDate: LocalDate? = null, + val paymentDescription: String? = null, +) { + override fun toString() = "$invoiceDate $invoiceNumber" +} \ No newline at end of file diff --git a/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/Demonstration.kt b/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/Demonstration.kt index 786bc40..694d9c7 100644 --- a/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/Demonstration.kt +++ b/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/Demonstration.kt @@ -3,10 +3,7 @@ package net.codinux.invoicing import net.codinux.invoicing.creation.EInvoiceCreator import net.codinux.invoicing.email.model.EmailAccount import net.codinux.invoicing.email.EmailsFetcher -import net.codinux.invoicing.model.EInvoiceXmlFormat -import net.codinux.invoicing.model.Invoice -import net.codinux.invoicing.model.InvoiceItem -import net.codinux.invoicing.model.Party +import net.codinux.invoicing.model.* import net.codinux.invoicing.reader.EInvoiceReader import net.codinux.invoicing.validation.EInvoiceValidator import java.io.File @@ -84,8 +81,7 @@ class Demonstration { private fun createInvoice() = Invoice( - invoiceNumber = "RE-00001", - invoiceDate = LocalDate.now(), + details = InvoiceDetails("RE-00001", LocalDate.now()), supplier = Party("codinux GmbH & Co. KG", "Fun Street 1", null, "12345", "Glückstadt"), customer = Party("Abzock GmbH", "Ausbeutstr.", null, "12345", "Abzockhausen"), items = listOf(InvoiceItem("Erbrachte Dienstleistungen", BigDecimal(170), "HUR", BigDecimal(1_000_000), BigDecimal(19))) // HUR = EN code for hour diff --git a/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/test/DataGenerator.kt b/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/test/DataGenerator.kt index 4bf90f3..a1f9958 100644 --- a/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/test/DataGenerator.kt +++ b/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/test/DataGenerator.kt @@ -1,9 +1,6 @@ package net.codinux.invoicing.test -import net.codinux.invoicing.model.BankDetails -import net.codinux.invoicing.model.Invoice -import net.codinux.invoicing.model.InvoiceItem -import net.codinux.invoicing.model.Party +import net.codinux.invoicing.model.* import java.math.BigDecimal import java.time.LocalDate import java.time.format.DateTimeFormatter @@ -57,7 +54,7 @@ object DataGenerator { dueDate: LocalDate? = DueDate, paymentDescription: String? = dueDate?.let { "Zahlbar ohne Abzug bis ${DateTimeFormatter.ofPattern("dd.MM.yyyy").format(dueDate)}" }, buyerReference: String? = null - ) = Invoice(invoiceNumber, invoiceDate, supplier, customer, items, dueDate, paymentDescription, buyerReference) + ) = Invoice(InvoiceDetails(invoiceNumber, invoiceDate, dueDate, paymentDescription), supplier, customer, items, buyerReference) fun createParty( name: String, diff --git a/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/test/InvoiceAsserter.kt b/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/test/InvoiceAsserter.kt index 23a2b8a..2c27e73 100644 --- a/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/test/InvoiceAsserter.kt +++ b/e-invoice-domain/src/test/kotlin/net/codinux/invoicing/test/InvoiceAsserter.kt @@ -59,8 +59,8 @@ object InvoiceAsserter { fun assertInvoice(invoice: Invoice?) { assertThat(invoice).isNotNull() - assertThat(invoice!!.invoiceNumber).isEqualTo(DataGenerator.InvoiceNumber) - assertThat(invoice.invoiceDate).isEqualTo(DataGenerator.InvoiceDate) + assertThat(invoice!!.details.invoiceNumber).isEqualTo(DataGenerator.InvoiceNumber) + assertThat(invoice.details.invoiceDate).isEqualTo(DataGenerator.InvoiceDate) assertParty(invoice.supplier, DataGenerator.SupplierName, DataGenerator.SupplierAddress, DataGenerator.SupplierPostalCode, DataGenerator.SupplierCity, DataGenerator.SupplierCountry, DataGenerator.SupplierVatId, DataGenerator.SupplierEmail, DataGenerator.SupplierPhone, DataGenerator.SupplierBankDetails)