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 53f53b2..123078c 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 @@ -341,7 +341,6 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { } - // } /** * This method loads a text-block for a specified ref and appends the named * fileData object of this document. diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapterByWeek.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapterByWeek.java index 334138a..6e9ce69 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapterByWeek.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapterByWeek.java @@ -38,6 +38,8 @@ 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; @@ -104,51 +106,144 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { public ItemCollection execute(ItemCollection document, ItemCollection event) throws AdapterException, PluginException { - // read the opliste options - ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "opliste", document, false); - if (evalItemCollection == null) { - throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), InvoiceService.ERROR_CONFIG, - "missing op-list configuration in model event - please check model configuration"); - } - // 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); - String textblock = evalItemCollection.getItemValueString("textblock"); - String template = evalItemCollection.getItemValueString("template"); - String targetName = evalItemCollection.getItemValueString("target-name"); + // read the template options + 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"); + } + 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"); + boolean filter = evalItemCollection.getItemValueBoolean("filter"); + // 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); - insertInvoiceRows(document, targetName, currency1, currency2); - } catch (PluginException | IOException | QueryException e) { - throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), InvoiceService.ERROR_CONFIG, + // 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); + + // first add the columns for the currency list + addCurrencyColumns(doc, sheet, currencyList); + + // insertInvoiceRows(sheet, document, targetName, filter, 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!"); + logger.fine("... completed!"); + return document; + + // 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); + + // insertInvoiceRows(document, targetName, currencyList.get(0), + // currencyList.get(1)); + // } catch (PluginException | IOException | QueryException e) { + // throw new PluginException(OPListExportAdapterByWeek.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.fine(".. add currency column..."); + POIUtil.insertColumn(sheet, 1, 2 + i); + } + + // Beschriftungen eintragen + int col = 1; + XSSFCell cell = null; + XSSFRow labelRow = sheet.getRow(10); + for (String currency : currencyList) { + cell = labelRow.getCell(col); + cell.setCellValue(currency); + col++; + } } /** @@ -529,12 +624,14 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { * @param document * @throws PluginException */ - private void appendExcelTemplate(ItemCollection document, String textblockRef, String template, String targetName) + 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(OPListExportAdapterByWeek.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 @@ -542,15 +639,16 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { // do we found the document? if (fileData == null) { - throw new PluginException(OPListExportAdapterByWeek.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.fine("...append new POI Template: " + targetName); document.addFileData(fileData); - + return fileData; } /** diff --git a/templates/op-liste_kw_template.xlsx b/templates/op-liste_kw_template.xlsx index 1397b3a..220211b 100644 Binary files a/templates/op-liste_kw_template.xlsx and b/templates/op-liste_kw_template.xlsx differ diff --git a/templates/op-liste_kw_template_01.xlsx b/templates/op-liste_kw_template_01.xlsx new file mode 100644 index 0000000..1397b3a Binary files /dev/null and b/templates/op-liste_kw_template_01.xlsx differ diff --git a/templates/op-liste_kw_template_mist.xlsx b/templates/op-liste_kw_template_mist.xlsx new file mode 100644 index 0000000..0786923 Binary files /dev/null and b/templates/op-liste_kw_template_mist.xlsx differ diff --git a/workflow/analyse-opliste-de-1.0.3.bpmn b/workflow/analyse-opliste-de-1.0.3.bpmn index e27ff79..46245bb 100644 --- a/workflow/analyse-opliste-de-1.0.3.bpmn +++ b/workflow/analyse-opliste-de-1.0.3.bpmn @@ -100,6 +100,7 @@ th { font-weight: bold;} gateway_L9r5iA gateway_37SSsw textAnnotation_iPsg3g + event_opebWA @@ -219,36 +220,6 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt - - 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 - -]]> - @@ -265,6 +236,30 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt + + + OP-Liste Template + + op-liste_dbtr.number_$lasteventdate.xlsx + + + + C6 + sequencenumber + text + + + B7 + space.name + text + + + + F6 + $lasteventdate + date + ]]> + SequenceFlow_5 @@ -302,6 +297,7 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt SequenceFlow_19 Association_1 sequenceFlow_N0jfWA + sequenceFlow_QUQCFw @@ -432,18 +428,17 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt Mahnwesen -OP-Liste KW Template -op-liste_kw_template.xlsx -op-liste_space.name_$lasteventdate.xlsx - - + + OP-Liste KW Template + + op-liste_space.name_$lasteventdate.xlsx + - I6 + A8 $lasteventdate date -I7 ]]> @@ -491,6 +486,101 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt + + + + + + + + + + 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.urlpages/workitems/workitem.jsf?id=$uniqueid + +Html-Footer]]>
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + Mahnwesen + + OP-Liste KW Template + + op-liste_space.name_$lasteventdate.xlsx + + + A8 + $lasteventdate + date + + +]]> + +
+ + + DataOutput_2 + + + sequenceFlow_QUQCFw +
+ + + @@ -671,6 +761,16 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt + + + + + + + + + +