From db7816750c7e12abb76ac89abf37b24a7f11f430 Mon Sep 17 00:00:00 2001
From: Sebastian Pongratz <s.pongratz@adito.de>
Date: Fri, 8 May 2020 07:37:17 +0000
Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Neon][TicketNr.:?=
 =?UTF-8?q?=201056853][Unverkn=C3=BCpfte=20Mails=20soll=20entfallen=20und?=
 =?UTF-8?q?=20durch=20Aktivit=C3=A4ten=20ausgetauscht=20werden]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 entity/Activity_entity/Activity_entity.aod    | 15 +++++++
 .../entityfields/countlinks/valueProcess.js   |  5 +++
 .../recordcontainers/db/conditionProcess.js   |  6 +++
 .../UniversalFileProcessor_entity.aod         | 14 ++++++
 .../activityids_param/valueProcess.js         |  4 ++
 .../drop_action/onActionProcess.js            | 11 ++++-
 .../_____LANGUAGE_EXTRA.aod                   | 15 +++++++
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     | 13 ++++++
 .../_____LANGUAGE_en/_____LANGUAGE_en.aod     | 15 +++++++
 neonContext/Activity/Activity.aod             |  4 ++
 ...ivityUniversalFileProcessorFilter_view.aod | 45 +++++++++++++++++++
 .../UniversalFileProcessorDropzone_view.aod   |  5 +++
 process/IncomingEmailExecutor_lib/process.js  | 10 +++--
 13 files changed, 156 insertions(+), 6 deletions(-)
 create mode 100644 entity/Activity_entity/entityfields/countlinks/valueProcess.js
 create mode 100644 entity/UniversalFileProcessor_entity/entityfields/activities/children/activityids_param/valueProcess.js
 create mode 100644 neonView/ActivityUniversalFileProcessorFilter_view/ActivityUniversalFileProcessorFilter_view.aod

diff --git a/entity/Activity_entity/Activity_entity.aod b/entity/Activity_entity/Activity_entity.aod
index 8258e93b05..bb17b9fa7f 100644
--- a/entity/Activity_entity/Activity_entity.aod
+++ b/entity/Activity_entity/Activity_entity.aod
@@ -264,6 +264,12 @@
           <fieldName>Activities</fieldName>
           <isConsumer v="false" />
         </entityDependency>
+        <entityDependency>
+          <name>943c36a2-d378-44a1-b214-25e92244c8cb</name>
+          <entityName>UniversalFileProcessor_entity</entityName>
+          <fieldName>Activities</fieldName>
+          <isConsumer v="false" />
+        </entityDependency>
       </dependencies>
       <children>
         <entityParameter>
@@ -595,6 +601,15 @@
       <name>VisitPlanEntryId_param</name>
       <expose v="true" />
     </entityParameter>
+    <entityParameter>
+      <name>ActivityIDs_param</name>
+      <expose v="true" />
+    </entityParameter>
+    <entityField>
+      <name>countLinks</name>
+      <title> number of connections</title>
+      <valueProcess>%aditoprj%/entity/Activity_entity/entityfields/countlinks/valueProcess.js</valueProcess>
+    </entityField>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
diff --git a/entity/Activity_entity/entityfields/countlinks/valueProcess.js b/entity/Activity_entity/entityfields/countlinks/valueProcess.js
new file mode 100644
index 0000000000..fbf4e2585e
--- /dev/null
+++ b/entity/Activity_entity/entityfields/countlinks/valueProcess.js
@@ -0,0 +1,5 @@
+import("system.result");
+import("system.vars");
+import("Sql_lib");
+
+result.string(newSelect("count(*)").from("ACTIVITYLINK").where("ACTIVITYLINK.ACTIVITY_ID", vars.get("$field.ACTIVITYID")).arrayColumn()[0]);
\ No newline at end of file
diff --git a/entity/Activity_entity/recordcontainers/db/conditionProcess.js b/entity/Activity_entity/recordcontainers/db/conditionProcess.js
index a90c77ea69..fe77ebfa1d 100644
--- a/entity/Activity_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Activity_entity/recordcontainers/db/conditionProcess.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("Employee_lib");
 import("system.vars");
 import("system.db");
