diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java index b56c6dd..17a9eed 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java @@ -26,11 +26,15 @@ import org.imixs.workflow.exceptions.PluginException; import org.imixs.workflow.exceptions.QueryException; import org.imixs.workflow.office.config.ConfigService; import org.imixs.workflow.poi.POIFindReplaceAdapter; +import org.imixs.workflow.poi.POIUtil; +import org.imixs.workflow.util.XMLParser; import jakarta.inject.Inject; /** - * Der OPListExportAdapter importiert eine Excel Datei aus einem Textblock + * Der OPListExportAdapter exportiert eine Excel Datei mit allen offenen + * Rechnungen gruppiert nach Debitor. Es werden alle Ausgehenden Währungen + * berücksichtigt und ab Spalte H eingefügt. * *
* {@code
@@ -45,10 +49,10 @@ import jakarta.inject.Inject;
*
*
* Der Adapter kopiert die Rechnungsdaten in neue Zeilen, welche ab Zeilennummer
- * 16 eingefügt werden.
+ * 12 eingefügt werden.
*
*
- * Abschliessend wird die Zelle 'TOTAL' noch aktualisiert.
+ * Abschliessend werden Summen Formeln in Zeile 14 für jede Währung eingefügt.
*
* Der Fälligkeitszeitrum von 21 Tagen kann über den Parameter
*
@@ -85,56 +89,157 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
// ermittle die Hauptwährungen
ItemCollection configItemCollection = configService.loadConfiguration("AGL_CONFIGURATION");
List currencyList = configItemCollection.getItemValue("currency.out");
- if (currencyList == null || currencyList.size() < 2) {
+ if (currencyList == null || currencyList.size() < 1) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"missing Currency configuration - please check parameters");
}
- String currency1 = currencyList.get(0);
- String currency2 = currencyList.get(1);
// read the zahlungsavis options
- ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "opliste", document, false);
- if (evalItemCollection == null) {
- throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
- "missing op-list configuration in model event - please check model configuration");
+ ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "opliste",
+ document,
+ false);
+ if (evalItemCollection == null || !evalItemCollection.hasItem("excel-export")) {
+ throw new PluginException(OPListExportAdapter.class.getSimpleName(), CONFIG_ERROR,
+ "missing opliste configuration in model event - please check model configuration");
}
- String textblock = evalItemCollection.getItemValueString("textblock");
- String template = evalItemCollection.getItemValueString("template");
- String targetName = evalItemCollection.getItemValueString("target-name");
- boolean filter = evalItemCollection.getItemValueBoolean("filter");
+ List excelDefList = evalItemCollection.getItemValue("excel-export");
+ ItemCollection excelDefCollection = XMLParser.parseItemStructure(excelDefList.get(0));
+
+ // // read the zahlungsavis options
+ // ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event,
+ // "opliste", document, false);
+ // if (evalItemCollection == null ||
+ // !evalItemCollection.hasItem("excel-export")) {
+ // throw new
+ // PluginException(AGLAnalyticExcelAdapterDebitor.class.getSimpleName(),
+ // CONFIG_ERROR,
+ // "missing opliste configuration in model event - please check model
+ // configuration");
+ // }
+
+ // List excelDefList = evalItemCollection.getItemValue("excel-export");
+ // ItemCollection excelDefCollection =
+ // XMLParser.parseItemStructure(excelDefList.get(0));
+
+ String textblock = excelDefCollection.getItemValueString("textblock");
+ String template = excelDefCollection.getItemValueString("template");
+ String targetName = excelDefCollection.getItemValueString("target-name");
+
// adapt text....
targetName = workflowService.adaptText(targetName, document);
-
- appendExcelTemplate(document, textblock, template, targetName);
-
- logger.info("... loading poi configuration..");
- // Process POI instructions
- // read the config
- ItemCollection poiConfig = workflowService.evalWorkflowResult(event, "poi-update", document, false);
- if (poiConfig == null || !poiConfig.hasItem("findreplace")) {
- throw new PluginException(POIFindReplaceAdapter.class.getSimpleName(), CONFIG_ERROR,
- "missing poi configuration");
- }
- List replaceDevList = poiConfig.getItemValue("findreplace");
- String eval = poiConfig.getItemValueString("eval");
try {
- logger.info("... update template with normal poi information..");
- this.updateFileData(document.getFileData(targetName), document, replaceDevList, eval);
+ FileData fileData = appendExcelTemplate(document, textblock, template, targetName);
- // now we add separate lines for each invoice....
- logger.info("... insert invoices - filter=" + filter);
- document.setItemValue("space.currency1", currency1);
- document.setItemValue("space.currency2", currency2);
+ // get workbook
+ XSSFWorkbook doc = null;
+ try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) {
+ doc = new XSSFWorkbook(imputStream);
+ // NOTE: we only take the first sheet !
+ XSSFSheet sheet = doc.getSheetAt(0);
- insertInvoiceRows(document, targetName, filter, currency1, currency2);
- } catch (PluginException | IOException | QueryException e) {
- throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
+ // first add the columns for the currency list
+ addCurrencyColumns(doc, sheet, currencyList);
+
+ // write back the updated excel file
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ doc.write(byteArrayOutputStream);
+
+ byte[] newContent = byteArrayOutputStream.toByteArray();
+ FileData fileDataNew = new FileData(fileData.getName(), newContent, fileData.getContentType(),
+ null);
+ document.addFileData(fileDataNew);
+ logger.finest("......new document added");
+ } catch (IOException e) {
+ throw new PluginException(OPListExportAdapter.class.getSimpleName(),
+ InvoiceService.ERROR_CONFIG,
+ "failed to update opliste: " + e.getMessage());
+ } finally {
+ if (doc != null) {
+ try {
+ doc.close();
+ } catch (IOException e) {
+ logger.severe("Failed to close workbook: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+ }
+
+ // Finally process POI instructions
+ processPOIUpdate(document, event, targetName);
+
+ } catch (PluginException e) {
+ throw new PluginException(OPListExportAdapter.class.getSimpleName(),
+ InvoiceService.ERROR_CONFIG,
"failed to update op-liste: " + e.getMessage());
}
logger.info("... completed!");
+
+ // appendExcelTemplate(document, textblock, template, targetName);
+
+ // logger.info("... loading poi configuration..");
+ // // Process POI instructions
+ // // read the config
+ // ItemCollection poiConfig = workflowService.evalWorkflowResult(event,
+ // "poi-update", document, false);
+ // if (poiConfig == null || !poiConfig.hasItem("findreplace")) {
+ // throw new PluginException(POIFindReplaceAdapter.class.getSimpleName(),
+ // CONFIG_ERROR,
+ // "missing poi configuration");
+ // }
+ // List replaceDevList = poiConfig.getItemValue("findreplace");
+ // String eval = poiConfig.getItemValueString("eval");
+ // try {
+ // logger.info("... update template with normal poi information..");
+ // this.updateFileData(document.getFileData(targetName), document,
+ // replaceDevList, eval);
+
+ // // now we add separate lines for each invoice....
+ // logger.info("... insert invoices - filter=" + filter);
+ // document.setItemValue("space.currency1", currency1);
+ // document.setItemValue("space.currency2", currency2);
+
+ // insertInvoiceRows(document, targetName, filter, currency1, currency2);
+ // } catch (PluginException | IOException | QueryException e) {
+ // throw new PluginException(OPListExportAdapter.class.getSimpleName(),
+ // InvoiceService.ERROR_CONFIG,
+ // "failed to update op-liste: " + e.getMessage());
+ // }
+ // logger.info("... completed!");
return document;
}
+ /**
+ * EIne OP Liste kann für eine oder mehrere Währungen erstellt werden. Diese
+ * Hilfsmethode fügt die Spalten anhand der Währungen ein.
+ *
+ *
+ * @param sheet
+ * @param currencyList
+ */
+ private void addCurrencyColumns(XSSFWorkbook doc, XSSFSheet sheet, List currencyList) {
+ if (currencyList == null || currencyList.size() <= 1) {
+ // no extra currencies defined!
+ return;
+ }
+
+ // zusaetzliche Zellen einfuegen...
+ int newColumns = (currencyList.size() - 1) * 1;
+ for (int i = 0; i < newColumns; i++) {
+ logger.info(".. add currency column...");
+ POIUtil.insertColumn(sheet, 5, 6 + i);
+ }
+
+ // Beschriftungen eintragen
+ int col = 5;
+ XSSFCell cell = null;
+ XSSFRow labelRow = sheet.getRow(9);
+ for (String currency : currencyList) {
+ cell = labelRow.getCell(col);
+ cell.setCellValue("Saldo " + currency);
+ col++;
+ }
+ }
+
/**
* This helper method inserts a row for each invoice of the OPListe at row 16
* into the excel template file
@@ -303,12 +408,51 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
* @param document
* @throws PluginException
*/
- private void appendExcelTemplate(ItemCollection document, String textblockRef, String template, String targetName)
+ // private void appendExcelTemplate(ItemCollection document, String
+ // textblockRef, String template, String targetName)
+ // throws PluginException {
+
+ // if ((template == null || template.isEmpty()) || (textblockRef == null ||
+ // textblockRef.isEmpty())) {
+ // throw new PluginException(OPListExportAdapter.class.getSimpleName(),
+ // InvoiceService.ERROR_CONFIG,
+ // "invalid op-list configuration in model event - textblock/template reference
+ // not defined!");
+ // }
+
+ // // load the text block
+ // FileData fileData = invoiceService.loadTextBlockFileData(textblockRef,
+ // template);
+
+ // // do we found the document?
+ // if (fileData == null) {
+ // throw new PluginException(OPListExportAdapter.class.getSimpleName(),
+ // InvoiceService.ERROR_CONFIG,
+ // "invalid op-list configuration in model event - template=" + template + " not
+ // found!");
+ // }
+ // fileData.setName(targetName);
+ // // append document
+ // logger.info("...append new op-list Template: " + targetName);
+
+ // document.addFileData(fileData);
+
+ // }
+ /**
+ * This method loads a text-block for a specified ref and appends the named
+ * fileData object of this document.
+ *
+ * @param document
+ * @throws PluginException
+ */
+ private FileData appendExcelTemplate(ItemCollection document, String textblockRef, String template,
+ String targetName)
throws PluginException {
if ((template == null || template.isEmpty()) || (textblockRef == null || textblockRef.isEmpty())) {
- throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
- "invalid op-list configuration in model event - textblock/template reference not defined!");
+ throw new PluginException(OPListExportAdapter.class.getSimpleName(),
+ InvoiceService.ERROR_CONFIG,
+ "invalid POI configuration in model event - textblock/template reference not defined!");
}
// load the text block
@@ -316,15 +460,16 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
// do we found the document?
if (fileData == null) {
- throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
- "invalid op-list configuration in model event - template=" + template + " not found!");
+ throw new PluginException(OPListExportAdapter.class.getSimpleName(),
+ InvoiceService.ERROR_CONFIG,
+ "invalid POI configuration in model event - template=" + template
+ + " not found!");
}
fileData.setName(targetName);
// append document
- logger.info("...append new op-list Template: " + targetName);
-
+ logger.info("...append new POI Template: " + targetName);
document.addFileData(fileData);
-
+ return fileData;
}
/**
diff --git a/templates/op-liste_template.xlsx b/templates/op-liste_template.xlsx
index f17aa94..20eafdf 100644
Binary files a/templates/op-liste_template.xlsx and b/templates/op-liste_template.xlsx differ
diff --git a/templates/soa_template (Kopie).xlsx b/templates/op-liste_template_01.xlsx
similarity index 68%
rename from templates/soa_template (Kopie).xlsx
rename to templates/op-liste_template_01.xlsx
index 099c4a0..f17aa94 100644
Binary files a/templates/soa_template (Kopie).xlsx and b/templates/op-liste_template_01.xlsx differ
diff --git a/templates/soa_template.xlsx b/templates/soa_template.xlsx
index ddf2a38..a888b42 100644
Binary files a/templates/soa_template.xlsx and b/templates/soa_template.xlsx differ
diff --git a/workflow/opliste-de-1.0.3.bpmn b/workflow/opliste-de-1.0.3.bpmn
new file mode 100644
index 0000000..0390732
--- /dev/null
+++ b/workflow/opliste-de-1.0.3.bpmn
@@ -0,0 +1,1122 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+$workflowstatus
+
+]]>
+
+
+
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ StartEvent_1
+ Task_1
+ IntermediateCatchEvent_3
+ IntermediateCatchEvent_1
+ Task_4
+ EndEvent_3
+ Task_2
+ IntermediateCatchEvent_2
+ IntermediateCatchEvent_8
+ Task_3
+ IntermediateCatchEvent_4
+ IntermediateCatchEvent_5
+
+ TextAnnotation_1
+ DataObject_1
+ event_1vVoBA
+
+
+
+ SequenceFlow_4
+
+
+
+
+
+ sequencenumber space.name - $lasteventdate ]]>
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $workflowgroup - $workflowstatus ]]>
+ SequenceFlow_1
+ SequenceFlow_9
+ SequenceFlow_17
+
+
+ SequenceFlow_19
+
+
+
+
+
+ sequencenumber space.name - $lasteventdate ]]>
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $workflowgroup - $workflowstatus ]]>
+ SequenceFlow_4
+ SequenceFlow_3
+ SequenceFlow_2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+ sequencenumber space.name - $created ]]>
+
+
+
+
+
+
+
+
+ Html-Header
+Hallo,
+
+Bitte prüfen Sie die angefügte OP-Liste. Diese enthält sämtlich noch offenen Rechnungen zum Zeitpunkt des Exports für diesen Fachbereich.
+
+
+Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt" ab.
+
+application.url pages/workitems/workitem.jsf?id=$uniqueid
+
+Html-Footer ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ home
+- Mahnwesen
+OP-Liste Template
+op-liste_template.xlsx
+op-liste_space.name _$lasteventdate .xlsx
+true
+
+ C6
+ sequencenumber
+ text
+
+
+ D6
+ Überfällig / 2. Mahnstufe
+ text
+
+
+ C8
+ space.name
+ text
+
+
+
+ I6
+ $lasteventdate
+ date
+
+]]>
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
+
+
+ SequenceFlow_5
+ SequenceFlow_9
+
+ DataOutput_2
+
+
+
+
+
+
+ sequencenumber space.name - $lasteventdate ]]>
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $workflowgroup - $workflowstatus ]]>
+ SequenceFlow_18
+ SequenceFlow_19
+
+
+
+
+
+
+
+ home]]>
+
+
+ SequenceFlow_17
+ SequenceFlow_8
+ SequenceFlow_18
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SequenceFlow_1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SequenceFlow_3
+ SequenceFlow_5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ OP-Liste Template
+ op-liste_template.xlsx
+ op-liste_dbtr.number _$lasteventdate .xlsx
+
+
+
+ C6
+ sequencenumber
+ text
+
+
+ B7
+ space.name
+ text
+
+
+
+ F6
+ $lasteventdate
+ date
+ ]]>
+
+
+ SequenceFlow_6
+
+
+ sequenceFlow_m5OB0Q
+
+
+
+
+
+
+
+
+
+
+ sequencenumber space.name - $lasteventdate ]]>
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $workflowgroup - $workflowstatus ]]>
+ SequenceFlow_6
+ SequenceFlow_10
+ SequenceFlow_8
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SequenceFlow_10
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SequenceFlow_2
+ sequenceFlow_m5OB0Q
+
+
+
+
+
+
+
+
+
+ event_yvRYxA
+ task_A5VcTw
+ event_a0OyNw
+ task_xZ1VEg
+ event_XWmcVw
+ task_R0QI0w
+ event_rkG39w
+ textAnnotation_5ZBmxg
+ event_0DGK7A
+ event_VMNwVw
+
+
+
+
+ sequenceFlow_71XoqA
+
+
+
+
+ $lasteventdate ]]>
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $workflowgroup - $workflowstatus ]]>
+ SequenceFlow_2
+ sequenceFlow_71XoqA
+ sequenceFlow_QzU0Xg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Mahnwesen
+OP-Liste KW Template
+op-liste_kw_template.xlsx
+op-liste_space.name _$lasteventdate .xlsx
+
+
+
+ I6
+ $lasteventdate
+ date
+
+
+I7
+]]>
+
+
+
+
+ sequenceFlow_64kfIA
+ sequenceFlow_JKOgiA
+
+
+
+
+ $lasteventdate ]]>
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $workflowgroup - $workflowstatus ]]>
+ SequenceFlow_10
+ sequenceFlow_64kfIA
+ sequenceFlow_W9rmgA
+ sequenceFlow_hH7RWQ
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ home]]>
+
+
+ SequenceFlow_8
+
+ sequenceFlow_W9rmgA
+ sequenceFlow_5c0Y8A
+
+
+
+
+ $lasteventdate ]]>
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $workflowgroup - $workflowstatus ]]>
+ sequenceFlow_5c0Y8A
+ sequenceFlow_00R0Qw
+
+
+
+ sequenceFlow_00R0Qw
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Mahnwesen
+OP-Liste KW Template
+op-liste_kw_template.xlsx
+op-liste_space.name _$lasteventdate .xlsx
+
+
+
+ I6
+ $lasteventdate
+ date
+
+
+I7
+]]>
+
+
+
+
+
+
+
+ sequenceFlow_hH7RWQ
+
+
+
+
+
+
+
+ sequenceFlow_QzU0Xg
+ sequenceFlow_JKOgiA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+