refactoring multi currency

This commit is contained in:
Ralph Soika 2024-11-18 20:09:50 +01:00
parent 81549ab4e0
commit a6f4b68fba
10 changed files with 113 additions and 81 deletions

View file

@ -67,7 +67,7 @@ public class AGLAnalyticExcelAdapter extends POIFindReplaceAdapter {
WorkflowService workflowService;
@Inject
OPListExportService opListExportService;
InvoiceService opListExportService;
@Inject
DocumentService documentService;
@ -90,12 +90,14 @@ public class AGLAnalyticExcelAdapter extends POIFindReplaceAdapter {
ItemCollection configItemCollection = configService.loadConfiguration("AGL_CONFIGURATION");
List<String> currencyList = configItemCollection.getItemValue("currency.out");
if (currencyList == null || currencyList.size() < 2) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG,
"missing Currency configuration - please check parameters");
}
// read the Steuerbescheide options
ItemCollection steuerbescheideConfig = workflowService.evalWorkflowResult(event, "steuerbescheide", document,
ItemCollection steuerbescheideConfig = workflowService.evalWorkflowResult(event, "steuerbescheide",
document,
false);
if (steuerbescheideConfig == null || !steuerbescheideConfig.hasItem("excel-export")) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(), CONFIG_ERROR,
@ -118,7 +120,8 @@ public class AGLAnalyticExcelAdapter extends POIFindReplaceAdapter {
logger.info("... loading poi configuration..");
// Process POI instructions
// read the config
ItemCollection poiConfig = workflowService.evalWorkflowResult(event, "poi-update", document, false);
ItemCollection poiConfig = workflowService.evalWorkflowResult(event, "poi-update", document,
false);
if (poiConfig == null || !poiConfig.hasItem("findreplace")) {
throw new PluginException(POIFindReplaceAdapter.class.getSimpleName(), CONFIG_ERROR,
"missing poi configuration");
@ -130,7 +133,8 @@ public class AGLAnalyticExcelAdapter extends POIFindReplaceAdapter {
this.updateFileData(document.getFileData(targetName), document, replaceDevList, eval);
} catch (PluginException | IOException | QueryException e) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG,
"failed to update steuerbescheide: " + e.getMessage());
}
logger.info("... completed!");
@ -218,14 +222,16 @@ public class AGLAnalyticExcelAdapter extends POIFindReplaceAdapter {
doc.write(byteArrayOutputStream);
byte[] newContent = byteArrayOutputStream.toByteArray();
FileData fileDataNew = new FileData(fileData.getName(), newContent, fileData.getContentType(), null);
FileData fileDataNew = new FileData(fileData.getName(), newContent, fileData.getContentType(),
null);
// update the fileData
document.addFileData(fileDataNew);
logger.finest("......new document added");
} catch (IOException e) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG,
"failed to update opliste: " + e.getMessage());
} finally {
if (doc != null) {
@ -246,11 +252,13 @@ public class AGLAnalyticExcelAdapter extends POIFindReplaceAdapter {
* @param document
* @throws PluginException
*/
private void appendExcelTemplate(ItemCollection document, String textblockRef, String template, String targetName)
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(AGLAnalyticExcelAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG,
"invalid steuerbescheide configuration in model event - textblock/template reference not defined!");
}
@ -259,8 +267,10 @@ public class AGLAnalyticExcelAdapter extends POIFindReplaceAdapter {
// do we found the document?
if (fileData == null) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
"invalid steuerbescheide configuration in model event - template=" + template + " not found!");
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG,
"invalid steuerbescheide configuration in model event - template=" + template
+ " not found!");
}
fileData.setName(targetName);
// append document

View file

