From 4507638daf7052395e71c3aa532ba2f2260cd904 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Tue, 7 Feb 2023 12:34:35 +0100 Subject: [PATCH] refactoring op listen --- office-alexander-logistics-app/pom.xml | 6 + .../OPListExportAdapter.java | 4 +- .../datev/DatevCargosoftImportAdapter.java | 23 ++- .../resources/bundle/custom_de.properties | 2 +- .../resources/bundle/custom_en.properties | 2 + .../com/alexanderlogistics/TestFormat.java | 16 +- .../migration/MigrationSpaceZuordnung.java | 178 ++++++++++++++++++ .../datev/EXTF_OPD_migration_2022-test-1.csv | 3 + pom.xml | 2 +- 9 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 office-alexander-logistics-app/src/test/java/com/alexanderlogistics/migration/MigrationSpaceZuordnung.java create mode 100644 office-alexander-logistics-app/src/test/resources/datev/EXTF_OPD_migration_2022-test-1.csv diff --git a/office-alexander-logistics-app/pom.xml b/office-alexander-logistics-app/pom.xml index 21765f6..a98128d 100644 --- a/office-alexander-logistics-app/pom.xml +++ b/office-alexander-logistics-app/pom.xml @@ -366,6 +366,12 @@ 3.3.6 test + + + org.imixs.workflow + imixs-melman + ${org.imixs.melman.version} + \ No newline at end of file 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 7dd40a1..3a63c9d 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 @@ -170,7 +170,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { // calculate summ of all invoices double catSum = 0; for (ItemCollection invoice : invoices) { - catSum = catSum + invoice.getItemValueDouble("invoice.total"); + catSum = catSum + invoice.getItemValueDouble("invoice.saldo"); } if (catSum < 0) { // SOLL @@ -192,7 +192,7 @@ public class OPListExportAdapter extends POIFindReplaceAdapter { row.getCell(3).setCellValue(invoice.getItemValueString("invoice.text")); row.getCell(4).setCellValue(invoice.getItemValueDate("invoice.date")); row.getCell(5).setCellValue(invoice.getItemValueDate("invoice.duedate")); - double total = invoice.getItemValueDouble("invoice.total"); + double total = invoice.getItemValueDouble("invoice.saldo"); if (total < 0) { // SOLL row.getCell(6).setCellValue(total); diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/datev/DatevCargosoftImportAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/datev/DatevCargosoftImportAdapter.java index e16d935..7cf9cca 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/datev/DatevCargosoftImportAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/datev/DatevCargosoftImportAdapter.java @@ -127,7 +127,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter { SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd"); // load spaces Pos Expressions - Map> spaces = loadSpacesConfig(); + Map> spacePosMappings = loadSpacePosMappings(); ItemCollection invoiceWorkitem = null; @@ -245,7 +245,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter { logger.info("...close workitem...."); // nein - also invoice schließen - closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen,spaces); + closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen,spacePosMappings); invoiceWorkitem = null; // neue Splitbuchungstabelle anlegen splitBuchungen = new ArrayList(); @@ -263,7 +263,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter { } } // wile end - closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen,spaces); + closeInvoiceWorkitem(invoiceWorkitem, splitBuchungen,spacePosMappings); } catch (IOException | ParseException e) { throw new PluginException(DatevCargosoftImportAdapter.class.getName(), @@ -292,9 +292,10 @@ public class DatevCargosoftImportAdapter implements SignalAdapter { /** * Helper method that loads all expressions from the spaces + * * @return List of list of expressions */ - private Map> loadSpacesConfig() { + private Map> loadSpacePosMappings() { Map> result =new HashMap<>(); // als erstes lesen wir die pos.mappings aus den Spaces ein, auf die dann eine // Rechnung emapped werden kann. @@ -389,7 +390,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter { * @throws AccessDeniedException */ private void closeInvoiceWorkitem(ItemCollection invoiceWorkitem, List splitBuchungen, - Map> expressionsMap) + Map> spacePosMappings) throws AccessDeniedException, ProcessingErrorException, PluginException, ModelException { if (invoiceWorkitem == null) { return; // no op @@ -430,7 +431,8 @@ public class DatevCargosoftImportAdapter implements SignalAdapter { // dazu kucken wir in alle spaces den config wert 'pos.mapping' String text = invoiceWorkitem.getItemValueString("invoice.text"); if (!text.isEmpty()) { - for (Map.Entry > entry : expressionsMap.entrySet()) { + boolean found=false; + for (Map.Entry > entry : spacePosMappings.entrySet()) { List expressionsList=entry.getValue(); for (String expr : expressionsList) { @@ -439,9 +441,13 @@ public class DatevCargosoftImportAdapter implements SignalAdapter { if (m.find()) { // we have a match invoiceWorkitem.setItemValue("space.ref", entry.getKey()); + found=true; break; } } + if (found) { + break; + } } } // Processe die Invoice @@ -450,6 +456,11 @@ public class DatevCargosoftImportAdapter implements SignalAdapter { } + + public static void updateSpaceRef(ItemCollection invoice) { + + } + /** * Convert the List of ItemCollections back into a List of Map elements * diff --git a/office-alexander-logistics-app/src/main/resources/bundle/custom_de.properties b/office-alexander-logistics-app/src/main/resources/bundle/custom_de.properties index 20a7a92..bbc8965 100644 --- a/office-alexander-logistics-app/src/main/resources/bundle/custom_de.properties +++ b/office-alexander-logistics-app/src/main/resources/bundle/custom_de.properties @@ -10,7 +10,7 @@ alexander_sub_positionen_read= alexander_sub_responsible= space.sub_custom=Konfiguration -space.help_custom=Bitte verwenden Sie hier Reguläre Ausdrücke wie z.B. /\bEX-SAL\b/ Dieser Ausdruck sucht nach dem Wert "EX-SAL" in einem String und achtet darauf, dass es nicht Teil eines größeren Ausdrucks ist (z.B. "EX-SALES"). +space.help_custom=Bitte verwenden Sie hier Reguläre Ausdrücke wie z.B. \\bEX-SAL Dieser Ausdruck sucht nach dem Wert "EX-SAL" in einem String und achtet darauf, dass es nicht Teil eines größeren Ausdrucks ist (z.B. "EX-SALES"). ERROR_INVALID_IBANBIC=Die Eingabe der IBAN/BIC is ungültig. Bitte überprüfen Sie Ihre Eingaben. \ No newline at end of file diff --git a/office-alexander-logistics-app/src/main/resources/bundle/custom_en.properties b/office-alexander-logistics-app/src/main/resources/bundle/custom_en.properties index 63f8eed..5163f8e 100644 --- a/office-alexander-logistics-app/src/main/resources/bundle/custom_en.properties +++ b/office-alexander-logistics-app/src/main/resources/bundle/custom_en.properties @@ -10,6 +10,8 @@ alexander_sub_positionen_read= alexander_sub_responsible= space.sub_custom=Konfiguration +space.help_custom=Bitte verwenden Sie hier Reguläre Ausdrücke wie z.B. \\bEX-SAL Dieser Ausdruck sucht nach dem Wert "EX-SAL" in einem String und achtet darauf, dass es nicht Teil eines größeren Ausdrucks ist (z.B. "EX-SALES"). + ERROR_INVALID_IBANBIC=Your input of the IBAN/BIC is invalid. Please check your data. diff --git a/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/TestFormat.java b/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/TestFormat.java index e959958..e53106d 100644 --- a/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/TestFormat.java +++ b/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/TestFormat.java @@ -65,11 +65,23 @@ public class TestFormat { if (m.find()) { System.out.println("Ich bin ein Held"); } - - + } + @Test + public void testRegex2() { + String text="R IM-GCA-2210-031"; + String expr="\\bIM-GCA"; + Pattern p = Pattern.compile(expr); + + p = Pattern.compile(expr); + Matcher m = p.matcher(text); + if (m.find()) { + System.out.println("Ich bin ein Held"); + } else { + System.out.println("Ich bin Kein Held"); + } } } diff --git a/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/migration/MigrationSpaceZuordnung.java b/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/migration/MigrationSpaceZuordnung.java new file mode 100644 index 0000000..3db2b83 --- /dev/null +++ b/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/migration/MigrationSpaceZuordnung.java @@ -0,0 +1,178 @@ +package com.alexanderlogistics.migration; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.imixs.melman.FormAuthenticator; +import org.imixs.melman.RestAPIException; +import org.imixs.melman.WorkflowClient; +import org.imixs.workflow.ItemCollection; +import org.imixs.workflow.exceptions.PluginException; +import org.junit.Before; +import org.junit.Test; + +import junit.framework.Assert; + +/** + * Dieser Agent ordnet nachträglich Ausgangsrechnungen aus der Migraiton einem + * Space zu. + * + * @author rsoika + * + */ +public class MigrationSpaceZuordnung { + + WorkflowClient workflowCLient = null; + String user = "archive"; + String ps = "archive4imixs"; + String restAPI = "https://test.alexander-logistics.office-workflow.de/api"; + int countProcessed = 0; + int notFound = 0; + int count = 0; + Map> spacePosMappings=null; + Map spaceNames=null; + + @Before + public void setup() throws PluginException, RestAPIException, UnsupportedEncodingException { + + // Init Workflow Client + workflowCLient = new WorkflowClient(restAPI); + FormAuthenticator formAuth = new FormAuthenticator(restAPI, user, ps); + workflowCLient.registerClientRequestFilter(formAuth); + + + // load spaces Pos Expressions + loadSpacePosMappings(); + + + } + + /** + * Diese methode liest offene Ausgangsrechnungen aus udn prüft of space.ref + * bereits getzt ist. + * + * @throws PluginException + * @throws RestAPIException + * @throws UnsupportedEncodingException + * + */ + @Test + public void anlysiere() throws RestAPIException, PluginException, UnsupportedEncodingException { + + System.out.println("***********************"); + System.out.println("* Update Ausgangsrechnungen Pos-Space Mapping *"); + System.out.println("***********************"); + + int maxCount = 10000; + + String query = "$modelversion:\"rechnungsausgang-de-1.0\" AND type:workitem"; + + int pageSize = 100; + int pageIndex = 0; + while (true) { + workflowCLient.setPageIndex(pageIndex); + workflowCLient.setPageSize(pageSize); + List invoices = workflowCLient.searchDocuments(query); + + + System.out.println("... ich processe " + invoices.size() +" invoices..."); + + // teste space.ref + for (ItemCollection invoice: invoices) { + count++; + boolean update=false; + if (invoice.getItemValueString("space.ref").isEmpty()) { + + // Jezt noch das Space mapping + // dazu kucken wir in alle spaces den config wert 'pos.mapping' + String text = invoice.getItemValueString("invoice.text"); + if (!text.isEmpty()) { + + for (Map.Entry > entry : spacePosMappings.entrySet()) { + List expressionsList=entry.getValue(); + for (String expr : expressionsList) { + + Pattern p = Pattern.compile(expr); + Matcher m = p.matcher(text); + if (m.find()) { + // we have a match + invoice.setItemValue("space.ref", entry.getKey()); + invoice.setItemValue("space.name", spaceNames.get(entry.getKey())); + + update=true; + break; + } + } + if (update) { + break; + } + } + } + } + + if (update) { + // update invioce + System.out.println("...ich update invoice: " + invoice.getUniqueID()); + try { + workflowCLient.saveDocument(invoice); + countProcessed++; + } catch (Exception e) { + e.printStackTrace(); + } + } + + + } + + // fetrig? + if (invoices.size() < pageSize) { + break; + } + if (count>=maxCount) { + break; + } + pageIndex++; + } + + System.out.println("================================================="); + System.out.println("... fininshed - read " + count + " invoices"); + System.out.println(" updated " + countProcessed + " invoices"); + + } + + /** + * Helper method that loads all expressions from the spaces + * + * @return List of list of expressions + * @throws UnsupportedEncodingException + * @throws RestAPIException + */ + private void loadSpacePosMappings() throws RestAPIException, UnsupportedEncodingException { + spacePosMappings = new HashMap<>(); + spaceNames= new HashMap<>(); + // als erstes lesen wir die pos.mappings aus den Spaces ein, auf die dann eine + // Rechnung emapped werden kann. + + List spaces_subs = workflowCLient.searchDocuments("type:space"); + for (ItemCollection space : spaces_subs) { + spacePosMappings.put(space.getUniqueID(), space.getItemValueList("pos.mapping", String.class)); + spaceNames.put(space.getUniqueID(), space.getItemValueString("space.name")); + } + + + } +} diff --git a/office-alexander-logistics-app/src/test/resources/datev/EXTF_OPD_migration_2022-test-1.csv b/office-alexander-logistics-app/src/test/resources/datev/EXTF_OPD_migration_2022-test-1.csv new file mode 100644 index 0000000..e0b7e91 --- /dev/null +++ b/office-alexander-logistics-app/src/test/resources/datev/EXTF_OPD_migration_2022-test-1.csv @@ -0,0 +1,3 @@ +"EXTF";"510";21;"Buchungsstapel";7;"20220721060421653";"";"CS";"cargoservice";"";"";"";"20220101";"4";"20220101";"20221231";"202206ALL";"CS";"";"";0;"EUR";"";"";"";"";"";"";"";"";"" +Umsatz (ohne Soll-/Haben-Kennzeichen);Soll-Haben-Kennzeichen;WKZ Umsatz;Kurs;Basisumsatz;WKZ Basisumsatz;Konto;Gegenkonto;BU-Schlüssel;Belegdatum;Belegfeld 1;Belegfeld 2;Skonto;Buchungstext;Postensperre;Diverse Adressnummer;Geschäftspartnerbank;Sachverhalt;Zinssperre;Beleglink;Beleginfo-Art 1;Beleginfo-Inhalt 1;Beleginfo-Art 2;Beleginfo-Inhalt 2;Beleginfo-Art 3;Beleginfo-Inhalt 3;Beleginfo-Art 4;Beleginfo-Inhalt 4;Beleginfo-Art 5;Beleginfo-Inhalt 5;Beleginfo-Art 6;Beleginfo-Inhalt 6;Beleginfo-Art 7;Beleginfo-Inhalt 7;Beleginfo-Art 8;Beleginfo-Inhalt 8;KOST1-Kostenstelle;KOST2-Kostenstelle;KOST-Menge;EU-Mitgliedstaatu. USt-IdNr.;EU-Steuersatz;Abw. Versteuerungsart;Sachverhalt L+L;Funktionserg�nzung L+L;BU 49 Hauptfunktionstyp;BU 49 Hauptfunktionsnummer;BU 49 Funktionserg�nzung;Zusatzinformation-Art 1;Zusatzinformation-Inhalt 1;Zusatzinformation-Art 2;Zusatzinformation-Inhalt 2;Zusatzinformation-Art 3;Zusatzinformation-Inhalt 3;Zusatzinformation-Art 4;Zusatzinformation-Inhalt 4;Zusatzinformation-Art 5;Zusatzinformation-Inhalt 5;Zusatzinformation-Art 6;Zusatzinformation-Inhalt 6;Zusatzinformation-Art 7;Zusatzinformation-Inhalt 7;Zusatzinformation-Art 8;Zusatzinformation-Inhalt 8;Zusatzinformation-Art 9;Zusatzinformation-Inhalt 9;Zusatzinformation-Art 10;Zusatzinformation-Inhalt 10;Zusatzinformation-Art 11;Zusatzinformation-Inhalt 11;Zusatzinformation-Art 12;Zusatzinformation-Inhalt 12;Zusatzinformation-Art 13;Zusatzinformation-Inhalt 13;Zusatzinformation-Art 14;Zusatzinformation-Inhalt 14;Zusatzinformation-Art 15;Zusatzinformation-Inhalt 15;Zusatzinformation-Art 16;Zusatzinformation-Inhalt 16;Zusatzinformation-Art 17;Zusatzinformation-Inhalt 17;Zusatzinformation-Art 18;Zusatzinformation-Inhalt 18;Zusatzinformation-Art 19;Zusatzinformation-Inhalt 19;Zusatzinformation-Art 20;Zusatzinformation-Inhalt 20;St�ck;Gewicht;Zahlweise;Forderungsart;Veranlagungsjahr;Zugeordnete F�lligkeit;Skontotyp;Auftragsnummer;Buchungstyp;USt-Schl�ssel (Anzahlungen);EU-Mitgliedstaat (Anzahlungen);Sachverhalt L+L (Anzahlungen);EU-Steuersatz (Anzahlungen);Erlöskonto (Anzahlungen);Herkunft-Kz;Leerfeld;KOST-Datum;SEPAMandatsreferenz;Skontosperre;Gesellschaftername;Beteiligtennummer;Identifikationsnummer;Zeichnernummer;Postensperre bis;Bezeichnung SoBil-Sachverhalt;Kennzeichen SoBil-Buchung;Festschreibung;Leistungsdatum;Datum Zuord. Steuerperiode +2810,00;"H";"EUR";0,000000;0,00;;8011;12976;;1410;"183885";;;"R IM-GCA-2210-031";0;;;0;;;;;Faelligkeit;20221113;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/pom.xml b/pom.xml index 101a6dc..89d1cd8 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 2.3.1 2.3.0 - 1.0.20 + 1.0.22 1.1.6-SNAPSHOT 2.2