diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftExportAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftExportAdapter.java index a5e780c..645ded0 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftExportAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftExportAdapter.java @@ -25,7 +25,7 @@ import org.imixs.workflow.exceptions.PluginException; *

* The adapter can be configured through the model result item 'cargosoft' *

- * report = report definition to transfere the workitem into the cargosoft xml + * report = report definition to transfers the workitem into the cargosoft xml * structure * *

diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisAppendAdapter.java
similarity index 79%
rename from office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisAdapter.java
rename to office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisAppendAdapter.java
index 8cc0f6e..839583f 100644
--- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisAdapter.java
+++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisAppendAdapter.java
@@ -23,14 +23,16 @@ import org.imixs.workflow.exceptions.QueryException;
  * Wurde die Rechnugn bereits einem Zahlungsavis zugeordnet passiert nichts.
  * 
  * 
+ * 
  * @version 1.0
  * @author rsoika
  */
-public class ZahlungsavisAdapter implements SignalAdapter {
+public class ZahlungsavisAppendAdapter implements SignalAdapter {
 
-    private static Logger logger = Logger.getLogger(ZahlungsavisAdapter.class.getName());
+    private static Logger logger = Logger.getLogger(ZahlungsavisAppendAdapter.class.getName());
 
     public static final String ERROR_MISSING_DATA = "MISSING_DATA";
+    public static final String ERROR_CONFIG = "CONFIG_ERROR";
 
     public static final String ITEM_CDTR_NUMBER = "cdtr.number";
     public static final String ITEM_CDTR_NAME = "cdtr.name";
@@ -46,10 +48,22 @@ public class ZahlungsavisAdapter implements SignalAdapter {
      * @throws PluginException
      */
     @Override
-    public ItemCollection execute(ItemCollection invoice, ItemCollection event)
+    public ItemCollection execute(ItemCollection document, ItemCollection event)
             throws AdapterException, PluginException {
 
-        String cdtrNumber = invoice.getItemValueString(ITEM_CDTR_NUMBER);
+        appendInvoice(document);
+
+        return document;
+    }
+
+    /**
+     * Diese method hängt eine referenz der aktuellen Rechnung an den Zahlungsavis
+     * 
+     * @param document
+     * @throws PluginException
+     */
+    private void appendInvoice(ItemCollection document) throws PluginException {
+        String cdtrNumber = document.getItemValueString(ITEM_CDTR_NUMBER);
 
         if (cdtrNumber == null || cdtrNumber.isEmpty()) {
             throw new PluginException(PluginException.class.getName(), ERROR_MISSING_DATA,
@@ -63,15 +77,15 @@ public class ZahlungsavisAdapter implements SignalAdapter {
                 // create a new one
                 zahlungsAvis = new ItemCollection().workflowGroup("Zahlungsavis").task(1000).event(100);
                 // add cdtr.name
-                zahlungsAvis.setItemValue(ITEM_CDTR_NAME, invoice.getItemValue(ITEM_CDTR_NAME));
-                zahlungsAvis.setItemValue(ITEM_CDTR_NUMBER, invoice.getItemValue(ITEM_CDTR_NUMBER));
-                zahlungsAvis.setItemValue(ITEM_CDTR_NAME_CARGOSOFT, invoice.getItemValue(ITEM_CDTR_NAME_CARGOSOFT));
+                zahlungsAvis.setItemValue(ITEM_CDTR_NAME, document.getItemValue(ITEM_CDTR_NAME));
+                zahlungsAvis.setItemValue(ITEM_CDTR_NUMBER, document.getItemValue(ITEM_CDTR_NUMBER));
+                zahlungsAvis.setItemValue(ITEM_CDTR_NAME_CARGOSOFT, document.getItemValue(ITEM_CDTR_NAME_CARGOSOFT));
             } else {
                 // zahlungsavis speichern
                 zahlungsAvis.event(100);
             }
             // Invoice mit zahlungsavis verknüpften (falls noch nicht verknüpft)
-            zahlungsAvis.appendItemValueUnique("$workitemref", invoice.getUniqueID());
+            zahlungsAvis.appendItemValueUnique("$workitemref", document.getUniqueID());
             workflowService.processWorkItem(zahlungsAvis);
 
         } catch (QueryException | AccessDeniedException | ProcessingErrorException | ModelException e1) {
@@ -79,8 +93,6 @@ public class ZahlungsavisAdapter implements SignalAdapter {
                     "Es konnte kein Zahlungsavis zugewiesen werden: " + e1.getMessage());
 
         }
-
-        return invoice;
     }
 
     /**
diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java
new file mode 100644
index 0000000..f3240e2
--- /dev/null
+++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java
@@ -0,0 +1,131 @@
+package com.alexanderlogistics;
+
+import java.util.Collection;
+import java.util.logging.Logger;
+
+import javax.inject.Inject;
+
+import org.imixs.workflow.FileData;
+import org.imixs.workflow.ItemCollection;
+import org.imixs.workflow.SignalAdapter;
+import org.imixs.workflow.engine.DocumentService;
+import org.imixs.workflow.engine.WorkflowService;
+import org.imixs.workflow.exceptions.AdapterException;
+import org.imixs.workflow.exceptions.PluginException;
+import org.imixs.workflow.exceptions.QueryException;
+
+/**
+ * Der ZahlungsavisAdapter importiert eine Excel Datei aus einem Textblock
+ * 
+ * 
+ * {@code
+        textblock-ref
+        filename
+   }
+ * 
+ *

+ * + * @version 1.0 + * @author rsoika + */ +public class ZahlungsavisExportAdapter implements SignalAdapter { + + private static Logger logger = Logger.getLogger(ZahlungsavisExportAdapter.class.getName()); + + public static final String ERROR_CONFIG = "CONFIG_ERROR"; + final String TYPE_TEXTBLOCK = "textblock"; + + @Inject + WorkflowService workflowService; + + @Inject + DocumentService documentService; + + /** + * This method finds or create the Zahlungsavis and adds a reference + * ($workitemref) to the current invoice. + * + * @throws PluginException + */ + @Override + public ItemCollection execute(ItemCollection document, ItemCollection event) + throws AdapterException, PluginException { + + // read the zahlungsavis options + ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "zahlungsavis", document, false); + if (evalItemCollection == null) { + throw new PluginException(ZahlungsavisExportAdapter.class.getSimpleName(), ERROR_CONFIG, + "missing zahlungsavis configuration in model event - please check model configuration"); + } + String textblock = evalItemCollection.getItemValueString("textblock"); + String template = evalItemCollection.getItemValueString("template"); + + appendExcelTemplate(document, textblock, template); + + return document; + } + + /** + * This method loads a text-block for a specified ref and appends the named + * fileData object of this document. + * + * @param document + * @throws PluginException + */ + private void appendExcelTemplate(ItemCollection document, String textblockRef, String template) + throws PluginException { + + if ((template == null || template.isEmpty()) || (textblockRef == null || textblockRef.isEmpty())) { + throw new PluginException(ZahlungsavisExportAdapter.class.getSimpleName(), ERROR_CONFIG, + "invalid zahlungsavis configuration in model event - textblock/template reference not defined!"); + } + + // load the text block + FileData fileData = null; + ItemCollection textBlockItemCollection = loadTextBlock(textblockRef); + if (textBlockItemCollection != null) { + // fetch attachment + fileData = textBlockItemCollection.getFileData(template); + } + + // do we found the document? + if (fileData == null) { + throw new PluginException(ZahlungsavisExportAdapter.class.getSimpleName(), ERROR_CONFIG, + "invalid zahlungsavis configuration in model event - template=" + template + " not found!"); + } + + // append document + logger.info("...append new Zahlugnsavis Template: " + template); + document.addFileData(fileData); + + } + + /** + * This method returns a text-block ItemCollection for a specified name. + * + * @param name in attribute txtname + * + * + */ + public ItemCollection loadTextBlock(String name) { + ItemCollection textBlockItemCollection = null; + + // load text-block by name.... + String sQuery = "(type:\"" + TYPE_TEXTBLOCK + "\" AND txtname:\"" + name + "\")"; + Collection col; + try { + col = documentService.find(sQuery, 1, 0); + + if (col.size() > 0) { + textBlockItemCollection = col.iterator().next(); + } else { + logger.warning("Missing text-block : '" + name + "'"); + } + } catch (QueryException e) { + logger.warning("getTextBlock - invalid query: " + e.getMessage()); + } + + return textBlockItemCollection; + } + +} \ No newline at end of file diff --git a/reports/zahlungsavis/zahlungsavis_template.xls b/reports/zahlungsavis/zahlungsavis_template.xls new file mode 100644 index 0000000..ee512eb Binary files /dev/null and b/reports/zahlungsavis/zahlungsavis_template.xls differ diff --git a/workflow/rechnungseingang-de-1.2.17.bpmn b/workflow/rechnungseingang-de-1.2.17.bpmn index c65dae5..0fb182f 100644 --- a/workflow/rechnungseingang-de-1.2.17.bpmn +++ b/workflow/rechnungseingang-de-1.2.17.bpmn @@ -46,7 +46,7 @@ - + @@ -5626,6 +5626,11 @@ result.isValid=true; + + + + + SequenceFlow_119 diff --git a/workflow/zahlungsavis-1.0.0.bpmn b/workflow/zahlungsavis-1.0.0.bpmn index a7ce928..c7ce522 100644 --- a/workflow/zahlungsavis-1.0.0.bpmn +++ b/workflow/zahlungsavis-1.0.0.bpmn @@ -30,6 +30,7 @@ + - home]]> + Zahlugnsavis Template + zahlungsavis_template.xls]]> @@ -342,6 +344,14 @@ result.isValid=true; SequenceFlow_8 SequenceFlow_2 + + + DataOutput_1 + + + DataOutput_1 + +