From aabb7ab04d879e5cdbdbca1c3436e30ca0fc212b Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Sun, 24 Nov 2024 14:54:46 +0100 Subject: [PATCH] opliste improvements --- .../OPListExportAdapterByWeek.java | 793 +++++++++--------- templates/op-liste_kw_template.xlsx | Bin 40219 -> 40223 bytes workflow/analyse-opliste-de-1.0.3.bpmn | 52 ++ 3 files changed, 443 insertions(+), 402 deletions(-) diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapterByWeek.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapterByWeek.java index b0dd286..729ab18 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapterByWeek.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapterByWeek.java @@ -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 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,356 +242,357 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { * @throws PluginException * @throws QueryException */ - private void insertInvoiceRows(ItemCollection document, String fileName, String currency1, - String currency2, List spaces) + private void insertInvoiceRows(XSSFWorkbook doc, XSSFSheet sheet, List currencyList, + List spaces) throws PluginException, QueryException { - Map totalsUeberfaelligCurrency1 = new HashMap(); - Map totalsFaelligCurrency1 = new HashMap(); - Map totalsUeberfaelligCurrency2 = new HashMap(); - Map totalsFaelligCurrency2 = new HashMap(); List spaceNames = new ArrayList(); Map weekDataMap = new HashMap(); - FileData fileData = document.getFileData(fileName); + Map totalDataMapFaellig = new HashMap(); + Map totalDataMapUeberFaellig = new HashMap(); - // load XSSFWorkbook - XSSFWorkbook doc = null; - try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) { - doc = new XSSFWorkbook(imputStream); + CellStyle headerCellStyle = doc.createCellStyle(); + // fill foreground color ... + headerCellStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.index); + // and solid fill pattern produces solid grey cell fill + headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); - // 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; - } + XSSFRow referenceRowValues = sheet.getRow(11); + XSSFRow referenceRowCurrentWeek = sheet.getRow(12); - CellStyle headerCellStyle = doc.createCellStyle(); - // fill foreground color ... - headerCellStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.index); - // and solid fill pattern produces solid grey cell fill - headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + XSSFRow referenceRowTotal = sheet.getRow(15); - // NOTE: we only take the first sheet ! - XSSFSheet sheet = doc.getSheetAt(0); + // 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); + 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); - XSSFRow referenceRowSpacesCurrencies = sheet.getRow(10); - XSSFRow referenceRowValues = sheet.getRow(11); - XSSFRow referenceRowCurrentWeek = sheet.getRow(12); + /* + * --- Phase 1 ------------------------------------------------------- + * Im folgenden gruppieren wir die Rechnungen nach Woche + */ - 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()); - 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; - } + /* + * --- 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(""); - /* - * --- Phase 1 ------------------------------------------------------- - * Im folgenden fügen wir erst einmal in der Kopfzeile zusätzlich - * Spaltenüberschriften für jede Abteilung ein - */ - XSSFCell cellSpaceLabelReference = rowSpacesLabels.getCell(2); - 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 USD + // column++; + // cell = referenceRowSpacesCurrencies.getCell(column, + // MissingCellPolicy.CREATE_NULL_AS_BLANK); + // cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy()); + // cell.setCellValue(currency2); - // Space currency EUR - cell = referenceRowSpacesCurrencies.getCell(column); - cell.copyCellFrom(cellSpaceCurrencyReference, new CellCopyPolicy()); - cell.setCellValue(currency1); + // // Space Label + // cell = rowSpacesLabels.getCell(column, + // MissingCellPolicy.CREATE_NULL_AS_BLANK); + // cell.copyCellFrom(cellKWTotalReference, new CellCopyPolicy()); + // cell.setCellValue("Total"); - // 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); - - // 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 sortedWeekList = new ArrayList(); - Iterator> iterator = weekDataMap.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry 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(); - } + /* + * --- 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 sortedWeekList = new ArrayList(); + Iterator> iterator = weekDataMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry 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.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 weekDataCache) { + + logger.info("...group invoices (DEBUG) for " + spaceName + "/" + spaceID); + try { + List 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 cache, String currency1) { - - logger.info("...group invoices (DEBUG) for " + spaceName + "/" + spaceID); - try { - List 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 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; - } else { - totalCurrency2 = totalCurrency2 + 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 { + return 0.0; + } + } + +} + +/** + * Data Element for invoice totals per space. + * The object holds multiple currencies. + */ +class TotalInvoiceData { + + String spaceName; + Map 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; + } + } + } \ No newline at end of file diff --git a/templates/op-liste_kw_template.xlsx b/templates/op-liste_kw_template.xlsx index 9d05546e73beb967bf68f0b81b1ce81edaf13d45..1d54b99d2f327f3fd6d685962686ad8f010d65de 100644 GIT binary patch delta 2584 zcmY*bc|6ql8~@H=%($YQkTv zpdVZ*pbCNN2Q!XAu+TjV25~7-GTC~fPbcoAVrrID6tflUj0c+kn74AMIurDJ^*u|U zQ}*qdGJQ!N%O4ldEP)lWCS=LDtKRw4$BCw9tkr1NOi%k2^(m=(XVn*5upse6h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p}R z1CCB?WT!bl6lM9A+%gUNU>)AUC;#}3fyrtt zv<>CDv+brCOF6-yq&;XC%9m==?Aujg3UeWAyfQr(h6h zkmF#=feAnc-);R;8P>8PoVAiV^PtY-VL9i+Q>RbZalZHY7=$xJc1L0HnSh#qqWF`g zj|5+AFKVY2+Tc-9F#yk!#eikqxyv2BHf!^4YREp$kb7~*`~_UB?f&`roG`1H-=?}Q zAP9g5N5}((f36b-d;Ra!{DYItPj4}b33tiQ*5YUI;Bg(#hj>B-JB=?Vc_nG3;9lB( z&iLRb7adZrQR>IX*=cLQO?R=BO0sc1Tv~TrLaisi_U>}g^!>V%v0D>#_a~!E_uWR! z;=Xe}XGq+m*cq2ETnsaai3&^(=jcgni5C2JN;-fTuT$vo_1W-sPeNFK4#im0UhL zF=JGh}_Qx?OUxTeJ&DS|% zd@kDM-=YVW^A*_!aWWF@3h0nkB-!SlOB)XQc{y+cVcZA>TMIBm2=xCEDcZ$mb^AJV z-%n?jggA@i}r?CpmM0uYpw?1Mf92`PdBtuT?J2k!$C_bp5!uu7DX zKWK?|`S}YTq{aYND5s!o`s~*M#0x~gy?}awq#Ij>aS|Qb*(X-8|7frS1S4}mAny<_ z+whRk2qn+ZP{rt=!2brF9t0)i?xWWB_pt-$DxkJNN`f7sI$bK{?*8pLhyUx70&EnZ K4qeJ;1OEr?vXaaI diff --git a/workflow/analyse-opliste-de-1.0.3.bpmn b/workflow/analyse-opliste-de-1.0.3.bpmn index 46245bb..83235b0 100644 --- a/workflow/analyse-opliste-de-1.0.3.bpmn +++ b/workflow/analyse-opliste-de-1.0.3.bpmn @@ -101,6 +101,7 @@ th { font-weight: bold;} gateway_37SSsw textAnnotation_iPsg3g event_opebWA + event_JraaXA @@ -298,6 +299,7 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt Association_1 sequenceFlow_N0jfWA sequenceFlow_QUQCFw + sequenceFlow_nrskqg @@ -581,6 +583,44 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt + + + + + + + + + + + + + + + + + Mahnwesen + + OP-Liste KW Template + + op-liste_space.name_$lasteventdate.xlsx + + + A8 + $lasteventdate + date + + +]]> + + + + + sequenceFlow_nrskqg + + + + @@ -771,6 +811,18 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt + + + + + + + + + + + +