update multi currency
This commit is contained in:
parent
b7011a5cf8
commit
89865fcde1
2 changed files with 77 additions and 81 deletions
|
|
@ -11,6 +11,7 @@ import java.util.logging.Logger;
|
||||||
import org.apache.poi.ss.usermodel.CellCopyPolicy;
|
import org.apache.poi.ss.usermodel.CellCopyPolicy;
|
||||||
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
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.XSSFRow;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
@ -124,9 +125,9 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
|
||||||
XSSFSheet sheet = doc.getSheetAt(0);
|
XSSFSheet sheet = doc.getSheetAt(0);
|
||||||
|
|
||||||
// first add the columns for the currency list
|
// first add the columns for the currency list
|
||||||
addCurrencyColumns(sheet, currencyList);
|
addCurrencyColumns(doc, sheet, currencyList);
|
||||||
|
|
||||||
// insertInvoiceRows(document, targetName);
|
insertInvoiceRows(sheet, document, currencyList);
|
||||||
|
|
||||||
// write back the updated excel file
|
// write back the updated excel file
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
|
@ -138,7 +139,7 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
|
||||||
document.addFileData(fileDataNew);
|
document.addFileData(fileDataNew);
|
||||||
logger.finest("......new document added");
|
logger.finest("......new document added");
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException | QueryException e) {
|
||||||
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
|
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
|
||||||
OPListExportService.ERROR_CONFIG,
|
OPListExportService.ERROR_CONFIG,
|
||||||
"failed to update opliste: " + e.getMessage());
|
"failed to update opliste: " + e.getMessage());
|
||||||
|
|
@ -189,19 +190,33 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
|
||||||
* @param sheet
|
* @param sheet
|
||||||
* @param currencyList
|
* @param currencyList
|
||||||
*/
|
*/
|
||||||
private void addCurrencyColumns(XSSFSheet sheet, List<String> currencyList) {
|
private void addCurrencyColumns(XSSFWorkbook doc, XSSFSheet sheet, List<String> currencyList) {
|
||||||
if (currencyList == null || currencyList.size() <= 1) {
|
if (currencyList == null || currencyList.size() <= 1) {
|
||||||
// no extra currencies defined!
|
// no extra currencies defined!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int newColumns = (currencyList.size() - 1) * 2;
|
|
||||||
|
|
||||||
|
// zusaetzliche Zellen einfuegen...
|
||||||
|
int newColumns = (currencyList.size() - 1) * 2;
|
||||||
for (int i = 0; i < newColumns; i++) {
|
for (int i = 0; i < newColumns; i++) {
|
||||||
logger.info(".. add currency column...");
|
logger.info(".. add currency column...");
|
||||||
POIUtil.insertColumn(sheet, 6, 8 + i);
|
POIUtil.insertColumn(sheet, 6, 8 + i);
|
||||||
// POIUtil.insertColumn(sheet, 6, 8 + i+1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Beschriftungen eintragen
|
||||||
|
int col = 6;
|
||||||
|
XSSFCell cell = null;
|
||||||
|
XSSFRow labelRow = sheet.getRow(9);
|
||||||
|
for (String currency : currencyList) {
|
||||||
|
|
||||||
|
cell = labelRow.getCell(col);
|
||||||
|
cell.setCellValue("Total " + currency);
|
||||||
|
col++;
|
||||||
|
|
||||||
|
cell = labelRow.getCell(col);
|
||||||
|
cell.setCellValue("Saldo " + currency);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -229,20 +244,14 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
|
||||||
* @throws PluginException
|
* @throws PluginException
|
||||||
* @throws QueryException
|
* @throws QueryException
|
||||||
*/
|
*/
|
||||||
private void insertInvoiceRows(ItemCollection document, String fileName)
|
private void insertInvoiceRows(XSSFSheet sheet, ItemCollection document, List<String> currencyList)
|
||||||
throws PluginException, QueryException {
|
throws PluginException, QueryException {
|
||||||
|
|
||||||
// load dummy rechnungen
|
// load dummy rechnungen
|
||||||
List<ItemCollection> invoices = loadInvoices(getDbtNr(document));
|
List<ItemCollection> invoices = loadInvoices(getDbtNr(document));
|
||||||
|
|
||||||
FileData fileData = document.getFileData(fileName);
|
|
||||||
|
|
||||||
// load XSSFWorkbook
|
// 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);
|
|
||||||
CellReference invoiceRefCell = new CellReference("A11");
|
CellReference invoiceRefCell = new CellReference("A11");
|
||||||
XSSFRow referenceRowInvoice = sheet.getRow(invoiceRefCell.getRow());
|
XSSFRow referenceRowInvoice = sheet.getRow(invoiceRefCell.getRow());
|
||||||
int referenceRowPos = 10;
|
int referenceRowPos = 10;
|
||||||
|
|
@ -252,7 +261,8 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
|
||||||
|
|
||||||
// jetzt füge alle Rechnungen an.
|
// jetzt füge alle Rechnungen an.
|
||||||
int totalRowCount = invoices.size();
|
int totalRowCount = invoices.size();
|
||||||
sheet.shiftRows(referenceRowPos, lastRow, totalRowCount, true, true);
|
POIUtil.insertRows(sheet, "A11", totalRowCount);
|
||||||
|
|
||||||
for (ItemCollection invoice : invoices) {
|
for (ItemCollection invoice : invoices) {
|
||||||
logger.fine("......add invoice " + invoice.getUniqueID());
|
logger.fine("......add invoice " + invoice.getUniqueID());
|
||||||
// now create a new line..
|
// now create a new line..
|
||||||
|
|
@ -273,53 +283,39 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
|
||||||
.setCellValue(invoice.getItemValueString("invoice.text"));
|
.setCellValue(invoice.getItemValueString("invoice.text"));
|
||||||
|
|
||||||
// Waehrung?
|
// Waehrung?
|
||||||
if (invoice.getItemValueDouble("invoice.rate") == 0) {
|
String currency = invoice.getItemValueString("invoice.currency");
|
||||||
row.getCell(6, MissingCellPolicy.CREATE_NULL_AS_BLANK)
|
int totalCol = findTotalPos(currency, currencyList);
|
||||||
|
|
||||||
|
row.getCell(totalCol, MissingCellPolicy.CREATE_NULL_AS_BLANK)
|
||||||
.setCellValue(invoice.getItemValueDouble("invoice.total"));
|
.setCellValue(invoice.getItemValueDouble("invoice.total"));
|
||||||
row.getCell(7, MissingCellPolicy.CREATE_NULL_AS_BLANK)
|
row.getCell(totalCol + 1, MissingCellPolicy.CREATE_NULL_AS_BLANK)
|
||||||
.setCellValue(invoice.getItemValueDouble("invoice.saldo"));
|
.setCellValue(invoice.getItemValueDouble("invoice.saldo"));
|
||||||
} else {
|
// Status
|
||||||
row.getCell(8, MissingCellPolicy.CREATE_NULL_AS_BLANK)
|
row.getCell(6 + (currencyList.size() * 2), MissingCellPolicy.CREATE_NULL_AS_BLANK)
|
||||||
.setCellValue(invoice.getItemValueDouble("invoice.total"));
|
|
||||||
row.getCell(9, MissingCellPolicy.CREATE_NULL_AS_BLANK)
|
|
||||||
.setCellValue(invoice.getItemValueDouble("invoice.saldo"));
|
|
||||||
}
|
|
||||||
row.getCell(10, MissingCellPolicy.CREATE_NULL_AS_BLANK)
|
|
||||||
.setCellValue(invoice.getItemValueString("$workflowstatus"));
|
.setCellValue(invoice.getItemValueString("$workflowstatus"));
|
||||||
|
|
||||||
rowPos++;
|
rowPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leerzeile
|
}
|
||||||
// categoryRow = sheet.createRow(rowPos);
|
|
||||||
rowPos++;
|
|
||||||
|
|
||||||
// write back the file
|
/**
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
* Findet die Total Spalte für eine Währung
|
||||||
doc.write(byteArrayOutputStream);
|
*
|
||||||
|
* @param currency
|
||||||
byte[] newContent = byteArrayOutputStream.toByteArray();
|
* @return
|
||||||
FileData fileDataNew = new FileData(fileData.getName(), newContent, fileData.getContentType(),
|
*/
|
||||||
null);
|
private int findTotalPos(String currency, List<String> currencyList) {
|
||||||
// update the fileData
|
int result = 6;
|
||||||
document.addFileData(fileDataNew);
|
if (currency != null) {
|
||||||
|
for (String cur : currencyList) {
|
||||||
logger.finest("......new document added");
|
if (currency.equals(cur)) {
|
||||||
|
return result;
|
||||||
} catch (IOException e) {
|
}
|
||||||
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
|
result = result + 2;
|
||||||
OPListExportService.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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue