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.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors; 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.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
@ -133,7 +132,6 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
String textblock = excelDefCollection.getItemValueString("textblock"); String textblock = excelDefCollection.getItemValueString("textblock");
String template = excelDefCollection.getItemValueString("template"); String template = excelDefCollection.getItemValueString("template");
String targetName = excelDefCollection.getItemValueString("target-name"); String targetName = excelDefCollection.getItemValueString("target-name");
boolean filter = evalItemCollection.getItemValueBoolean("filter");
// adapt text.... // adapt text....
targetName = workflowService.adaptText(targetName, document); targetName = workflowService.adaptText(targetName, document);
@ -150,7 +148,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
// first add the columns for the currency list // first add the columns for the currency list
addCurrencyColumns(doc, sheet, currencyList, spaces); addCurrencyColumns(doc, sheet, currencyList, spaces);
// insertInvoiceRows(sheet, document, targetName, filter, currencyList); insertInvoiceRows(doc, sheet, currencyList, spaces);
// write back the updated excel file // write back the updated excel file
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@ -162,7 +160,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
document.addFileData(fileDataNew); document.addFileData(fileDataNew);
logger.finest("......new document added"); logger.finest("......new document added");
} catch (IOException e) { } catch (IOException | QueryException e) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), throw new PluginException(OPListExportAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG, InvoiceService.ERROR_CONFIG,
"failed to update opliste: " + e.getMessage()); "failed to update opliste: " + e.getMessage());
@ -204,7 +202,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
List<ItemCollection> spaces) { List<ItemCollection> spaces) {
// zusaetzliche spalten einfuegen... // zusaetzliche spalten einfuegen...
int newColumns = (currencyList.size() * spaces.size()) - 1; int newColumns = (currencyList.size() * spaces.size()) - 0;
for (int i = 0; i < newColumns; i++) { for (int i = 0; i < newColumns; i++) {
logger.fine(".. add currency column..."); logger.fine(".. add currency column...");
POIUtil.insertColumn(sheet, 1, 2 + i); POIUtil.insertColumn(sheet, 1, 2 + i);
@ -226,6 +224,8 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
col++; col++;
} }
} }
// Add the total column
spaceRow.getCell(col).setCellValue("Total");
} }
/** /**
@ -242,356 +242,357 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
* @throws PluginException * @throws PluginException
* @throws QueryException * @throws QueryException
*/ */
private void insertInvoiceRows(ItemCollection document, String fileName, String currency1, private void insertInvoiceRows(XSSFWorkbook doc, XSSFSheet sheet, List<String> currencyList,
String currency2, List<ItemCollection> spaces) List<ItemCollection> spaces)
throws PluginException, QueryException { 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>(); List<String> spaceNames = new ArrayList<String>();
Map<String, WeekInvoiceData> weekDataMap = new HashMap<String, WeekInvoiceData>(); Map<String, WeekInvoiceData> weekDataMap = new HashMap<String, WeekInvoiceData>();
FileData fileData = document.getFileData(fileName); Map<String, TotalInvoiceData> totalDataMapFaellig = new HashMap<String, TotalInvoiceData>();
Map<String, TotalInvoiceData> totalDataMapUeberFaellig = new HashMap<String, TotalInvoiceData>();
// load XSSFWorkbook CellStyle headerCellStyle = doc.createCellStyle();
XSSFWorkbook doc = null; // fill foreground color ...
try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) { headerCellStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.index);
doc = new XSSFWorkbook(imputStream); // and solid fill pattern produces solid grey cell fill
headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// compute current week XSSFRow referenceRowValues = sheet.getRow(11);
Calendar calendar = new GregorianCalendar(); XSSFRow referenceRowCurrentWeek = sheet.getRow(12);
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;
}
CellStyle headerCellStyle = doc.createCellStyle(); XSSFRow referenceRowTotal = sheet.getRow(15);
// fill foreground color ...
headerCellStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.index);
// and solid fill pattern produces solid grey cell fill
headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// NOTE: we only take the first sheet ! // Aktuelle KW berechnen
XSSFSheet sheet = doc.getSheetAt(0); Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
int currentWeekNumber = calendar.get(Calendar.WEEK_OF_YEAR);
int currentYear = calendar.get(Calendar.YEAR);
String currentWeekCategory = currentYear + "/";
if (currentWeekNumber < 10) {
currentWeekCategory = currentWeekCategory + "0" + currentWeekNumber;
} else {
currentWeekCategory = currentWeekCategory + currentWeekNumber;
}
logger.info("----------HACK");
currentWeekCategory = "2023/06";
// First we create a column for each Space..... /*
XSSFRow rowSpacesLabels = sheet.getRow(9); * --- Phase 1 -------------------------------------------------------
XSSFRow referenceRowSpacesCurrencies = sheet.getRow(10); * Im folgenden gruppieren wir die Rechnungen nach Woche
XSSFRow referenceRowValues = sheet.getRow(11); */
XSSFRow referenceRowCurrentWeek = sheet.getRow(12);
XSSFRow referenceRowTotal = sheet.getRow(15); // XSSFCell cellKWTotalReference = referenceRowTotal.getCell(14);
int column = 1; // beginn in der 2. Spalte!
for (ItemCollection space : spaces) {
String spaceName = space.getItemValueString("space.name");
spaceNames.add(spaceName);
logger.info("...grouping invoices by week...");
groupInvoicesByWeek(space.getUniqueID(), spaceName, weekDataMap);
}
// init totals
for (String name : spaceNames) {
totalDataMapFaellig.put(name, new TotalInvoiceData(name));
totalDataMapUeberFaellig.put(name, new TotalInvoiceData(name));
}
totalDataMapFaellig.put("TOTAL", new TotalInvoiceData("TOTAL"));
totalDataMapUeberFaellig.put("TOTAL", new TotalInvoiceData("TOTAL"));
// Aktuelle KW berechnen /*
calendar.setTime(new Date()); * --- Phase 2 -------------------------------------------------------
int currentWeekNumber = calendar.get(Calendar.WEEK_OF_YEAR); * Nun bilden wir nochmal 2 weitere Spalten am Ende um eine Summenbildung in
int currentYear = calendar.get(Calendar.YEAR); * EUR/USD pro KW zu ermöglichen
String currentWeekCategory = currentYear + "/"; */
if (currentWeekNumber < 10) { // XSSFCell cell = null;
currentWeekCategory = currentWeekCategory + "0" + currentWeekNumber; // column++;
} else { // // Space currency EUR
currentWeekCategory = currentWeekCategory + currentWeekNumber; // 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
* --- Phase 1 ------------------------------------------------------- // column++;
* Im folgenden fügen wir erst einmal in der Kopfzeile zusätzlich // cell = referenceRowSpacesCurrencies.getCell(column,
* Spaltenüberschriften für jede Abteilung ein // MissingCellPolicy.CREATE_NULL_AS_BLANK);
*/ // cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
XSSFCell cellSpaceLabelReference = rowSpacesLabels.getCell(2); // cell.setCellValue(currency2);
XSSFCell cellSpaceCurrencyReference = referenceRowSpacesCurrencies.getCell(1);
// XSSFCell cellKWTotalReference = referenceRowCurrentWeek.getCell(1);
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 // // Space Label
cell = referenceRowSpacesCurrencies.getCell(column); // cell = rowSpacesLabels.getCell(column,
cell.copyCellFrom(cellSpaceCurrencyReference, new CellCopyPolicy()); // MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell.setCellValue(currency1); // cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy());
// cell.setCellValue("Total");
// Space currency USD /*
column++; * --- Phase 3 -------------------------------------------------------
cell = referenceRowSpacesCurrencies.getCell(column); * now build a new row for each week and print out the collected invoice data
cell.copyCellFrom(cellSpaceCurrencyReference, new CellCopyPolicy()); * first iterate over all objects and collect all known weeks and sort them into
cell.setCellValue(currency2); * a ordered list....
*/
// Space Label List<String> sortedWeekList = new ArrayList<String>();
cell = rowSpacesLabels.getCell(column); Iterator<Map.Entry<String, WeekInvoiceData>> iterator = weekDataMap.entrySet().iterator();
cell.setCellValue(spaceName); while (iterator.hasNext()) {
Map.Entry<String, WeekInvoiceData> entry = iterator.next();
// create two new cells... WeekInvoiceData weekInvoiceData = entry.getValue();
column++; if (!sortedWeekList.contains(weekInvoiceData.week)) {
cell = rowSpacesLabels.createCell(column); sortedWeekList.add(weekInvoiceData.week);
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);
// 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);
}
}
totalsUeberfaelligCurrency1.put("TOTAL", 0.0);
totalsFaelligCurrency1.put("TOTAL", 0.0);
totalsUeberfaelligCurrency2.put("TOTAL", 0.0);
totalsFaelligCurrency2.put("TOTAL", 0.0);
/*
* --- 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;
// 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 USD
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");
/*
* --- Phase 3 -------------------------------------------------------
* now build a new row for each week and print out the collected invoice data
* first iterate over all objects and collect all known weeks and sort them into
* a ordered list....
*/
List<String> sortedWeekList = new ArrayList<String>();
Iterator<Map.Entry<String, WeekInvoiceData>> iterator = weekDataMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, WeekInvoiceData> entry = iterator.next();
WeekInvoiceData weekInvoiceData = entry.getValue();
if (!sortedWeekList.contains(weekInvoiceData.week)) {
sortedWeekList.add(weekInvoiceData.week);
}
}
Collections.sort(sortedWeekList);
/*
* --- Phase 4 -------------------------------------------------------
* Nun müssen wir so viele Zeilen nach unten schieben wie wir gleich einfügen.
* Dazu müssen wir kurz einen Probelauf machen um die geplante Anzahl zu
* errechnen....
*/
int rowPos = 11;
int insertCount = sortedWeekList.size();
sheet.shiftRows(rowPos + 1, 2999, insertCount, true, true);
/*
* --- Phase 5 -------------------------------------------------------
* Jetzt Zahlen Zeile für Zeile einfügen....
*/
boolean ueberFaellig = true;
for (String week : sortedWeekList) {
// now create a new line..
rowPos++;
logger.fine("--> Zeile " + rowPos + " Week=" + week);
XSSFRow row = sheet.createRow(rowPos);
if (week.equals(currentWeekCategory)) {
row.copyRowFrom(referenceRowCurrentWeek, new CellCopyPolicy());
ueberFaellig = false;
} else {
row.copyRowFrom(referenceRowValues, new CellCopyPolicy());
}
// insert values
row.getCell(0).setCellValue(week);
// iterate over all spaceNames and test if we have any data to put it into the
// row cells....
column = 1;
double kwTotalEUR = 0;
double kwTotalUSD = 0;
for (String name : spaceNames) {
String key = name + "/" + week;
logger.fine("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);
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");
// skip columns
column = column + 2;
}
}
// KW Summe anzeigen
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);
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);
}
}
// 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);
/*
* --- Phase 6 -------------------------------------------------------
* now lets update the totals...
* Überfällig
*/
int _rowNo = sortedWeekList.size() + 11;
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) {
totalCell = rowUeberFaellig.getCell(column);
totalCell.setCellValue(totalsUeberfaelligCurrency1.get(name));
totalCell = rowFaellig.getCell(column);
totalCell.setCellValue(totalsFaelligCurrency1.get(name));
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));
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"));
// delete placeholder row
sheet.shiftRows(_rowNo, _rowNo + 3, -1);
// write back the file
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
doc.write(byteArrayOutputStream);
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) {
try {
doc.close();
} catch (IOException e) {
logger.severe("Failed to close workbook: " + e.getMessage());
e.printStackTrace();
}
} }
} }
Collections.sort(sortedWeekList);
/*
* --- Phase 4 -------------------------------------------------------
* Nun müssen wir so viele Zeilen nach unten schieben wie wir gleich einfügen.
* Dazu müssen wir kurz einen Probelauf machen um die geplante Anzahl zu
* errechnen....
*/
int rowPos = 11;
int insertCount = sortedWeekList.size();
sheet.shiftRows(rowPos + 1, 2999, insertCount, true, true);
/*
* --- Phase 5 -------------------------------------------------------
* Jetzt Zahlen Zeile für Zeile einfügen....
*/
boolean ueberFaellig = true;
for (String week : sortedWeekList) {
// now create a new line..
rowPos++;
logger.info("--> Zeile " + rowPos + " Week=" + week);
XSSFRow row = sheet.createRow(rowPos);
if (week.equals(currentWeekCategory)) {
row.copyRowFrom(referenceRowCurrentWeek, new CellCopyPolicy());
ueberFaellig = false;
} else {
row.copyRowFrom(referenceRowValues, new CellCopyPolicy());
}
// insert values
row.getCell(0).setCellValue(week);
// iterate over all spaceNames and test if we have any data to put it into the
// row cells....
column = 1;
double kwTotalEUR = 0;
double kwTotalUSD = 0;
for (String name : spaceNames) {
String key = name + "/" + week;
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);
for (String currency : currencyList) {
logger.info("-- Col Number=" + column);
double betrag = weekData.getTotal(currency);
row.getCell(column).setCellValue(betrag);
if (ueberFaellig) {
totalDataMapUeberFaellig.get(name).add(betrag, currency);
} else {
totalDataMapFaellig.get(name).add(betrag, currency);
}
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.info("...... NOT FOUND");
// skip columns
for (String currency : currencyList) {
column++;
}
}
}
// KW Summe anzeigen
// 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);
// 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);
// }
}
// delete reference rows
// 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() + 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(totalDataUeberFaellig.getTotal(currency));
// noch nicht fällig
totalCell = rowFaellig.getCell(column);
totalCell.setCellValue(totalDataFaellig.getTotal(currency));
// total...
totalCell = rowTotal.getCell(column);
totalCell.setCellValue(InvoiceUtil
.round(totalDataUeberFaellig.getTotal(currency) + totalDataFaellig.getTotal(currency)));
column++;
}
}
// // 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);
logger.finest("......invoices added");
}
/**
* 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 {
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; 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 { class WeekInvoiceData {
String week; String week;
String spaceName; String spaceName;
double totalCurrency1; Map<String, Double> totals = new HashMap<>();
double totalCurrency2;
public WeekInvoiceData(String spaceName, String week) { public WeekInvoiceData(String spaceName, String week) {
this.spaceName = spaceName; this.spaceName = spaceName;
this.week = week; this.week = week;
} }
public void add(ItemCollection invoice, String currency1) { public void add(ItemCollection invoice) {
String spaceName = invoice.getItemValueString("space.name");
String currency = invoice.getItemValueString("invoice.currency"); String currency = invoice.getItemValueString("invoice.currency");
// Double total = invoice.getItemValueDouble("invoice.total");
Double total = invoice.getItemValueDouble("invoice.saldo"); Double total = invoice.getItemValueDouble("invoice.saldo");
if (currency1.equals(currency)) { Double totalCurrency = totals.get(currency);
totalCurrency1 = totalCurrency1 + total; if (totalCurrency == null) {
} else { totalCurrency = 0.0;
totalCurrency2 = totalCurrency2 + total;
} }
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;
}
}
}
/**
* 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>gateway_37SSsw</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>textAnnotation_iPsg3g</bpmn2:flowNodeRef> <bpmn2:flowNodeRef>textAnnotation_iPsg3g</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>event_opebWA</bpmn2:flowNodeRef> <bpmn2:flowNodeRef>event_opebWA</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>event_JraaXA</bpmn2:flowNodeRef>
</bpmn2:lane> </bpmn2:lane>
</bpmn2:laneSet> </bpmn2:laneSet>
<bpmn2:startEvent id="StartEvent_1" name="Start"> <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>Association_1</bpmn2:incoming>
<bpmn2:incoming>sequenceFlow_N0jfWA</bpmn2:incoming> <bpmn2:incoming>sequenceFlow_N0jfWA</bpmn2:incoming>
<bpmn2:incoming>sequenceFlow_QUQCFw</bpmn2:incoming> <bpmn2:incoming>sequenceFlow_QUQCFw</bpmn2:incoming>
<bpmn2:incoming>sequenceFlow_nrskqg</bpmn2:incoming>
</bpmn2:task> </bpmn2:task>
<bpmn2:sequenceFlow id="SequenceFlow_19" sourceRef="Task_4" targetRef="EndEvent_3"> <bpmn2:sequenceFlow id="SequenceFlow_19" sourceRef="Task_4" targetRef="EndEvent_3">
<bpmn2:documentation id="documentation_AvvoyQ"/> <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:sequenceFlow id="sequenceFlow_QUQCFw" sourceRef="event_opebWA" targetRef="Task_4">
<bpmn2:documentation id="documentation_SzbLsw"/> <bpmn2:documentation id="documentation_SzbLsw"/>
</bpmn2:sequenceFlow> </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> </bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1" name="Default Process Diagram"> <bpmndi:BPMNDiagram id="BPMNDiagram_1" name="Default Process Diagram">
<bpmndi:BPMNPlane bpmnElement="Collaboration_1" id="BPMNPlane_1"> <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="527.0"/>
<di:waypoint x="1015.0" y="460.0"/> <di:waypoint x="1015.0" y="460.0"/>
</bpmndi:BPMNEdge> </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:BPMNPlane>
<bpmndi:BPMNLabelStyle id="BPMNLabelStyle_1"> <bpmndi:BPMNLabelStyle id="BPMNLabelStyle_1">
<dc:Font name="arial" size="9.0"/> <dc:Font name="arial" size="9.0"/>