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 a48fad0..0c89680 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 @@ -155,10 +155,16 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { private void insertInvoiceRows(ItemCollection document, String fileName) throws PluginException, QueryException { - double saldoUSD1 = 0; - double saldoEUR1 = 0; - double saldoUSD2 = 0; - double saldoEUR2 = 0; + // double saldoUSD1 = 0; + // double saldoEUR1 = 0; + // double saldoUSD2 = 0; + // double saldoEUR2 = 0; + + Map totalsUeberfaelligEUR = new HashMap(); + Map totalsFaelligEUR = new HashMap(); + Map totalsUeberfaelligUSD = new HashMap(); + Map totalsFaelligUSD = new HashMap(); + // double saldoUSD3 = 0; // double saldoEUR3 = 0; List spaceNames = new ArrayList(); @@ -260,8 +266,19 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { logger.info("...grouping invoices by week..."); // collect all invoices for this space grouped by week.... groupInvoicesByWeek(spaceID, spaceName, weekDataMap); - } + // init totals + for (String name : spaceNames) { + totalsUeberfaelligEUR.put(name, 0.0); + totalsFaelligEUR.put(name, 0.0); + totalsUeberfaelligUSD.put(name, 0.0); + totalsFaelligUSD.put(name, 0.0); + } + } + totalsUeberfaelligEUR.put("TOTAL", 0.0); + totalsFaelligEUR.put("TOTAL", 0.0); + totalsUeberfaelligUSD.put("TOTAL", 0.0); + totalsFaelligUSD.put("TOTAL", 0.0); /* * --- Phase 2 ------------------------------------------------------- * Nun bilden wir nochmal 2 weitere Spalten am Ende um eine Summenbildung in @@ -341,6 +358,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { column = 1; double kwTotalEUR = 0; double kwTotalUSD = 0; + for (String name : spaceNames) { String key = name + "/" + week; logger.info("search WeekInvoiceData for " + key); @@ -352,11 +370,23 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { column++; row.getCell(column).setCellValue(weekData.totalUSD); if (ueberFaellig) { - saldoEUR1 = InvoiceUtil.round(saldoEUR1 + weekData.totalEUR); - saldoUSD1 = InvoiceUtil.round(saldoUSD1 + weekData.totalUSD); + double eur = totalsUeberfaelligEUR.get(name); + eur = InvoiceUtil.round(eur + weekData.totalEUR); + totalsUeberfaelligEUR.put(name, eur); + double usd = totalsUeberfaelligUSD.get(name); + usd = InvoiceUtil.round(usd + weekData.totalUSD); + totalsUeberfaelligUSD.put(name, usd); + // saldoEUR1 = InvoiceUtil.round(saldoEUR1 + weekData.totalEUR); + // saldoUSD1 = InvoiceUtil.round(saldoUSD1 + weekData.totalUSD); } else { - saldoEUR2 = InvoiceUtil.round(saldoEUR2 + weekData.totalEUR); - saldoUSD2 = InvoiceUtil.round(saldoUSD2 + weekData.totalUSD); + double eur = totalsFaelligEUR.get(name); + eur = InvoiceUtil.round(eur + weekData.totalEUR); + totalsFaelligEUR.put(name, eur); + double usd = totalsFaelligUSD.get(name); + usd = InvoiceUtil.round(usd + weekData.totalUSD); + totalsFaelligUSD.put(name, usd); + // saldoEUR2 = InvoiceUtil.round(saldoEUR2 + weekData.totalEUR); + // saldoUSD2 = InvoiceUtil.round(saldoUSD2 + weekData.totalUSD); } kwTotalEUR = kwTotalEUR + weekData.totalEUR; kwTotalUSD = kwTotalUSD + weekData.totalUSD; @@ -392,6 +422,23 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { } + // store totals + if (ueberFaellig) { + double eur = totalsUeberfaelligEUR.get("TOTAL"); + eur = InvoiceUtil.round(eur + kwTotalEUR); + totalsUeberfaelligEUR.put("TOTAL", eur); + double usd = totalsUeberfaelligUSD.get("TOTAL"); + usd = InvoiceUtil.round(usd + kwTotalUSD); + totalsUeberfaelligUSD.put("TOTAL", usd); + } else { + double eur = totalsFaelligEUR.get("TOTAL"); + eur = InvoiceUtil.round(eur + kwTotalEUR); + totalsFaelligEUR.put("TOTAL", eur); + double usd = totalsFaelligUSD.get("TOTAL"); + usd = InvoiceUtil.round(usd + kwTotalUSD); + totalsFaelligUSD.put("TOTAL", usd); + } + } // delete reference rows logger.info("..shift 12 to " + rowPos); @@ -403,19 +450,45 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter { * now lets update the totals... * Überfällig */ - XSSFCell cTotalEUR1 = getCellByRef(doc, sheet, "TOTALEUR1"); - XSSFCell cTotalUSD1 = getCellByRef(doc, sheet, "TOTALUSD1"); - cTotalEUR1.setCellValue(saldoEUR1); - cTotalUSD1.setCellValue(saldoUSD1); - XSSFCell cTotalEUR2 = getCellByRef(doc, sheet, "TOTALEUR2"); - XSSFCell cTotalUSD2 = getCellByRef(doc, sheet, "TOTALUSD2"); - cTotalEUR2.setCellValue(saldoEUR2); - cTotalUSD2.setCellValue(saldoUSD2); + 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(totalsUeberfaelligEUR.get(name)); + totalCell = rowFaellig.getCell(column); + totalCell.setCellValue(totalsFaelligEUR.get(name)); + totalCell = rowTotal.getCell(column); + totalCell.setCellValue(totalsUeberfaelligEUR.get(name) + totalsFaelligEUR.get(name)); + column++; + totalCell = rowUeberFaellig.getCell(column); + totalCell.setCellValue(totalsUeberfaelligUSD.get(name)); + totalCell = rowFaellig.getCell(column); + totalCell.setCellValue(totalsFaelligUSD.get(name)); + totalCell = rowTotal.getCell(column); + totalCell.setCellValue(totalsUeberfaelligUSD.get(name) + totalsFaelligUSD.get(name)); + column++; + } + // totals + totalCell = rowUeberFaellig.getCell(column); + totalCell.setCellValue(totalsUeberfaelligEUR.get("TOTAL")); + totalCell = rowFaellig.getCell(column); + totalCell.setCellValue(totalsFaelligEUR.get("TOTAL")); + totalCell = rowTotal.getCell(column); + totalCell.setCellValue(totalsUeberfaelligEUR.get("TOTAL") + totalsFaelligEUR.get("TOTAL")); + column++; + totalCell = rowUeberFaellig.getCell(column); + totalCell.setCellValue(totalsUeberfaelligUSD.get("TOTAL")); + totalCell = rowFaellig.getCell(column); + totalCell.setCellValue(totalsFaelligUSD.get("TOTAL")); + totalCell = rowTotal.getCell(column); + totalCell.setCellValue(totalsUeberfaelligUSD.get("TOTAL") + totalsFaelligUSD.get("TOTAL")); - XSSFCell cTotalEUR3 = getCellByRef(doc, sheet, "TOTALEUR3"); - XSSFCell cTotalUSD3 = getCellByRef(doc, sheet, "TOTALUSD3"); - cTotalEUR3.setCellValue(InvoiceUtil.round(saldoEUR1 + saldoEUR2)); - cTotalUSD3.setCellValue(InvoiceUtil.round(saldoUSD1 + saldoUSD2)); + // delete placeholder row + sheet.shiftRows(_rowNo, _rowNo + 3, -1); // write back the file ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); diff --git a/templates/op-liste_kw_template.xlsx b/templates/op-liste_kw_template.xlsx index d8c8d56..71427d1 100644 Binary files a/templates/op-liste_kw_template.xlsx and b/templates/op-liste_kw_template.xlsx differ