From 49c62814a990f138db52c48c0870f3c564916402 Mon Sep 17 00:00:00 2001
From: Benjamin Ulrich <b.ulrich@adito.de>
Date: Wed, 29 Sep 2021 14:39:40 +0000
Subject: [PATCH] [Projekt: xRM-Sales][TicketNr.: 2000786][Bearbeiter der
 Aufgabe nach Vertagt + Verantwortlicher checklisteneintrag]

---
 .../objectrowid_param/valueProcess.js         |  1 -
 .../recordcontainers/db/onDBUpdate.js         |  2 +-
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     |  4 ++
 process/ActivityTask_lib/process.js           |  9 ++++-
 .../ChecklistEntryRegistry_basic/process.js   | 40 +++++++++++--------
 5 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/entity/Salesproject_entity/entityfields/checklistentryvalues/children/objectrowid_param/valueProcess.js b/entity/Salesproject_entity/entityfields/checklistentryvalues/children/objectrowid_param/valueProcess.js
index 35c86fce60..c8150fdcd5 100644
--- a/entity/Salesproject_entity/entityfields/checklistentryvalues/children/objectrowid_param/valueProcess.js
+++ b/entity/Salesproject_entity/entityfields/checklistentryvalues/children/objectrowid_param/valueProcess.js
@@ -1,5 +1,4 @@
 import("system.result");
 import("system.vars");
 
-
 result.string(vars.get("$field.SALESPROJECTID"));
\ No newline at end of file
diff --git a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
index 98e485c0fb..61aa43cba4 100644
--- a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
@@ -90,7 +90,7 @@ vars.get("$local.changed").forEach(function(fieldName) {
                                                 , "progress": $KeywordRegistry.taskProgress$0()
                                                 , "status": $KeywordRegistry.taskStatus$assigned()
                                                 , "protectionlevel": "0"
-                                                }, [["Salesproject", vars.getString("$local.uid")]]);
+                                                , "attendees": [contactId]}, [["Salesproject", vars.getString("$local.uid")]]);
 
      
                 // ask if forecast should be cleared. Else reset to old value.
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index 2751e87f90..dbd16e49ae 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -145,6 +145,10 @@
       <key>Open Visitrecommendation</key>
       <value>Offener Besuchsvorschlag</value>
     </entry>
+    <entry>
+      <key>Sales project responsibility set</key>
+      <value>Vertriebsprojekt Verantwortlichen gesetzt</value>
+    </entry>
     <entry>
       <key>Number of openers</key>
       <value>Anzahl Openers</value>
diff --git a/process/ActivityTask_lib/process.js b/process/ActivityTask_lib/process.js
index 722d202ca0..7013700616 100644
--- a/process/ActivityTask_lib/process.js
+++ b/process/ActivityTask_lib/process.js
@@ -885,6 +885,7 @@ TaskUtils.createNewTaskSilent = function(pDataPreset, pTaskLinks, pDbAlias)
     var taskId = dataPreset.taskId || util.getNewUUID();
     var startDate = dataPreset.startDate || datetime.date();
     var marturityDate = dataPreset.marturityDate || marturityDate;
