draft op liste
This commit is contained in:
parent
8b22337548
commit
a1c3330cd3
5 changed files with 1311 additions and 44 deletions
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
|
|
@ -45,10 +49,10 @@ import jakarta.inject.Inject;
|
|||
*
|
||||
* <p>
|
||||
* Der Adapter kopiert die Rechnungsdaten in neue Zeilen, welche ab Zeilennummer
|
||||
* 16 eingefügt werden.
|
||||
* 12 eingefügt werden.
|
||||
* <p>
|
||||
*
|
||||
* 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
1122
workflow/opliste-de-1.0.3.bpmn
Normal file
1122
workflow/opliste-de-1.0.3.bpmn
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue