datev import logging verbessert
This commit is contained in:
parent
406f0a415b
commit
fe86360a3a
3 changed files with 142 additions and 51 deletions
|
|
@ -25,6 +25,7 @@ import org.imixs.workflow.exceptions.AdapterException;
|
||||||
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.imixs.workflow.exceptions.QueryException;
|
||||||
|
|
||||||
import com.alexanderlogistics.KreditorDebitorService;
|
import com.alexanderlogistics.KreditorDebitorService;
|
||||||
|
|
||||||
|
|
@ -68,7 +69,8 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
||||||
|
|
||||||
logger.info("...parse datev file import...");
|
logger.info("...parse datev file import...");
|
||||||
try {
|
try {
|
||||||
readData(workitem);
|
List<String> log = readData(workitem);
|
||||||
|
workitem.setItemValue("import.log", log);
|
||||||
} catch (ModelException e) {
|
} catch (ModelException e) {
|
||||||
throw new AdapterException(PluginException.class.getSimpleName(), DatevImportAdapter.DATEV_IMPORT_ERROR,
|
throw new AdapterException(PluginException.class.getSimpleName(), DatevImportAdapter.DATEV_IMPORT_ERROR,
|
||||||
"Failed to import datev data!", e);
|
"Failed to import datev data!", e);
|
||||||
|
|
@ -91,21 +93,27 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
||||||
* @throws ProcessingErrorException
|
* @throws ProcessingErrorException
|
||||||
* @throws AccessDeniedException
|
* @throws AccessDeniedException
|
||||||
*/
|
*/
|
||||||
private void readData(ItemCollection workitem)
|
private List<String> readData(ItemCollection workitem)
|
||||||
throws PluginException, AccessDeniedException, ProcessingErrorException, ModelException {
|
throws PluginException, AccessDeniedException, ProcessingErrorException, ModelException {
|
||||||
|
List<String> logBuffer = new ArrayList<String>();
|
||||||
|
int line = 0;
|
||||||
|
int positions = 0;
|
||||||
|
int invoices = 0;
|
||||||
|
int dupplicates = 0;
|
||||||
|
|
||||||
String dataLine;
|
String dataLine;
|
||||||
// Start Datum Wirtschaftsjahr berechnen (JJJJMMTT)
|
// Start Datum Wirtschaftsjahr berechnen (JJJJMMTT)
|
||||||
String wjBeginn=workitem.getItemValueString("datev.WJ-Beginn");
|
String wjBeginn = workitem.getItemValueString("datev.WJ-Beginn");
|
||||||
String wjBeginnMonat=wjBeginn.substring(4,6);
|
String wjBeginnMonat = wjBeginn.substring(4, 6);
|
||||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
|
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
|
||||||
|
|
||||||
ItemCollection invoiceWorkitem = null;
|
ItemCollection invoiceWorkitem = null;
|
||||||
List<ItemCollection> splitBuchungen = new ArrayList<ItemCollection>();
|
List<ItemCollection> splitBuchungen = new ArrayList<ItemCollection>();
|
||||||
|
|
||||||
FileData fileData = workitem.getFileData().get(0);
|
FileData fileData = workitem.getFileData().get(0);
|
||||||
ByteArrayInputStream imputStream = new ByteArrayInputStream(fileData.getContent());
|
ByteArrayInputStream imputStream = new ByteArrayInputStream(fileData.getContent());
|
||||||
|
|
||||||
|
log(logBuffer, "Importdatei: " + fileData.getName());
|
||||||
try {
|
try {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(imputStream, ENCODING));
|
BufferedReader in = new BufferedReader(new InputStreamReader(imputStream, ENCODING));
|
||||||
|
|
||||||
|
|
@ -114,7 +122,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
||||||
in.readLine();
|
in.readLine();
|
||||||
|
|
||||||
// read content....
|
// read content....
|
||||||
int line = 0;
|
line = 0;
|
||||||
int blockSize = 0;
|
int blockSize = 0;
|
||||||
while ((dataLine = in.readLine()) != null) {
|
while ((dataLine = in.readLine()) != null) {
|
||||||
line++;
|
line++;
|
||||||
|
|
@ -126,8 +134,8 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
||||||
// alle werte parsen
|
// alle werte parsen
|
||||||
String[] header1List = dataLine.split(";(?=([^\"]*\"[^\"]*\")*[^\"]*$)", 99);
|
String[] header1List = dataLine.split(";(?=([^\"]*\"[^\"]*\")*[^\"]*$)", 99);
|
||||||
if (header1List.length < 6) {
|
if (header1List.length < 6) {
|
||||||
throw new PluginException(DatevCargosoftImportAdapter.class.getName(),DatevImportAdapter.DATEV_IMPORT_ERROR,
|
throw new PluginException(DatevCargosoftImportAdapter.class.getName(),
|
||||||
"Invalid data in line " + line);
|
DatevImportAdapter.DATEV_IMPORT_ERROR, "Invalid data in line " + line);
|
||||||
}
|
}
|
||||||
|
|
||||||
String belegNummer = DatevImportAdapter.csvVal(header1List[10]);
|
String belegNummer = DatevImportAdapter.csvVal(header1List[10]);
|
||||||
|
|
@ -135,26 +143,26 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
||||||
String text = DatevImportAdapter.csvVal(header1List[13]);
|
String text = DatevImportAdapter.csvVal(header1List[13]);
|
||||||
String buchungsTag = DatevImportAdapter.csvVal(header1List[9]);
|
String buchungsTag = DatevImportAdapter.csvVal(header1List[9]);
|
||||||
// cargosoft laesst gerne die führende 0 weg....
|
// cargosoft laesst gerne die führende 0 weg....
|
||||||
if (buchungsTag.length()==3) {
|
if (buchungsTag.length() == 3) {
|
||||||
buchungsTag="0"+buchungsTag;
|
buchungsTag = "0" + buchungsTag;
|
||||||
}
|
}
|
||||||
// berechne Buchungsdatum DDMM
|
// berechne Buchungsdatum DDMM
|
||||||
String tag=buchungsTag.substring(0,2);
|
String tag = buchungsTag.substring(0, 2);
|
||||||
String monat=buchungsTag.substring(2,4);
|
String monat = buchungsTag.substring(2, 4);
|
||||||
String jahr=wjBeginn.substring(0,4);
|
String jahr = wjBeginn.substring(0, 4);
|
||||||
// compute next year if start of WJ is not January
|
// compute next year if start of WJ is not January
|
||||||
if (Integer.parseInt(wjBeginnMonat)>Integer.parseInt(monat)) {
|
if (Integer.parseInt(wjBeginnMonat) > Integer.parseInt(monat)) {
|
||||||
jahr=Integer.parseInt(jahr+1)+"";
|
jahr = Integer.parseInt(jahr + 1) + "";
|
||||||
}
|
}
|
||||||
Date dateBuchung = dateFormatter.parse(jahr+monat+tag);
|
Date dateBuchung = dateFormatter.parse(jahr + monat + tag);
|
||||||
// Fälligkeit
|
// Fälligkeit
|
||||||
Date dueDate=dateFormatter.parse(DatevImportAdapter.csvVal(header1List[23]));
|
Date dueDate = dateFormatter.parse(DatevImportAdapter.csvVal(header1List[23]));
|
||||||
String paymentTerm= DatevImportAdapter.csvVal(header1List[31]);
|
String paymentTerm = DatevImportAdapter.csvVal(header1List[31]);
|
||||||
String waehrung = DatevImportAdapter.csvVal(header1List[2]);
|
String waehrung = DatevImportAdapter.csvVal(header1List[2]);
|
||||||
|
|
||||||
// kurse
|
// kurse
|
||||||
double kurs=parseBetrag(DatevImportAdapter.csvVal(header1List[3]));
|
double kurs = parseBetrag(DatevImportAdapter.csvVal(header1List[3]));
|
||||||
double basisumsatz= parseBetrag(DatevImportAdapter.csvVal(header1List[4]));
|
double basisumsatz = parseBetrag(DatevImportAdapter.csvVal(header1List[4]));
|
||||||
|
|
||||||
// Skip Eingangsrechnungen
|
// Skip Eingangsrechnungen
|
||||||
if (!gegenKonto.startsWith("1")) {
|
if (!gegenKonto.startsWith("1")) {
|
||||||
|
|
@ -162,8 +170,8 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
positions++;
|
||||||
logger.info("...read dbtr: " + gegenKonto + " beleg-nr: "+belegNummer);
|
logger.info("...read dbtr: " + gegenKonto + " beleg-nr: " + belegNummer);
|
||||||
|
|
||||||
// Erzeuge einen Buchungssatz
|
// Erzeuge einen Buchungssatz
|
||||||
ItemCollection dataItemCol = new ItemCollection();
|
ItemCollection dataItemCol = new ItemCollection();
|
||||||
|
|
@ -175,15 +183,18 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
||||||
dataItemCol.setItemValue("datev.basisumsatz", parseBetrag(DatevImportAdapter.csvVal(header1List[4])));
|
dataItemCol.setItemValue("datev.basisumsatz", parseBetrag(DatevImportAdapter.csvVal(header1List[4])));
|
||||||
dataItemCol.setItemValue("datev.konto", DatevImportAdapter.csvVal(header1List[6]));
|
dataItemCol.setItemValue("datev.konto", DatevImportAdapter.csvVal(header1List[6]));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Haben wir schon eine Invoice Workitem angelegt?
|
// Haben wir schon eine Invoice Workitem angelegt?
|
||||||
if (invoiceWorkitem == null) {
|
if (invoiceWorkitem == null) {
|
||||||
logger.info("...create new workitem....");
|
logger.info("...create new workitem....");
|
||||||
// erzeuge ein neues
|
// erzeuge ein neues
|
||||||
invoiceWorkitem =createEmptyInvoice(belegNummer,text,gegenKonto,dateBuchung,dueDate,paymentTerm,waehrung,kurs,basisumsatz );
|
try {
|
||||||
|
invoiceWorkitem = createEmptyInvoice(belegNummer, text, gegenKonto, dateBuchung, dueDate,
|
||||||
|
paymentTerm, waehrung, kurs, basisumsatz);
|
||||||
|
invoices++;
|
||||||
|
} catch (AdapterException e) {
|
||||||
|
dupplicates++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ist es noch die selbe Belegnummer?
|
// ist es noch die selbe Belegnummer?
|
||||||
|
|
@ -196,44 +207,97 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
||||||
|
|
||||||
// nein - also invoice schließen
|
// nein - also invoice schließen
|
||||||
closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen);
|
closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen);
|
||||||
|
invoiceWorkitem=null;
|
||||||
// neue Splitbuchungstabelle anlegen
|
// neue Splitbuchungstabelle anlegen
|
||||||
splitBuchungen = new ArrayList<ItemCollection>();
|
splitBuchungen = new ArrayList<ItemCollection>();
|
||||||
// invoice zurücksetzten
|
// invoice zurücksetzten
|
||||||
// erzeuge ein neues
|
// erzeuge ein neues
|
||||||
invoiceWorkitem =createEmptyInvoice(belegNummer,text,gegenKonto,dateBuchung,dueDate,paymentTerm,waehrung,kurs,basisumsatz );
|
try {
|
||||||
|
invoiceWorkitem = createEmptyInvoice(belegNummer, text, gegenKonto, dateBuchung, dueDate,
|
||||||
|
paymentTerm, waehrung, kurs, basisumsatz);
|
||||||
|
invoices++;
|
||||||
|
} catch (AdapterException e) {
|
||||||
|
dupplicates++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
splitBuchungen.add(dataItemCol);
|
splitBuchungen.add(dataItemCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
}// wile end
|
} // wile end
|
||||||
closeInvoiceWorkitem(invoiceWorkitem,splitBuchungen);
|
closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen);
|
||||||
|
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
throw new PluginException(DatevCargosoftImportAdapter.class.getName(), DatevImportAdapter.DATEV_IMPORT_ERROR,
|
throw new PluginException(DatevCargosoftImportAdapter.class.getName(),
|
||||||
"Unable to read file", e);
|
DatevImportAdapter.DATEV_IMPORT_ERROR, "Unable to read file", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log(logBuffer, line + " Zeilen eingelesen ");
|
||||||
|
log(logBuffer, positions + " Rechnungspositionen eingelesen ");
|
||||||
|
log(logBuffer, invoices + " Rechnungen importiert ");
|
||||||
|
if (dupplicates > 0) {
|
||||||
|
log(logBuffer, dupplicates + " Rechnungen wurden übersprungen da diese bereits importiert wurden!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// return log
|
||||||
|
return logBuffer;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns a new empty invoice ItemCollection.
|
||||||
|
* <p>
|
||||||
|
* The method tests if an invoice with this number already exits. If so, the
|
||||||
|
* method throws a AdapterException
|
||||||
|
*
|
||||||
|
* @param belegNummer
|
||||||
|
* @param text
|
||||||
|
* @param gegenKonto
|
||||||
|
* @param dateBuchung
|
||||||
|
* @param dueDate
|
||||||
|
* @param paymentTerm
|
||||||
|
* @param currency
|
||||||
|
* @param kurs
|
||||||
|
* @param basisUmsatz
|
||||||
|
* @return
|
||||||
|
* @throws AdapterException
|
||||||
|
*/
|
||||||
|
private ItemCollection createEmptyInvoice(String belegNummer, String text, String gegenKonto, Date dateBuchung,
|
||||||
|
Date dueDate, String paymentTerm, String currency, double kurs, double basisUmsatz)
|
||||||
|
throws AdapterException {
|
||||||
|
|
||||||
|
// test if invoice was already imported before
|
||||||
|
String sQuery = "((type:workitem OR type:workitemarchive) AND $modelversion:rechnungsausgang* AND invoice.number:\""+belegNummer+"\")";
|
||||||
|
try {
|
||||||
|
// find the textblock...
|
||||||
|
List<ItemCollection> result = documentService.find(sQuery, 1, 0);
|
||||||
|
if (result.size() > 0) {
|
||||||
|
throw new AdapterException(DatevCargosoftImportAdapter.class.getName(), "DUPPLICATE",
|
||||||
|
"Invoice already imported");
|
||||||
|
}
|
||||||
|
} catch (QueryException e) {
|
||||||
|
logger.warning("failed to search invoices by query: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemCollection createEmptyInvoice(String belegNummer, String text, String gegenKonto, Date dateBuchung,Date dueDate,String paymentTerm,String currency,
|
|
||||||
double kurs,double basisUmsatz) {
|
|
||||||
ItemCollection invoiceWorkitem = new ItemCollection();
|
ItemCollection invoiceWorkitem = new ItemCollection();
|
||||||
invoiceWorkitem.setItemValue("invoice.number", belegNummer);
|
invoiceWorkitem.setItemValue("invoice.number", belegNummer);
|
||||||
invoiceWorkitem.setItemValue("invoice.currency", currency);
|
invoiceWorkitem.setItemValue("invoice.currency", currency);
|
||||||
invoiceWorkitem.setItemValue("invoice.text", text);
|
invoiceWorkitem.setItemValue("invoice.text", text);
|
||||||
invoiceWorkitem.setItemValue("invoice.date", dateBuchung);
|
invoiceWorkitem.setItemValue("invoice.date", dateBuchung);
|
||||||
invoiceWorkitem.setItemValue("dbtr.number", gegenKonto);
|
invoiceWorkitem.setItemValue("dbtr.number", gegenKonto);
|
||||||
invoiceWorkitem.setItemValue("invoice.duedate",dueDate);
|
invoiceWorkitem.setItemValue("invoice.duedate", dueDate);
|
||||||
invoiceWorkitem.setItemValue("invoice.reminder", dueDate);
|
invoiceWorkitem.setItemValue("invoice.reminder", dueDate);
|
||||||
invoiceWorkitem.setItemValue("payment.term",paymentTerm);
|
invoiceWorkitem.setItemValue("payment.term", paymentTerm);
|
||||||
|
|
||||||
|
invoiceWorkitem.setItemValue("invoice.rate", kurs);
|
||||||
invoiceWorkitem.setItemValue("invoice.rate",kurs);
|
invoiceWorkitem.setItemValue("invoice.base.amount", basisUmsatz);
|
||||||
invoiceWorkitem.setItemValue("invoice.base.amount",basisUmsatz);
|
|
||||||
|
|
||||||
return invoiceWorkitem;
|
return invoiceWorkitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void log(List<String> log, String message) {
|
||||||
|
log.add(new Date() + ": " + message+"\n");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* . entfernen , mit punkt ersetzten
|
* . entfernen , mit punkt ersetzten
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:ui="http://java.sun.com/jsf/facelets"
|
||||||
|
xmlns:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:c="http://java.sun.com/jsp/jstl/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h:panelGroup styleClass="imixs-form-section" id="import-log">
|
||||||
|
|
||||||
|
<h3>Protokoll:</h3>
|
||||||
|
|
||||||
|
|
||||||
|
<ui:repeat value="#{workitem.itemList['import.log']}" var="entry">
|
||||||
|
<h:outputText value="#{entry}" />
|
||||||
|
<br />
|
||||||
|
</ui:repeat>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</h:panelGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ui:composition>
|
||||||
|
|
||||||
|
|
@ -165,7 +165,7 @@ result.isValid=true;
|
||||||
<imixs:value><![CDATA[typcn-download-outline||typcn-tick,imixs-success]]></imixs:value>
|
<imixs:value><![CDATA[typcn-download-outline||typcn-tick,imixs-success]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="txteditorid" type="xs:string">
|
<imixs:item name="txteditorid" type="xs:string">
|
||||||
<imixs:value><![CDATA[form_basic]]></imixs:value>
|
<imixs:value><![CDATA[form_basic#import_log]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="txttype" type="xs:string">
|
<imixs:item name="txttype" type="xs:string">
|
||||||
<imixs:value><![CDATA[workitemarchive]]></imixs:value>
|
<imixs:value><![CDATA[workitemarchive]]></imixs:value>
|
||||||
|
|
@ -232,7 +232,7 @@ if (workitem['$file.count'][0]!=1) {
|
||||||
<imixs:value><![CDATA[DATEV-Import <itemvalue format="EEEE, d. MMMM yyyy" locale="de_DE">$created</itemvalue>]]></imixs:value>
|
<imixs:value><![CDATA[DATEV-Import <itemvalue format="EEEE, d. MMMM yyyy" locale="de_DE">$created</itemvalue>]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="txteditorid" type="xs:string">
|
<imixs:item name="txteditorid" type="xs:string">
|
||||||
<imixs:value><![CDATA[form_basic]]></imixs:value>
|
<imixs:value><![CDATA[form_basic#import_log]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="txtimageurl" type="xs:string">
|
<imixs:item name="txtimageurl" type="xs:string">
|
||||||
<imixs:value><![CDATA[typcn-download-outline||||]]></imixs:value>
|
<imixs:value><![CDATA[typcn-download-outline||||]]></imixs:value>
|
||||||
|
|
@ -277,7 +277,7 @@ if (workitem['$file.count'][0]!=1) {
|
||||||
<imixs:value><![CDATA[typcn-download-outline||typcn-times,imixs-error]]></imixs:value>
|
<imixs:value><![CDATA[typcn-download-outline||typcn-times,imixs-error]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="txteditorid" type="xs:string">
|
<imixs:item name="txteditorid" type="xs:string">
|
||||||
<imixs:value><![CDATA[form_basic]]></imixs:value>
|
<imixs:value><![CDATA[form_basic#import_log]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="txttype" type="xs:string">
|
<imixs:item name="txttype" type="xs:string">
|
||||||
<imixs:value><![CDATA[workitemarchive]]></imixs:value>
|
<imixs:value><![CDATA[workitemarchive]]></imixs:value>
|
||||||
|
|
@ -318,7 +318,7 @@ if (workitem['$file.count'][0]!=1) {
|
||||||
<imixs:value><![CDATA[typcn-download-outline||typcn-time,imixs-warning]]></imixs:value>
|
<imixs:value><![CDATA[typcn-download-outline||typcn-time,imixs-warning]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="txteditorid" type="xs:string">
|
<imixs:item name="txteditorid" type="xs:string">
|
||||||
<imixs:value><![CDATA[form_basic]]></imixs:value>
|
<imixs:value><![CDATA[form_basic#import_log]]></imixs:value>
|
||||||
</imixs:item>
|
</imixs:item>
|
||||||
<imixs:item name="txttype" type="xs:string">
|
<imixs:item name="txttype" type="xs:string">
|
||||||
<imixs:value><![CDATA[workitem]]></imixs:value>
|
<imixs:value><![CDATA[workitem]]></imixs:value>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue