From 566c32c94a0f807aeddb31a6bb90c98aac4151a1 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Thu, 21 Nov 2024 08:55:43 +0100 Subject: [PATCH] op liste multi currency --- .../OPListExportAdapter.java | 290 ++++++------------ templates/op-liste_template.xlsx | Bin 40175 -> 40174 bytes 2 files changed, 101 insertions(+), 189 deletions(-) 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 17a9eed..ff67a83 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 @@ -94,7 +94,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { "missing Currency configuration - please check parameters"); } - // read the zahlungsavis options + // read the template options ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "opliste", document, false); @@ -105,25 +105,10 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { List excelDefList = evalItemCollection.getItemValue("excel-export"); ItemCollection excelDefCollection = XMLParser.parseItemStructure(excelDefList.get(0)); - // // read the zahlungsavis options - // ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, - // "opliste", document, false); - // if (evalItemCollection == null || - // !evalItemCollection.hasItem("excel-export")) { - // throw new - // PluginException(AGLAnalyticExcelAdapterDebitor.class.getSimpleName(), - // CONFIG_ERROR, - // "missing opliste configuration in model event - please check model - // configuration"); - // } - - // List excelDefList = evalItemCollection.getItemValue("excel-export"); - // ItemCollection excelDefCollection = - // XMLParser.parseItemStructure(excelDefList.get(0)); - 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); @@ -140,6 +125,8 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { // first add the columns for the currency list addCurrencyColumns(doc, sheet, currencyList); + insertInvoiceRows(sheet, document, targetName, filter, currencyList); + // write back the updated excel file ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); doc.write(byteArrayOutputStream); @@ -149,7 +136,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { null); 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()); @@ -167,7 +154,9 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { // Finally process POI instructions processPOIUpdate(document, event, targetName); - } catch (PluginException e) { + } catch ( + + PluginException e) { throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG, "failed to update op-liste: " + e.getMessage()); @@ -252,8 +241,8 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { * @throws PluginException * @throws QueryException */ - private void insertInvoiceRows(ItemCollection document, String fileName, boolean filter, String currency1, - String currency2) + private void insertInvoiceRows(XSSFSheet sheet, ItemCollection document, String fileName, boolean filter, + List currencyList) throws PluginException, QueryException { double saldo1 = 0; @@ -264,179 +253,102 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { logger.info("... space.ref=" + spaceID + " ...grouping invoices by spaceid...."); Map> invoiceMap = groupInvoicesBySpaceID(spaceID, filter); - FileData fileData = document.getFileData(fileName); + CellReference categoryRefCell = new CellReference("A11"); + XSSFRow referenceRowCategory = sheet.getRow(categoryRefCell.getRow()); + CellReference invoiceRefCell = new CellReference("A12"); + XSSFRow referenceRowInvoice = sheet.getRow(invoiceRefCell.getRow()); - // load XSSFWorkbook - XSSFWorkbook doc = null; - try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) { - doc = new XSSFWorkbook(imputStream); - // NOTE: we only take the first sheet ! - XSSFSheet sheet = doc.getSheetAt(0); - // Währungsüberschriften setzten - sheet.getRow(10).getCell(6).setCellValue(currency1); - sheet.getRow(10).getCell(8).setCellValue(currency2); + int referenceRowPos = 11; + int rowPos = 11; + int lastRow = 4999; + logger.finest("Last rownum=" + lastRow); - CellReference categoryRefCell = new CellReference("A12"); - XSSFRow referenceRowCategory = sheet.getRow(categoryRefCell.getRow()); - CellReference invoiceRefCell = new CellReference("A13"); - XSSFRow referenceRowInvoice = sheet.getRow(invoiceRefCell.getRow()); - - int referenceRowPos = 12; - int rowPos = 12; - int lastRow = 2999; - logger.finest("Last rownum=" + lastRow); - - int totalRowCount = invoiceMap.size() * 2; - for (List list : invoiceMap.values()) { - totalRowCount = totalRowCount + list.size(); - } - if (totalRowCount == 0) { - logger.warning("No Invoices found - skip update workbook!"); - return; - } - sheet.shiftRows(rowPos, lastRow, totalRowCount, true, true); - for (Map.Entry> entry : invoiceMap.entrySet()) { - String dbtrNumber = entry.getKey(); - List invoices = entry.getValue(); - - // erzeuge eine Zwischenüberschrift für den Debitor.... - XSSFRow categoryRow = sheet.createRow(rowPos); - categoryRow.copyRowFrom(referenceRowCategory, new CellCopyPolicy()); - // insert values - categoryRow.getCell(0).setCellValue(dbtrNumber); - String debitorName = invoices.get(0).getItemValueString("dbtr.name"); - categoryRow.getCell(1).setCellValue(debitorName); - - // calculate summ of all invoices - double catSumEUR = 0; - double catSumUSD = 0; - for (ItemCollection invoice : invoices) { - if (currency1.equals(invoice.getItemValueString("invoice.currency"))) { - catSumEUR = catSumEUR + invoice.getItemValueDouble("invoice.saldo"); - } else { - catSumUSD = catSumUSD + invoice.getItemValueDouble("invoice.saldo"); - } - } - categoryRow.getCell(6).setCellValue(catSumEUR); - categoryRow.getCell(8).setCellValue(catSumUSD); - - rowPos++; - - // jetzt füge alle Rechnungen an. - for (ItemCollection invoice : invoices) { - logger.fine("......add invoice " + invoice.getUniqueID()); - - // now create a new line.. - XSSFRow row = sheet.createRow(rowPos); - row.copyRowFrom(referenceRowInvoice, new CellCopyPolicy()); - // insert values - if (invoice.getItemValueBoolean("invoice.protest")) { - row.getCell(2).setCellValue(invoice.getItemValueString("invoice.number") + " (R)"); - } else { - row.getCell(2).setCellValue(invoice.getItemValueString("invoice.number")); - } - row.getCell(3).setCellValue(invoice.getItemValueString("invoice.text")); - row.getCell(4).setCellValue(invoice.getItemValueDate("invoice.date")); - row.getCell(5).setCellValue(invoice.getItemValueDate("invoice.duedate")); - double total = invoice.getItemValueDouble("invoice.saldo"); - String currency = invoice.getItemValueString("invoice.currency"); - 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); - } - row.getCell(10).setCellValue(invoice.getItemValueString("$workflowstatus")); - - rowPos++; - } - - // Leerzeile - categoryRow = sheet.createRow(rowPos); - rowPos++; - } - // delete reference row 12 - sheet.shiftRows(referenceRowPos, lastRow + totalRowCount, -1, true, true); - - // finally update the total formula... - XSSFCell cTotal1 = getCellByRef(doc, sheet, "TOTAL1"); - XSSFCell cTotal2 = getCellByRef(doc, sheet, "TOTAL2"); - cTotal1.setCellValue(saldo1); - cTotal2.setCellValue(saldo2); - // Set währung - XSSFCell cTotalCurrency1 = getCellByRef(doc, sheet, "TOTAL_CURRENCY1"); - XSSFCell cTotalCurrency2 = getCellByRef(doc, sheet, "TOTAL_CURRENCY2"); - cTotalCurrency1.setCellValue(currency1); - cTotalCurrency2.setCellValue(currency2); - - // 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.currency1", saldo1); - document.setItemValue("space.saldo.currency2", saldo2); - logger.finest("......new document added"); - - } catch (IOException e) { - throw new PluginException(OPListExportAdapter.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(); - } - } + int totalRowCount = invoiceMap.size() * 2; + for (List list : invoiceMap.values()) { + totalRowCount = totalRowCount + list.size(); } + if (totalRowCount == 0) { + logger.warning("No Invoices found - skip update workbook!"); + return; + } + sheet.shiftRows(rowPos, lastRow, totalRowCount, true, true); + // Build a category for each debitor... + for (Map.Entry> entry : invoiceMap.entrySet()) { + String dbtrNumber = entry.getKey(); + List invoices = entry.getValue(); + + // erzeuge eine Zwischenüberschrift für den Debitor.... + XSSFRow categoryRow = sheet.createRow(rowPos); + categoryRow.copyRowFrom(referenceRowCategory, new CellCopyPolicy()); + // insert values + categoryRow.getCell(0).setCellValue(dbtrNumber); + String debitorName = invoices.get(0).getItemValueString("dbtr.name"); + categoryRow.getCell(1).setCellValue(debitorName); + + categoryRow.getCell(6).setCellValue(42); + categoryRow.getCell(8).setCellValue(42); + + rowPos++; + + // Init Saldo Map + Map currencySum = new HashMap(); + for (String cur : currencyList) { + Double saldo = Double.valueOf(0); + currencySum.put(cur, saldo); + } + + // jetzt füge alle Rechnungen an. + for (ItemCollection invoice : invoices) { + logger.fine("......add invoice " + invoice.getUniqueID()); + + // now create a new line.. + XSSFRow row = sheet.createRow(rowPos); + row.copyRowFrom(referenceRowInvoice, new CellCopyPolicy()); + // insert values + if (invoice.getItemValueBoolean("invoice.protest")) { + row.getCell(1).setCellValue(invoice.getItemValueString("invoice.number") + " (R)"); + } else { + row.getCell(1).setCellValue(invoice.getItemValueString("invoice.number")); + } + row.getCell(2).setCellValue(invoice.getItemValueString("invoice.text")); + row.getCell(3).setCellValue(invoice.getItemValueDate("invoice.date")); + row.getCell(4).setCellValue(invoice.getItemValueDate("invoice.duedate")); + double total = invoice.getItemValueDouble("invoice.saldo"); + + // calculate summary + String currency = invoice.getItemValueString("invoice.currency"); + Double saldo = currencySum.get(currency); + saldo = InvoiceUtil.round(saldo + total); + currencySum.put(currency, saldo); + + // 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); + // } + row.getCell(5 + currencyList.size()).setCellValue(invoice.getItemValueString("$workflowstatus")); + + rowPos++; + } + + // Leerzeile + categoryRow = sheet.createRow(rowPos); + rowPos++; + } + // delete reference row 11 + sheet.shiftRows(referenceRowPos, lastRow + totalRowCount, -1, true, true); + } - /** - * This method loads a text-block for a specified ref and appends the named - * fileData object of this document. - * - * @param document - * @throws PluginException - */ - // private void appendExcelTemplate(ItemCollection document, String - // textblockRef, String template, String targetName) - // throws PluginException { - - // if ((template == null || template.isEmpty()) || (textblockRef == null || - // textblockRef.isEmpty())) { - // throw new PluginException(OPListExportAdapter.class.getSimpleName(), - // InvoiceService.ERROR_CONFIG, - // "invalid op-list configuration in model event - textblock/template reference - // not defined!"); - // } - - // // load the text block - // FileData fileData = invoiceService.loadTextBlockFileData(textblockRef, - // template); - - // // do we found the document? - // if (fileData == null) { - // throw new PluginException(OPListExportAdapter.class.getSimpleName(), - // InvoiceService.ERROR_CONFIG, - // "invalid op-list configuration in model event - template=" + template + " not - // found!"); - // } - // fileData.setName(targetName); - // // append document - // logger.info("...append new op-list Template: " + targetName); - - // document.addFileData(fileData); - // } /** * This method loads a text-block for a specified ref and appends the named diff --git a/templates/op-liste_template.xlsx b/templates/op-liste_template.xlsx index 20eafdfbc9cbcefecc0731a10eaea3219bd7e2c7..cc83a1b9ad81f688ce2966a54c4519b895ee9306 100644 GIT binary patch delta 1734 zcmZ8h2~?746a~aw(!>#$G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