opliste improvements

This commit is contained in:
Ralph Soika 2024-11-24 14:54:46 +01:00
parent 2a12ecaf3c
commit aabb7ab04d
3 changed files with 443 additions and 402 deletions

View file

@ -22,7 +22,6 @@ import org.apache.poi.ss.usermodel.CellCopyPolicy;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
@ -133,7 +132,6 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
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);
@ -150,7 +148,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
// first add the columns for the currency list
addCurrencyColumns(doc, sheet, currencyList, spaces);
// insertInvoiceRows(sheet, document, targetName, filter, currencyList);
insertInvoiceRows(doc, sheet, currencyList, spaces);
// write back the updated excel file
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@ -162,7 +160,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
document.addFileData(fileDataNew);
logger.finest("......new document added");
} catch (IOException e) {
} catch (IOException | QueryException e) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG,
"failed to update opliste: " + e.getMessage());
@ -204,7 +202,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
List<ItemCollection> spaces) {
// zusaetzliche spalten einfuegen...
int newColumns = (currencyList.size() * spaces.size()) - 1;
int newColumns = (currencyList.size() * spaces.size()) - 0;
for (int i = 0; i < newColumns; i++) {
logger.fine(".. add currency column...");
POIUtil.insertColumn(sheet, 1, 2 + i);
@ -226,6 +224,8 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
col++;
}
}
// Add the total column
spaceRow.getCell(col).setCellValue("Total");
}
/**
@ -242,35 +242,15 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
* @throws PluginException
* @throws QueryException
*/
private void insertInvoiceRows(ItemCollection document, String fileName, String currency1,
String currency2, List<ItemCollection> spaces)
private void insertInvoiceRows(XSSFWorkbook doc, XSSFSheet sheet, List<String> currencyList,
List<ItemCollection> spaces)
throws PluginException, QueryException {
Map<String, Double> totalsUeberfaelligCurrency1 = new HashMap<String, Double>();
Map<String, Double> totalsFaelligCurrency1 = new HashMap<String, Double>();
Map<String, Double> totalsUeberfaelligCurrency2 = new HashMap<String, Double>();
Map<String, Double> totalsFaelligCurrency2 = new HashMap<String, Double>();
List<String> spaceNames = new ArrayList<String>();
Map<String, WeekInvoiceData> weekDataMap = new HashMap<String, WeekInvoiceData>();
FileData fileData = document.getFileData(fileName);
// load XSSFWorkbook
XSSFWorkbook doc = null;
try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) {
doc = new XSSFWorkbook(imputStream);
// compute current week
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
int weekNumber = calendar.get(Calendar.WEEK_OF_YEAR);
int year = calendar.get(Calendar.YEAR);
String currentWeek = year + "/";
if (weekNumber < 10) {
currentWeek = currentWeek + "0" + weekNumber;
} else {
currentWeek = currentWeek + weekNumber;
}
Map<String, TotalInvoiceData> totalDataMapFaellig = new HashMap<String, TotalInvoiceData>();
Map<String, TotalInvoiceData> totalDataMapUeberFaellig = new HashMap<String, TotalInvoiceData>();
CellStyle headerCellStyle = doc.createCellStyle();
// fill foreground color ...
@ -278,18 +258,13 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
// and solid fill pattern produces solid grey cell fill
headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// NOTE: we only take the first sheet !
XSSFSheet sheet = doc.getSheetAt(0);
// First we create a column for each Space.....
XSSFRow rowSpacesLabels = sheet.getRow(9);
XSSFRow referenceRowSpacesCurrencies = sheet.getRow(10);
XSSFRow referenceRowValues = sheet.getRow(11);
XSSFRow referenceRowCurrentWeek = sheet.getRow(12);
XSSFRow referenceRowTotal = sheet.getRow(15);
// Aktuelle KW berechnen
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
int currentWeekNumber = calendar.get(Calendar.WEEK_OF_YEAR);
int currentYear = calendar.get(Calendar.YEAR);
@ -299,89 +274,59 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
} else {
currentWeekCategory = currentWeekCategory + currentWeekNumber;
}
logger.info("----------HACK");
currentWeekCategory = "2023/06";
/*
* --- Phase 1 -------------------------------------------------------
* Im folgenden fügen wir erst einmal in der Kopfzeile zusätzlich
* Spaltenüberschriften für jede Abteilung ein
* Im folgenden gruppieren wir die Rechnungen nach Woche
*/
XSSFCell cellSpaceLabelReference = rowSpacesLabels.getCell(2);
XSSFCell cellSpaceCurrencyReference = referenceRowSpacesCurrencies.getCell(1);
// XSSFCell cellKWTotalReference = referenceRowCurrentWeek.getCell(1);
XSSFCell cellKWTotalReference = referenceRowTotal.getCell(14);
// XSSFCell cellKWTotalReference = referenceRowTotal.getCell(14);
int column = 1; // beginn in der 2. Spalte!
for (ItemCollection space : spaces) {
XSSFCell cell = null;
String spaceName = space.getItemValueString("space.name");
String spaceID = space.getUniqueID();
spaceNames.add(spaceName);
// Space currency EUR
cell = referenceRowSpacesCurrencies.getCell(column);
cell.copyCellFrom(cellSpaceCurrencyReference, new CellCopyPolicy());
cell.setCellValue(currency1);
// Space currency USD
column++;
cell = referenceRowSpacesCurrencies.getCell(column);
cell.copyCellFrom(cellSpaceCurrencyReference, new CellCopyPolicy());
cell.setCellValue(currency2);
// Space Label
cell = rowSpacesLabels.getCell(column);
cell.setCellValue(spaceName);
// create two new cells...
column++;
cell = rowSpacesLabels.createCell(column);
cell.copyCellFrom(cellSpaceLabelReference, new CellCopyPolicy());
cell.setCellValue("");
cell = rowSpacesLabels.createCell(column);
cell.copyCellFrom(cellSpaceLabelReference, new CellCopyPolicy());
cell.setCellValue("");
logger.info("...grouping invoices by week...");
// collect all invoices for this space grouped by week....
groupInvoicesByWeek(spaceID, spaceName, weekDataMap, currency1);
groupInvoicesByWeek(space.getUniqueID(), spaceName, weekDataMap);
}
// init totals
for (String name : spaceNames) {
totalsUeberfaelligCurrency1.put(name, 0.0);
totalsFaelligCurrency1.put(name, 0.0);
totalsUeberfaelligCurrency2.put(name, 0.0);
totalsFaelligCurrency2.put(name, 0.0);
totalDataMapFaellig.put(name, new TotalInvoiceData(name));
totalDataMapUeberFaellig.put(name, new TotalInvoiceData(name));
}
}
totalsUeberfaelligCurrency1.put("TOTAL", 0.0);
totalsFaelligCurrency1.put("TOTAL", 0.0);
totalsUeberfaelligCurrency2.put("TOTAL", 0.0);
totalsFaelligCurrency2.put("TOTAL", 0.0);
totalDataMapFaellig.put("TOTAL", new TotalInvoiceData("TOTAL"));
totalDataMapUeberFaellig.put("TOTAL", new TotalInvoiceData("TOTAL"));
/*
* --- Phase 2 -------------------------------------------------------
* Nun bilden wir nochmal 2 weitere Spalten am Ende um eine Summenbildung in
* EUR/USD pro KW zu ermöglichen
*/
XSSFCell cell = null;
// XSSFCell cell = null;
// column++;
// Space currency EUR
cell = referenceRowSpacesCurrencies.getCell(column, MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
cell.setCellValue(currency1);
cell = rowSpacesLabels.getCell(column, MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
cell.setCellValue("");
// // Space currency EUR
// cell = referenceRowSpacesCurrencies.getCell(column,
// MissingCellPolicy.CREATE_NULL_AS_BLANK);
// cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
// cell.setCellValue(currency1);
// cell = rowSpacesLabels.getCell(column,
// MissingCellPolicy.CREATE_NULL_AS_BLANK);
// cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
// cell.setCellValue("");
// Space currency USD
column++;
cell = referenceRowSpacesCurrencies.getCell(column, MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
cell.setCellValue(currency2);
// column++;
// cell = referenceRowSpacesCurrencies.getCell(column,
// MissingCellPolicy.CREATE_NULL_AS_BLANK);
// cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
// cell.setCellValue(currency2);
// Space Label
cell = rowSpacesLabels.getCell(column, MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
cell.setCellValue("Total");
// // Space Label
// cell = rowSpacesLabels.getCell(column,
// MissingCellPolicy.CREATE_NULL_AS_BLANK);
// cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
// cell.setCellValue("Total");
/*
* --- Phase 3 -------------------------------------------------------
@ -418,7 +363,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
for (String week : sortedWeekList) {
// now create a new line..
rowPos++;
logger.fine("--> Zeile " + rowPos + " Week=" + week);
logger.info("--> Zeile " + rowPos + " Week=" + week);
XSSFRow row = sheet.createRow(rowPos);
if (week.equals(currentWeekCategory)) {
@ -439,159 +384,215 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
for (String name : spaceNames) {
String key = name + "/" + week;
logger.fine("search WeekInvoiceData for " + key);
logger.info("search WeekInvoiceData for " + key);
// list of invoices
WeekInvoiceData weekData = weekDataMap.get(key);
if (weekData != null) {
logger.fine(" " + currency1 + "=" + weekData.totalCurrency1 + " " + currency2 + "="
+ weekData.totalCurrency2);
row.getCell(column).setCellValue(weekData.totalCurrency1);
column++;
row.getCell(column).setCellValue(weekData.totalCurrency2);
// logger.fine(" " + currency1 + "=" + weekData.totalCurrency1 + " " + currency2
// + "="
// + weekData.totalCurrency2);
for (String currency : currencyList) {
logger.info("-- Col Number=" + column);
double betrag = weekData.getTotal(currency);
row.getCell(column).setCellValue(betrag);
if (ueberFaellig) {
double eur = totalsUeberfaelligCurrency1.get(name);
eur = InvoiceUtil.round(eur + weekData.totalCurrency1);
totalsUeberfaelligCurrency1.put(name, eur);
double usd = totalsUeberfaelligCurrency2.get(name);
usd = InvoiceUtil.round(usd + weekData.totalCurrency2);
totalsUeberfaelligCurrency2.put(name, usd);
// saldoEUR1 = InvoiceUtil.round(saldoEUR1 + weekData.totalEUR);
// saldoUSD1 = InvoiceUtil.round(saldoUSD1 + weekData.totalUSD);
totalDataMapUeberFaellig.get(name).add(betrag, currency);
} else {
double eur = totalsFaelligCurrency1.get(name);
eur = InvoiceUtil.round(eur + weekData.totalCurrency1);
totalsFaelligCurrency1.put(name, eur);
double usd = totalsFaelligCurrency2.get(name);
usd = InvoiceUtil.round(usd + weekData.totalCurrency2);
totalsFaelligCurrency2.put(name, usd);
// saldoEUR2 = InvoiceUtil.round(saldoEUR2 + weekData.totalEUR);
// saldoUSD2 = InvoiceUtil.round(saldoUSD2 + weekData.totalUSD);
totalDataMapFaellig.get(name).add(betrag, currency);
}
kwTotalEUR = kwTotalEUR + weekData.totalCurrency1;
kwTotalUSD = kwTotalUSD + weekData.totalCurrency2;
column++;
}
// row.getCell(column).setCellValue(weekData.totalCurrency1);
// column++;
// row.getCell(column).setCellValue(weekData.totalCurrency2);
// if (ueberFaellig) {
// double eur = totalsUeberfaelligCurrency1.get(name);
// eur = InvoiceUtil.round(eur + weekData.totalCurrency1);
// totalsUeberfaelligCurrency1.put(name, eur);
// double usd = totalsUeberfaelligCurrency2.get(name);
// usd = InvoiceUtil.round(usd + weekData.totalCurrency2);
// totalsUeberfaelligCurrency2.put(name, usd);
// // saldoEUR1 = InvoiceUtil.round(saldoEUR1 + weekData.totalEUR);
// // saldoUSD1 = InvoiceUtil.round(saldoUSD1 + weekData.totalUSD);
// } else {
// double eur = totalsFaelligCurrency1.get(name);
// eur = InvoiceUtil.round(eur + weekData.totalCurrency1);
// totalsFaelligCurrency1.put(name, eur);
// double usd = totalsFaelligCurrency2.get(name);
// usd = InvoiceUtil.round(usd + weekData.totalCurrency2);
// totalsFaelligCurrency2.put(name, usd);
// // saldoEUR2 = InvoiceUtil.round(saldoEUR2 + weekData.totalEUR);
// // saldoUSD2 = InvoiceUtil.round(saldoUSD2 + weekData.totalUSD);
// }
// kwTotalEUR = kwTotalEUR + weekData.totalCurrency1;
// kwTotalUSD = kwTotalUSD + weekData.totalCurrency2;
// column++;
} else {
logger.fine("...... NOT FOUND");
logger.info("...... NOT FOUND");
// skip columns
column = column + 2;
for (String currency : currencyList) {
column++;
}
}
}
// KW Summe anzeigen
if (week.equals(currentWeekCategory)) {
XSSFCell kwTotalCell = row.getCell(column);
// if (week.equals(currentWeekCategory)) {
// XSSFCell kwTotalCell = row.getCell(column);
// // kwTotalCell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
// kwTotalCell.setCellValue(kwTotalEUR);
// column++;
// // row.getCell(column).setCellValue(kwTotalUSD);
// kwTotalCell = row.getCell(column);
// // kwTotalCell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
// kwTotalCell.setCellValue(kwTotalUSD);
// } else {
// XSSFCell kwTotalCell = row.getCell(column);
// kwTotalCell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
kwTotalCell.setCellValue(kwTotalEUR);
// kwTotalCell.setCellValue(kwTotalEUR);
column++;
// row.getCell(column).setCellValue(kwTotalUSD);
kwTotalCell = row.getCell(column);
// column++;
// // row.getCell(column).setCellValue(kwTotalUSD);
// kwTotalCell = row.getCell(column);
// kwTotalCell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
kwTotalCell.setCellValue(kwTotalUSD);
// kwTotalCell.setCellValue(kwTotalUSD);
} else {
XSSFCell kwTotalCell = row.getCell(column);
kwTotalCell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
kwTotalCell.setCellValue(kwTotalEUR);
column++;
// row.getCell(column).setCellValue(kwTotalUSD);
kwTotalCell = row.getCell(column);
kwTotalCell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
kwTotalCell.setCellValue(kwTotalUSD);
}
// }
// store totals
if (ueberFaellig) {
double eur = totalsUeberfaelligCurrency1.get("TOTAL");
eur = InvoiceUtil.round(eur + kwTotalEUR);
totalsUeberfaelligCurrency1.put("TOTAL", eur);
double usd = totalsUeberfaelligCurrency2.get("TOTAL");
usd = InvoiceUtil.round(usd + kwTotalUSD);
totalsUeberfaelligCurrency2.put("TOTAL", usd);
} else {
double eur = totalsFaelligCurrency1.get("TOTAL");
eur = InvoiceUtil.round(eur + kwTotalEUR);
totalsFaelligCurrency1.put("TOTAL", eur);
double usd = totalsFaelligCurrency2.get("TOTAL");
usd = InvoiceUtil.round(usd + kwTotalUSD);
totalsFaelligCurrency2.put("TOTAL", usd);
}
// if (ueberFaellig) {
// double eur = totalsUeberfaelligCurrency1.get("TOTAL");
// eur = InvoiceUtil.round(eur + kwTotalEUR);
// totalsUeberfaelligCurrency1.put("TOTAL", eur);
// double usd = totalsUeberfaelligCurrency2.get("TOTAL");
// usd = InvoiceUtil.round(usd + kwTotalUSD);
// totalsUeberfaelligCurrency2.put("TOTAL", usd);
// } else {
// double eur = totalsFaelligCurrency1.get("TOTAL");
// eur = InvoiceUtil.round(eur + kwTotalEUR);
// totalsFaelligCurrency1.put("TOTAL", eur);
// double usd = totalsFaelligCurrency2.get("TOTAL");
// usd = InvoiceUtil.round(usd + kwTotalUSD);
// totalsFaelligCurrency2.put("TOTAL", usd);
// }
}
// delete reference rows
logger.finest("..shift 12 to " + rowPos);
sheet.shiftRows(12, rowPos, -1, true, true);
sheet.shiftRows(rowPos + 2, rowPos + 6, -3, true, true);
// logger.info("..shift 12 to " + rowPos);
// sheet.shiftRows(12, rowPos, -1, true, true);
// sheet.shiftRows(rowPos + 2, rowPos + 6, -3, true, true);
/*
* --- Phase 6 -------------------------------------------------------
* now lets update the totals...
* Überfällig
*/
int _rowNo = sortedWeekList.size() + 11;
int _rowNo = sortedWeekList.size() + 14;
XSSFRow rowUeberFaellig = sheet.getRow(_rowNo);
XSSFRow rowFaellig = sheet.getRow(_rowNo + 1);
XSSFRow rowTotal = sheet.getRow(_rowNo + 2);
column = 1;
XSSFCell totalCell = null;
for (String name : spaceNames) {
TotalInvoiceData totalDataUeberFaellig = totalDataMapUeberFaellig.get(name);
TotalInvoiceData totalDataFaellig = totalDataMapFaellig.get(name);
for (String currency : currencyList) {
// überfällig
totalCell = rowUeberFaellig.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency1.get(name));
totalCell.setCellValue(totalDataUeberFaellig.getTotal(currency));
// noch nicht fällig
totalCell = rowFaellig.getCell(column);
totalCell.setCellValue(totalsFaelligCurrency1.get(name));
totalCell.setCellValue(totalDataFaellig.getTotal(currency));
// total...
totalCell = rowTotal.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency1.get(name) + totalsFaelligCurrency1.get(name));
column++;
totalCell = rowUeberFaellig.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency2.get(name));
totalCell = rowFaellig.getCell(column);
totalCell.setCellValue(totalsFaelligCurrency2.get(name));
totalCell = rowTotal.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency2.get(name) + totalsFaelligCurrency2.get(name));
totalCell.setCellValue(InvoiceUtil
.round(totalDataUeberFaellig.getTotal(currency) + totalDataFaellig.getTotal(currency)));
column++;
}
// totals
totalCell = rowUeberFaellig.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency1.get("TOTAL"));
totalCell = rowFaellig.getCell(column);
totalCell.setCellValue(totalsFaelligCurrency1.get("TOTAL"));
totalCell = rowTotal.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency1.get("TOTAL") + totalsFaelligCurrency1.get("TOTAL"));
column++;
totalCell = rowUeberFaellig.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency2.get("TOTAL"));
totalCell = rowFaellig.getCell(column);
totalCell.setCellValue(totalsFaelligCurrency2.get("TOTAL"));
totalCell = rowTotal.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency2.get("TOTAL") + totalsFaelligCurrency2.get("TOTAL"));
}
// // totals
// totalCell = rowUeberFaellig.getCell(column);
// totalCell.setCellValue(totalsUeberfaellig.get("TOTAL"));
// totalCell = rowFaellig.getCell(column);
// totalCell.setCellValue(totalsFaelligCurrency1.get("TOTAL"));
// totalCell = rowTotal.getCell(column);
// totalCell.setCellValue(totalsUeberfaelligCurrency1.get("TOTAL") +
// totalsFaelligCurrency1.get("TOTAL"));
// column++;
// totalCell = rowUeberFaellig.getCell(column);
// totalCell.setCellValue(totalsUeberfaelligCurrency2.get("TOTAL"));
// totalCell = rowFaellig.getCell(column);
// totalCell.setCellValue(totalsFaelligCurrency2.get("TOTAL"));
// totalCell = rowTotal.getCell(column);
// totalCell.setCellValue(totalsUeberfaelligCurrency2.get("TOTAL") +
// totalsFaelligCurrency2.get("TOTAL"));
// delete placeholder row
sheet.shiftRows(_rowNo, _rowNo + 3, -1);
// write back the file
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
doc.write(byteArrayOutputStream);
logger.finest("......invoices added");
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(OPListExportAdapterByWeek.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"failed to update opliste: " + e.getMessage());
} finally {
if (doc != null) {
/**
* Diese Methode gruppiert eine Rechnungsliste nach Kalenderwoche
*
* @param spaceID - Space Ref to select a list of invoices associated with
* a
* space
* @param weekDataCache - a local cache storing all invoices by week
*
*
*/
private void groupInvoicesByWeek(String spaceID, String spaceName,
Map<String, WeekInvoiceData> weekDataCache) {
logger.info("...group invoices (DEBUG) for " + spaceName + "/" + spaceID);
try {
doc.close();
} catch (IOException e) {
logger.severe("Failed to close workbook: " + e.getMessage());
List<ItemCollection> invoices = documentService.find(
"$modelversion:rechnungsausgang-* AND type:workitem AND $uniqueidref:" + spaceID, 9999, 0,
"invoice.number", false);
logger.fine(" found " + invoices.size() + " for space " + spaceName);
for (ItemCollection invoice : invoices) {
// compute Week
Date dueDate = invoice.getItemValueDate("invoice.duedate");
LocalDate localDate = dueDate.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
int weekNumber = localDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
int weekBasedYear = localDate.get(IsoFields.WEEK_BASED_YEAR);
String weekCategory = weekBasedYear + "/" + String.format("%02d", weekNumber);
if ("2024/01".equals(weekCategory)) {
logger.warning("--> Invoice found with 2024/01: " + invoice.getUniqueID());
}
// haben wir schon ein listchen?
String key = spaceName + "/" + weekCategory;
logger.fine(" ....building weekInvoiceData object for " + key);
WeekInvoiceData weekData = weekDataCache.get(key);
if (weekData == null) {
weekData = new WeekInvoiceData(spaceName, weekCategory);
}
// Jetzt Rechnung addieren
weekData.add(invoice);
weekDataCache.put(key, weekData);
}
} catch (
QueryException e) {
e.printStackTrace();
}
}
}
}
/**
@ -628,88 +629,76 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
return fileData;
}
/**
* Diese Methode gruppiert eine Rechnungsliste nach Kalenderwoche
*
* @param spaceID - Space Ref to select a list of invoices associated with a
* space
* @param cache - a local cache storing all invoices by week
*
*
*/
private void groupInvoicesByWeek(String spaceID, String spaceName,
Map<String, WeekInvoiceData> cache, String currency1) {
logger.info("...group invoices (DEBUG) for " + spaceName + "/" + spaceID);
try {
List<ItemCollection> invoices = documentService.find(
"$modelversion:rechnungsausgang-* AND type:workitem AND $uniqueidref:" + spaceID, 9999, 0,
"invoice.number", false);
logger.fine(" found " + invoices.size() + " for space " + spaceName);
for (ItemCollection invoice : invoices) {
// compute Week
Date dueDate = invoice.getItemValueDate("invoice.duedate");
LocalDate localDate = dueDate.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
int weekNumber = localDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
int weekBasedYear = localDate.get(IsoFields.WEEK_BASED_YEAR);
String weekCategory = weekBasedYear + "/" + String.format("%02d", weekNumber);
if ("2024/01".equals(weekCategory)) {
logger.warning("--> Invoice found with 2024/01: " + invoice.getUniqueID());
}
// haben wir schon ein listchen?
String key = spaceName + "/" + weekCategory;
logger.fine(" ....building weekInvoiceData object for " + key);
WeekInvoiceData weekData = cache.get(key);
if (weekData == null) {
weekData = new WeekInvoiceData(spaceName, weekCategory);
}
// Jetzt Rechnung addieren
weekData.add(invoice, currency1);
cache.put(key, weekData);
}
} catch (
QueryException e) {
e.printStackTrace();
}
}
}
/**
* Data Element for invoice totals per week and space
* Data Element for invoice totals per week and space.
* The object holds multiple currencies.
*/
class WeekInvoiceData {
String week;
String spaceName;
double totalCurrency1;
double totalCurrency2;
Map<String, Double> totals = new HashMap<>();
public WeekInvoiceData(String spaceName, String week) {
this.spaceName = spaceName;
this.week = week;
}
public void add(ItemCollection invoice, String currency1) {
String spaceName = invoice.getItemValueString("space.name");
public void add(ItemCollection invoice) {
String currency = invoice.getItemValueString("invoice.currency");
// Double total = invoice.getItemValueDouble("invoice.total");
Double total = invoice.getItemValueDouble("invoice.saldo");
if (currency1.equals(currency)) {
totalCurrency1 = totalCurrency1 + total;
Double totalCurrency = totals.get(currency);
if (totalCurrency == null) {
totalCurrency = 0.0;
}
totalCurrency = totalCurrency + total;
totals.put(currency, InvoiceUtil.round(totalCurrency));
}
public double getTotal(String currency) {
Double result = totals.get(currency);
if (result != null) {
return result;
} else {
totalCurrency2 = totalCurrency2 + total;
return 0.0;
}
}
}
/**
* Data Element for invoice totals per space.
* The object holds multiple currencies.
*/
class TotalInvoiceData {
String spaceName;
Map<String, Double> totals = new HashMap<>();
public TotalInvoiceData(String spaceName) {
this.spaceName = spaceName;
}
public void add(Double total, String currency) {
Double totalCurrency = totals.get(currency);
if (totalCurrency == null) {
totalCurrency = 0.0;
}
totalCurrency = totalCurrency + total;
totals.put(currency, InvoiceUtil.round(totalCurrency));
}
public double getTotal(String currency) {
Double result = totals.get(currency);
if (result != null) {
return result;
} else {
return 0.0;
}
}
}

Binary file not shown.

View file

@ -101,6 +101,7 @@ th { font-weight: bold;}
<bpmn2:flowNodeRef>gateway_37SSsw</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>textAnnotation_iPsg3g</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>event_opebWA</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>event_JraaXA</bpmn2:flowNodeRef>
</bpmn2:lane>
</bpmn2:laneSet>
<bpmn2:startEvent id="StartEvent_1" name="Start">
@ -298,6 +299,7 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt
<bpmn2:incoming>Association_1</bpmn2:incoming>
<bpmn2:incoming>sequenceFlow_N0jfWA</bpmn2:incoming>
<bpmn2:incoming>sequenceFlow_QUQCFw</bpmn2:incoming>
<bpmn2:incoming>sequenceFlow_nrskqg</bpmn2:incoming>
</bpmn2:task>
<bpmn2:sequenceFlow id="SequenceFlow_19" sourceRef="Task_4" targetRef="EndEvent_3">
<bpmn2:documentation id="documentation_AvvoyQ"/>
@ -581,6 +583,44 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt
<bpmn2:sequenceFlow id="sequenceFlow_QUQCFw" sourceRef="event_opebWA" targetRef="Task_4">
<bpmn2:documentation id="documentation_SzbLsw"/>
</bpmn2:sequenceFlow>
<bpmn2:intermediateCatchEvent id="event_JraaXA" imixs:activityid="30" name="OP Liste Außenstände">
<bpmn2:extensionElements>
<imixs:item name="txtmailsubject" type="xs:string">
<imixs:value/>
</imixs:item>
<imixs:item name="keymailreceiverfields" type="xs:string"/>
<imixs:item name="rtfmailbody" type="CDATA">
<imixs:value/>
</imixs:item>
<imixs:item name="rtfresultlog" type="xs:string">
<imixs:value><![CDATA[Liste Außenstände erstellt]]></imixs:value>
</imixs:item>
<imixs:item name="keypublicresult" type="xs:string">
<imixs:value><![CDATA[1]]></imixs:value>
</imixs:item>
<imixs:item name="txtactivityresult" type="xs:string">
<imixs:value><![CDATA[<item name="process">Mahnwesen</item>
<opliste name="excel-export">
<textblock>OP-Liste KW Template</textblock>
<template>op-liste_kw_template.xlsx</template>
<target-name>op-liste_<itemvalue>space.name</itemvalue>_<itemvalue format="yyyy-MM-dd">$lasteventdate</itemvalue>.xlsx</target-name>
</opliste>
<poi-update name="findreplace">
<find>A8</find>
<replace><itemvalue format="dd.MM.yyyy">$lasteventdate</itemvalue></replace>
<type>date</type>
</poi-update>
]]></imixs:value>
</imixs:item>
</bpmn2:extensionElements>
<bpmn2:signalEventDefinition id="signalEventDefinition_nQ5AuQ" signalRef="signal_2"/>
<bpmn2:documentation id="documentation_bmiCEg"/>
<bpmn2:outgoing>sequenceFlow_nrskqg</bpmn2:outgoing>
</bpmn2:intermediateCatchEvent>
<bpmn2:sequenceFlow id="sequenceFlow_nrskqg" sourceRef="event_JraaXA" targetRef="Task_4">
<bpmn2:documentation id="documentation_511ixA"/>
</bpmn2:sequenceFlow>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1" name="Default Process Diagram">
<bpmndi:BPMNPlane bpmnElement="Collaboration_1" id="BPMNPlane_1">
@ -771,6 +811,18 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt
<di:waypoint x="1015.0" y="527.0"/>
<di:waypoint x="1015.0" y="460.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="event_JraaXA" id="BPMNShape_CmZ0yQ">
<dc:Bounds height="36.0" width="36.0" x="1154.0" y="542.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_mLiQ4w">
<dc:Bounds height="20.0" width="100.0" x="1122.0" y="581.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_nrskqg" id="BPMNEdge_3Q16KA" sourceElement="BPMNShape_CmZ0yQ" targetElement="BPMNShape_Task_4">
<di:waypoint x="1154.0" y="560.0"/>
<di:waypoint x="1112.0" y="560.0"/>
<di:waypoint x="1112.0" y="435.0"/>
<di:waypoint x="1070.0" y="435.0"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
<bpmndi:BPMNLabelStyle id="BPMNLabelStyle_1">
<dc:Font name="arial" size="9.0"/>