From 556c59ba3a16bea655f5976c6565a446efd1d43d Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 24 Nov 2024 16:06:02 +0100 Subject: [PATCH] Renamed LineItem to InvoiceItem, price to unitPrice and vatPercentage to vatRate --- README.md | 2 +- .../codinux/invoicing/mapper/MustangMapper.kt | 10 +++++----- .../net/codinux/invoicing/model/Invoice.kt | 2 +- .../model/{LineItem.kt => InvoiceItem.kt} | 10 +++++----- .../net/codinux/invoicing/Demonstration.kt | 4 ++-- .../codinux/invoicing/test/DataGenerator.kt | 18 +++++++++--------- .../codinux/invoicing/test/InvoiceAsserter.kt | 19 ++++++++++--------- 7 files changed, 33 insertions(+), 32 deletions(-) rename e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/{LineItem.kt => InvoiceItem.kt} (53%) diff --git a/README.md b/README.md index 60cd0a7..c2447e1 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ private fun createInvoice() = Invoice( invoicingDate = LocalDate.now(), sender = Party("codinux GmbH & Co. KG", "Fun Street 1", "12345", "Glückstadt"), recipient = Party("Abzock GmbH", "Ausbeutstr.", "12345", "Abzockhausen"), - items = listOf(LineItem("Erbrachte Dienstleistungen", "HUR", BigDecimal(170), BigDecimal(1_000_000), BigDecimal(19))) // HUR = EN code for hour + items = listOf(InvoiceItem("Erbrachte Dienstleistungen", BigDecimal(170), "HUR", BigDecimal(105), BigDecimal(19))) // HUR = EN code for hour ) ``` 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 6fbb9ac..c45200a 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,6 +1,6 @@ package net.codinux.invoicing.mapper -import net.codinux.invoicing.model.LineItem +import net.codinux.invoicing.model.InvoiceItem import net.codinux.invoicing.model.Party import org.mustangproject.* import org.mustangproject.ZUGFeRD.IExportableTransaction @@ -45,9 +45,9 @@ open class MustangMapper { } } - open fun mapLineItem(item: LineItem): IZUGFeRDExportableItem = Item( + 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.vatPercentage), item.price, item.quantity + Product(item.name, item.description ?: "", item.unit, item.vatRate), item.unitPrice, item.quantity ).apply { } @@ -72,8 +72,8 @@ open class MustangMapper { party.bankDetails?.firstOrNull()?.let { net.codinux.invoicing.model.BankDetails(it.iban, it.bic, it.accountName) } ) - open fun mapLineItem(item: IZUGFeRDExportableItem) = LineItem( - item.product.name, item.product.unit, item.quantity, item.price, item.product.vatPercent, item.product.description.takeUnless { it.isBlank() } + 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() } ) 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 a53ff76..2e09a04 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 @@ -7,7 +7,7 @@ class Invoice( val invoicingDate: LocalDate, val sender: Party, val recipient: Party, - val items: List, + val items: List, val dueDate: LocalDate? = null, val paymentDescription: String? = null, diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/LineItem.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceItem.kt similarity index 53% rename from e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/LineItem.kt rename to e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceItem.kt index 29f0342..2a9becc 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/LineItem.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/model/InvoiceItem.kt @@ -2,13 +2,13 @@ package net.codinux.invoicing.model import java.math.BigDecimal -class LineItem( +class InvoiceItem( val name: String, - val unit: String, val quantity: BigDecimal, - val price: BigDecimal, - val vatPercentage: BigDecimal, + val unit: String, + val unitPrice: BigDecimal, + val vatRate: BigDecimal, val description: String? = null, ) { - override fun toString() = "$name, $quantity x $price, $vatPercentage %" + override fun toString() = "$name, $quantity x $unitPrice, $vatRate %" } \ 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 659ec84..1e4ac16 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 @@ -4,7 +4,7 @@ import net.codinux.invoicing.creation.EInvoiceCreator import net.codinux.invoicing.mail.MailAccount import net.codinux.invoicing.mail.MailReader import net.codinux.invoicing.model.Invoice -import net.codinux.invoicing.model.LineItem +import net.codinux.invoicing.model.InvoiceItem import net.codinux.invoicing.model.Party import net.codinux.invoicing.reader.EInvoiceReader import net.codinux.invoicing.validation.EInvoiceValidator @@ -83,6 +83,6 @@ class Demonstration { invoicingDate = LocalDate.now(), sender = Party("codinux GmbH & Co. KG", "Fun Street 1", "12345", "Glückstadt"), recipient = Party("Abzock GmbH", "Ausbeutstr.", "12345", "Abzockhausen"), - items = listOf(LineItem("Erbrachte Dienstleistungen", "HUR", BigDecimal(170), 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 ) } \ No newline at end of file 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 840fdfe..ea069f6 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 @@ -2,7 +2,7 @@ package net.codinux.invoicing.test import net.codinux.invoicing.model.BankDetails import net.codinux.invoicing.model.Invoice -import net.codinux.invoicing.model.LineItem +import net.codinux.invoicing.model.InvoiceItem import net.codinux.invoicing.model.Party import java.math.BigDecimal import java.time.LocalDate @@ -35,10 +35,10 @@ object DataGenerator { val RecipientBankDetails: BankDetails? = null const val ItemName = "Erbrachte Dienstleistungen" - const val ItemUnit = "HUR" // EN code for 'hour' val ItemQuantity = BigDecimal(1) - val ItemPrice = BigDecimal(99) - val ItemVatPercentage = BigDecimal(19) + const val ItemUnit = "HUR" // EN code for 'hour' + val ItemUnitPrice = BigDecimal(99) + val ItemVatRate = BigDecimal(19) val ItemDescription: String? = null @@ -49,7 +49,7 @@ object DataGenerator { bankDetails = SenderBankDetails), recipient: Party = createParty(RecipientName, RecipientStreet, RecipientPostalCode, RecipientCity, RecipientCountry, RecipientVatId, RecipientEmail, RecipientPhone, bankDetails = RecipientBankDetails), - items: List = listOf(createItem()), + 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 @@ -71,11 +71,11 @@ object DataGenerator { fun createItem( name: String = ItemName, - unit: String = ItemUnit, quantity: BigDecimal = ItemQuantity, - price: BigDecimal = ItemPrice, - vatPercentage: BigDecimal = ItemVatPercentage, + unit: String = ItemUnit, + unitPrice: BigDecimal = ItemUnitPrice, + vatRate: BigDecimal = ItemVatRate, description: String? = ItemDescription, - ) = LineItem(name, unit, quantity, price, vatPercentage, description) + ) = InvoiceItem(name, quantity, unit, unitPrice, vatRate, description) } \ No newline at end of file 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 8461b1e..cbf7011 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 @@ -4,7 +4,7 @@ import assertk.assertThat import assertk.assertions.* import net.codinux.invoicing.model.BankDetails import net.codinux.invoicing.model.Invoice -import net.codinux.invoicing.model.LineItem +import net.codinux.invoicing.model.InvoiceItem import net.codinux.invoicing.model.Party import java.math.BigDecimal @@ -25,7 +25,7 @@ object InvoiceAsserter { assertParty(asserter, receiverXPath, DataGenerator.RecipientName, DataGenerator.RecipientStreet, DataGenerator.RecipientPostalCode, DataGenerator.RecipientCity, DataGenerator.RecipientVatId, DataGenerator.RecipientEmail, DataGenerator.RecipientPhone) val lineItemXPath = "//rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem" - assertLineItem(asserter, lineItemXPath, DataGenerator.ItemName, DataGenerator.ItemUnit, DataGenerator.ItemQuantity, DataGenerator.ItemPrice, DataGenerator.ItemVatPercentage, DataGenerator.ItemDescription) + assertLineItem(asserter, lineItemXPath, DataGenerator.ItemName, DataGenerator.ItemQuantity, DataGenerator.ItemUnit, DataGenerator.ItemUnitPrice, DataGenerator.ItemVatRate, DataGenerator.ItemDescription) } private fun assertParty(asserter: XPathAsserter, partyXPath: String, name: String, street: String, postalCode: String, city: String, vatId: String, email: String, phone: String) { @@ -42,14 +42,15 @@ object InvoiceAsserter { asserter.xpathHasValue("$partyXPath/ram:DefinedTradeContact/ram:TelephoneUniversalCommunication/ram:CompleteNumber", phone) } - private fun assertLineItem(asserter: XPathAsserter, itemXPath: String, name: String, unit: String, quantity: BigDecimal, price: BigDecimal, vatPercentage: BigDecimal, description: String?) { + private fun assertLineItem(asserter: XPathAsserter, itemXPath: String, name: String, quantity: BigDecimal, unit: String, unitPrice: BigDecimal, vatRate: BigDecimal, description: String?) { asserter.xpathHasValue("$itemXPath/ram:SpecifiedTradeProduct/ram:Name", name) asserter.xpathHasValue("$itemXPath/ram:SpecifiedLineTradeDelivery/ram:BilledQuantity/@unitCode", unit) asserter.xpathHasValue("$itemXPath/ram:SpecifiedLineTradeDelivery/ram:BilledQuantity", quantity, 4) - asserter.xpathHasValue("$itemXPath/ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount", price, 2) - asserter.xpathHasValue("$itemXPath/ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:RateApplicablePercent", vatPercentage, 2) + asserter.xpathHasValue("$itemXPath/ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount", unitPrice, 2) + asserter.xpathHasValue("$itemXPath/ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:RateApplicablePercent", + vatRate, 2) // asserter.xpathHasValue("$partyXPath/ram:URIUniversalCommunication/ram:URIID", description) } @@ -66,7 +67,7 @@ object InvoiceAsserter { assertParty(invoice.recipient, DataGenerator.RecipientName, DataGenerator.RecipientStreet, DataGenerator.RecipientPostalCode, DataGenerator.RecipientCity, DataGenerator.RecipientCountry, DataGenerator.RecipientVatId, DataGenerator.RecipientEmail, DataGenerator.RecipientPhone, DataGenerator.RecipientBankDetails) assertThat(invoice.items).hasSize(1) - assertLineItem(invoice.items.first(), DataGenerator.ItemName, DataGenerator.ItemUnit, DataGenerator.ItemQuantity, DataGenerator.ItemPrice, DataGenerator.ItemVatPercentage, DataGenerator.ItemDescription) + assertLineItem(invoice.items.first(), DataGenerator.ItemName, DataGenerator.ItemQuantity, DataGenerator.ItemUnit, DataGenerator.ItemUnitPrice, DataGenerator.ItemVatRate, DataGenerator.ItemDescription) } private fun assertParty(party: Party, name: String, street: String, postalCode: String, city: String, country: String?, vatId: String, email: String, phone: String, bankDetails: BankDetails?) { @@ -92,14 +93,14 @@ object InvoiceAsserter { } } - private fun assertLineItem(item: LineItem, name: String, unit: String, quantity: BigDecimal, price: BigDecimal, vatPercentage: BigDecimal, description: String?) { + private fun assertLineItem(item: InvoiceItem, name: String, quantity: BigDecimal, unit: String, unitPrice: BigDecimal, vatRate: BigDecimal, description: String?) { assertThat(item.name).isEqualTo(name) assertThat(item.unit).isEqualTo(unit) assertThat(item.quantity).isEqualTo(quantity.setScale(4)) - assertThat(item.price).isEqualTo(price.setScale(4)) - assertThat(item.vatPercentage).isEqualTo(vatPercentage.setScale(2)) + assertThat(item.unitPrice).isEqualTo(unitPrice.setScale(4)) + assertThat(item.vatRate).isEqualTo(vatRate.setScale(2)) // assertThat(item.description).isEqualTo(description) }