zahlugnsavis
This commit is contained in:
parent
011e9b0b47
commit
ed87041611
4 changed files with 133 additions and 7 deletions
|
|
@ -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;
|
|||
<zahlungsavis name="textblock">textblock-ref</zahlungsavis>
|
||||
<zahlungsavis name="template">filename</zahlungsavis>
|
||||
<zahlungsavis name="targetname">filename</zahlungsavis>
|
||||
}
|
||||
}
|
||||
* </pre>
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* The method copies the Row A16 as a reference row
|
||||
* <p>
|
||||
* The named cell 'TOTAL' should contain the summary formula
|
||||
*
|
||||
* @throws PluginException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void insertInvoiceRows(ItemCollection document, String fileName) throws PluginException {
|
||||
List<String> 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);
|
||||
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -337,12 +337,22 @@ result.isValid=true;
|
|||
<find>C10</find>
|
||||
<replace><itemvalue>numsequencenumber</itemvalue></replace>
|
||||
<type>text</type>
|
||||
</poi-update>
|
||||
</poi-update>
|
||||
<poi-update name="findreplace">
|
||||
<find>A12</find>
|
||||
<replace><itemvalue>cdtr.number</itemvalue></replace>
|
||||
<type>text</type>
|
||||
</poi-update>
|
||||
<poi-update name="findreplace">
|
||||
<find>B12</find>
|
||||
<replace><itemvalue>cdtr.name.cargosoft</itemvalue></replace>
|
||||
<type>text</type>
|
||||
</poi-update>
|
||||
<poi-update name="findreplace">
|
||||
<find>F10</find>
|
||||
<replace><itemvalue>$modified</itemvalue></replace>
|
||||
<type>date</type>
|
||||
</poi-update>]]></imixs:value>
|
||||
</poi-update>]]></imixs:value>
|
||||
</imixs:item>
|
||||
<imixs:item name="keyownershipmode" type="xs:string">
|
||||
<imixs:value><![CDATA[0]]></imixs:value>
|
||||
|
|
@ -548,12 +558,22 @@ result.isValid=true;
|
|||
<find>C10</find>
|
||||
<replace><itemvalue>numsequencenumber</itemvalue></replace>
|
||||
<type>text</type>
|
||||
</poi-update>
|
||||
</poi-update>
|
||||
<poi-update name="findreplace">
|
||||
<find>A12</find>
|
||||
<replace><itemvalue>cdtr.number</itemvalue></replace>
|
||||
<type>text</type>
|
||||
</poi-update>
|
||||
<poi-update name="findreplace">
|
||||
<find>B12</find>
|
||||
<replace><itemvalue>cdtr.name.cargosoft</itemvalue></replace>
|
||||
<type>text</type>
|
||||
</poi-update>
|
||||
<poi-update name="findreplace">
|
||||
<find>F10</find>
|
||||
<replace><itemvalue>$modified</itemvalue></replace>
|
||||
<type>date</type>
|
||||
</poi-update>]]></imixs:value>
|
||||
</poi-update>]]></imixs:value>
|
||||
</imixs:item>
|
||||
<imixs:item name="keyownershipmode" type="xs:string">
|
||||
<imixs:value><![CDATA[0]]></imixs:value>
|
||||
|
|
|
|||
Loading…
Reference in a new issue