@@ -40,6 +41,11 @@ if(vars.getString("$param.OnlyInnate_param") == "true")
         loadNothing = true;
 }
 
+if (vars.exists("$param.ActivityIDs_param") && vars.get("$param.ActivityIDs_param")) {
+    var acticityIDs = JSON.parse(vars.get("$param.ActivityIDs_param"));
+    cond.and("ACTIVITY.ACTIVITYID",acticityIDs , SqlBuilder.IN());
+}
+
 if (loadNothing)
 {
     resCond = "1 = 2";
diff --git a/entity/UniversalFileProcessor_entity/UniversalFileProcessor_entity.aod b/entity/UniversalFileProcessor_entity/UniversalFileProcessor_entity.aod
index 85dbe914eb..b46af9a58f 100644
--- a/entity/UniversalFileProcessor_entity/UniversalFileProcessor_entity.aod
+++ b/entity/UniversalFileProcessor_entity/UniversalFileProcessor_entity.aod
@@ -22,5 +22,19 @@
       <name>category_param</name>
       <expose v="true" />
     </entityParameter>
+    <entityConsumer>
+      <name>Activities</name>
+      <dependency>
+        <name>dependency</name>
+        <entityName>Activity_entity</entityName>
+        <fieldName>LinkedObjects</fieldName>
+      </dependency>
+      <children>
+        <entityParameter>
+          <name>ActivityIDs_param</name>
+          <valueProcess>%aditoprj%/entity/UniversalFileProcessor_entity/entityfields/activities/children/activityids_param/valueProcess.js</valueProcess>
+        </entityParameter>
+      </children>
+    </entityConsumer>
   </entityFields>
 </entity>
diff --git a/entity/UniversalFileProcessor_entity/entityfields/activities/children/activityids_param/valueProcess.js b/entity/UniversalFileProcessor_entity/entityfields/activities/children/activityids_param/valueProcess.js
new file mode 100644
index 0000000000..826d12e6b5
--- /dev/null
+++ b/entity/UniversalFileProcessor_entity/entityfields/activities/children/activityids_param/valueProcess.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("system.result");
+
+result.string(vars.exists("$global.ACTIVITY_IDS")? vars.get("$global.ACTIVITY_IDS"):"[]");
\ No newline at end of file
diff --git a/entity/UniversalFileProcessor_entity/entityfields/drop_action/onActionProcess.js b/entity/UniversalFileProcessor_entity/entityfields/drop_action/onActionProcess.js
index b538d551ae..f72044a7c9 100644
--- a/entity/UniversalFileProcessor_entity/entityfields/drop_action/onActionProcess.js
+++ b/entity/UniversalFileProcessor_entity/entityfields/drop_action/onActionProcess.js
@@ -17,6 +17,7 @@ var status = {
     otherImportedFiles: 0,
     skippedFiles: 0
 };
+var activityIDs = [];
 
 for (var i = 0, l = files.length; i < l; i++) 
 {
@@ -34,12 +35,16 @@ for (var i = 0, l = files.length; i < l; i++)
                 var incomingMailExec = new IncomingEmailExecutor(mailObj);
                 incomingMailExec.setAlias(dbAlias);
                 var mailImportResult = incomingMailExec.autoProcess()
-                if (mailImportResult.activityId)
+                if ((!mailImportResult.unlinkedMailId) && mailImportResult.activityId)
                     status.activitiesCreated++;
-                else if (mailImportResult.unlinkedMailId)
+                else if (mailImportResult.unlinkedMailId && mailImportResult.activityId)
                     status.unlinkedMailsCreated++;
                 else
                     status.skippedFiles++;
+                
+                if (mailImportResult.activityId){
+                    activityIDs.push(mailImportResult.activityId);
+                }
             }
             else
                 status.skippedFiles++;
@@ -50,6 +55,8 @@ for (var i = 0, l = files.length; i < l; i++)
     }
 }
 
+vars.set("$global.ACTIVITY_IDS", JSON.stringify(activityIDs)); //TODO: Änderung auf andere Variable #1057014
+
 if (status.activitiesCreated > 0 || status.unlinkedMailsCreated > 0 || status.otherImportedFiles > 0)
     neon.refreshAll();//this is needed for the dashboard: other elements are refreshed and display for example unlinkedMails
 
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index b3dae9683d..fe27631e36 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -6653,6 +6653,9 @@
     <entry>
       <key>Leadimport Reset</key>
     </entry>
