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 {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static Logger logger = Logger.getLogger(MahnlaufExecuteAdapter.class.getName());
|
||||
@SuppressWarnings("unused")
|
||||
private static Logger logger = Logger.getLogger(MahnlaufExecuteAdapter.class.getName());
|
||||
|
||||
@EJB
|
||||
ModelService modelService;
|
||||
@EJB
|
||||
ModelService modelService;
|
||||
|
||||
@EJB
|
||||
WorkflowService workflowService = null;
|
||||
@EJB
|
||||
WorkflowService workflowService = null;
|
||||
|
||||
@Inject
|
||||
MahnlaufService mahnlaufService;
|
||||
@Inject
|
||||
MahnlaufService mahnlaufService;
|
||||
|
||||
/**
|
||||
* This method finds all invices ($workitemref) and tirgges event 300
|
||||
*
|
||||
* @throws PluginException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ItemCollection execute(ItemCollection mahnLaufWorkitem, ItemCollection event)
|
||||
throws AdapterException, PluginException {
|
||||
/**
|
||||
* This method finds all invices ($workitemref) and tirgges event 300
|
||||
*
|
||||
* @throws PluginException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ItemCollection execute(ItemCollection mahnLaufWorkitem, ItemCollection event)
|
||||
throws AdapterException, PluginException {
|
||||
|
||||
if (mahnLaufWorkitem.isItemEmpty("$workitemref")) {
|
||||
throw new PluginException(MahnlaufRefAddAdapter.class.getName(), MahnlaufService.ERROR_WORKFLOW,
|
||||
"Es wurden keine Rechnungen ausgewählt. Der Mahnlauf kann nicht gestartet werden.");
|
||||
}
|
||||
|
||||
// get all Invoices of this Mahnlauf
|
||||
List<Map<String, List<Object>>> invoiceList = new ArrayList<Map<String, List<Object>>>();
|
||||
List<String> refList = mahnLaufWorkitem.getItemValue("$workitemref");
|
||||
|
||||
// sind die Wärhungen idendtisch (mischmasch geht niht)
|
||||
String lastCurrency="";
|
||||
for (String uniqueId : refList) {
|
||||
if (mahnLaufWorkitem.isItemEmpty("$workitemref")) {
|
||||
throw new PluginException(MahnlaufRefAddAdapter.class.getName(), MahnlaufService.ERROR_WORKFLOW,
|
||||
"Es wurden keine Rechnungen ausgewählt. Der Mahnlauf kann nicht gestartet werden.");
|
||||
}
|
||||
|
||||
// get all Invoices of this Mahnlauf
|
||||
List<Map<String, List<Object>>> invoiceList = new ArrayList<Map<String, List<Object>>>();
|
||||
List<String> refList = mahnLaufWorkitem.getItemValue("$workitemref");
|
||||
|
||||
// sind die Wärhungen idendtisch (mischmasch geht niht)
|
||||
String lastCurrency = "";
|
||||
for (String uniqueId : refList) {
|
||||
ItemCollection invoice = workflowService.getWorkItem(uniqueId);
|
||||
String invoiceCurrency=invoice.getItemValueString("invoice.currency");
|
||||
String invoiceCurrency = invoice.getItemValueString("invoice.currency");
|
||||
if (lastCurrency.isEmpty()) {
|
||||
lastCurrency=invoiceCurrency;
|
||||
lastCurrency = invoiceCurrency;
|
||||
} else {
|
||||
if (!lastCurrency.equals(invoiceCurrency)) {
|
||||
throw new PluginException(MahnlaufRefAddAdapter.class.getName(), MahnlaufService.ERROR_WORKFLOW,
|
||||
"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
|
||||
if (isInDue(invoice)) {
|
||||
try {
|
||||
// first fetch the event of the invoice to be processed
|
||||
Model invoiceModel;
|
||||
invoiceModel = this.modelService.getModel(invoice.getModelVersion());
|
||||
ItemCollection invoiceEvent = invoiceModel.getEvent(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());
|
||||
}
|
||||
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)) {
|
||||
|
||||
} catch (ModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mahnlaufService.processInvoice(invoice.event(MahnlaufService.EVENT_MAHNLAUF_EXECUTE));
|
||||
}
|
||||
|
||||
|
||||
switch (invoice.getTaskID()) {
|
||||
// set new invoice.reminder date only if we in due
|
||||
if (isInDue(invoice)) {
|
||||
try {
|
||||
// first fetch the event of the invoice to be processed
|
||||
Model invoiceModel;
|
||||
invoiceModel = this.modelService.getModel(invoice.getModelVersion());
|
||||
ItemCollection invoiceEvent = invoiceModel.getEvent(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:
|
||||
dunningLevel=1;
|
||||
if (dunningLevel < 1)
|
||||
dunningLevel = 1;
|
||||
break;
|
||||
case 5210:
|
||||
dunningLevel=2;
|
||||
if (dunningLevel < 2)
|
||||
dunningLevel = 2;
|
||||
break;
|
||||
case 5220:
|
||||
dunningLevel=3;
|
||||
if (dunningLevel < 3)
|
||||
dunningLevel = 3;
|
||||
break;
|
||||
default:
|
||||
dunningLevel=1;
|
||||
if (dunningLevel < 1)
|
||||
dunningLevel = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// create a workitem stub for the mail message
|
||||
ItemCollection invoiceStub = new ItemCollection();
|
||||
invoiceStub.setItemValue("invoice.number", invoice.getItemValue("invoice.number"));
|
||||
invoiceStub.setItemValue("invoice.total", invoice.getItemValue("invoice.total"));
|
||||
invoiceStub.setItemValue("invoice.saldo", invoice.getItemValue("invoice.saldo"));
|
||||
invoiceStub.setItemValue("invoice.currency", invoice.getItemValue("invoice.currency"));
|
||||
invoiceStub.setItemValue("invoice.date", invoice.getItemValue("invoice.date"));
|
||||
invoiceStub.setItemValue("invoice.duedate", invoice.getItemValue("invoice.duedate"));
|
||||
invoiceStub.setItemValue("$workflowstatus", invoice.getItemValue("$workflowstatus"));
|
||||
// test if we have a international status translation..
|
||||
if (!invoice.getItemValueString("workflowstatus_en").isEmpty()) {
|
||||
invoiceStub.setItemValue("workflowstatus_en", invoice.getItemValue("workflowstatus_en"));
|
||||
} else {
|
||||
// default
|
||||
|
||||
// create a workitem stub for the mail message
|
||||
ItemCollection invoiceStub = new ItemCollection();
|
||||
invoiceStub.setItemValue("invoice.number", invoice.getItemValue("invoice.number"));
|
||||
invoiceStub.setItemValue("invoice.total", invoice.getItemValue("invoice.total"));
|
||||
invoiceStub.setItemValue("invoice.saldo", invoice.getItemValue("invoice.saldo"));
|
||||
invoiceStub.setItemValue("invoice.currency", invoice.getItemValue("invoice.currency"));
|
||||
invoiceStub.setItemValue("invoice.date", invoice.getItemValue("invoice.date"));
|
||||
invoiceStub.setItemValue("invoice.duedate", invoice.getItemValue("invoice.duedate"));
|
||||
invoiceStub.setItemValue("$workflowstatus", invoice.getItemValue("$workflowstatus"));
|
||||
// test if we have a international status translation..
|
||||
if (!invoice.getItemValueString("workflowstatus_en").isEmpty()) {
|
||||
invoiceStub.setItemValue("workflowstatus_en", invoice.getItemValue("workflowstatus_en"));
|
||||
} else {
|
||||
// default
|
||||
invoiceStub.setItemValue("workflowstatus_en", invoice.getItemValue("$workflowstatus"));
|
||||
}
|
||||
invoiceList.add(invoiceStub.getAllItems());
|
||||
}
|
||||
invoiceList.add(invoiceStub.getAllItems());
|
||||
|
||||
// store currency in mahnlauf
|
||||
currency = invoice.getItemValueString("invoice.currency");
|
||||
// store currency in mahnlauf
|
||||
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.saldo", saldo);
|
||||
mahnLaufWorkitem.setItemValue("dunning.currency", currency);
|
||||
mahnLaufWorkitem.setItemValue("dunning.level", dunningLevel);
|
||||
|
||||
// compute subject
|
||||
switch (dunningLevel) {
|
||||
mahnLaufWorkitem.setItemValue("dunning.details", invoiceList);
|
||||
mahnLaufWorkitem.setItemValue("dunning.saldo", saldo);
|
||||
mahnLaufWorkitem.setItemValue("dunning.currency", currency);
|
||||
mahnLaufWorkitem.setItemValue("dunning.level", dunningLevel);
|
||||
|
||||
// compute subject
|
||||
switch (dunningLevel) {
|
||||
|
||||
case 2:
|
||||
mahnLaufWorkitem.setItemValue("mail.subject_de", "2. MAHNUNG");
|
||||
|
|
@ -177,20 +177,19 @@ public class MahnlaufExecuteAdapter implements SignalAdapter {
|
|||
mahnLaufWorkitem.setItemValue("mail.subject_en", "1. REMINDER");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return mahnLaufWorkitem;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the reminder date is today or in the past
|
||||
* @param uniqueid
|
||||
* @return
|
||||
*/
|
||||
public boolean isInDue(ItemCollection invoice) {
|
||||
LocalDate date = invoice.getItemValueLocalDate("invoice.reminder");
|
||||
return date.compareTo(LocalDate.now())<=0;
|
||||
}
|
||||
|
||||
return mahnLaufWorkitem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the reminder date is today or in the past
|
||||
*
|
||||
* @param uniqueid
|
||||
* @return
|
||||
*/
|
||||
public boolean isInDue(ItemCollection invoice) {
|
||||
LocalDate date = invoice.getItemValueLocalDate("invoice.reminder");
|
||||
return date.compareTo(LocalDate.now()) <= 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue