diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungseingangSaldoAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungseingangSaldoAdapter.java index 102427a..c9e3af5 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungseingangSaldoAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungseingangSaldoAdapter.java @@ -29,82 +29,102 @@ import org.imixs.workflow.exceptions.PluginException; */ public class ZahlungseingangSaldoAdapter implements SignalAdapter { - private static Logger logger = Logger.getLogger(ZahlungseingangSaldoAdapter.class.getName()); + private static Logger logger = Logger.getLogger(ZahlungseingangSaldoAdapter.class.getName()); + @Inject + ZahlungseingangService zahlungseingangService; - @Inject - ZahlungseingangService zahlungseingangService; + /** + * This method finds the outgoing invoicdes and updates the saldo + * (payment.total). + * + * @throws PluginException + */ + @Override + public ItemCollection execute(ItemCollection document, ItemCollection event) + throws AdapterException, PluginException { - /** - * This method finds the outgoing invoicdes and updates the saldo - * (payment.total). - * - * @throws PluginException - */ - @Override - public ItemCollection execute(ItemCollection document, ItemCollection event) - throws AdapterException, PluginException { + updateSaldo(document); - updateSaldo(document); + return document; + } - return document; - } + /** + * Diese method hängt eine referenz der aktuellen Rechnung an den Zahlungsavis + * + * @param document + * @throws PluginException + */ + private void updateSaldo(ItemCollection document) throws PluginException { - /** - * Diese method hängt eine referenz der aktuellen Rechnung an den Zahlungsavis - * - * @param document - * @throws PluginException - */ - private void updateSaldo(ItemCollection document) throws PluginException { + // payment currency + String paymentCurrency = document.getItemValueString("payment.currency"); + double masterPaymentAmount = document.getItemValueDouble("payment.amount"); + String paymentWarning = document.getItemValueString("payment.warning"); - // payment currency - String paymentCurrency = document.getItemValueString("payment.currency"); + List paymentDetails = zahlungseingangService.loadPaymentDetails(document); - List paymentDetails = zahlungseingangService.loadPaymentDetails(document); + if (paymentDetails.size() == 0) { + throw new PluginException(PluginException.class.getName(), + ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, + "Bitte wählen Sie die zugeordneten Rechnungen aus."); + } - if (paymentDetails.size()==0) { - throw new PluginException(PluginException.class.getName(),ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, - "Bitte wählen Sie die zugeordneten Rechnungen aus."); - } - - logger.info("......Updating " + paymentDetails.size() + " outgoing invoices...."); - for (ItemCollection payment : paymentDetails) { + logger.info("......Updating " + paymentDetails.size() + " outgoing invoices...."); + double einzelPayments = 0; + for (ItemCollection payment : paymentDetails) { - ItemCollection invoice = zahlungseingangService.findInvoice(payment.getUniqueID()); + ItemCollection invoice = zahlungseingangService.findInvoice(payment.getUniqueID()); - if (invoice != null) { - String invoiceNumber = invoice.getItemValueString("invoice.number"); - String invoiceCurrency = invoice.getItemValueString("invoice.currency"); + if (invoice != null) { + String invoiceNumber = invoice.getItemValueString("invoice.number"); + String invoiceCurrency = invoice.getItemValueString("invoice.currency"); - if (!invoiceCurrency.equals(paymentCurrency)) { - throw new PluginException(PluginException.class.getName(),ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, - "Der Zahlungseingang kann nicht verbucht werden, da die Währung " + paymentCurrency - + " nicht mit der Währung der Rechnung " + invoiceNumber + " übereinstimmt!"); - } + if (!invoiceCurrency.equals(paymentCurrency)) { + throw new PluginException(PluginException.class.getName(), + ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, + "Der Zahlungseingang kann nicht verbucht werden, da die Währung " + paymentCurrency + + " nicht mit der Währung der Rechnung " + invoiceNumber + " übereinstimmt!"); + } - float invoiceSaldo = invoice.getItemValueFloat("invoice.saldo"); - float paymentAmount = payment.getItemValueFloat("payment.amount"); + float invoiceSaldo = invoice.getItemValueFloat("invoice.saldo"); + float paymentAmount = payment.getItemValueFloat("payment.amount"); + einzelPayments = einzelPayments + paymentAmount; - if (Math.abs(paymentAmount) > Math.abs(invoiceSaldo)) { - throw new PluginException(PluginException.class.getName(), ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, - "Der Zahlungseingang kann nicht verbucht werden, da der Restsaldo der Rechnung " - + invoiceNumber + " kleiner als der Zahlbetrag ist!"); - } - - - invoiceSaldo=invoiceSaldo-paymentAmount; - invoice.setItemValue("invoice.saldo", invoiceSaldo); - invoice.event(ZahlungseingangService.EVENT_UPDATE_INVOICE); - zahlungseingangService.processInvoice(invoice); - + + // vergeiche Beträge + if (Math.abs(paymentAmount) > Math.abs(invoiceSaldo)) { + throw new PluginException(PluginException.class.getName(), + ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, + "Der Zahlungseingang kann nicht verbucht werden, da der Restsaldo der Rechnung " + + invoiceNumber + " kleiner als der Zahlbetrag ist!"); + } + + + // Prüfe auf Plausisbilität + if (paymentWarning.isEmpty()) { + // falls mehr einzelsummen eingeben wurden als der oben angegeben Total Pamyment + // dann soll eine Warnung ausgegen werden. + if (masterPaymentAmount > einzelPayments) { + document.setItemValue("payment.warning", "invalid saldo"); + throw new PluginException(PluginException.class.getName(), + ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, + "Der Zahlungseingang ist größer als die ausgebuchten Rechnungssalden. Sollte die Eingabe korrekt sein, wiederholen Sie die Aktion."); + } - } else { - throw new PluginException(PluginException.class.getName(), ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, - "Rechnung konnte nicht gefunden werden!"); - } - } + } - } + invoiceSaldo = invoiceSaldo - paymentAmount; + invoice.setItemValue("invoice.saldo", invoiceSaldo); + invoice.event(ZahlungseingangService.EVENT_UPDATE_INVOICE); + zahlungseingangService.processInvoice(invoice); + + } else { + throw new PluginException(PluginException.class.getName(), + ZahlungseingangService.ERROR_PAYMENT_BOOKING_FAILED, "Rechnung konnte nicht gefunden werden!"); + } + } + + } } \ No newline at end of file diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/mahnlauf/MahnlaufExecuteAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/mahnlauf/MahnlaufExecuteAdapter.java index 0b5636d..ba471a5 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/mahnlauf/MahnlaufExecuteAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/mahnlauf/MahnlaufExecuteAdapter.java @@ -1,21 +1,31 @@ package com.alexanderlogistics.mahnlauf; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import javax.ejb.EJB; import javax.inject.Inject; import org.imixs.workflow.ItemCollection; +import org.imixs.workflow.Model; import org.imixs.workflow.SignalAdapter; import org.imixs.workflow.engine.ModelService; import org.imixs.workflow.engine.WorkflowService; import org.imixs.workflow.exceptions.AdapterException; +import org.imixs.workflow.exceptions.ModelException; import org.imixs.workflow.exceptions.PluginException; /** * The MahnlaufExecuteAdapter triggers the event 300 for all linked invoices *

+ * The Adapter also creates a child item '_invoices' with the details of the + * processed invoices. This item is used in the Workflow Model to construct a + * HTML Table wen sending the mail. + * * * @version 1.0 * @author rsoika @@ -50,17 +60,53 @@ public class MahnlaufExecuteAdapter implements SignalAdapter { } // get all Invoices of this Mahnlauf + List>> invoiceList = new ArrayList>>(); List refList = mahnLaufWorkitem.getItemValue("$workitemref"); 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 + // first fetch the event of the invoice to be processed + try { + 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)); + + // 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")); + invoiceList.add(invoiceStub.getAllItems()); + } } + mahnLaufWorkitem.setItemValue("dunning.details", invoiceList); + return mahnLaufWorkitem; } -} \ No newline at end of file +} diff --git a/office-alexander-logistics-app/src/main/webapp/pages/workitems/forms/alexander/section_opliste_mahnlauf.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/workitems/forms/alexander/section_opliste_mahnlauf.xhtml index dda6c5c..6743a77 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/workitems/forms/alexander/section_opliste_mahnlauf.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/workitems/forms/alexander/section_opliste_mahnlauf.xhtml @@ -22,6 +22,7 @@ #{message['form.date']} #{message['form.deadline']} + #{message['form.reminder']} Status S/H @@ -48,6 +49,11 @@ + + + + diff --git a/workflow/mahnlauf-de-1.0.0.bpmn b/workflow/mahnlauf-de-1.0.0.bpmn index b3a55c4..86c1403 100644 --- a/workflow/mahnlauf-de-1.0.0.bpmn +++ b/workflow/mahnlauf-de-1.0.0.bpmn @@ -37,7 +37,7 @@