This commit is contained in:
Ralph Soika 2024-05-15 11:02:05 +02:00
parent c3a8957c25
commit 545bd30d92
2 changed files with 28 additions and 81 deletions

View file

@ -129,9 +129,6 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
private String INITIAL_MODEL_VERSION_INVOICE; private String INITIAL_MODEL_VERSION_INVOICE;
private int INITIAL_TASK_ID_INVOICE; private int INITIAL_TASK_ID_INVOICE;
private int INITIAL_EVENT_ID_INVOICE; private int INITIAL_EVENT_ID_INVOICE;
private String INITIAL_MODEL_VERSION_TAX;
private int INITIAL_TASK_ID_TAX;
private int INITIAL_EVENT_ID_TAX;
/** /**
* This method finds or create the Datev Export and adds a reference * This method finds or create the Datev Export and adds a reference
@ -149,10 +146,6 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
INITIAL_TASK_ID_INVOICE = 5001; INITIAL_TASK_ID_INVOICE = 5001;
INITIAL_EVENT_ID_INVOICE = 980; INITIAL_EVENT_ID_INVOICE = 980;
INITIAL_MODEL_VERSION_TAX = "zollanmeldung-de-1.0";
INITIAL_TASK_ID_TAX = 1000;
INITIAL_EVENT_ID_TAX = 980;
// Try to read the optional cargosoft import options... // Try to read the optional cargosoft import options...
ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "datev-cargosoft-import", ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "datev-cargosoft-import",
workitem, false); workitem, false);
@ -170,20 +163,6 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
if (INITIAL_EVENT_ID_INVOICE == 0) { if (INITIAL_EVENT_ID_INVOICE == 0) {
INITIAL_EVENT_ID_INVOICE = 980; // set default INITIAL_EVENT_ID_INVOICE = 980; // set default
} }
// Zollanmeldung
INITIAL_MODEL_VERSION_TAX = evalItemCollection.getItemValueString("model-tax");
if (INITIAL_MODEL_VERSION_TAX.isEmpty()) {
INITIAL_MODEL_VERSION_TAX = "zollanmeldung-de-1.0"; // set default
}
INITIAL_TASK_ID_TAX = evalItemCollection.getItemValueInteger("task-tax");
if (INITIAL_TASK_ID_TAX == 0) {
INITIAL_TASK_ID_TAX = 1000; // set default
}
INITIAL_EVENT_ID_TAX = evalItemCollection.getItemValueInteger("event-tax");
if (INITIAL_EVENT_ID_TAX == 0) {
INITIAL_EVENT_ID_TAX = 980; // set default
}
} }
try { try {
// Datei einlesen // Datei einlesen
@ -310,8 +289,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
double basisumsatz = parseBetrag(DatevImportAdapter.csvVal(dataList[4])); double basisumsatz = parseBetrag(DatevImportAdapter.csvVal(dataList[4]));
// Skip Eingangsrechnungen // Skip Eingangsrechnungen
// Wenn es aber eine ATC Belegnummer ist dann ist es doch interessant if (!gegenKonto.startsWith("1")) {
if (!gegenKonto.startsWith("1") && !belegNummer.startsWith("ATC")) {
eingangsrechnungen++; eingangsrechnungen++;
// skip // skip
continue; continue;
@ -451,11 +429,8 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
throws AdapterException { throws AdapterException {
// test if invoice was already imported before // test if invoice was already imported before
// zollanmeldung
// String sQuery = "((type:workitem OR type:workitemarchive) AND String sQuery = "((type:workitem OR type:workitemarchive) AND $modelversion:rechnungsausgang* AND invoice.number:\""
// $modelversion:rechnungsausgang* AND invoice.number:\""
// + belegNummer + "\")";
String sQuery = "((type:workitem OR type:workitemarchive) AND ($modelversion:rechnungsausgang* OR $modelversion:zollanmeldung*) AND invoice.number:\""
+ belegNummer + "\")"; + belegNummer + "\")";
try { try {
// find the textblock... // find the textblock...
@ -572,59 +547,10 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
} }
} }
// Processe die Invoice // Processe die Invoice
// In Abhängkeit von der Belegart 'Ausgangsrechnung' | 'Zollanmeldung' wird ein
// neues Workitem erzeugt.
String belegNummer = datevWorkitem.getItemValueString("invoice.number");
if (belegNummer.startsWith("ATC")) {
// Zollanmeldung
// Lookup Kreditor data... and switch dbtr to cdtr
updateATCInvoice(datevWorkitem);
datevWorkitem.model(INITIAL_MODEL_VERSION_TAX).task(INITIAL_TASK_ID_TAX).event(INITIAL_EVENT_ID_TAX);
} else {
// Normale Ausgangsrechnung
datevWorkitem.model(INITIAL_MODEL_VERSION_INVOICE).task(INITIAL_TASK_ID_INVOICE) datevWorkitem.model(INITIAL_MODEL_VERSION_INVOICE).task(INITIAL_TASK_ID_INVOICE)
.event(INITIAL_EVENT_ID_INVOICE); .event(INITIAL_EVENT_ID_INVOICE);
}
workflowService.processWorkItem(datevWorkitem); workflowService.processWorkItem(datevWorkitem);
} }
/**
* This helper method updates some attributes of a DATEV Import regarding ATC
* Invoice (Zollanmeldungen)
*
* Hier handelt es sich praktisch um eine Eingangsrechnung, daher tauschen wir
* die Vorzeichen und dbtr/cdtr
*
* @param datevWorkitem
* @throws PluginException
*/
private void updateATCInvoice(ItemCollection datevWorkitem) throws PluginException {
String cdtrNumber = datevWorkitem.getItemValueString("dbtr.number");
datevWorkitem.setItemValue("cdtr.number", cdtrNumber);
datevWorkitem.removeItem("dbtr.number");
ItemCollection creditor = kreditorDebitorService.findCreditor(cdtrNumber);
if (creditor != null) {
// update name....
datevWorkitem.setItemValue(InvoiceUtil.ITEM_CDTR_NAME, creditor.getItemValueString("_VENDOR_Name"));
}
// Update invoice.positions
InvoiceUtil.updateInvoicePositions(datevWorkitem);
// Switch S/H
List<ItemCollection> childs = InvoiceUtil.explodeChildList(datevWorkitem);
for (ItemCollection posItem : childs) {
if (posItem.hasItem("datev.shzeichen")) {
String sh = posItem.getItemValueString("datev.shzeichen");
if ("S".equalsIgnoreCase(sh)) {
sh = "H";
} else {
sh = "S";
}
posItem.setItemValue("datev.shzeichen", sh);
}
}
InvoiceUtil.implodeChildList(datevWorkitem, childs);
}
} }

