From ad23dc3fc3ee4e0bbdd0c96c62fea05c418571e8 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 2 Dec 2024 17:58:54 +0100 Subject: [PATCH] Renamed totalAmounts to totals and added articleNumber to InvoiceItem --- README.md | 2 +- .../net/codinux/invoicing/mapper/MustangMapper.kt | 13 ++++++++----- .../kotlin/net/codinux/invoicing/model/Invoice.kt | 4 ++-- .../net/codinux/invoicing/model/InvoiceItem.kt | 1 + .../kotlin/net/codinux/invoicing/Demonstration.kt | 2 +- .../net/codinux/invoicing/test/DataGenerator.kt | 12 ++++++++---- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e132efe..7f1d1a6 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ val fetchResult = emailsFetcher.fetchAllEmails(EmailAccount( )) fetchResult.emails.forEach { email -> - println("${email.sender}: ${email.attachments.firstNotNullOfOrNull { it.invoice }?.totalAmounts?.duePayableAmount}") + println("${email.sender}: ${email.attachments.firstNotNullOfOrNull { it.invoice }?.totals?.duePayableAmount}") } ``` 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 946e65a..21e7b81 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 @@ -36,8 +36,8 @@ open class MustangMapper( adjustments.allowances.forEach { this.addAllowance(mapAllowance(it)) } } - if (invoice.totalAmounts == null) { - invoice.totalAmounts = calculator.calculateTotalAmounts(this) + if (invoice.totals == null) { + invoice.totals = calculator.calculateTotalAmounts(this) } } @@ -64,7 +64,10 @@ open class MustangMapper( open fun mapLineItem(item: InvoiceItem): IZUGFeRDExportableItem = Item( // description has to be an empty string if not set - Product(item.name, item.description ?: "", item.unit, item.vatRate), item.unitPrice, item.quantity + Product(item.name, item.description ?: "", item.unit, item.vatRate).apply { + this.sellerAssignedID = item.articleNumber // TODO: what is the articleNumber? sellerAssignedId, globalId, ...? + }, + item.unitPrice, item.quantity ).apply { } @@ -101,7 +104,7 @@ open class MustangMapper( amountAdjustments = mapAmountAdjustments(invoice), - totalAmounts = calculator.calculateTotalAmounts(invoice) + totals = calculator.calculateTotalAmounts(invoice) ) open fun mapParty(party: TradeParty) = Party( @@ -111,7 +114,7 @@ open class MustangMapper( ) open fun mapLineItem(item: IZUGFeRDExportableItem) = InvoiceItem( - item.product.name, item.quantity, item.product.unit, item.price, item.product.vatPercent, item.product.description.takeUnless { it.isBlank() } + item.product.name, item.quantity, item.product.unit, item.price, item.product.vatPercent, item.product.sellerAssignedID, item.product.description.takeUnless { it.isBlank() } ) protected open fun mapAmountAdjustments(invoice: Invoice): AmountAdjustments? { 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 00cfa7f..4d23539 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 @@ -19,7 +19,7 @@ class Invoice( * For outgoing invoices: You don't have to calculate them, we do this for you. This ensures that all total amounts * are in accordance to other data of the invoice like the invoice item amounts and amount adjustments. */ - var totalAmounts: TotalAmounts? = null + var totals: TotalAmounts? = null ) { - override fun toString() = "$details to $customer ${totalAmounts?.duePayableAmount?.let { " (${it.toPlainString()})" } ?: ""}" + override fun toString() = "$details to $customer ${totals?.duePayableAmount?.let { " (${it.toPlainString()})" } ?: ""}" } \ No newline at end of file diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceItem.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceItem.kt index 2a9becc..1e1bb5a 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceItem.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceItem.kt @@ -8,6 +8,7 @@ class InvoiceItem( val unit: String, val unitPrice: BigDecimal, val vatRate: BigDecimal, + val articleNumber: String? = null, val description: String? = null, ) { override fun toString() = "$name, $quantity x $unitPrice, $vatRate %" 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 694d9c7..aac8cb9 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 @@ -33,7 +33,7 @@ class Demonstration { )) fetchResult.emails.forEach { email -> - println("${email.sender}: ${email.attachments.firstNotNullOfOrNull { it.invoice }?.totalAmounts?.duePayableAmount}") + println("${email.sender}: ${email.attachments.firstNotNullOfOrNull { it.invoice }?.totals?.duePayableAmount}") } } 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 a1f9958..d44a96f 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,5 +1,6 @@ package net.codinux.invoicing.test +import net.codinux.invoicing.calculator.AmountsCalculator import net.codinux.invoicing.model.* import java.math.BigDecimal import java.time.LocalDate @@ -21,7 +22,7 @@ object DataGenerator { const val SupplierEmail = "working-class-hero@rock.me" const val SupplierPhone = "+4917012345678" val SupplierFax: String? = null - val SupplierBankDetails = BankDetails("DE00123456780987654321", "ABZODEFFXXX", "Manuela Musterfrau") + val SupplierBankDetails = BankDetails("DE00123456780987654321", "ABZODEFFXXX", "Manuela Musterfrau", "Abzock-Bank") const val CustomerName = "Untertänigster Leistungsempfänger" const val CustomerAddress = "Party Street 1" @@ -40,6 +41,7 @@ object DataGenerator { const val ItemUnit = "HUR" // EN code for 'hour' val ItemUnitPrice = BigDecimal(99) val ItemVatRate = BigDecimal(19) + val ItemArticleNumber: String? = null val ItemDescription: String? = null @@ -53,8 +55,9 @@ object DataGenerator { items: List = listOf(createItem()), dueDate: LocalDate? = DueDate, paymentDescription: String? = dueDate?.let { "Zahlbar ohne Abzug bis ${DateTimeFormatter.ofPattern("dd.MM.yyyy").format(dueDate)}" }, - buyerReference: String? = null - ) = Invoice(InvoiceDetails(invoiceNumber, invoiceDate, dueDate, paymentDescription), supplier, customer, items, buyerReference) + ) = Invoice(InvoiceDetails(invoiceNumber, invoiceDate, dueDate, paymentDescription), supplier, customer, items).apply { + this.totals = AmountsCalculator().calculateTotalAmounts(this) + } fun createParty( name: String, @@ -77,7 +80,8 @@ object DataGenerator { unit: String = ItemUnit, unitPrice: BigDecimal = ItemUnitPrice, vatRate: BigDecimal = ItemVatRate, + articleNumber: String? = ItemArticleNumber, description: String? = ItemDescription, - ) = InvoiceItem(name, quantity, unit, unitPrice, vatRate, description) + ) = InvoiceItem(name, quantity, unit, unitPrice, vatRate, articleNumber, description) } \ No newline at end of file