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.PluginException;
|
||||
import org.imixs.workflow.exceptions.ProcessingErrorException;
|
||||
import org.imixs.workflow.exceptions.QueryException;
|
||||
|
||||
import com.alexanderlogistics.KreditorDebitorService;
|
||||
|
||||
|
|
@ -68,7 +69,8 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
|
||||
logger.info("...parse datev file import...");
|
||||
try {
|
||||
readData(workitem);
|
||||
List<String> log = readData(workitem);
|
||||
workitem.setItemValue("import.log", log);
|
||||
} catch (ModelException e) {
|
||||
throw new AdapterException(PluginException.class.getSimpleName(), DatevImportAdapter.DATEV_IMPORT_ERROR,
|
||||
"Failed to import datev data!", e);
|
||||
|
|
@ -91,21 +93,27 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
* @throws ProcessingErrorException
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
private void readData(ItemCollection workitem)
|
||||
private List<String> readData(ItemCollection workitem)
|
||||
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;
|
||||
// Start Datum Wirtschaftsjahr berechnen (JJJJMMTT)
|
||||
String wjBeginn = workitem.getItemValueString("datev.WJ-Beginn");
|
||||
String wjBeginnMonat = wjBeginn.substring(4, 6);
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
|
||||
ItemCollection invoiceWorkitem = null;
|
||||
List<ItemCollection> splitBuchungen = new ArrayList<ItemCollection>();
|
||||
|
||||
FileData fileData = workitem.getFileData().get(0);
|
||||
ByteArrayInputStream imputStream = new ByteArrayInputStream(fileData.getContent());
|
||||
|
||||
log(logBuffer, "Importdatei: " + fileData.getName());
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(imputStream, ENCODING));
|
||||
|
||||
|
|
@ -114,7 +122,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
in.readLine();
|
||||
|
||||
// read content....
|
||||
int line = 0;
|
||||
line = 0;
|
||||
int blockSize = 0;
|
||||
while ((dataLine = in.readLine()) != null) {
|
||||
line++;
|
||||
|
|
@ -126,8 +134,8 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
// alle werte parsen
|
||||
String[] header1List = dataLine.split(";(?=([^\"]*\"[^\"]*\")*[^\"]*$)", 99);
|
||||
if (header1List.length < 6) {
|
||||
throw new PluginException(DatevCargosoftImportAdapter.class.getName(),DatevImportAdapter.DATEV_IMPORT_ERROR,
|
||||
"Invalid data in line " + line);
|
||||
throw new PluginException(DatevCargosoftImportAdapter.class.getName(),
|
||||
DatevImportAdapter.DATEV_IMPORT_ERROR, "Invalid data in line " + line);
|
||||
}
|
||||
|
||||
String belegNummer = DatevImportAdapter.csvVal(header1List[10]);
|
||||
|
|
@ -162,7 +170,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
continue;
|
||||
}
|
||||
|
||||
|
||||
positions++;
|
||||
logger.info("...read dbtr: " + gegenKonto + " beleg-nr: " + belegNummer);
|
||||
|
||||
// Erzeuge einen Buchungssatz
|
||||
|
|
@ -175,15 +183,18 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
dataItemCol.setItemValue("datev.basisumsatz", parseBetrag(DatevImportAdapter.csvVal(header1List[4])));
|
||||
dataItemCol.setItemValue("datev.konto", DatevImportAdapter.csvVal(header1List[6]));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Haben wir schon eine Invoice Workitem angelegt?
|
||||
if (invoiceWorkitem == null) {
|
||||
logger.info("...create new workitem....");
|
||||
// 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?
|
||||
|
|
@ -196,12 +207,19 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
|
||||
// nein - also invoice schließen
|
||||
closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen);
|
||||
|
||||
invoiceWorkitem=null;
|
||||
// neue Splitbuchungstabelle anlegen
|
||||
splitBuchungen = new ArrayList<ItemCollection>();
|
||||
// invoice zurücksetzten
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
@ -209,14 +227,57 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen);
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
throw new PluginException(DatevCargosoftImportAdapter.class.getName(), DatevImportAdapter.DATEV_IMPORT_ERROR,
|
||||
"Unable to read file", e);
|
||||
throw new PluginException(DatevCargosoftImportAdapter.class.getName(),
|
||||
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();
|
||||
invoiceWorkitem.setItemValue("invoice.number", belegNummer);
|
||||
invoiceWorkitem.setItemValue("invoice.currency", currency);
|
||||
|
|
@ -227,13 +288,16 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
invoiceWorkitem.setItemValue("invoice.reminder", dueDate);
|
||||
invoiceWorkitem.setItemValue("payment.term", paymentTerm);
|
||||
|
||||
|
||||
invoiceWorkitem.setItemValue("invoice.rate", kurs);
|
||||
invoiceWorkitem.setItemValue("invoice.base.amount", basisUmsatz);
|
||||
|
||||
return invoiceWorkitem;
|
||||
}
|
||||
|
||||
private void log(List<String> log, String message) {
|
||||
log.add(new Date() + ": " + message+"\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* . 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:item>
|
||||
<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 name="txttype" type="xs:string">
|
||||
<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:item>
|
||||
<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 name="txtimageurl" type="xs:string">
|
||||
<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:item>
|
||||
<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 name="txttype" type="xs:string">
|
||||
<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:item>
|
||||
<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 name="txttype" type="xs:string">
|
||||
<imixs:value><![CDATA[workitem]]></imixs:value>
|
||||
|
|
|
|||
Loading…
Reference in a new issue