+    <entry>
+      <key>Offer status changed!</key>
+    </entry>
     <entry>
       <key>Möchten Sie den Import abbrechen?</key>
     </entry>
@@ -6716,6 +6719,18 @@
     <entry>
       <key>New Visit Recommendation</key>
     </entry>
+    <entry>
+      <key>Set salesproject phase</key>
+    </entry>
+    <entry>
+      <key>Create salesproject</key>
+    </entry>
+    <entry>
+      <key> number of connections</key>
+    </entry>
+    <entry>
+      <key>Create salesproject touchpoint</key>
+    </entry>
     <entry>
       <key>Limited details</key>
     </entry>
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index a86202bad8..a06d484d4b 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -8588,6 +8588,19 @@ Bitte Datumseingabe prüfen</value>
     <entry>
       <key>Abomodel</key>
     </entry>
+    <entry>
+      <key>Set salesproject phase</key>
+    </entry>
+    <entry>
+      <key>Create salesproject</key>
+    </entry>
+    <entry>
+      <key> number of connections</key>
+      <value>Anzahl Verknüpfungen</value>
+    </entry>
+    <entry>
+      <key>Create salesproject touchpoint</key>
+    </entry>
     <entry>
       <key>Limited details</key>
       <value>Eingeschränkte Details</value>
diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
index bf4c766385..fd3c8a7f0d 100644
--- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
+++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
@@ -6706,6 +6706,9 @@
     <entry>
       <key>Leadimport Reset</key>
     </entry>
+    <entry>
+      <key>Offer status changed!</key>
+    </entry>
     <entry>
       <key>Möchten Sie den Import abbrechen?</key>
     </entry>
@@ -6772,6 +6775,18 @@
     <entry>
       <key>ankle of</key>
     </entry>
+    <entry>
+      <key>Set salesproject phase</key>
+    </entry>
+    <entry>
+      <key>Create salesproject</key>
+    </entry>
+    <entry>
+      <key> number of connections</key>
+    </entry>
+    <entry>
+      <key>Create salesproject touchpoint</key>
+    </entry>
     <entry>
       <key>Visit Planning</key>
     </entry>
diff --git a/neonContext/Activity/Activity.aod b/neonContext/Activity/Activity.aod
index ab6c658846..a1422e41f5 100644
--- a/neonContext/Activity/Activity.aod
+++ b/neonContext/Activity/Activity.aod
@@ -37,5 +37,9 @@
       <name>3884f349-be09-47bd-8930-47e0697d658f</name>
       <view>ActivityMultiEdit_view</view>
     </neonViewReference>
+    <neonViewReference>
+      <name>01feb10a-34d2-4ef3-b87b-a1e35a4b12e0</name>
+      <view>ActivityUniversalFileProcessorFilter_view</view>
+    </neonViewReference>
   </references>
 </neonContext>