@ -70,7 +70,7 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
WorkflowService workflowService;
@Inject
OPListExportService opListExportService;
InvoiceService invoiceService;
@Inject
DocumentService documentService;
@ -89,13 +89,7 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
throws AdapterException, PluginException {
// ermittle die Hauptwährungen
ItemCollection configItemCollection = configService.loadConfiguration("AGL_CONFIGURATION");
List<String> currencyList = configItemCollection.getItemValue("currency.out");
if (currencyList == null || currencyList.size() < 1) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
OPListExportService.ERROR_CONFIG,
"missing Currency configuration - please check parameters");
}
List<String> currencyList = invoiceService.getCurrenciesOut();
// read the options
ItemCollection ausgangsrechnungConfig = workflowService.evalWorkflowResult(event, "soa",
@ -142,7 +136,7 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
} catch (IOException | QueryException e) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
OPListExportService.ERROR_CONFIG,
InvoiceService.ERROR_CONFIG,
"failed to update opliste: " + e.getMessage());
} finally {
if (doc != null) {
@ -160,7 +154,7 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
} catch (PluginException e) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
OPListExportService.ERROR_CONFIG,
InvoiceService.ERROR_CONFIG,
"failed to update steuerbescheide: " + e.getMessage());
}
logger.info("... completed!");
@ -329,17 +323,17 @@ public class AGLAnalyticExcelAdapterDebitor extends POIFindReplaceAdapter {
if ((template == null || template.isEmpty()) || (textblockRef == null || textblockRef.isEmpty())) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
OPListExportService.ERROR_CONFIG,
InvoiceService.ERROR_CONFIG,
"invalid SOA configuration in model event - textblock/template reference not defined!");
}
// load the text block
FileData fileData = opListExportService.loadTextBlockFileData(textblockRef, template);
FileData fileData = invoiceService.loadTextBlockFileData(textblockRef, template);
// do we found the document?
if (fileData == null) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
OPListExportService.ERROR_CONFIG,
InvoiceService.ERROR_CONFIG,
"invalid SOA configuration in model event - template=" + template
+ " not found!");
}

View file

@ -29,6 +29,7 @@ package com.alexanderlogistics;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;
import org.eclipse.microprofile.config.inject.ConfigProperty;
@ -36,25 +37,27 @@ import org.imixs.archive.core.SnapshotService;
import org.imixs.workflow.FileData;
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.engine.DocumentService;
import org.imixs.workflow.exceptions.PluginException;
import org.imixs.workflow.exceptions.QueryException;
import org.imixs.workflow.office.config.ConfigService;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.Singleton;
import jakarta.inject.Inject;
/**
* Der OPListExportService ist im Grunde nur dafür da das overdue date zu
* ermitteln.
* Ausgangsrechnungen zu akutalisieren.
* Der InvoiceService stellt einige Hilfsmethoden bereit.
*
* @author rsoika
*
*/
@Singleton
@RunAs("org.imixs.ACCESSLEVEL.MANAGERACCESS")
public class OPListExportService {
public class InvoiceService {
private static Logger logger = Logger.getLogger(OPListExportService.class.getName());
private static Logger logger = Logger.getLogger(InvoiceService.class.getName());
@Inject
ConfigService configService;
public static final int MAX_COUNT = 999;
final String TYPE_TEXTBLOCK = "textblock";
@ -74,6 +77,44 @@ public class OPListExportService {
@Inject
DocumentService documentService;
/**
* Liefert die Liste der Ausgehenden Währungen
*
* @return
* @throws PluginException
*/
public List<String> getCurrenciesOut() throws PluginException {
// ermittle die Hauptwährungen
ItemCollection configItemCollection = configService.loadConfiguration("AGL_CONFIGURATION");
List<String> currencyList = configItemCollection.getItemValue("currency.out");
if (currencyList == null || currencyList.size() < 1) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG,
"missing Currency configuration - please check parameters");
}
return currencyList;
}
/**
* Liefert die Liste der Eingehenden Währungen
*
* @return
* @throws PluginException
*/
public List<String> getCurrenciesIn() throws PluginException {
// ermittle die Hauptwährungen
ItemCollection configItemCollection = configService.loadConfiguration("AGL_CONFIGURATION");
List<String> currencyList = configItemCollection.getItemValue("currency.in");
if (currencyList == null || currencyList.size() < 1) {
throw new PluginException(AGLAnalyticExcelAdapter.class.getSimpleName(),
InvoiceService.ERROR_CONFIG,
"missing Currency configuration - please check parameters");
}
return currencyList;
}
/**
* Prüft ob der Vorgang überflällig ist.
* Default ist 21 tage.

View file

@ -54,12 +54,12 @@ public class InvoiceUtil {
.matches();
}
@Deprecated
public static double roundConservative(double value) {
value = value * 100;
long tmp = Math.round(value);
return (double) tmp / 100;
}
// @Deprecated
// public static double roundConservative(double value) {
// value = value * 100;
// long tmp = Math.round(value);
// return (double) tmp / 100;
// }
/**
* converts the Map List of a workitem into a List of ItemCollectons

View file

@ -348,6 +348,14 @@ public class OPListController implements Serializable {
}
/**
* Berechnet die Summer aller Rechnungen zu einer Währung.
* Es werden nur Rechnungen berücksichtigt, deren Haupt Währung der übergebenen
* Währung entspricht.
*
* @param currency
* @return
*/
public double calculateInvoiceTotal(String currency) {
double result = 0;
for (ItemCollection invoice : invoiceList) {
@ -355,13 +363,13 @@ public class OPListController implements Serializable {
result = result + invoice.getItemValueDouble("invoice.total");
}
}
// rond with 2 digits
// round with 2 digits
return InvoiceUtil.round(result);
}
/**
* Berechnet den gesammten OP Saldo
* Berechnet den gesamten OP Saldo
*
* @return
*/
@ -372,7 +380,7 @@ public class OPListController implements Serializable {
result = result + invoice.getItemValueDouble("invoice.saldo");
}
}
// rond with 2 digits
// round with 2 digits
return InvoiceUtil.round(result);
}