View file

@ -28,14 +28,19 @@
package com.alexanderlogistics.xml; package com.alexanderlogistics.xml;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.enterprise.event.Observes; import javax.enterprise.event.Observes;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClient;
@ -50,6 +55,10 @@ import org.imixs.workflow.exceptions.AccessDeniedException;
import org.imixs.workflow.exceptions.ModelException; import org.imixs.workflow.exceptions.ModelException;
import org.imixs.workflow.exceptions.PluginException; import org.imixs.workflow.exceptions.PluginException;
import org.imixs.workflow.exceptions.ProcessingErrorException; import org.imixs.workflow.exceptions.ProcessingErrorException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/** /**
* Der CargosoftXMLInvoiceImportImportService erweitert den FTPImportService und * Der CargosoftXMLInvoiceImportImportService erweitert den FTPImportService und
@ -58,8 +67,7 @@ import org.imixs.workflow.exceptions.ProcessingErrorException;
* konfiguriert werden. * konfiguriert werden.
* <p> * <p>
* Im Gegensatz zum FTPImportService werden die XML Dateien nach einem * Im Gegensatz zum FTPImportService werden die XML Dateien nach einem
* speziellen * speziellen Verfahren geparsed und dann als Ausgangsrechnungen importiert.
* Verfahren geparsed und dann als Ausgangsrechnungen importiert.
* Der Service ersetzt den alten DATEV Import. Falls eine Rechnung schon * Der Service ersetzt den alten DATEV Import. Falls eine Rechnung schon
* existiert (Rechnungsnummer) wird der Datensatz vom FTP Laufwerk gelöscht und * existiert (Rechnungsnummer) wird der Datensatz vom FTP Laufwerk gelöscht und
* nicht importiert. * nicht importiert.
@ -291,6 +299,19 @@ public class CargosoftXMLInvoiceImportImportService {
workitem.event(source.getItemValueInteger(DocumentImportService.SOURCE_ITEM_EVENT)); workitem.event(source.getItemValueInteger(DocumentImportService.SOURCE_ITEM_EVENT));
workitem.setWorkflowGroup(source.getItemValueString("workflowgroup")); workitem.setWorkflowGroup(source.getItemValueString("workflowgroup"));
// Now we parse the rawData....
InputStream inputStream = new ByteArrayInputStream(rawData);
InputSource inputSource = new InputSource(inputStream);
DocumentBuilder documentBuilder;
try {
documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = documentBuilder.parse(inputSource);
Node node = doc.importNode(doc.getDocumentElement(), true);
} catch (ParserConfigurationException | SAXException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return workitem; return workitem;
} }