Added example how to create eInvoice
This commit is contained in:
parent
9e765c53a9
commit
449a6a7764
44
README.md
44
README.md
|
@ -19,12 +19,40 @@ val invoiceFromXml = reader.readFromXml(File("XRechnung.xml"))
|
||||||
### Find all invoices of an IMAP email account
|
### Find all invoices of an IMAP email account
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val mailReader = MailReader()
|
val mailReader = MailReader()
|
||||||
|
|
||||||
val mailsWithEInvoices = mailReader.listAllMessagesWithEInvoice(MailAccount(
|
val mailsWithEInvoices = mailReader.listAllMessagesWithEInvoice(MailAccount(
|
||||||
username = "", // your mail account username
|
username = "", // your mail account username
|
||||||
password = "", // your mail account username
|
password = "", // your mail account username
|
||||||
serverAddress = "", // IMAP server address
|
serverAddress = "", // IMAP server address
|
||||||
port = null // IMAP server port, leave null if default port 993
|
port = null // IMAP server port, leave null if default port 993
|
||||||
))
|
))
|
||||||
|
```
|
||||||
|
|
||||||
|
## Create eInvoice
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
fun create() {
|
||||||
|
val invoice = createInvoice()
|
||||||
|
val pdfResultFile = File.createTempFile("Zugferd", ".pdf")
|
||||||
|
|
||||||
|
val creator = EInvoiceCreator()
|
||||||
|
|
||||||
|
// create a PDF that also contains the eInvoice as XML attachment
|
||||||
|
creator.createZugferdPdf(invoice, pdfResultFile)
|
||||||
|
|
||||||
|
// create only the XML file
|
||||||
|
val xml = creator.createZugferdXml(invoice)
|
||||||
|
|
||||||
|
// create a XRechnung
|
||||||
|
val xRechnung = creator.createXRechnungXml(invoice)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createInvoice() = Invoice(
|
||||||
|
invoiceNumber = "RE-00001",
|
||||||
|
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
|
||||||
|
)
|
||||||
```
|
```
|
|
@ -1,9 +1,15 @@
|
||||||
package net.codinux.invoicing
|
package net.codinux.invoicing
|
||||||
|
|
||||||
|
import net.codinux.invoicing.creation.EInvoiceCreator
|
||||||
import net.codinux.invoicing.mail.MailAccount
|
import net.codinux.invoicing.mail.MailAccount
|
||||||
import net.codinux.invoicing.mail.MailReader
|
import net.codinux.invoicing.mail.MailReader
|
||||||
|
import net.codinux.invoicing.model.Invoice
|
||||||
|
import net.codinux.invoicing.model.LineItem
|
||||||
|
import net.codinux.invoicing.model.Party
|
||||||
import net.codinux.invoicing.reader.EInvoiceReader
|
import net.codinux.invoicing.reader.EInvoiceReader
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.math.BigDecimal
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
class Demonstration {
|
class Demonstration {
|
||||||
|
|
||||||
|
@ -27,4 +33,28 @@ class Demonstration {
|
||||||
port = null // IMAP server port, leave null if default port 993
|
port = null // IMAP server port, leave null if default port 993
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun create() {
|
||||||
|
val invoice = createInvoice()
|
||||||
|
val pdfResultFile = File.createTempFile("Zugferd", ".pdf")
|
||||||
|
|
||||||
|
val creator = EInvoiceCreator()
|
||||||
|
|
||||||
|
// create a PDF that also contains the eInvoice as XML attachment
|
||||||
|
creator.createZugferdPdf(invoice, pdfResultFile)
|
||||||
|
|
||||||
|
// create only the XML file
|
||||||
|
val xml = creator.createZugferdXml(invoice)
|
||||||
|
|
||||||
|
// create a XRechnung
|
||||||
|
val xRechnung = creator.createXRechnungXml(invoice)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createInvoice() = Invoice(
|
||||||
|
invoiceNumber = "RE-00001",
|
||||||
|
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
|
||||||
|
)
|
||||||
}
|
}
|
Loading…
Reference in New Issue