193 lines
6.8 KiB
Java
193 lines
6.8 KiB
Java
/*******************************************************************************
|
|
* Imixs Workflow
|
|
* Copyright (C) 2001, 2011 Imixs Software Solutions GmbH,
|
|
* http://www.imixs.com
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You can receive a copy of the GNU General Public
|
|
* License at http://www.gnu.org/licenses/gpl.html
|
|
*
|
|
* Project:
|
|
* http://www.imixs.org
|
|
* http://java.net/projects/imixs-workflow
|
|
*
|
|
* Contributors:
|
|
* Imixs Software Solutions GmbH - initial API and implementation
|
|
* Ralph Soika - Software Developer
|
|
*******************************************************************************/
|
|
|
|
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;
|
|
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 InvoiceService stellt einige Hilfsmethoden bereit.
|
|
*
|
|
* @author rsoika
|
|
*
|
|
*/
|
|
@Singleton
|
|
@RunAs("org.imixs.ACCESSLEVEL.MANAGERACCESS")
|
|
public class InvoiceService {
|
|
|
|
private static Logger logger = Logger.getLogger(InvoiceService.class.getName());
|
|
@Inject
|
|
ConfigService configService;
|
|
|
|
public static final int MAX_COUNT = 999;
|
|
final String TYPE_TEXTBLOCK = "textblock";
|
|
public static final String ERROR_CONFIG = "CONFIG_ERROR";
|
|
public static final String OPLIST_ERROR = "OPLIST_ERROR";
|
|
public static final int TASK_MAHNUNG_2ND = 5210;
|
|
public static final int TASK_MAHNUNG_LAST = 5220;
|
|
public static final String ENV_OPLIST_OVERDUE = "oplist.overdue";
|
|
|
|
@Inject
|
|
@ConfigProperty(name = ENV_OPLIST_OVERDUE, defaultValue = "10")
|
|
long overdueDays;
|
|
|
|
@Inject
|
|
SnapshotService snapshotService;
|
|
|
|
@Inject
|
|
DocumentService documentService;
|
|
|
|
public ItemCollection findOutboundInvoiceByNumber(String invoiceNumber) {
|
|
ItemCollection result = null;
|
|
try {
|
|
String query = "($modelversion:rechnungsausgang*) AND (invoice.number:" + invoiceNumber + ")";
|
|
List<ItemCollection> list;
|
|
list = documentService.find(query, 1, 0);
|
|
if (list != null && list.size() > 0) {
|
|
result = list.get(0);
|
|
}
|
|
} catch (QueryException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* Gibt die Hauptwährung zurück (1. in der liste)
|
|
*
|
|
* @return
|
|
* @throws PluginException
|
|
*/
|
|
public String getCurrenciesOutMain() throws PluginException {
|
|
logger.info("Load currency Configuration....");
|
|
// 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.get(0);
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
public boolean isOverdue(Date date, int taskid) {
|
|
Date now = new Date();
|
|
long diffInMillies = now.getTime() - date.getTime();
|
|
int tage = (int) (diffInMillies / 1000 / 60 / 60 / 24);
|
|
// logger.info("...taskid=" + taskid + " date=" + date + " tage=" + tage);
|
|
return ((taskid >= TASK_MAHNUNG_2ND && taskid <= TASK_MAHNUNG_LAST) || tage >= overdueDays);
|
|
|
|
}
|
|
|
|
/**
|
|
* This method returns a text-block ItemCollection for a specified name.
|
|
*
|
|
* @param name in attribute txtname
|
|
*
|
|
*
|
|
*/
|
|
public FileData loadTextBlockFileData(String name, String fileName) {
|
|
ItemCollection textBlockItemCollection = null;
|
|
|
|
// load text-block by name....
|
|
String sQuery = "(type:\"" + TYPE_TEXTBLOCK + "\" AND txtname:\"" + name + "\")";
|
|
Collection<ItemCollection> col;
|
|
try {
|
|
// find the textblock...
|
|
col = documentService.find(sQuery, 1, 0);
|
|
if (col.size() > 0) {
|
|
textBlockItemCollection = col.iterator().next();
|
|
// fetch the fileData...
|
|
return snapshotService.getWorkItemFile(textBlockItemCollection.getUniqueID(), fileName);
|
|
|
|
} else {
|
|
logger.warning("Missing text-block : '" + name + "'");
|
|
}
|
|
} catch (QueryException e) {
|
|
logger.warning("getTextBlock - invalid query: " + e.getMessage());
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
}
|