-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #163
- Loading branch information
Showing
9 changed files
with
711 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# eInvoicing Adapter | ||
|
||
The Imixs eInvoicing Adapter provides methods to parse and produce eInvoice files according to the [EN 16931 compliance](https://ec.europa.eu/digital-building-blocks/sites/display/DIGITAL/EN+16931+compliance). | ||
|
||
## Field Mapping | ||
|
||
In the default configuration the adapter supports the following items: | ||
|
||
|
||
| Item | xPath | Example | | ||
|--------------------------------- |------------------------------------------------------|------------------------------------------------------------------- | | ||
| invoice.number | Disable JNDI lookup | false | | ||
| invoice.total | Search Context | DC=intern,DC=ib-vassen,DC=de | | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.imixs.workflow</groupId> | ||
<artifactId>imixs-adapters</artifactId> | ||
<version>3.0.2-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>imixs-adapters-e-invoice</artifactId> | ||
<name>Imixs eInvoice Adapter</name> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.imixs.workflow</groupId> | ||
<artifactId>imixs-workflow-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.imixs.workflow</groupId> | ||
<artifactId>imixs-workflow-engine</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
<url>https://github.com/imixs/imixs-adapters</url> | ||
<description>Imixs eInvoicing Adapter</description> | ||
</project> |
97 changes: 97 additions & 0 deletions
97
imixs-adapters-e-invoice/src/main/java/org/imixs/workflow/einvoice/UBLParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.imixs.workflow.einvoice; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
import java.util.logging.Logger; | ||
|
||
import javax.xml.xpath.XPath; | ||
import javax.xml.xpath.XPathConstants; | ||
import javax.xml.xpath.XPathExpression; | ||
import javax.xml.xpath.XPathExpressionException; | ||
import javax.xml.xpath.XPathFactory; | ||
|
||
import org.imixs.workflow.ItemCollection; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
|
||
/** | ||
* This util class supports parsing a eInvoice file in UBL format | ||
*/ | ||
public class UBLParser { | ||
|
||
private static Logger logger = Logger.getLogger(UBLParser.class.getName()); | ||
|
||
public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; | ||
|
||
/** | ||
* This method parses a UBL Dom Tree and adapts the eInvoice fields to the Imixs | ||
* Inovice Items | ||
*/ | ||
public static void parse(Document doc, ItemCollection workitem) { | ||
|
||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/InvoiceNumber", | ||
workitem, "invoice.number", String.class); | ||
|
||
} | ||
|
||
/** | ||
* Reads a tag value from the xml tree and set the value into the given | ||
* workitem. | ||
* | ||
* /Invoices/Invoice/InvoiceHeader/Client/Code | ||
* | ||
* Beispiel Datum: | ||
* <InvoiceDate>2024-05-13T00:00:00+02:00</InvoiceDate> | ||
* | ||
* @param doc - xml doc | ||
* @param expression - xpath expression | ||
* @param workitem | ||
* @param itemName | ||
* @param itemType | ||
*/ | ||
private static <T> void readXMLValue(Document doc, String expression, ItemCollection workitem, String itemName, | ||
Class<T> itemType) { | ||
// create XPath... | ||
XPathFactory xpathFactory = XPathFactory.newInstance(); | ||
XPath xpath = xpathFactory.newXPath(); | ||
XPathExpression xPathExpression; | ||
try { | ||
xPathExpression = xpath.compile(expression); | ||
|
||
// extract node value | ||
Node valueNode = (Node) xPathExpression.evaluate(doc, XPathConstants.NODE); | ||
if (valueNode != null) { | ||
String value = valueNode.getTextContent(); | ||
|
||
if (itemType == Date.class) { | ||
// 2024-05-13T00:00:00+02:00 | ||
SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); | ||
formatter.setTimeZone(TimeZone.getTimeZone("CET")); | ||
try { | ||
workitem.setItemValue(itemName, formatter.parse(value)); | ||
} catch (ParseException e) { | ||
logger.warning("Invalid Date Format"); | ||
} | ||
return; | ||
} | ||
if (itemType == Double.class && value != null && !value.isEmpty()) { | ||
workitem.setItemValue(itemName, Double.parseDouble(value)); | ||
return; | ||
} | ||
if (itemType == Integer.class && value != null && !value.isEmpty()) { | ||
workitem.setItemValue(itemName, Integer.parseInt(value)); | ||
return; | ||
} | ||
// Default String format | ||
workitem.setItemValue(itemName, value); | ||
|
||
} | ||
} catch (XPathExpressionException e) { | ||
logger.warning("Unable to read data field '" + expression + "' : " + e.getMessage()); | ||
|
||
} | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
imixs-adapters-e-invoice/src/main/resources/META-INF/beans.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd" | ||
bean-discovery-mode="all" version="3.0"> | ||
</beans> |
24 changes: 24 additions & 0 deletions
24
imixs-adapters-e-invoice/src/main/resources/META-INF/copyright.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Imixs Workflow | ||
Copyright (C) 2001, 2011 Imixs Software Solutions GmbH, | ||
http://www.imixs.com | ||
|
||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
|
||
You can receive a copy of the GNU General Public | ||
License at http://www.gnu.org/licenses/gpl.html | ||
|
||
Project: | ||
http://www.imixs.org | ||
http://java.net/projects/imixs-workflow | ||
|
||
Contributors: | ||
Imixs Software Solutions GmbH - initial API and implementation | ||
Ralph Soika - Software Developer |
Oops, something went wrong.