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 9d05546..1d54b99 100644 Binary files a/templates/op-liste_kw_template.xlsx and b/templates/op-liste_kw_template.xlsx differ 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 + + + + + + + + + + + +