op listen export

This commit is contained in:
Ralph Soika 2023-02-08 11:12:07 +01:00
parent 0a4254b8ae
commit 723599dafb
6 changed files with 122 additions and 68 deletions

View file

@ -93,6 +93,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
appendExcelTemplate(document, textblock, template, targetName); appendExcelTemplate(document, textblock, template, targetName);
logger.info("... loading poi configuration..");
// Process POI instructions // Process POI instructions
// read the config // read the config
ItemCollection poiConfig = workflowService.evalWorkflowResult(event, "poi-update", document, false); ItemCollection poiConfig = workflowService.evalWorkflowResult(event, "poi-update", document, false);
@ -103,14 +104,17 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
List<String> replaceDevList = poiConfig.getItemValue("findreplace"); List<String> replaceDevList = poiConfig.getItemValue("findreplace");
String eval = poiConfig.getItemValueString("eval"); String eval = poiConfig.getItemValueString("eval");
try { try {
logger.info("... update template with normal poi information..");
this.updateFileData(document.getFileData(targetName), document, replaceDevList, eval); this.updateFileData(document.getFileData(targetName), document, replaceDevList, eval);
// now we add separate lines for each invoice.... // now we add separate lines for each invoice....
logger.info("... insert invoices..");
insertInvoiceRows(document, targetName); insertInvoiceRows(document, targetName);
} catch (PluginException | IOException | QueryException e) { } catch (PluginException | IOException | QueryException e) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), ERROR_CONFIG, throw new PluginException(OPListExportAdapter.class.getSimpleName(), ERROR_CONFIG,
"failed to update op-liste: " + e.getMessage()); "failed to update op-liste: " + e.getMessage());
} }
logger.info("... completed!");
return document; return document;
} }
@ -132,36 +136,44 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
// load dummy rechnungen // load dummy rechnungen
String spaceID = document.getItemValueString("space.ref"); String spaceID = document.getItemValueString("space.ref");
logger.info("... space.ref=" + spaceID + " ...grouping invoices by spaceid....");
Map<String, List<ItemCollection>> invoiceMap = groupInvoicesBySpaceID(spaceID); Map<String, List<ItemCollection>> invoiceMap = groupInvoicesBySpaceID(spaceID);
FileData fileData = document.getFileData(fileName); FileData fileData = document.getFileData(fileName);
logger.info("... processing workbook... DEBUG MODE");
// load XSSFWorkbook // load XSSFWorkbook
XSSFWorkbook doc = null;
try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) { try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) {
XSSFWorkbook doc = new XSSFWorkbook(imputStream); doc = new XSSFWorkbook(imputStream);
// NOTE: we only take the first sheet ! // NOTE: we only take the first sheet !
XSSFSheet sheet = doc.getSheetAt(0); XSSFSheet sheet = doc.getSheetAt(0);
CellReference cr = new CellReference("A12"); CellReference categoryRefCell = new CellReference("A12");
XSSFRow referenceRow = sheet.getRow(cr.getRow()); XSSFRow referenceRowCategory = sheet.getRow(categoryRefCell.getRow());
CellReference invoiceRefCell = new CellReference("A13");
XSSFRow referenceRowInvoice = sheet.getRow(invoiceRefCell.getRow());
int referenceRowPos = 12; int referenceRowPos = 12;
int rowPos = 12; int rowPos = 12;
// int lastRow = sheet.getLastRowNum(); int lastRow = 2999;
int lastRow = 999;
logger.finest("Last rownum=" + lastRow); logger.finest("Last rownum=" + lastRow);
int totalRowCount = invoiceMap.size(); int totalRowCount = invoiceMap.size();
for (List<?> list : invoiceMap.values()) { for (List<?> list : invoiceMap.values()) {
totalRowCount = totalRowCount + list.size(); totalRowCount = totalRowCount + list.size();
} }
if (totalRowCount == 0) {
logger.warning("No Invoices found - skip update workbook!");
return;
}
sheet.shiftRows(rowPos, lastRow, totalRowCount, true, true); sheet.shiftRows(rowPos, lastRow, totalRowCount, true, true);
for (Map.Entry<String, List<ItemCollection>> entry : invoiceMap.entrySet()) { for (Map.Entry<String, List<ItemCollection>> entry : invoiceMap.entrySet()) {
String dbtrNumber = entry.getKey(); String dbtrNumber = entry.getKey();
logger.info("......add debitor " + dbtrNumber);
List<ItemCollection> invoices = entry.getValue(); List<ItemCollection> invoices = entry.getValue();
// erzeuge eine Zwischenüberschrift für den Debitor.... // erzeuge eine Zwischenüberschrift für den Debitor....
XSSFRow categoryRow = sheet.createRow(rowPos); XSSFRow categoryRow = sheet.createRow(rowPos);
categoryRow.copyRowFrom(referenceRow, new CellCopyPolicy()); categoryRow.copyRowFrom(referenceRowCategory, new CellCopyPolicy());
// insert values // insert values
categoryRow.getCell(0).setCellValue(dbtrNumber); categoryRow.getCell(0).setCellValue(dbtrNumber);
String debitorName = invoices.get(0).getItemValueString("dbtr.name"); String debitorName = invoices.get(0).getItemValueString("dbtr.name");
@ -172,35 +184,32 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
for (ItemCollection invoice : invoices) { for (ItemCollection invoice : invoices) {
catSum = catSum + invoice.getItemValueDouble("invoice.saldo"); catSum = catSum + invoice.getItemValueDouble("invoice.saldo");
} }
if (catSum < 0) { logger.fine("......... sum=" + catSum);
// SOLL categoryRow.getCell(10).setCellValue(catSum);
categoryRow.getCell(6).setCellValue(catSum);
} else {
categoryRow.getCell(8).setCellValue(catSum);
}
rowPos++; rowPos++;
// jetzt füge alle Rechnungen an. // jetzt füge alle Rechnungen an.
for (ItemCollection invoice : invoices) { for (ItemCollection invoice : invoices) {
logger.finest("......copy row..."); logger.fine("......add invoice " + invoice.getUniqueID());
// now create a new line.. // now create a new line..
XSSFRow row = sheet.createRow(rowPos); XSSFRow row = sheet.createRow(rowPos);
row.copyRowFrom(referenceRow, new CellCopyPolicy()); row.copyRowFrom(referenceRowInvoice, new CellCopyPolicy());
// insert values // insert values
row.getCell(2).setCellValue(invoice.getItemValueString("invoice.number")); row.getCell(2).setCellValue(invoice.getItemValueString("invoice.number"));
row.getCell(3).setCellValue(invoice.getItemValueString("invoice.text")); row.getCell(3).setCellValue(invoice.getItemValueString("invoice.text"));
row.getCell(4).setCellValue(invoice.getItemValueDate("invoice.date")); row.getCell(4).setCellValue(invoice.getItemValueDate("invoice.date"));
row.getCell(5).setCellValue(invoice.getItemValueDate("invoice.duedate")); row.getCell(5).setCellValue(invoice.getItemValueDate("invoice.duedate"));
double total = invoice.getItemValueDouble("invoice.saldo"); double total = invoice.getItemValueDouble("invoice.saldo");
if (total < 0) { String currency=invoice.getItemValueString("invoice.currency");
// SOLL if ("EUR".equals(currency)) {
// EUR
row.getCell(6).setCellValue(total); row.getCell(6).setCellValue(total);
row.getCell(7).setCellValue(invoice.getItemValueString("invoice.currency")); row.getCell(7).setCellValue(currency);
} else { } else {
// HABEN // USD
row.getCell(8).setCellValue(total); row.getCell(8).setCellValue(total);
row.getCell(9).setCellValue(invoice.getItemValueString("invoice.currency")); row.getCell(9).setCellValue(currency);
} }
row.getCell(10).setCellValue(invoice.getItemValueString("$workflowstatus")); row.getCell(10).setCellValue(invoice.getItemValueString("$workflowstatus"));
saldo = saldo + total; saldo = saldo + total;
@ -211,13 +220,14 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
sheet.shiftRows(referenceRowPos, lastRow + totalRowCount, -1, true, true); sheet.shiftRows(referenceRowPos, lastRow + totalRowCount, -1, true, true);
// finally update the total formula... // finally update the total formula...
evalXSSFSheet(doc, sheet, "TOTAL"); evalXSSFSheet(doc, sheet, "TOTALEUR");
evalXSSFSheet(doc, sheet, "TOTALUSD");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
// write back the file // write back the file
doc.write(byteArrayOutputStream); doc.write(byteArrayOutputStream);
doc.close();
byte[] newContent = byteArrayOutputStream.toByteArray(); byte[] newContent = byteArrayOutputStream.toByteArray();
FileData fileDataNew = new FileData(fileData.getName(), newContent, fileData.getContentType(), null); FileData fileDataNew = new FileData(fileData.getName(), newContent, fileData.getContentType(), null);
// update the fileData // update the fileData
@ -228,6 +238,15 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
} catch (IOException e) { } catch (IOException e) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), ERROR_CONFIG, throw new PluginException(OPListExportAdapter.class.getSimpleName(), ERROR_CONFIG,
"failed to update opliste: " + e.getMessage()); "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();
}
}
} }
} }