View file

@ -63,7 +63,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
WorkflowService workflowService;
@Inject
OPListExportService opListExportService;
InvoiceService invoiceService;
@Inject
DocumentService documentService;
@ -86,7 +86,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
ItemCollection configItemCollection = configService.loadConfiguration("AGL_CONFIGURATION");
List<String> currencyList = configItemCollection.getItemValue("currency.out");
if (currencyList == null || currencyList.size() < 2) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"missing Currency configuration - please check parameters");
}
String currency1 = currencyList.get(0);
@ -95,7 +95,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
// read the zahlungsavis options
ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "opliste", document, false);
if (evalItemCollection == null) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"missing op-list configuration in model event - please check model configuration");
}
String textblock = evalItemCollection.getItemValueString("textblock");
@ -128,7 +128,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
insertInvoiceRows(document, targetName, filter, currency1, currency2);
} catch (PluginException | IOException | QueryException e) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"failed to update op-liste: " + e.getMessage());
}
logger.info("... completed!");
@ -282,7 +282,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
logger.finest("......new document added");
} catch (IOException e) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"failed to update opliste: " + e.getMessage());
} finally {
if (doc != null) {
@ -307,16 +307,16 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
throws PluginException {
if ((template == null || template.isEmpty()) || (textblockRef == null || textblockRef.isEmpty())) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
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 = opListExportService.loadTextBlockFileData(textblockRef, template);
FileData fileData = invoiceService.loadTextBlockFileData(textblockRef, template);
// do we found the document?
if (fileData == null) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"invalid op-list configuration in model event - template=" + template + " not found!");
}
fileData.setName(targetName);
@ -357,7 +357,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter {
if (filter) {
Date date = invoice.getItemValueDate("invoice.duedate");
if (opListExportService.isOverdue(date, invoice.getTaskID())) {
if (invoiceService.isOverdue(date, invoice.getTaskID())) {
// logger.info("...invoice - " +invoice.getUniqueID() + " is in overdue");
invoiceList.add(invoice);
}

View file

@ -88,7 +88,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
ConfigService configService;
@Inject
OPListExportService opListExportService;
InvoiceService invoiceService;
// cache for all invoices grouped by week
Map<String, List<ItemCollection>> invoiceMap = null;
@ -107,7 +107,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
// read the opliste options
ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "opliste", document, false);
if (evalItemCollection == null) {
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"missing op-list configuration in model event - please check model configuration");
}
@ -115,7 +115,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
ItemCollection configItemCollection = configService.loadConfiguration("AGL_CONFIGURATION");
List<String> currencyList = configItemCollection.getItemValue("currency.out");
if (currencyList == null || currencyList.size() < 2) {
throw new PluginException(OPListExportAdapter.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapter.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"missing Currency configuration - please check parameters");
}
String currency1 = currencyList.get(0);
@ -144,7 +144,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
insertInvoiceRows(document, targetName, currency1, currency2);
} catch (PluginException | IOException | QueryException e) {
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"failed to update op-liste: " + e.getMessage());
}
logger.info("... completed!");
@ -508,7 +508,7 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
logger.finest("......new document added");
} catch (IOException e) {
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"failed to update opliste: " + e.getMessage());
} finally {
if (doc != null) {
@ -533,16 +533,16 @@ public class OPListExportAdapterByWeek extends POIFindReplaceAdapter {
throws PluginException {
if ((template == null || template.isEmpty()) || (textblockRef == null || textblockRef.isEmpty())) {
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"invalid op-list configuration in model event - textblock/template reference not defined!");
}
// load the text block
FileData fileData = opListExportService.loadTextBlockFileData(textblockRef, template);
FileData fileData = invoiceService.loadTextBlockFileData(textblockRef, template);
// do we found the document?
if (fileData == null) {
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), OPListExportService.ERROR_CONFIG,
throw new PluginException(OPListExportAdapterByWeek.class.getSimpleName(), InvoiceService.ERROR_CONFIG,
"invalid op-list configuration in model event - template=" + template + " not found!");
}
fileData.setName(targetName);

View file

@ -79,7 +79,7 @@ public class OPListExportScheduler implements Scheduler {
DocumentService documentService;
@Inject
OPListExportService opListExportService;
InvoiceService invoiceService;
@EJB
TeamService teamService;
@ -148,7 +148,7 @@ public class OPListExportScheduler implements Scheduler {
for (ItemCollection invoice : invoices) {
Date date = invoice.getItemValueDate("invoice.duedate");
if (opListExportService.isOverdue(date, invoice.getTaskID())) {
if (invoiceService.isOverdue(date, invoice.getTaskID())) {
return true;
}
}

View file

@ -138,7 +138,7 @@
</strong></td>
<td><strong>EUR<br />USD</strong></td>
<td><strong>EUR<br />#{invoice.item['invoice.currency']}</strong></td>
<td />

View file

@ -321,37 +321,16 @@ th { font-weight: bold;}
<template>soa_template.xlsx</template>
<target-name>soa_<itemvalue>dbtr.number</itemvalue>_<itemvalue format="yyyy-MM-dd">$lasteventdate</itemvalue>.xlsx</target-name>
</soa>
<poi-update name="findreplace">
<find>I6</find>
<find>F6</find>
<replace><itemvalue format="dd.MM.yyyy">$lasteventdate</itemvalue></replace>
<type>date</type>
</poi-update>
<poi-update name="findreplace">
<find>D6</find>
<find>A7</find>
<replace><itemvalue>dbtr.name</itemvalue></replace>
<type>date</type>
</poi-update>
<poi-update name="findreplace">
<find>G10</find>
<replace>Total AED</replace>
</poi-update>
<poi-update name="findreplace">
<find>H10</find>
<replace>Saldo AED</replace>
</poi-update>
<poi-update name="findreplace">
<find>I10</find>
<replace>Total USD</replace>
</poi-update>
<poi-update name="findreplace">
<find>J10</find>
<replace>Saldo USD</replace>
</poi-update>
<poi-update name="eval">TOTAL1;TOTAL2;TOTAL3;TOTAL4</poi-update>
]]></imixs:value>
</imixs:item>
</bpmn2:extensionElements>