+    var attendees = dataPreset.attendees || [];
     
     var fieldValues = {
         "TASKID": taskId
@@ -917,7 +918,7 @@ TaskUtils.createNewTaskSilent = function(pDataPreset, pTaskLinks, pDbAlias)
     
     if (pTaskLinks)
     {
-        for (var i = 0, l = pTaskLinks.length; i < l; i++)
+        for (let i = 0, l = pTaskLinks.length; i < l; i++)
         {
             insertStatements.push(new SqlBuilder().buildInsertStatement({"TASKLINKID": util.getNewUUID()
                                                                         , "TASK_ID": taskId
@@ -925,6 +926,12 @@ TaskUtils.createNewTaskSilent = function(pDataPreset, pTaskLinks, pDbAlias)
                                                                         , "OBJECT_ROWID": pTaskLinks[i][1]}, "TASKLINK"));
         }
     }
+    for (let i = 0; i < attendees.length; i++)
+    {
+        insertStatements.push(new SqlBuilder().buildInsertStatement({"TASKATTENDEESID": util.getNewUUID()
+                                                                        , "TASK_ID": taskId
+                                                                        , "CONTACT_ID": attendees[i]}, "TASKATTENDEES"));
+    }
     
     db.execute(insertStatements, dbAlias);
 
diff --git a/process/ChecklistEntryRegistry_basic/process.js b/process/ChecklistEntryRegistry_basic/process.js
index 9cf5b604d5..14505ec309 100644
--- a/process/ChecklistEntryRegistry_basic/process.js
+++ b/process/ChecklistEntryRegistry_basic/process.js
@@ -168,7 +168,7 @@ $ChecklistEntryRegistry.salesprojectVolume = function(){
         verifierFn: function(pSalesprojectId){
             
             var spRows = $ChecklistEntryRegistry._getRows(pSalesprojectId, "Salesproject_entity", ["VOLUME"], null, "NoPhaseRequirementLoading");
-            if(spRows[0]["VOLUME"] && spRows[0]["VOLUME"] != "") 
+            if(spRows && spRows[0] && spRows[0]["VOLUME"] && spRows[0]["VOLUME"] != "") 
             {
                 return true;
             }
@@ -189,7 +189,7 @@ $ChecklistEntryRegistry.salesprojectProjStart = function(){
         verifierFn: function(pSalesprojectId){
             
             var spRows = $ChecklistEntryRegistry._getRows(pSalesprojectId, "Salesproject_entity", ["STARTDATE"], null, "NoPhaseRequirementLoading");
-            if(spRows[0]["STARTDATE"] && spRows[0]["STARTDATE"] != "") 
+            if(spRows && spRows[0] && spRows[0]["STARTDATE"] && spRows[0]["STARTDATE"] != "") 
             {
                 return true;
             }
@@ -406,7 +406,7 @@ $ChecklistEntryRegistry.salesprojectStatusWon = function(){
         verifierFn: function(pSalesprojectId){
             
             var spRows = $ChecklistEntryRegistry._getRows(pSalesprojectId, "Salesproject_entity", ["STATUS"], null, "NoPhaseRequirementLoading");
-            if(spRows[0]["STATUS"] && (spRows[0]["STATUS"] == $KeywordRegistry.salesprojectState$partialOrder() ||
+            if(spRows && spRows[0] && spRows[0]["STATUS"] && (spRows[0]["STATUS"] == $KeywordRegistry.salesprojectState$partialOrder() ||
                     spRows[0]["STATUS"] == $KeywordRegistry.salesprojectState$order())) 
             {
                 return true;
@@ -452,21 +452,28 @@ $ChecklistEntryRegistry.salesprojectRoleProjectteam = function(){
         title: translate.text("Project team"),
         verifierFn: function(pSalesprojectId){
             var spRows = $ChecklistEntryRegistry._getRows(pSalesprojectId, "Salesproject_entity", ["SALESPROJECTID", "MST_TEAM_ID", "PROJECTCODE"], null, "NoPhaseRequirementLoading");
-            var memberRows = $ChecklistEntryRegistry._getRows(null, "Member_entity", ["MEMBERROLE"], [["EnableMSTeams_param", spRows[0]["MST_TEAM_ID"]], 
-                                                                    ["ObjectRowId_param", spRows[0]["SALESPROJECTID"]]], "WithDistrictResponsibles");
-            var roles = ["MEMROLEINITIATOR", "MEMROLEDECISIONMAKER", "MEMROLEADVISE", "MEMROLEUSER", "MEMROLEEXSALEMANAG"];
-            var halfLength = Math.floor(roles.length / 2);
-            
-            for (let i = 0; i < memberRows.length; i++) 
+            if(spRows && spRows.length > 0)
             {
-                var role = memberRows[i]["MEMBERROLE"];
-                var index = roles.indexOf(role);
-                if (index !== -1)
+                var memberRows = $ChecklistEntryRegistry._getRows(null, "Member_entity", ["MEMBERROLE"], [["EnableMSTeams_param", spRows[0]["MST_TEAM_ID"]], 
+                                                                        ["ObjectRowId_param", spRows[0]["SALESPROJECTID"]]], "WithDistrictResponsibles");
+                var roles = ["MEMROLEINITIATOR", "MEMROLEDECISIONMAKER", "MEMROLEADVISE", "MEMROLEUSER", "MEMROLEEXSALEMANAG"];
+                var halfLength = Math.floor(roles.length / 2);
+
+                for (let i = 0; i < memberRows.length; i++) 
                 {
-                    roles.splice(index, 1);
+                    var role = memberRows[i]["MEMBERROLE"];
+                    var index = roles.indexOf(role);
+                    if (index !== -1)
+                    {
+                        roles.splice(index, 1);
+                    }
                 }
+                return roles.length <= halfLength;
+            }
+            else
+            {
+                return false;
             }
-            return roles.length <= halfLength;
         }
     };
 }
@@ -667,12 +674,13 @@ $ChecklistEntryRegistry.filter = function(){
  */
 $ChecklistEntryRegistry.salesprojectResponsible = function(){
     return{
-        title: translate.text("Sales project responibility set"),
+        context: ["Salesproject"],
+        title: translate.text("Sales project responsibility set"),
         verifierFn: function(pSalesprojectId){
             var memberRows = $ChecklistEntryRegistry._getRows(null, "Member_entity", ["RESPONSIBLE"], [["EnableMSTeams_param", ""], 
                                                                     ["ObjectRowId_param", pSalesprojectId]], "WithDistrictResponsibles");
             
-            memberRows.some(function (row) { return row["RESPONSIBLE"] == 1; });
+            return memberRows.some(function (row) { return Utils.toBoolean(row["RESPONSIBLE"]); });
         }
     };
 }
\ No newline at end of file
-- 
GitLab