View file

@ -25,10 +25,11 @@ package com.alexanderlogistics;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.ejb.Timer;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import org.imixs.workflow.engine.scheduler.SchedulerController; import org.imixs.workflow.engine.scheduler.SchedulerController;
/** /**
@ -60,6 +61,10 @@ public class OPListExportController extends SchedulerController {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(OPListExportController.class.getName()); private static Logger logger = Logger.getLogger(OPListExportController.class.getName());
@Inject
OPListExportScheduler opListExportScheduler;
@Override @Override
public String getName() { public String getName() {
return OPLIST_EXPORT_CONFIGURATION; return OPLIST_EXPORT_CONFIGURATION;
@ -78,4 +83,8 @@ public class OPListExportController extends SchedulerController {
return schedulerClass; return schedulerClass;
} }
} }

View file

@ -26,18 +26,16 @@ import java.text.DateFormat;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import org.imixs.marty.team.TeamService; import org.imixs.marty.team.TeamService;
import org.imixs.workflow.FileData;
import org.imixs.workflow.ItemCollection; import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.engine.DocumentService; import org.imixs.workflow.engine.DocumentService;
import org.imixs.workflow.engine.ModelService;
import org.imixs.workflow.engine.ReportService;
import org.imixs.workflow.engine.WorkflowService; import org.imixs.workflow.engine.WorkflowService;
import org.imixs.workflow.engine.scheduler.Scheduler; import org.imixs.workflow.engine.scheduler.Scheduler;
import org.imixs.workflow.engine.scheduler.SchedulerException; import org.imixs.workflow.engine.scheduler.SchedulerException;
@ -69,21 +67,15 @@ public class OPListExportScheduler implements Scheduler {
public static DecimalFormat decimalFormat = new DecimalFormat("0.00", public static DecimalFormat decimalFormat = new DecimalFormat("0.00",
new DecimalFormatSymbols(java.util.Locale.GERMANY)); new DecimalFormatSymbols(java.util.Locale.GERMANY));
@EJB
DocumentService documentService;
@EJB @EJB
WorkflowService workflowService; WorkflowService workflowService;
@EJB @EJB
ModelService modelService; DocumentService documentService;
@EJB @EJB
TeamService teamService; TeamService teamService;
@EJB
ReportService reportService;
private static Logger logger = Logger.getLogger(OPListExportScheduler.class.getName()); private static Logger logger = Logger.getLogger(OPListExportScheduler.class.getName());
/** /**
@ -96,45 +88,73 @@ public class OPListExportScheduler implements Scheduler {
* @throws QueryException * @throws QueryException
*/ */
public ItemCollection run(ItemCollection configuration) throws SchedulerException { public ItemCollection run(ItemCollection configuration) throws SchedulerException {
List<ItemCollection> invoices = null; try {
StringBuffer buffer = new StringBuffer(); configuration.removeItem("_scheduler_logmessage");
int lines = 0; logMessage("....export OP-Listen...", configuration, null);
// Hole dir alle Bereiche
List<ItemCollection> spaces = teamService.getSpaces();
// Jezt erzeugen wir für jeden Bereich ein neues Workitem .
for (ItemCollection space : spaces) {
configuration.removeItem("_scheduler_logmessage"); // Gibt es Rechnungen?
logMessage(configuration, "....export OP-Listen..."); try {
List<ItemCollection> invoices = documentService
.find("$modelversion:rechnungsausgang-de-1.0 AND type:workitem AND $uniqueidref:"
+ space.getUniqueID(), 1, 0);
if (invoices.size() > 0) {
// erzeuge eine OP-Liste
ItemCollection workitem = new ItemCollection();
workitem.setItemValue("space.ref", space.getUniqueID());
processOPListe(workitem);
}
} catch (QueryException e) {
// not possible
e.printStackTrace();
}
// Hole dir alle Bereiche
List<ItemCollection> spaces = teamService.getSpaces();
// Jezt erzeugen wir für jeden Berich ein neues Workitem falls offene Rechnungen
for (ItemCollection space : spaces) {
ItemCollection workitem = new ItemCollection();
workitem.setItemValue("space.ref", space.getUniqueID());
try {
workflowService.processWorkItem( //
workitem.task(1000). //
event(100). //
model("opliste-de-1.0"));
} catch (AccessDeniedException | ProcessingErrorException | PluginException | ModelException e) {
e.printStackTrace();
} }
logMessage("...completed", configuration, null);
} catch (RuntimeException e) {
// continue with log message
logger.severe("...OPList Error");
logMessage("...Failed to create OPLists: " + e.getMessage(), configuration, null);
} catch (PluginException | ModelException e2) {
logger.severe("Error processing OP-List for space: " + e2.getMessage());
throw new SchedulerException("OP-LIST-ERROR", "OPList Processing failed : " + e2.getMessage(), e2);
} }
// transfer file via FTP...
DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm");
// MMM d, yyyy HH:mm a
FileData fileData = new FileData("OPD_" + formatter.format(new Date()) + ".txt",
String.valueOf(buffer).getBytes(), null, null);
logMessage(configuration, "...completed: " + lines + " lines");
return configuration; return configuration;
} }
private void logMessage(ItemCollection configuration, String message) { @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
configuration.appendItemValue("_scheduler_logmessage", message); public void processOPListe(ItemCollection workitem)
throws PluginException, AccessDeniedException, ProcessingErrorException, ModelException {
workflowService.processWorkItem( //
workitem.task(1000). //
event(100). //
model("opliste-de-1.0"));
}
/**
* Creates a new log entry stored in the item _scheduler_log. The log can be
* writen optional to the configuraiton and the workitem
*
* @param message
* @param configuration
*/
public void logMessage(String message, ItemCollection configuration, ItemCollection workitem) {
if (configuration != null) {
configuration.appendItemValue(Scheduler.ITEM_LOGMESSAGE, message);
}
if (workitem != null) {
workitem.appendItemValue(Scheduler.ITEM_LOGMESSAGE, message);
}
logger.info(message); logger.info(message);
} }
} }

