Extracted InvoiceDetails

This commit is contained in:
dankito 2024-12-02 04:08:07 +01:00
parent 68b1f56cfa
commit d8f707e5eb
7 changed files with 31 additions and 35 deletions

View File

@ -94,7 +94,7 @@ class InvoicingResource(
private fun createPdfFileResponse(pdfFile: java.nio.file.Path, invoice: Invoice): Response = private fun createPdfFileResponse(pdfFile: java.nio.file.Path, invoice: Invoice): Response =
Response.ok(pdfFile) 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() .build()
} }

View File

@ -1,11 +1,10 @@
package net.codinux.invoicing.mapper package net.codinux.invoicing.mapper
import net.codinux.invoicing.calculator.AmountsCalculator import net.codinux.invoicing.calculator.AmountsCalculator
import net.codinux.invoicing.model.AmountAdjustments import net.codinux.invoicing.model.*
import net.codinux.invoicing.model.ChargeOrAllowance
import net.codinux.invoicing.model.InvoiceItem
import net.codinux.invoicing.model.Party
import org.mustangproject.* import org.mustangproject.*
import org.mustangproject.BankDetails
import org.mustangproject.Invoice
import org.mustangproject.ZUGFeRD.IExportableTransaction import org.mustangproject.ZUGFeRD.IExportableTransaction
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem
import java.math.BigDecimal import java.math.BigDecimal
@ -19,15 +18,15 @@ open class MustangMapper(
) { ) {
open fun mapToTransaction(invoice: net.codinux.invoicing.model.Invoice): IExportableTransaction = Invoice().apply { open fun mapToTransaction(invoice: net.codinux.invoicing.model.Invoice): IExportableTransaction = Invoice().apply {
this.number = invoice.invoiceNumber this.number = invoice.details.invoiceNumber
this.issueDate = map(invoice.invoiceDate) this.issueDate = map(invoice.details.invoiceDate)
this.sender = mapParty(invoice.supplier) this.sender = mapParty(invoice.supplier)
this.recipient = mapParty(invoice.customer) this.recipient = mapParty(invoice.customer)
this.setZFItems(ArrayList(invoice.items.map { mapLineItem(it) })) this.setZFItems(ArrayList(invoice.items.map { mapLineItem(it) }))
this.dueDate = map(invoice.dueDate) this.dueDate = map(invoice.details.dueDate)
this.paymentTermDescription = invoice.paymentDescription this.paymentTermDescription = invoice.details.paymentDescription
this.referenceNumber = invoice.customerReference this.referenceNumber = invoice.customerReference
@ -92,15 +91,12 @@ open class MustangMapper(
open fun mapToInvoice(invoice: Invoice) = net.codinux.invoicing.model.Invoice( open fun mapToInvoice(invoice: Invoice) = net.codinux.invoicing.model.Invoice(
invoiceNumber = invoice.number, details = InvoiceDetails(invoice.number, map(invoice.issueDate), map(invoice.dueDate ?: invoice.paymentTerms?.dueDate), invoice.paymentTermDescription ?: invoice.paymentTerms?.description),
invoiceDate = map(invoice.issueDate),
supplier = mapParty(invoice.sender), supplier = mapParty(invoice.sender),
customer = mapParty(invoice.recipient), customer = mapParty(invoice.recipient),
items = invoice.zfItems.map { mapLineItem(it) }, items = invoice.zfItems.map { mapLineItem(it) },
dueDate = map(invoice.dueDate ?: invoice.paymentTerms?.dueDate),
paymentDescription = invoice.paymentTermDescription ?: invoice.paymentTerms?.description,
customerReference = invoice.referenceNumber, customerReference = invoice.referenceNumber,
amountAdjustments = mapAmountAdjustments(invoice), amountAdjustments = mapAmountAdjustments(invoice),

View File

@ -1,17 +1,11 @@
package net.codinux.invoicing.model package net.codinux.invoicing.model
import java.time.LocalDate
class Invoice( class Invoice(
val invoiceNumber: String, val details: InvoiceDetails,
val invoiceDate: LocalDate,
val supplier: Party, val supplier: Party,
val customer: Party, val customer: Party,
val items: List<InvoiceItem>, val items: List<InvoiceItem>,
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) * 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 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()})" } ?: ""}"
} }

View File

@ -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"
}

View File

@ -3,10 +3,7 @@ package net.codinux.invoicing
import net.codinux.invoicing.creation.EInvoiceCreator import net.codinux.invoicing.creation.EInvoiceCreator
import net.codinux.invoicing.email.model.EmailAccount import net.codinux.invoicing.email.model.EmailAccount
import net.codinux.invoicing.email.EmailsFetcher import net.codinux.invoicing.email.EmailsFetcher
import net.codinux.invoicing.model.EInvoiceXmlFormat import net.codinux.invoicing.model.*
import net.codinux.invoicing.model.Invoice
import net.codinux.invoicing.model.InvoiceItem
import net.codinux.invoicing.model.Party
import net.codinux.invoicing.reader.EInvoiceReader import net.codinux.invoicing.reader.EInvoiceReader
import net.codinux.invoicing.validation.EInvoiceValidator import net.codinux.invoicing.validation.EInvoiceValidator
import java.io.File import java.io.File
@ -84,8 +81,7 @@ class Demonstration {
private fun createInvoice() = Invoice( private fun createInvoice() = Invoice(
invoiceNumber = "RE-00001", details = InvoiceDetails("RE-00001", LocalDate.now()),
invoiceDate = LocalDate.now(),
supplier = Party("codinux GmbH & Co. KG", "Fun Street 1", null, "12345", "Glückstadt"), supplier = Party("codinux GmbH & Co. KG", "Fun Street 1", null, "12345", "Glückstadt"),
customer = Party("Abzock GmbH", "Ausbeutstr.", null, "12345", "Abzockhausen"), 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 items = listOf(InvoiceItem("Erbrachte Dienstleistungen", BigDecimal(170), "HUR", BigDecimal(1_000_000), BigDecimal(19))) // HUR = EN code for hour

View File

@ -1,9 +1,6 @@
package net.codinux.invoicing.test package net.codinux.invoicing.test
import net.codinux.invoicing.model.BankDetails import net.codinux.invoicing.model.*
import net.codinux.invoicing.model.Invoice
import net.codinux.invoicing.model.InvoiceItem
import net.codinux.invoicing.model.Party
import java.math.BigDecimal import java.math.BigDecimal
import java.time.LocalDate import java.time.LocalDate
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@ -57,7 +54,7 @@ object DataGenerator {
dueDate: LocalDate? = DueDate, dueDate: LocalDate? = DueDate,
paymentDescription: String? = dueDate?.let { "Zahlbar ohne Abzug bis ${DateTimeFormatter.ofPattern("dd.MM.yyyy").format(dueDate)}" }, paymentDescription: String? = dueDate?.let { "Zahlbar ohne Abzug bis ${DateTimeFormatter.ofPattern("dd.MM.yyyy").format(dueDate)}" },
buyerReference: String? = null buyerReference: String? = null
) = Invoice(invoiceNumber, invoiceDate, supplier, customer, items, dueDate, paymentDescription, buyerReference) ) = Invoice(InvoiceDetails(invoiceNumber, invoiceDate, dueDate, paymentDescription), supplier, customer, items, buyerReference)
fun createParty( fun createParty(
name: String, name: String,

View File

@ -59,8 +59,8 @@ object InvoiceAsserter {
fun assertInvoice(invoice: Invoice?) { fun assertInvoice(invoice: Invoice?) {
assertThat(invoice).isNotNull() assertThat(invoice).isNotNull()
assertThat(invoice!!.invoiceNumber).isEqualTo(DataGenerator.InvoiceNumber) assertThat(invoice!!.details.invoiceNumber).isEqualTo(DataGenerator.InvoiceNumber)
assertThat(invoice.invoiceDate).isEqualTo(DataGenerator.InvoiceDate) 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) assertParty(invoice.supplier, DataGenerator.SupplierName, DataGenerator.SupplierAddress, DataGenerator.SupplierPostalCode, DataGenerator.SupplierCity, DataGenerator.SupplierCountry, DataGenerator.SupplierVatId, DataGenerator.SupplierEmail, DataGenerator.SupplierPhone, DataGenerator.SupplierBankDetails)