fix
This commit is contained in:
parent
c0c50bc178
commit
2c5695f8fc
1 changed files with 115 additions and 116 deletions
|
|
@ -33,136 +33,136 @@ import org.imixs.workflow.exceptions.PluginException;
|
||||||
*/
|
*/
|
||||||
public class MahnlaufExecuteAdapter implements SignalAdapter {
|
public class MahnlaufExecuteAdapter implements SignalAdapter {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static Logger logger = Logger.getLogger(MahnlaufExecuteAdapter.class.getName());
|
private static Logger logger = Logger.getLogger(MahnlaufExecuteAdapter.class.getName());
|
||||||
|
|
||||||
@EJB
|
@EJB
|
||||||
ModelService modelService;
|
ModelService modelService;
|
||||||
|
|
||||||
@EJB
|
@EJB
|
||||||
WorkflowService workflowService = null;
|
WorkflowService workflowService = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
MahnlaufService mahnlaufService;
|
MahnlaufService mahnlaufService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method finds all invices ($workitemref) and tirgges event 300
|
* This method finds all invices ($workitemref) and tirgges event 300
|
||||||
*
|
*
|
||||||
* @throws PluginException
|
* @throws PluginException
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public ItemCollection execute(ItemCollection mahnLaufWorkitem, ItemCollection event)
|
public ItemCollection execute(ItemCollection mahnLaufWorkitem, ItemCollection event)
|
||||||
throws AdapterException, PluginException {
|
throws AdapterException, PluginException {
|
||||||
|
|
||||||
if (mahnLaufWorkitem.isItemEmpty("$workitemref")) {
|
if (mahnLaufWorkitem.isItemEmpty("$workitemref")) {
|
||||||
throw new PluginException(MahnlaufRefAddAdapter.class.getName(), MahnlaufService.ERROR_WORKFLOW,
|
throw new PluginException(MahnlaufRefAddAdapter.class.getName(), MahnlaufService.ERROR_WORKFLOW,
|
||||||
"Es wurden keine Rechnungen ausgewählt. Der Mahnlauf kann nicht gestartet werden.");
|
"Es wurden keine Rechnungen ausgewählt. Der Mahnlauf kann nicht gestartet werden.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all Invoices of this Mahnlauf
|
// get all Invoices of this Mahnlauf
|
||||||
List<Map<String, List<Object>>> invoiceList = new ArrayList<Map<String, List<Object>>>();
|
List<Map<String, List<Object>>> invoiceList = new ArrayList<Map<String, List<Object>>>();
|
||||||
List<String> refList = mahnLaufWorkitem.getItemValue("$workitemref");
|
List<String> refList = mahnLaufWorkitem.getItemValue("$workitemref");
|
||||||
|
|
||||||
// sind die Wärhungen idendtisch (mischmasch geht niht)
|
// sind die Wärhungen idendtisch (mischmasch geht niht)
|
||||||
String lastCurrency="";
|
String lastCurrency = "";
|
||||||
for (String uniqueId : refList) {
|
for (String uniqueId : refList) {
|
||||||
ItemCollection invoice = workflowService.getWorkItem(uniqueId);
|
ItemCollection invoice = workflowService.getWorkItem(uniqueId);
|
||||||
String invoiceCurrency=invoice.getItemValueString("invoice.currency");
|
String invoiceCurrency = invoice.getItemValueString("invoice.currency");
|
||||||
if (lastCurrency.isEmpty()) {
|
if (lastCurrency.isEmpty()) {
|
||||||
lastCurrency=invoiceCurrency;
|
lastCurrency = invoiceCurrency;
|
||||||
} else {
|
} else {
|
||||||
if (!lastCurrency.equals(invoiceCurrency)) {
|
if (!lastCurrency.equals(invoiceCurrency)) {
|
||||||
throw new PluginException(MahnlaufRefAddAdapter.class.getName(), MahnlaufService.ERROR_WORKFLOW,
|
throw new PluginException(MahnlaufRefAddAdapter.class.getName(), MahnlaufService.ERROR_WORKFLOW,
|
||||||
"In einem Mahnlauf können nur Rechnungen mit der selben Währung ausgewählt werden.");
|
"In einem Mahnlauf können nur Rechnungen mit der selben Währung ausgewählt werden.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double saldo = 0;
|
|
||||||
int dunningLevel=0;
|
|
||||||
String currency = "";
|
|
||||||
for (String uniqueId : refList) {
|
|
||||||
ItemCollection invoice = workflowService.getWorkItem(uniqueId);
|
|
||||||
if (invoice != null && (invoice.getTaskID() >= MahnlaufService.TASK_MAHNLAUF_START
|
|
||||||
&& invoice.getTaskID() <= MahnlaufService.TASK_MAHNLAUF_END)) {
|
|
||||||
|
|
||||||
// set new invoice.reminder date only if we in due
|
double saldo = 0;
|
||||||
if (isInDue(invoice)) {
|
int dunningLevel = 0;
|
||||||
try {
|
String currency = "";
|
||||||
// first fetch the event of the invoice to be processed
|
for (String uniqueId : refList) {
|
||||||
Model invoiceModel;
|
ItemCollection invoice = workflowService.getWorkItem(uniqueId);
|
||||||
invoiceModel = this.modelService.getModel(invoice.getModelVersion());
|
if (invoice != null && (invoice.getTaskID() >= MahnlaufService.TASK_MAHNLAUF_START
|
||||||
ItemCollection invoiceEvent = invoiceModel.getEvent(invoice.getTaskID(),
|
&& invoice.getTaskID() <= MahnlaufService.TASK_MAHNLAUF_END)) {
|
||||||
MahnlaufService.EVENT_MAHNLAUF_EXECUTE);
|
|
||||||
if (invoiceEvent != null) {
|
|
||||||
ItemCollection eventDunningConfig = this.workflowService.evalWorkflowResult(invoiceEvent,
|
|
||||||
"dunning", invoice);
|
|
||||||
int period = eventDunningConfig.getItemValueInteger("period");
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTime(new Date());
|
|
||||||
cal.add(Calendar.DATE, period);
|
|
||||||
invoice.setItemValue("invoice.reminder", cal.getTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (ModelException e) {
|
// set new invoice.reminder date only if we in due
|
||||||
e.printStackTrace();
|
if (isInDue(invoice)) {
|
||||||
}
|
try {
|
||||||
mahnlaufService.processInvoice(invoice.event(MahnlaufService.EVENT_MAHNLAUF_EXECUTE));
|
// first fetch the event of the invoice to be processed
|
||||||
}
|
Model invoiceModel;
|
||||||
|
invoiceModel = this.modelService.getModel(invoice.getModelVersion());
|
||||||
|
ItemCollection invoiceEvent = invoiceModel.getEvent(invoice.getTaskID(),
|
||||||
switch (invoice.getTaskID()) {
|
MahnlaufService.EVENT_MAHNLAUF_EXECUTE);
|
||||||
|
if (invoiceEvent != null) {
|
||||||
|
ItemCollection eventDunningConfig = this.workflowService.evalWorkflowResult(invoiceEvent,
|
||||||
|
"dunning", invoice);
|
||||||
|
int period = eventDunningConfig.getItemValueInteger("period");
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(new Date());
|
||||||
|
cal.add(Calendar.DATE, period);
|
||||||
|
invoice.setItemValue("invoice.reminder", cal.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (ModelException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
mahnlaufService.processInvoice(invoice.event(MahnlaufService.EVENT_MAHNLAUF_EXECUTE));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (invoice.getTaskID()) {
|
||||||
case 5200:
|
case 5200:
|
||||||
dunningLevel=1;
|
if (dunningLevel < 1)
|
||||||
|
dunningLevel = 1;
|
||||||
break;
|
break;
|
||||||
case 5210:
|
case 5210:
|
||||||
dunningLevel=2;
|
if (dunningLevel < 2)
|
||||||
|
dunningLevel = 2;
|
||||||
break;
|
break;
|
||||||
case 5220:
|
case 5220:
|
||||||
dunningLevel=3;
|
if (dunningLevel < 3)
|
||||||
|
dunningLevel = 3;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dunningLevel=1;
|
if (dunningLevel < 1)
|
||||||
|
dunningLevel = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create a workitem stub for the mail message
|
||||||
// create a workitem stub for the mail message
|
ItemCollection invoiceStub = new ItemCollection();
|
||||||
ItemCollection invoiceStub = new ItemCollection();
|
invoiceStub.setItemValue("invoice.number", invoice.getItemValue("invoice.number"));
|
||||||
invoiceStub.setItemValue("invoice.number", invoice.getItemValue("invoice.number"));
|
invoiceStub.setItemValue("invoice.total", invoice.getItemValue("invoice.total"));
|
||||||
invoiceStub.setItemValue("invoice.total", invoice.getItemValue("invoice.total"));
|
invoiceStub.setItemValue("invoice.saldo", invoice.getItemValue("invoice.saldo"));
|
||||||
invoiceStub.setItemValue("invoice.saldo", invoice.getItemValue("invoice.saldo"));
|
invoiceStub.setItemValue("invoice.currency", invoice.getItemValue("invoice.currency"));
|
||||||
invoiceStub.setItemValue("invoice.currency", invoice.getItemValue("invoice.currency"));
|
invoiceStub.setItemValue("invoice.date", invoice.getItemValue("invoice.date"));
|
||||||
invoiceStub.setItemValue("invoice.date", invoice.getItemValue("invoice.date"));
|
invoiceStub.setItemValue("invoice.duedate", invoice.getItemValue("invoice.duedate"));
|
||||||
invoiceStub.setItemValue("invoice.duedate", invoice.getItemValue("invoice.duedate"));
|
invoiceStub.setItemValue("$workflowstatus", invoice.getItemValue("$workflowstatus"));
|
||||||
invoiceStub.setItemValue("$workflowstatus", invoice.getItemValue("$workflowstatus"));
|
// test if we have a international status translation..
|
||||||
// test if we have a international status translation..
|
if (!invoice.getItemValueString("workflowstatus_en").isEmpty()) {
|
||||||
if (!invoice.getItemValueString("workflowstatus_en").isEmpty()) {
|
invoiceStub.setItemValue("workflowstatus_en", invoice.getItemValue("workflowstatus_en"));
|
||||||
invoiceStub.setItemValue("workflowstatus_en", invoice.getItemValue("workflowstatus_en"));
|
} else {
|
||||||
} else {
|
// default
|
||||||
// default
|
|
||||||
invoiceStub.setItemValue("workflowstatus_en", invoice.getItemValue("$workflowstatus"));
|
invoiceStub.setItemValue("workflowstatus_en", invoice.getItemValue("$workflowstatus"));
|
||||||
}
|
}
|
||||||
invoiceList.add(invoiceStub.getAllItems());
|
invoiceList.add(invoiceStub.getAllItems());
|
||||||
|
|
||||||
// store currency in mahnlauf
|
// store currency in mahnlauf
|
||||||
currency = invoice.getItemValueString("invoice.currency");
|
currency = invoice.getItemValueString("invoice.currency");
|
||||||
|
|
||||||
saldo = saldo + invoice.getItemValueDouble("invoice.saldo");
|
saldo = saldo + invoice.getItemValueDouble("invoice.saldo");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mahnLaufWorkitem.setItemValue("dunning.details", invoiceList);
|
mahnLaufWorkitem.setItemValue("dunning.details", invoiceList);
|
||||||
mahnLaufWorkitem.setItemValue("dunning.saldo", saldo);
|
mahnLaufWorkitem.setItemValue("dunning.saldo", saldo);
|
||||||
mahnLaufWorkitem.setItemValue("dunning.currency", currency);
|
mahnLaufWorkitem.setItemValue("dunning.currency", currency);
|
||||||
mahnLaufWorkitem.setItemValue("dunning.level", dunningLevel);
|
mahnLaufWorkitem.setItemValue("dunning.level", dunningLevel);
|
||||||
|
|
||||||
// compute subject
|
// compute subject
|
||||||
switch (dunningLevel) {
|
switch (dunningLevel) {
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
mahnLaufWorkitem.setItemValue("mail.subject_de", "2. MAHNUNG");
|
mahnLaufWorkitem.setItemValue("mail.subject_de", "2. MAHNUNG");
|
||||||
|
|
@ -177,20 +177,19 @@ public class MahnlaufExecuteAdapter implements SignalAdapter {
|
||||||
mahnLaufWorkitem.setItemValue("mail.subject_en", "1. REMINDER");
|
mahnLaufWorkitem.setItemValue("mail.subject_en", "1. REMINDER");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mahnLaufWorkitem;
|
||||||
return mahnLaufWorkitem;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Returns true if the reminder date is today or in the past
|
||||||
/**
|
*
|
||||||
* Returns true if the reminder date is today or in the past
|
* @param uniqueid
|
||||||
* @param uniqueid
|
* @return
|
||||||
* @return
|
*/
|
||||||
*/
|
public boolean isInDue(ItemCollection invoice) {
|
||||||
public boolean isInDue(ItemCollection invoice) {
|
LocalDate date = invoice.getItemValueLocalDate("invoice.reminder");
|
||||||
LocalDate date = invoice.getItemValueLocalDate("invoice.reminder");
|
return date.compareTo(LocalDate.now()) <= 0;
|
||||||
return date.compareTo(LocalDate.now())<=0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue