import Datum und name Debitor
This commit is contained in:
parent
1d447da7e6
commit
c4f0e9c5d6
2 changed files with 67 additions and 6 deletions
|
|
@ -4,7 +4,10 @@ import java.io.BufferedReader;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -15,12 +18,16 @@ import org.imixs.workflow.FileData;
|
|||
import org.imixs.workflow.ItemCollection;
|
||||
import org.imixs.workflow.SignalAdapter;
|
||||
import org.imixs.workflow.datev.imports.DatevImportAdapter;
|
||||
import org.imixs.workflow.engine.DocumentService;
|
||||
import org.imixs.workflow.engine.WorkflowService;
|
||||
import org.imixs.workflow.exceptions.AccessDeniedException;
|
||||
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.CargosoftController;
|
||||
|
||||
/**
|
||||
* Der DatevCargosoftImportAdapter liest eine von Cargosoft bereitgestellte
|
||||
|
|
@ -41,9 +48,13 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
|
||||
public static final String ENCODING = "ISO-8859-1";
|
||||
public static final String CHILD_ITEM_PROPERTY = "_ChildItems";
|
||||
|
||||
@Inject
|
||||
WorkflowService workflowService;
|
||||
|
||||
@Inject
|
||||
DocumentService documentService;
|
||||
|
||||
/**
|
||||
* This method finds or create the Datev Export and adds a reference
|
||||
* ($workitemref) to the current invoice.
|
||||
|
|
@ -82,6 +93,12 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
private void readData(ItemCollection workitem)
|
||||
throws PluginException, AccessDeniedException, ProcessingErrorException, ModelException {
|
||||
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>();
|
||||
|
||||
|
|
@ -115,6 +132,20 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
String belegNummer = DatevImportAdapter.csvVal(header1List[10]);
|
||||
String gegenKonto = DatevImportAdapter.csvVal(header1List[7]);
|
||||
String text = DatevImportAdapter.csvVal(header1List[13]);
|
||||
String buchungsTag = DatevImportAdapter.csvVal(header1List[9]);
|
||||
// cargosoft laesst gerne die führende 0 weg....
|
||||
if (buchungsTag.length()==3) {
|
||||
buchungsTag="0"+buchungsTag;
|
||||
}
|
||||
// berechne Buchungsdatum DDMM
|
||||
String tag=buchungsTag.substring(0,2);
|
||||
String monat=buchungsTag.substring(2,4);
|
||||
String jahr=wjBeginn.substring(0,4);
|
||||
// compute next year if start of WJ is not January
|
||||
if (Integer.parseInt(wjBeginnMonat)>Integer.parseInt(monat)) {
|
||||
jahr=Integer.parseInt(jahr+1)+"";
|
||||
}
|
||||
Date dateBuchung = dateFormatter.parse(jahr+monat+tag);
|
||||
|
||||
// Skip Eingangsrechnungen
|
||||
if (!gegenKonto.startsWith("1")) {
|
||||
|
|
@ -139,7 +170,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
if (invoiceWorkitem == null) {
|
||||
logger.info("...create new workitem....");
|
||||
// erzeuge ein neues
|
||||
invoiceWorkitem =createEmptyInvoice(belegNummer,text,gegenKonto);
|
||||
invoiceWorkitem =createEmptyInvoice(belegNummer,text,gegenKonto,dateBuchung);
|
||||
}
|
||||
|
||||
// ist es noch die selbe Belegnummer?
|
||||
|
|
@ -157,24 +188,25 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
splitBuchungen = new ArrayList<ItemCollection>();
|
||||
// invoice zurücksetzten
|
||||
// erzeuge ein neues
|
||||
invoiceWorkitem =createEmptyInvoice(belegNummer,text,gegenKonto);
|
||||
invoiceWorkitem =createEmptyInvoice(belegNummer,text,gegenKonto,dateBuchung);
|
||||
splitBuchungen.add(dataItemCol);
|
||||
}
|
||||
|
||||
}// wile end
|
||||
closeInvoiceWorkitem(invoiceWorkitem,splitBuchungen);
|
||||
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | ParseException e) {
|
||||
throw new PluginException(DatevCargosoftImportAdapter.class.getName(), DatevImportAdapter.DATEV_IMPORT_ERROR,
|
||||
"Unable to read file", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ItemCollection createEmptyInvoice(String belegNummer, String text, String gegenKonto) {
|
||||
private ItemCollection createEmptyInvoice(String belegNummer, String text, String gegenKonto,Date dateBuchung ) {
|
||||
ItemCollection invoiceWorkitem = new ItemCollection();
|
||||
invoiceWorkitem.setItemValue("invoice.number", belegNummer);
|
||||
invoiceWorkitem.setItemValue("invoice.text", text);
|
||||
invoiceWorkitem.setItemValue("invoice.date", dateBuchung);
|
||||
invoiceWorkitem.setItemValue("dbtr.number", gegenKonto);
|
||||
return invoiceWorkitem;
|
||||
}
|
||||
|
|
@ -223,6 +255,14 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
invoiceWorkitem.setItemValue("invoice.total", total);
|
||||
// implode die Splitbuchungen
|
||||
implodeChildList(invoiceWorkitem, splitBuchungen);
|
||||
|
||||
// set dbtr.name
|
||||
ItemCollection dbtrItemCol=findDbtr(invoiceWorkitem.getItemValueString("dbtr.number"));
|
||||
if (dbtrItemCol!=null) {
|
||||
invoiceWorkitem.setItemValue("dbtr.name", dbtrItemCol.getItemValueString("_VENDOR_Name"));
|
||||
}
|
||||
|
||||
|
||||
// Processe die Invoice
|
||||
invoiceWorkitem.model("rechnungsausgang-de-1.0").task(5001).event(980);
|
||||
workflowService.processWorkItem(invoiceWorkitem);
|
||||
|
|
@ -251,4 +291,25 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method searches a dbtr by number
|
||||
*/
|
||||
private ItemCollection findDbtr(String number) {
|
||||
// die cargosoft Kreditornummer beginnt seltsamerweise mit einem K
|
||||
// und die Debitoren mit einem D.....
|
||||
String query = "(type:" + CargosoftController.TYPE_CARGOSOFTKREDITOR + ") AND (name:D" + number+")";
|
||||
|
||||
try {
|
||||
List<ItemCollection> result = documentService.find(query, 1, 0, "$modified", true);
|
||||
logger.info("found " + result.size() + " debitors...");
|
||||
if (result != null && result.size()>0) {
|
||||
return result.get(0);
|
||||
|
||||
}
|
||||
} catch (QueryException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -297,7 +297,7 @@ Bei Fragen wenden Sie sich bitte an info@imixs.com
|
|||
<imixs:value><![CDATA[typcn-download]]></imixs:value>
|
||||
</imixs:item>
|
||||
<imixs:item name="txtworkflowsummary" type="xs:string">
|
||||
<imixs:value><![CDATA[<itemvalue>dbtr.number</itemvalue> <itemvalue>invoice.number</itemvalue> (<itemvalue>invoice.currency</itemvalue> <itemvalue>invoice.total</itemvalue>) ]]></imixs:value>
|
||||
<imixs:value><![CDATA[<itemvalue>invoice.number</itemvalue> <itemvalue>dbtr.number</itemvalue> <itemvalue>dbtr.name</itemvalue> (<itemvalue>invoice.currency</itemvalue> <itemvalue>invoice.total</itemvalue>) ]]></imixs:value>
|
||||
</imixs:item>
|
||||
<imixs:item name="keyupdateacl" type="xs:boolean">
|
||||
<imixs:value>true</imixs:value>
|
||||
|
|
|
|||
Loading…
Reference in a new issue