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 6befc60..b9525ac 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 @@ -15,6 +15,7 @@ import javax.inject.Inject; import org.apache.poi.ss.usermodel.CellCopyPolicy; import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -132,7 +133,8 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { */ private void insertInvoiceRows(ItemCollection document, String fileName) throws PluginException, QueryException { - double saldo = 0; + double saldoUSD = 0; + double saldoEUR = 0; // load dummy rechnungen String spaceID = document.getItemValueString("space.ref"); @@ -180,12 +182,20 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { categoryRow.getCell(1).setCellValue(debitorName); // calculate summ of all invoices - double catSum = 0; + double catSumEUR = 0; + double catSumUSD = 0; for (ItemCollection invoice : invoices) { - catSum = catSum + invoice.getItemValueDouble("invoice.saldo"); + if ("EUR".equals(invoice.getItemValueString("invoice.currency"))) { + catSumEUR = catSumEUR + invoice.getItemValueDouble("invoice.saldo"); + + } else { + catSumUSD = catSumUSD + invoice.getItemValueDouble("invoice.saldo"); + + } } - logger.fine("......... sum=" + catSum); - categoryRow.getCell(10).setCellValue(catSum); + + categoryRow.getCell(6).setCellValue(catSumEUR); + categoryRow.getCell(8).setCellValue(catSumUSD); rowPos++; // jetzt füge alle Rechnungen an. @@ -206,13 +216,15 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { // EUR row.getCell(6).setCellValue(total); row.getCell(7).setCellValue(currency); + saldoEUR =roundD( saldoEUR + total); } else { // USD row.getCell(8).setCellValue(total); row.getCell(9).setCellValue(currency); + saldoUSD = roundD( saldoUSD + total); } row.getCell(10).setCellValue(invoice.getItemValueString("$workflowstatus")); - saldo = saldo + total; + rowPos++; } } @@ -220,19 +232,21 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { sheet.shiftRows(referenceRowPos, lastRow + totalRowCount, -1, true, true); // finally update the total formula... - evalXSSFSheet(doc, sheet, "TOTALEUR"); - evalXSSFSheet(doc, sheet, "TOTALUSD"); + XSSFCell cTotalEUR = getCellByRef(doc, sheet, "TOTALEUR"); + XSSFCell cTotalUSD = getCellByRef(doc, sheet, "TOTALUSD"); + cTotalEUR.setCellValue(saldoEUR); + cTotalUSD.setCellValue(saldoUSD); - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); // 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); - document.setItemValue("space.saldo", saldo); + document.setItemValue("space.saldo.eur", saldoEUR); + document.setItemValue("space.saldo.usd", saldoUSD); logger.finest("......new document added"); } catch (IOException e) { @@ -350,5 +364,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { return result; } - + private double roundD(double wert) { + return Math.round(wert * 100.0f) / 100.0f; + } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8ccfd64..320ae4a 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ yyyyMMddHHmmss - 5.2.16 + 5.2.18 4.2.3 4.5.3 2.3.1 diff --git a/templates/op-liste_template.xlsx b/templates/op-liste_template.xlsx index 8769e24..a60024f 100644 Binary files a/templates/op-liste_template.xlsx and b/templates/op-liste_template.xlsx differ