diff --git a/neonView/ActivityUniversalFileProcessorFilter_view/ActivityUniversalFileProcessorFilter_view.aod b/neonView/ActivityUniversalFileProcessorFilter_view/ActivityUniversalFileProcessorFilter_view.aod
new file mode 100644
index 0000000000..a40577f24e
--- /dev/null
+++ b/neonView/ActivityUniversalFileProcessorFilter_view/ActivityUniversalFileProcessorFilter_view.aod
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.6" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.6">
+  <name>ActivityUniversalFileProcessorFilter_view</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <groupLayout>
+      <name>layout</name>
+    </groupLayout>
+  </layout>
+  <children>
+    <tableViewTemplate>
+      <name>ActivityUniversalFileProcessorFilterTable</name>
+      <iconField>#IMAGE</iconField>
+      <titleField>SUBJECT</titleField>
+      <subtitleField>ENTRYDAY</subtitleField>
+      <descriptionField>DIRECTION</descriptionField>
+      <entityField>#ENTITY</entityField>
+      <linkedColumns>
+        <element>SUBJECT</element>
+      </linkedColumns>
+      <columns>
+        <neonTableColumn>
+          <name>d97147cc-cbdc-4eab-99b3-8c6fd092329d</name>
+          <entityField>entryDateDateFormat</entityField>
+        </neonTableColumn>
+        <neonTableColumn>
+          <name>030dcd56-6f13-4f93-b37e-7ebb4eaa4b70</name>
+          <entityField>countLinks</entityField>
+        </neonTableColumn>
+        <neonTableColumn>
+          <name>fa2cad56-c55d-48c9-b77c-5741b7299131</name>
+          <entityField>RESPONSIBLE</entityField>
+        </neonTableColumn>
+        <neonTableColumn>
+          <name>4505af54-c491-4f59-a5b7-ae93718baa70</name>
+          <entityField>SUBJECT</entityField>
+        </neonTableColumn>
+        <neonTableColumn>
+          <name>a32a87b0-79ed-4774-9331-a814298c4ee8</name>
+          <entityField>INFO</entityField>
+        </neonTableColumn>
+      </columns>
+    </tableViewTemplate>
+  </children>
+</neonView>
diff --git a/neonView/UniversalFileProcessorDropzone_view/UniversalFileProcessorDropzone_view.aod b/neonView/UniversalFileProcessorDropzone_view/UniversalFileProcessorDropzone_view.aod
index 15a8687076..8072435ed1 100644
--- a/neonView/UniversalFileProcessorDropzone_view/UniversalFileProcessorDropzone_view.aod
+++ b/neonView/UniversalFileProcessorDropzone_view/UniversalFileProcessorDropzone_view.aod
@@ -37,5 +37,10 @@
       <descriptionField>INFO</descriptionField>
       <entityField>#ENTITY</entityField>
     </dragAndDropViewTemplate>
+    <neonViewReference>
+      <name>9cddaca9-6c6a-426c-90f1-54f6d21305d4</name>
+      <entityField>Activities</entityField>
+      <view>ActivityUniversalFileProcessorFilter_view</view>
+    </neonViewReference>
   </children>
 </neonView>
diff --git a/process/IncomingEmailExecutor_lib/process.js b/process/IncomingEmailExecutor_lib/process.js
index ce4cbed279..6841b19deb 100644
--- a/process/IncomingEmailExecutor_lib/process.js
+++ b/process/IncomingEmailExecutor_lib/process.js
@@ -71,6 +71,7 @@ IncomingEmailExecutor.prototype.setActivityEmployeeContact = function (pContactI
     else
     {
         this.activityData.employeeContactId = pContactId;
+        this.activityData.links.push(["Person", pContactId]);
         this.activityData.employeeContactLanguage = pLanguageIso3;
     }
 }
@@ -198,7 +199,7 @@ IncomingEmailExecutor.prototype.createActivity = function(pAdditionalLinks)
     activityLinks = ArrayUtils.distinct2d(activityLinks);//TODO: better check before adding the elements into the array if it already exists there
     var activityDocs = [["mail.eml", util.encodeBase64String(mail.toRFC(this.rawMail)), true]];
     
-    var activityRes = ActivityUtils.insertNewActivity(activityDataForInsert, activityLinks, activityDocs, this._alias);
+    var activityRes = ActivityUtils.insertNewActivity(activityDataForInsert, activityLinks, activityDocs, this._alias, this.mailSentDate);
     return activityRes;
 }
 
@@ -210,6 +211,7 @@ IncomingEmailExecutor.prototype.deleteUnlinkedMail = function (pUnlinkedMailId)
 
 IncomingEmailExecutor.prototype.autoProcess = function(pUnlinkedMailId)
 {
+    let tempResult = {};
     if (this.isUnlinkable())
     {
         if (pUnlinkedMailId)
@@ -217,12 +219,12 @@ IncomingEmailExecutor.prototype.autoProcess = function(pUnlinkedMailId)
                 unlinkedMailId: pUnlinkedMailId
             };
         else
-            return this.insertUnlinkedMail();
+            tempResult.unlinkedMailId = this.insertUnlinkedMail();
     }
 
-    var activityRes = this.createActivity();
+    tempResult.activityId = this.createActivity().activityId;
     this.deleteUnlinkedMail(pUnlinkedMailId);
-    return activityRes;
+    return tempResult;
 }
 
 IncomingEmailExecutor.prototype._getProcessingFunction = function (pIsSender, pTargetArray)
-- 
GitLab