From 0cbf4b2d3ee5831cc1a68307ae9add67c64356e8 Mon Sep 17 00:00:00 2001
From: Carolin Wimmer <c.wimmer@adito.de>
Date: Wed, 11 Nov 2020 10:19:52 +0100
Subject: [PATCH] =?UTF-8?q?[Projekt:=20Crowd-Development=20/=20Besuch=20vo?=
 =?UTF-8?q?r=20Ort][TicketNr.:=201066742][[aus=20Schmalz]=20Besuchsvorschl?=
 =?UTF-8?q?ags-Logik=20unter=20Ber=C3=BCcksichtigung=20bereits=20erfolgter?=
 =?UTF-8?q?=20Aktivit=C3=A4ten]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../recordcontainers/db/onDBInsert.js              |  4 ++--
 .../VisitRecommendation_entity.aod                 |  2 +-
 .../entityfields/contact_id/valueProcess.js        |  2 +-
 .../recordcontainers/jdito/contentProcess.js       | 14 +++++++++++---
 .../recordcontainers/jdito/onInsert.js             |  3 +--
 .../recordcontainers/jdito/onUpdate.js             |  1 +
 6 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/entity/Activity_entity/recordcontainers/db/onDBInsert.js b/entity/Activity_entity/recordcontainers/db/onDBInsert.js
index 488c561a6ef..03ba2693c5c 100644
--- a/entity/Activity_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/Activity_entity/recordcontainers/db/onDBInsert.js
@@ -32,8 +32,8 @@ if(vars.exists("$param.VisitPlanEntryId_param") && vars.get("$param.VisitPlanEnt
                             .updateData(true, "VISITPLANENTRY", columns, null, values);
                             
     var recommendationId = newSelect("VISITPLANENTRY.VISITRECOMMENDATION_ID").from("VISITPLANENTRY").where("VISITPLANENTRY.VISITPLANENTRYID", vars.get("$param.VisitPlanEntryId_param"))
-    var updateRecommendation = newWhere("VISITRECOMMENDATION.VISITRECOMMENDATIONID", recommendationId)
-                                .updateData(true, "VISITRECOMMENDATION", ["STATUS"], null, [$KeywordRegistry.visitPlanEntryStatus$Visitreportcreated()])
+    
+    newWhere("VISITRECOMMENDATION.VISITRECOMMENDATIONID", recommendationId).deleteData(true, "VISITRECOMMENDATION");
 }
 
 if (vars.exists("$param.InsertLinks_param") && vars.get("$param.InsertLinks_param"))
diff --git a/entity/VisitRecommendation_entity/VisitRecommendation_entity.aod b/entity/VisitRecommendation_entity/VisitRecommendation_entity.aod
index 10c06c68da9..3ee0de7653f 100644
--- a/entity/VisitRecommendation_entity/VisitRecommendation_entity.aod
+++ b/entity/VisitRecommendation_entity/VisitRecommendation_entity.aod
@@ -68,7 +68,7 @@
       <name>DUE_DATE</name>
       <title>Due Date</title>
       <contentType>DATE</contentType>
-      <resolution>MINUTE</resolution>
+      <resolution>DAY</resolution>
       <outputFormat>dd.MM.yyyy</outputFormat>
       <inputFormat>dd.MM.yyyy</inputFormat>
       <groupable v="true" />
diff --git a/entity/VisitRecommendation_entity/entityfields/contact_id/valueProcess.js b/entity/VisitRecommendation_entity/entityfields/contact_id/valueProcess.js
index 683ba24292b..f816ac54f7e 100644
--- a/entity/VisitRecommendation_entity/entityfields/contact_id/valueProcess.js
+++ b/entity/VisitRecommendation_entity/entityfields/contact_id/valueProcess.js
@@ -3,5 +3,5 @@ import("system.neon");
 import("system.result");
 import("system.vars");
 
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && (vars.get("$this.value") == null || vars.get("$this.value") == undefined))
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value") == null)
     result.string(vars.get("$param.ContactId_param"));
\ No newline at end of file
diff --git a/entity/VisitRecommendation_entity/recordcontainers/jdito/contentProcess.js b/entity/VisitRecommendation_entity/recordcontainers/jdito/contentProcess.js
index 2bce193407b..81f33468c7c 100644
--- a/entity/VisitRecommendation_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/VisitRecommendation_entity/recordcontainers/jdito/contentProcess.js
@@ -182,13 +182,21 @@ if(idValues == false)
             "" //RESPONSIBLE.value
         ];
         
-        var manualRec = newSelect("STATUS")
+        var manualRec = newSelect("VISITRECOMMENDATION.VISITRECOMMENDATIONID")
         .from("VISITRECOMMENDATION")
         .where("VISITRECOMMENDATION.CONTACT_ID", tmpData[0])
         .or("VISITRECOMMENDATION.CONTACT_PERSON_ID", tmpData[0])
         .cell()
-
-        if(manualRec == "VISITSTATUSREPORTCREATED            ")
+        
+        var visitEntry = newSelect("VISITPLANENTRY.VISITPLANENTRYID")
+        .from("VISITPLANENTRY")
+        .where(newWhere("VISITPLANENTRY.CONTACT_ID", tmpData[0])
+            .or("VISITPLANENTRY.ORGANISATION_CONTACT_ID", tmpData[0]))
+        .and(newWhere("VISITPLANENTRY.ENTRYDATE", eMath.subInt(vars.get("$sys.today"), datetime.ONE_DAY * 7), SqlBuilder.LESS_OR_EQUAL())
+            .and("VISITPLANENTRY.STATUS", $KeywordRegistry.visitPlanEntryStatus$Visitreportcreated(), SqlBuilder.NOT_EQUAL()))
+            .cell();
+        
+        if(!manualRec || visitEntry)
             recommendationData.push(tmpData);
     }
 }
diff --git a/entity/VisitRecommendation_entity/recordcontainers/jdito/onInsert.js b/entity/VisitRecommendation_entity/recordcontainers/jdito/onInsert.js
index 7854dbf79c7..39eb6a4365c 100644
--- a/entity/VisitRecommendation_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/VisitRecommendation_entity/recordcontainers/jdito/onInsert.js
@@ -3,12 +3,11 @@ import("system.db");
 import("system.vars");
 
 var rowData = vars.get("$local.rowdata");
-var contact_id = rowData["CONTACT_ID.value"];
 var source = $KeywordRegistry.visitRecommendationPrioSource$manual();
 
 var values = [
     rowData["UID.value"],
-    contact_id,
+    rowData["CONTACT_ID.value"],
     rowData["DUE_DATE.value"],
     rowData["PRIORITY.value"],
     source,
diff --git a/entity/VisitRecommendation_entity/recordcontainers/jdito/onUpdate.js b/entity/VisitRecommendation_entity/recordcontainers/jdito/onUpdate.js
index 8d745ec1463..bf266e7b778 100644
--- a/entity/VisitRecommendation_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/VisitRecommendation_entity/recordcontainers/jdito/onUpdate.js
@@ -5,6 +5,7 @@ import("system.vars");
 var rowdata = vars.get("$local.rowdata");
 var dbFields = {
     "ORGANISATION_NAME.value": "ORGANISATION_NAME",
+    "CONTACT_ID.value": "CONTACT_ID",
     "ORGANISATION_POINT_OF_CONTACT.value": "ORGANISATION_POINT_OF_CONTACT",
     "ORGANISATION_ADDRESS.value" : "ORGANISATION_ADDRESS",
     "PRIORITY.value" : "PRIORITY",
-- 
GitLab