From f6bb14c8decbe516bc825bd6bd80f59a965bf1f7 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Tue, 7 Mar 2023 16:23:11 +0100 Subject: [PATCH] OP Listen update --- .../OPListExportAdapter.java | 75 +- .../OPListExportScheduler.java | 68 +- workflow/opliste-de-1.0.0.bpmn | 48 +- workflow/rechnungsausgang-de-1.0.1a.bpmn | 2 +- workflow/rechnungsausgang-de-1.0.2-test.bpmn | 904 +++++++++++------- 5 files changed, 679 insertions(+), 418 deletions(-) diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java index e5d410d..9b2900f 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportAdapter.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,6 +59,9 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { private static Logger logger = Logger.getLogger(OPListExportAdapter.class.getName()); public static final String ERROR_CONFIG = "CONFIG_ERROR"; + public static final int TASK_MAHNUNG_2ND = 5210; + public static final int TASK_MAHNUNG_LAST = 5220; + final String TYPE_TEXTBLOCK = "textblock"; @Inject @@ -69,6 +73,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { @Inject SnapshotService snapshotService; + /** * This method finds or create the Zahlungsavis and adds a reference * ($workitemref) to the current invoice. @@ -89,6 +94,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { String textblock = evalItemCollection.getItemValueString("textblock"); String template = evalItemCollection.getItemValueString("template"); String targetName = evalItemCollection.getItemValueString("target-name"); + boolean filter = evalItemCollection.getItemValueBoolean("filter"); // adapt text.... targetName = workflowService.adaptText(targetName, document); @@ -110,7 +116,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { // now we add separate lines for each invoice.... logger.info("... insert invoices.."); - insertInvoiceRows(document, targetName); + insertInvoiceRows(document, targetName, filter); } catch (PluginException | IOException | QueryException e) { throw new PluginException(OPListExportAdapter.class.getSimpleName(), ERROR_CONFIG, "failed to update op-liste: " + e.getMessage()); @@ -120,8 +126,8 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { } /** - * This helper method inserts a row for each invoice of the current Zahlunsavis - * at row 16 into the excel template file + * This helper method inserts a row for each invoice of the OPListe at row 16 + * into the excel template file *

* The method copies the Row A16 as a reference row *

@@ -131,7 +137,8 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { * @throws PluginException * @throws QueryException */ - private void insertInvoiceRows(ItemCollection document, String fileName) throws PluginException, QueryException { + private void insertInvoiceRows(ItemCollection document, String fileName, boolean filter) + throws PluginException, QueryException { double saldoUSD = 0; double saldoEUR = 0; @@ -139,10 +146,10 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { String spaceID = document.getItemValueString("space.ref"); logger.info("... space.ref=" + spaceID + " ...grouping invoices by spaceid...."); - Map> invoiceMap = groupInvoicesBySpaceID(spaceID); + Map> invoiceMap = groupInvoicesBySpaceID(spaceID, filter); FileData fileData = document.getFileData(fileName); - + // load XSSFWorkbook XSSFWorkbook doc = null; try (InputStream imputStream = new ByteArrayInputStream(fileData.getContent())) { @@ -159,7 +166,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { int lastRow = 2999; logger.finest("Last rownum=" + lastRow); - int totalRowCount = invoiceMap.size()*2; + int totalRowCount = invoiceMap.size() * 2; for (List list : invoiceMap.values()) { totalRowCount = totalRowCount + list.size(); } @@ -170,7 +177,6 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { sheet.shiftRows(rowPos, lastRow, totalRowCount, true, true); for (Map.Entry> entry : invoiceMap.entrySet()) { String dbtrNumber = entry.getKey(); - logger.info("......add debitor " + dbtrNumber); List invoices = entry.getValue(); // erzeuge eine Zwischenüberschrift für den Debitor.... @@ -187,18 +193,18 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { for (ItemCollection invoice : invoices) { if ("EUR".equals(invoice.getItemValueString("invoice.currency"))) { catSumEUR = catSumEUR + invoice.getItemValueDouble("invoice.saldo"); - + } else { catSumUSD = catSumUSD + invoice.getItemValueDouble("invoice.saldo"); - + } } - + categoryRow.getCell(6).setCellValue(catSumEUR); categoryRow.getCell(8).setCellValue(catSumUSD); rowPos++; - + // jetzt füge alle Rechnungen an. for (ItemCollection invoice : invoices) { logger.fine("......add invoice " + invoice.getUniqueID()); @@ -212,23 +218,23 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { row.getCell(4).setCellValue(invoice.getItemValueDate("invoice.date")); row.getCell(5).setCellValue(invoice.getItemValueDate("invoice.duedate")); double total = invoice.getItemValueDouble("invoice.saldo"); - String currency=invoice.getItemValueString("invoice.currency"); + String currency = invoice.getItemValueString("invoice.currency"); if ("EUR".equals(currency)) { // EUR row.getCell(6).setCellValue(total); row.getCell(7).setCellValue(currency); - saldoEUR =roundD( saldoEUR + total); + saldoEUR = roundD(saldoEUR + total); } else { // USD row.getCell(8).setCellValue(total); row.getCell(9).setCellValue(currency); - saldoUSD = roundD( saldoUSD + total); + saldoUSD = roundD(saldoUSD + total); } row.getCell(10).setCellValue(invoice.getItemValueString("$workflowstatus")); - + rowPos++; } - + // Leerzeile categoryRow = sheet.createRow(rowPos); rowPos++; @@ -334,16 +340,20 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { /** * Diese Methode groupiert eine Rechnugnsliste nach Debitorennummern * + * Falls 'filter==true' werden nur Rechnungen ab der 2. Mahnung oder mit einer + * Fälligkeit >21 Tage ausgegeben + * * @param spaceID * @return */ - private Map> groupInvoicesBySpaceID(String spaceID) { + private Map> groupInvoicesBySpaceID(String spaceID, boolean filter) { Map> result = new HashMap<>(); try { List invoices = documentService.find( - "$modelversion:rechnungsausgang-de-1.0 AND type:workitem AND $uniqueidref:" + spaceID, 9999, 0,"invoice.number",false); + "$modelversion:rechnungsausgang-de-1.0 AND type:workitem AND $uniqueidref:" + spaceID, 9999, 0, + "invoice.number", false); for (ItemCollection invoice : invoices) { @@ -355,21 +365,40 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { invoiceList = new ArrayList(); } - invoiceList.add(invoice); + if (filter) { + Date date = invoice.getItemValueDate("invoice.duedate"); + if (OPListExportAdapter.isOverdue(date, invoice.getTaskID())) { + invoiceList.add(invoice); + } + } else { + // jede Rechnung zählt (manuelle OPListe) + invoiceList.add(invoice); + } - // speicher wieder die neue liste - result.put(dbtrNumber, invoiceList); + // speicher wieder die neue liste wenn es mindestens eine Rechnung gab + if (invoiceList.size()>0) { + result.put(dbtrNumber, invoiceList); + } } } catch (QueryException e) { - // TODO Auto-generated catch block e.printStackTrace(); } return result; } + private double roundD(double wert) { return Math.round(wert * 100.0f) / 100.0f; } + + public static boolean isOverdue(Date date, int taskid) { + Date now = new Date(); + long diffInMillies = Math.abs(now.getTime() - date.getTime()); + int tage = (int) (diffInMillies / 1000 / 60 / 60 / 24); + return ((taskid >= TASK_MAHNUNG_2ND && taskid <= TASK_MAHNUNG_2ND) || tage >= 21); + + } + } \ No newline at end of file diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportScheduler.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportScheduler.java index 1368999..7fe4312 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportScheduler.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/OPListExportScheduler.java @@ -26,6 +26,7 @@ import java.text.DateFormat; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.logging.Logger; @@ -52,7 +53,9 @@ import org.imixs.workflow.exceptions.QueryException; * The OPListExportScheduler erzeugt für jeden Berich ein neues Workitem mit * einer Excel Datei mit allen offenen Rechnungen. *

- * bei den OP Listen für die Abteilungen dürfen nur Rechnungen aktiviert werden, wo die 2. Mahnung bereits versandt wurde bzw. wo die Fälligkeit der Rechnungen 21 Tage übersteigt. + * bei den OP Listen für die Abteilungen dürfen nur Rechnungen aktiviert werden, + * wo die 2. Mahnung bereits versandt wurde bzw. wo die Fälligkeit der + * Rechnungen 21 Tage übersteigt. *

* The class implements the interface * _org.imixs.workflow.engine.scheduler.Scheduler_ and can be used in @@ -66,7 +69,9 @@ public class OPListExportScheduler implements Scheduler { public static final int MAX_COUNT = 999; 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 DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); public static DecimalFormat decimalFormat = new DecimalFormat("0.00", new DecimalFormatSymbols(java.util.Locale.GERMANY)); @@ -99,25 +104,17 @@ public class OPListExportScheduler implements Scheduler { List spaces = teamService.getSpaces(); // Jezt erzeugen wir für jeden Bereich ein neues Workitem . for (ItemCollection space : spaces) { - - // Gibt es Rechnungen? - try { - List invoices = documentService - .find("$modelversion:rechnungsausgang-de-1.0 AND type:workitem AND $uniqueidref:" - + space.getUniqueID(), 1, 0); - if (invoices.size() > 0) { - // erzeuge eine OP-Liste - ItemCollection workitem = new ItemCollection(); - workitem.setItemValue("space.ref", space.getUniqueID()); - // set creation date! - workitem.setItemValue(WorkflowKernel.CREATED,new Date()); - processOPListe(workitem); - } - } catch (QueryException e) { - // not possible - e.printStackTrace(); + // Gibt es Rechnungen in diesem Space? + if (existsOverdueInvoices(space)) { + // erzeuge eine OP-Liste + ItemCollection workitem = new ItemCollection(); + workitem.setItemValue("space.ref", space.getUniqueID()); + // set creation date! + workitem.setItemValue(WorkflowKernel.CREATED, new Date()); + processOPListe(workitem); + } else { + logger.info("....no invoices in overdue for "+space.getItemValueString("name")); } - } logMessage("...completed", configuration, null); @@ -134,6 +131,37 @@ public class OPListExportScheduler implements Scheduler { return configuration; } + /** + * Prüfen ob es Rechnugen in diesem Space gibt die entweder die 2. Mahnstufe + * erreicht habne oder deren Fälligkeit um mehr als 21 Tage überschritten ist. + * + * @param space + * @return + */ + private boolean existsOverdueInvoices(ItemCollection space) { + List invoices = new ArrayList(); + try { + invoices = documentService.find( + "$modelversion:rechnungsausgang-de-1.0 AND type:workitem AND $uniqueidref:" + space.getUniqueID(), + 999, 0); + } catch (QueryException e) { + logger.warning("Failed to compute invoice list: " + e.getMessage()); + e.printStackTrace(); + } + + for (ItemCollection invoice : invoices) { + Date date = invoice.getItemValueDate("invoice.duedate"); + if (OPListExportAdapter.isOverdue(date,invoice.getTaskID())) { + return true; + } + } + return false; + } + + + + + @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW) public void processOPListe(ItemCollection workitem) throws PluginException, AccessDeniedException, ProcessingErrorException, ModelException { diff --git a/workflow/opliste-de-1.0.0.bpmn b/workflow/opliste-de-1.0.0.bpmn index 6a74f6f..36e7890 100644 --- a/workflow/opliste-de-1.0.0.bpmn +++ b/workflow/opliste-de-1.0.0.bpmn @@ -251,14 +251,19 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt home Mahnwesen OP-Liste Template - op-liste_template.xlsx +op-liste_template.xlsx op-liste_space.name_$lasteventdate.xlsx - +true C6 sequencenumber text + + D6 + Überfällig / 2. Mahnstufe + text + C8 space.name @@ -401,7 +406,7 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt Mahnwesen OP-Liste Template - op-liste_template.xlsx +op-liste_template.xlsx op-liste_space.name_$lasteventdate.xlsx @@ -409,6 +414,11 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt sequencenumber text + + D6 + Gesamtübersicht + text + C8 space.name @@ -487,6 +497,14 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt + + Filter: 2. Mahnstufe / 21 Tage überfällig + + + Alle Rechnungen + + + @@ -598,6 +616,18 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt + + + + + + + + + + + + @@ -688,6 +718,18 @@ Nach Prüfung schließen Sie bitte den Vorgang über die Schaltfläche "Erledigt + + + + + + + + + + + + diff --git a/workflow/rechnungsausgang-de-1.0.1a.bpmn b/workflow/rechnungsausgang-de-1.0.1a.bpmn index fb5405a..1285d2f 100644 --- a/workflow/rechnungsausgang-de-1.0.1a.bpmn +++ b/workflow/rechnungsausgang-de-1.0.1a.bpmn @@ -984,7 +984,7 @@ Betrag: _amount (Brutto € _amount_brutto - + diff --git a/workflow/rechnungsausgang-de-1.0.2-test.bpmn b/workflow/rechnungsausgang-de-1.0.2-test.bpmn index 6dcfa1a..f4fe701 100644 --- a/workflow/rechnungsausgang-de-1.0.2-test.bpmn +++ b/workflow/rechnungsausgang-de-1.0.2-test.bpmn @@ -98,61 +98,64 @@ th { font-weight: bold;} ExclusiveGateway_1 StartEvent_1 IntermediateCatchEvent_6 - IntermediateCatchEvent_17 - IntermediateCatchEvent_2 - IntermediateCatchEvent_3 - ExclusiveGateway_5 EventBasedGateway_1 IntermediateCatchEvent_13 - EventBasedGateway_2 - IntermediateCatchEvent_5000-20 - IntermediateCatchEvent_18 IntermediateThrowEvent_11 IntermediateThrowEvent_8 - Task_5 - EndEvent_2 - IntermediateCatchEvent_23 IntermediateCatchEvent_1 - IntermediateCatchEvent_27 + IntermediateCatchEvent_5000-20 Task_8 + Task_6 + Task_5 + IntermediateCatchEvent_23 + IntermediateCatchEvent_27 EndEvent_1 + EndEvent_3 + EndEvent_2 + IntermediateCatchEvent_3 + ExclusiveGateway_5 + IntermediateCatchEvent_18 + IntermediateCatchEvent_17 + IntermediateCatchEvent_2 + IntermediateCatchEvent_5 - Task_5005 - Task_4 - IntermediateCatchEvent_8 - IntermediateCatchEvent_9 - EventBasedGateway_3 - IntermediateCatchEvent_14 - Task_3 - IntermediateCatchEvent_16 - IntermediateCatchEvent_4 - IntermediateThrowEvent_5 - EventBasedGateway_4 - IntermediateCatchEvent_15 - IntermediateCatchEvent_29 - IntermediateCatchEvent_26 - ExclusiveGateway_4 - IntermediateCatchEvent_11 - Task_7 - IntermediateCatchEvent_28 - EventBasedGateway_5 - IntermediateThrowEvent_7 - IntermediateThrowEvent_12 - IntermediateCatchEvent_19 - IntermediateCatchEvent_25 IntermediateCatchEvent_22 - IntermediateCatchEvent_5005-10 - IntermediateCatchEvent_10 - IntermediateThrowEvent_1 - IntermediateCatchEvent_21 - IntermediateCatchEvent_20 + Task_7 Task_1 + IntermediateThrowEvent_12 + Task_3 + IntermediateCatchEvent_4 + EventBasedGateway_3 + EventBasedGateway_4 + IntermediateThrowEvent_1 + IntermediateCatchEvent_29 + IntermediateCatchEvent_9 + IntermediateCatchEvent_21 + Task_4 + IntermediateCatchEvent_14 ExclusiveGateway_3 - IntermediateThrowEvent_10 - IntermediateThrowEvent_9 IntermediateThrowEvent_6 + IntermediateCatchEvent_20 + IntermediateCatchEvent_10 + ExclusiveGateway_4 + IntermediateCatchEvent_15 + IntermediateCatchEvent_19 + IntermediateCatchEvent_8 + IntermediateCatchEvent_25 + EventBasedGateway_5 + IntermediateCatchEvent_5005-10 + IntermediateCatchEvent_28 + IntermediateThrowEvent_10 + IntermediateCatchEvent_11 + IntermediateCatchEvent_24 + IntermediateCatchEvent_26 + IntermediateThrowEvent_9 + Task_5005 + IntermediateThrowEvent_7 IntermediateThrowEvent_4 + IntermediateThrowEvent_5 + IntermediateCatchEvent_16 @@ -235,7 +238,7 @@ Bei Fragen wenden Sie sich bitte an info@imixs.com - SequenceFlow_32 + SequenceFlow_22 SequenceFlow_27 @@ -395,8 +398,8 @@ Bei Fragen wenden Sie sich bitte an info@imixs.com SequenceFlow_14 SequenceFlow_15 SequenceFlow_39 - SequenceFlow_46 SequenceFlow_37 + SequenceFlow_22 @@ -651,6 +654,7 @@ Bei Fragen wenden Sie sich bitte an info@imixs.com SequenceFlow_4 SequenceFlow_18 SequenceFlow_35 + SequenceFlow_34 @@ -699,8 +703,8 @@ Bei Fragen wenden Sie sich bitte an info@imixs.com SequenceFlow_39 SequenceFlow_17 SequenceFlow_65 + SequenceFlow_13 - @@ -1049,7 +1053,7 @@ result.isValid=true; SequenceFlow_18 SequenceFlow_25 SequenceFlow_64 - SequenceFlow_34 + SequenceFlow_9 @@ -1423,12 +1427,7 @@ Betrag: invoice.total invoice.currency - - SequenceFlow_46 - SequenceFlow_32 - - - + @@ -2175,7 +2174,7 @@ Bei Fragen wenden Sie sich bitte an info@imixs.com SequenceFlow_53 - + @@ -2351,9 +2350,9 @@ Bei Fragen wenden Sie sich bitte an info@imixs.com SequenceFlow_24 - SequenceFlow_67 - SequenceFlow_63 SequenceFlow_50 + SequenceFlow_63 + SequenceFlow_67 @@ -2374,6 +2373,133 @@ Bei Fragen wenden Sie sich bitte an info@imixs.com + + + + + + + + + + _subject]]> + + + + + + + + + _amount (Brutto € _amount_brutto) +_description]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + home]]> + + + + + + + + + + + + false + + + + + + + SequenceFlow_9 + SequenceFlow_13 + SequenceFlow_5 + + + + + + + + + + + txtlastcomment]]> + + + + + + + + + invoice.number dbtr.number dbtr.name (invoice.currency invoice.total) ]]> + + + true + + + + + + + + + + + + + + + $workflowgroup - $workflowstatus]]> + SequenceFlow_5 + SequenceFlow_19 + + + SequenceFlow_19 + + + Trigger über ZahlungseingangsSaldoAdapter @@ -2395,21 +2521,21 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + - + - + - + - + - + @@ -2419,21 +2545,21 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + - + - + - + - + - + @@ -2453,9 +2579,9 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + - + @@ -2465,15 +2591,15 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + - + - + - + @@ -2483,21 +2609,21 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + - + - + - + - + - + @@ -2505,101 +2631,101 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2609,15 +2735,15 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + - + - + - + @@ -2638,126 +2764,122 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2767,21 +2889,39 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + - + - + - + - + + + + + + + + + + + + + + + + + + + @@ -2798,17 +2938,16 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - - - + + + - - - - - + + + + @@ -2818,9 +2957,9 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - - - + + + @@ -2829,137 +2968,127 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - - - - - - - - - - + + + - - - + + + + - - - - + + + + - - - - + + + - - - + + + - - - + + + - - - - + + + - - - + + + - - - - + + + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + - - - + + + @@ -2969,249 +3098,282 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - - - - + + + - - - + + + - - - - - - - - - - + + + + - - - + + + - - - - + + + + - - - + + + + - - + + - - - + + + - - - + + + + - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - + + + + - - - + + + + - - - + + + + - - - + + + + + - - - + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +