diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java index ff67a83..6f187a6 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java @@ -272,6 +272,11 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { return; } sheet.shiftRows(rowPos, lastRow, totalRowCount, true, true); + + Map currencyTotalSum = new HashMap(); + for (String cur : currencyList) { + currencyTotalSum.put(cur, Double.valueOf(0)); + } // Build a category for each debitor... for (Map.Entry> entry : invoiceMap.entrySet()) { String dbtrNumber = entry.getKey(); @@ -285,8 +290,23 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { String debitorName = invoices.get(0).getItemValueString("dbtr.name"); categoryRow.getCell(1).setCellValue(debitorName); - categoryRow.getCell(6).setCellValue(42); - categoryRow.getCell(8).setCellValue(42); + // calculate summ of all invoices for this debitor... + Map currencyCatSum = new HashMap(); + for (String cur : currencyList) { + currencyCatSum.put(cur, Double.valueOf(0)); + } + for (ItemCollection invoice : invoices) { + String currency = invoice.getItemValueString("invoice.currency"); + Double saldo = currencyCatSum.get(currency); + saldo = InvoiceUtil.round(saldo + invoice.getItemValueDouble("invoice.saldo")); + currencyCatSum.put(currency, saldo); + } + int i = 0; + for (String cur : currencyList) { + i++; + Double catSum = currencyCatSum.get(cur); + categoryRow.getCell(4 + i).setCellValue(catSum); + } rowPos++; @@ -324,17 +344,12 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { // Saldo in richtige Spalte setzen... int currencyColIndex = currencyList.indexOf(currency); row.getCell(5 + currencyColIndex).setCellValue(total); - // if (currency1.equals(currency)) { - // // EUR - // row.getCell(6).setCellValue(total); - // row.getCell(7).setCellValue(currency); - // saldo1 = InvoiceUtil.round(saldo1 + total); - // } else { - // // USD - // row.getCell(8).setCellValue(total); - // row.getCell(9).setCellValue(currency); - // saldo2 = InvoiceUtil.round(saldo2 + total); - // } + + // Gesamtsumme berechnen + Double totalSaldo = currencyTotalSum.get(currency); + totalSaldo = InvoiceUtil.round(totalSaldo + total); + currencyTotalSum.put(currency, totalSaldo); + row.getCell(5 + currencyList.size()).setCellValue(invoice.getItemValueString("$workflowstatus")); rowPos++; @@ -345,7 +360,17 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { rowPos++; } // delete reference row 11 - sheet.shiftRows(referenceRowPos, lastRow + totalRowCount, -1, true, true); + // sheet.shiftRows(referenceRowPos, lastRow + totalRowCount, -3, true, true); + // sheet.shiftRows(rowPos, lastRow, -3, true, true); + + // finally update the totals... + int i = 0; + XSSFRow totalRow = sheet.getRow(rowPos + 1); + for (String cur : currencyList) { + i++; + Double totalSum = currencyTotalSum.get(cur); + totalRow.getCell(4 + i).setCellValue(totalSum); + } } diff --git a/templates/op-liste_template.xlsx b/templates/op-liste_template.xlsx index cc83a1b..8f3b329 100644 Binary files a/templates/op-liste_template.xlsx and b/templates/op-liste_template.xlsx differ