With our new project Imixs E-Invoice we provide an easy to use pure java library to read and write e-invoice documents in XML.
Imixs E-Invoice stands out for its independence from external dependencies. In contrast to libraries like the Mustang project Imixs E-Invoice does not have any external dependencies. The library seamlessly integrates into modern Java projects and makes it a good choice for custom projects and adapters.
Imixs E-Invoice supports the major European e-invoice standards factur-x (CII) and UBL. To get started just add the Maven dependency:
<dependency>
<groupId>org.imixs.util</groupId>
<artifactId>imixs-e-invoice</artifactId>
<version>1.0.1</version>
</dependency>
Now you can read any e-invoice xml document and translate it into a EInvocieModel
EInvoiceModel eInvoiceModel =null;
try (InputStream is = myInputStream) {
if (is == null) {
throw new IOException("Resource not found" );
}
eInvoiceModel= EInvoiceModelFactory.read(is);
}
// Verify the result
assertNotNull(eInvoiceModel);
assertEquals("R-00010", eInvoiceModel.getId());
LocalDate invoiceDate = eInvoiceModel.getIssueDateTime();
assertEquals(LocalDate.of(2021, 7, 28), invoiceDate);
assertEquals(new BigDecimal("4380.9"), eInvoiceModel.getGrandTotalAmount());
assertEquals(new BigDecimal("510.9"), eInvoiceModel.getTaxTotalAmount());
assertEquals(new BigDecimal("3870.00"), eInvoiceModel.getNetTotalAmount());
// Test SellerTradeParty
TradeParty seller = eInvoiceModel.findTradeParty("seller");
assertNotNull(seller);
assertEquals("Max Mustermann", seller.getName());
assertEquals("DE111111111", seller.getVatNumber());
You have full access to the XML tree behind by using standard Java xml dom objects:
// get the w3c Dom Document
Document xmlDocument = eInvoiceModel.getDoc();
// get the root Element
Element root = eInvoiceModel.getRoot();
Write a E-Invoice XML Document
You can also create a e-invoice document by simply using XML templates. To create a new e-invoice document you can work with any valid e-invoice template as an XML file. The template is the base for the core model that can be updated by the library. See the following example code:
// read the XML Template
EInvoiceModel model = EInvoiceModelFactory.read(new ByteArrayInputStream(myXMLTemplate));
// Update data
model.setNetTotalAmount(100.00);
model.setTaxTotalAmount(19.00);
model.setGrandTotalAmount(119.00);
model.setIssueDateTime(myInvoiceDate);
model.setId("R-10000");
// Addresses
TradeParty billingAddress = new TradeParty("buyer");
billingAddress.setName("Max Mustermann");
billingAddress.setPostcodeCode("1000");
billingAddress.setCityName("Berlin");
billingAddress.setStreetAddress("Lindenstr. 1");
model.setTradeParty(billingAddress);
// Invoice Items
TradeLineItem tradeLineItem = new TradeLineItem("1");
tradeLineItem.setName("Moon Rocket");
tradeLineItem.setDescription("Fly my to the moon");
tradeLineItem.setGrossPrice(1000000.00);
tradeLineItem.setQuantity(1.0);
tradeLineItem.setVat(19.0);
tradeLineItem.setTotal(1000000.00);
model.setTradeLineItem(tradeLineItem);
// finally update the template file
byte[] myEInvoice=model.getContent();
Join the Project
We maintain Imixs e-invoice as an open source project on GitHub and welcome you to join our community. Whether you want to fix bugs, add new features, or improve documentation – your contributions are valuable to us. You can start by forking the repository, creating issues for bug reports or feature requests, or submitting pull requests with your improvements. We actively review contributions and provides feedback to ensure high code quality.