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
index 58cab96..218af2c 100644
--- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java
+++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java
@@ -1,12 +1,20 @@
package com.alexanderlogistics;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.imixs.archive.core.SnapshotService;
import org.imixs.workflow.FileData;
import org.imixs.workflow.ItemCollection;
@@ -26,7 +34,7 @@ import org.imixs.workflow.poi.POIFindReplaceAdapter;
textblock-ref
filename
filename
- }
+ }
*
*
* Der Adapter erweitert den POIAdapter somit können felder aktualisiert werden:
@@ -82,7 +90,7 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter {
String targetName = evalItemCollection.getItemValueString("target-name");
// adapt text....
targetName = workflowService.adaptText(targetName, document);
-
+
appendExcelTemplate(document, textblock, template, targetName);
// Process POI instructions
@@ -100,9 +108,107 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter {
throw new PluginException(ZahlungsavisExportAdapter.class.getSimpleName(), ERROR_CONFIG,
"failed to update zahlungsavis - wrong POI configuraiton: " + e.getMessage());
}
+
+ // now we add separate lines for each invoice....
+ insertInvoiceRows(document, targetName);
+
return document;
}
+ /**
+ * This helper method inserts a row for each invoice of the current Zahlunsavis
+ * at row 16 into the excel template file
+ *
+ * The method copies the Row A16 as a reference row
+ *
+ * The named cell 'TOTAL' should contain the summary formula
+ *
+ * @throws PluginException
+ */
+ @SuppressWarnings("unchecked")
+ private void insertInvoiceRows(ItemCollection document, String fileName) throws PluginException {
+ List invoiceIDs = document.getItemValue("$workitemref");
+ FileData fileData = document.getFileData(fileName);
+
+ // load XSSFWorkbook
+ try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) {
+ XSSFWorkbook doc = new XSSFWorkbook(imputStream);
+ // NOTE: we only take the first sheet !
+ XSSFSheet sheet = doc.getSheetAt(0);
+ XSSFCell cell = null;
+
+ CellReference cr = new CellReference("A16");
+ XSSFRow referenceRow = sheet.getRow(cr.getRow());
+ int referenceRowPos = 16;
+ int rowPos = 16;
+ int lastRow = 19;// sheet.getLastRowNum();
+ sheet.shiftRows(rowPos, lastRow, invoiceIDs.size(), true, true);
+
+ for (String invoiceID : invoiceIDs) {
+ logger.finest("......copy row...");
+ ItemCollection invoice = documentService.load(invoiceID);
+ // now create a new line..
+ XSSFRow row = sheet.createRow(rowPos);
+ // copy cells
+ cell= copyCell( referenceRow, row, 0);
+ cell.setCellValue(invoice.getItemValueString("numsequecenumber"));
+
+ cell= copyCell( referenceRow, row, 1);
+ cell.setCellValue(invoice.getItemValueDate("invoice.date"));
+
+ cell= copyCell( referenceRow, row, 2);
+ cell.setCellValue(invoice.getItemValueString("invoice.number"));
+
+ cell= copyCell( referenceRow, row, 3);
+ cell.setCellValue(invoice.getItemValueDate("invoice.due.date"));
+
+ cell= copyCell( referenceRow, row, 4);
+ cell.setCellValue(0.00);
+
+ cell= copyCell( referenceRow, row, 5);
+ cell.setCellValue(invoice.getItemValueDouble("invoice.total"));
+
+ rowPos++;
+ }
+ // delete reference cell
+ sheet.shiftRows(referenceRowPos, lastRow + invoiceIDs.size(), -1, true, true);
+
+ // finally update the total formula...
+ evalXSSFSheet(doc, sheet, "TOTAL");
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ // write back the file
+
+ doc.write(byteArrayOutputStream);
+ doc.close();
+ byte[] newContent = byteArrayOutputStream.toByteArray();
+ FileData fileDataNew = new FileData(fileData.getName(), newContent, fileData.getContentType(), null);
+ // update the fileData
+ document.addFileData(fileDataNew);
+ logger.finest("......new document added");
+
+ } catch (IOException e) {
+ throw new PluginException(ZahlungsavisExportAdapter.class.getSimpleName(), ERROR_CONFIG,
+ "failed to update zahlungsavis: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Helper method to copy a cell (It is heavy how many lines of code are
+ * necessary to work with Excel and POI
+ *
+ * @param row
+ * @param column
+ * @return
+ */
+ private XSSFCell copyCell(XSSFRow referenceRow, XSSFRow row, int column) {
+ XSSFCell cell = row.createCell(column);
+ XSSFCell refCell = referenceRow.getCell(column);
+ cell.setCellType(refCell.getCellType());
+ cell.setCellStyle(refCell.getCellStyle());
+ return cell;
+ }
+
/**
* This method loads a text-block for a specified ref and appends the named
* fileData object of this document.
@@ -129,7 +235,7 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter {
fileData.setName(targetName);
// append document
logger.info("...append new Zahlugnsavis Template: " + targetName);
-
+
document.addFileData(fileData);
}
diff --git a/reports/zahlungsavis/zahlungsavis_template.xls b/reports/zahlungsavis/zahlungsavis_template.xls
deleted file mode 100644
index 322f50a..0000000
Binary files a/reports/zahlungsavis/zahlungsavis_template.xls and /dev/null differ
diff --git a/reports/zahlungsavis/zahlungsavis_template.xlsx b/reports/zahlungsavis/zahlungsavis_template.xlsx
index 1bc3ff8..f21ad47 100644
Binary files a/reports/zahlungsavis/zahlungsavis_template.xlsx and b/reports/zahlungsavis/zahlungsavis_template.xlsx differ
diff --git a/workflow/zahlungsavis-1.0.0.bpmn b/workflow/zahlungsavis-1.0.0.bpmn
index af57cde..cd37d65 100644
--- a/workflow/zahlungsavis-1.0.0.bpmn
+++ b/workflow/zahlungsavis-1.0.0.bpmn
@@ -337,12 +337,22 @@ result.isValid=true;
C10
numsequencenumber
text
-
+
+
+ A12
+ cdtr.number
+ text
+
+
+ B12
+ cdtr.name.cargosoft
+ text
+
F10
$modified
date
- ]]>
+ ]]>
@@ -548,12 +558,22 @@ result.isValid=true;
C10
numsequencenumber
text
-
+
+
+ A12
+ cdtr.number
+ text
+
+
+ B12
+ cdtr.name.cargosoft
+ text
+
F10
$modified
date
- ]]>
+ ]]>