View file

@ -56,7 +56,7 @@
<div class="imixs-footer"> <div class="imixs-footer">
<h:outputLabel value="#{message.modified}: " /> <h:outputLabel value="#{message.modified}: " />
<h:outputText <h:outputText
value="#{cargosoftExportController.configuration.item['$modified']}"> value="#{oplistExportController.configuration.item['$modified']}">
<f:convertDateTime timeZone="#{message.timeZone}" type="both" <f:convertDateTime timeZone="#{message.timeZone}" type="both"
pattern="#{message.dateTimePattern}" /> pattern="#{message.dateTimePattern}" />
</h:outputText> </h:outputText>
@ -64,6 +64,7 @@
<br /> <br />
<h:commandButton <h:commandButton
actionListener="#{oplistExportController.saveConfiguration()}" actionListener="#{oplistExportController.saveConfiguration()}"
value="#{message.save}"> value="#{message.save}">

View file

@ -86,6 +86,7 @@ public class MigrationSpaceZuordnung {
while (true) { while (true) {
workflowCLient.setPageIndex(pageIndex); workflowCLient.setPageIndex(pageIndex);
workflowCLient.setPageSize(pageSize); workflowCLient.setPageSize(pageSize);
workflowCLient.setSortBy("$created");
List<ItemCollection> invoices = workflowCLient.searchDocuments(query); List<ItemCollection> invoices = workflowCLient.searchDocuments(query);
@ -95,7 +96,10 @@ public class MigrationSpaceZuordnung {
for (ItemCollection invoice: invoices) { for (ItemCollection invoice: invoices) {
count++; count++;
boolean update=false; boolean update=false;
if (invoice.getItemValueString("space.ref").isEmpty()) {
String currentSpaceRef=invoice.getItemValueString("space.ref");
List<String> refList=invoice.getItemValueList("$uniqueidref",String.class);
if (currentSpaceRef.isEmpty() || !refList.contains(currentSpaceRef)) {
// Jezt noch das Space mapping // Jezt noch das Space mapping
// dazu kucken wir in alle spaces den config wert 'pos.mapping' // dazu kucken wir in alle spaces den config wert 'pos.mapping'
@ -112,6 +116,7 @@ public class MigrationSpaceZuordnung {
// we have a match // we have a match
invoice.setItemValue("space.ref", entry.getKey()); invoice.setItemValue("space.ref", entry.getKey());
invoice.setItemValue("space.name", spaceNames.get(entry.getKey())); invoice.setItemValue("space.name", spaceNames.get(entry.getKey()));
invoice.appendItemValueUnique("$uniqueidref", entry.getKey());
update=true; update=true;
break; break;

Binary file not shown.