From 1e5e059ea78e1b4339d05f95cafa79ae6f43bd69 Mon Sep 17 00:00:00 2001
From: "c.wimmer" <c.wimmer@cwimmer-nb.aditosoftware.local>
Date: Mon, 16 Nov 2020 15:42:48 +0100
Subject: [PATCH] [Projekt: Crowd-Development / Besuch vor Ort][TicketNr.:
 1068872][[Bug] Wochenplaneintrag Vorbelegung von Kontakt fehlerhaft]

---
 .../VisitPlanEntry_entity/VisitPlanEntry_entity.aod |  1 -
 .../entityfields/contact_id/valueProcess.js         | 12 +++++++++++-
 .../organisation_contact_id/stateProcess.js         | 10 ----------
 .../organisation_contact_id/valueProcess.js         | 13 ++++++++++++-
 4 files changed, 23 insertions(+), 13 deletions(-)
 delete mode 100644 entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/stateProcess.js

diff --git a/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod b/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
index b640c523a5..e8c7c0ba81 100644
--- a/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
+++ b/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
@@ -36,7 +36,6 @@
       <title>Organisation</title>
       <consumer>Organisations</consumer>
       <mandatory v="true" />
-      <stateProcess>%aditoprj%/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/stateProcess.js</stateProcess>
       <valueProcess>%aditoprj%/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/valueProcess.js</valueProcess>
       <displayValueProcess>%aditoprj%/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/displayValueProcess.js</displayValueProcess>
     </entityField>
diff --git a/entity/VisitPlanEntry_entity/entityfields/contact_id/valueProcess.js b/entity/VisitPlanEntry_entity/entityfields/contact_id/valueProcess.js
index 5862792995..357a962388 100644
--- a/entity/VisitPlanEntry_entity/entityfields/contact_id/valueProcess.js
+++ b/entity/VisitPlanEntry_entity/entityfields/contact_id/valueProcess.js
@@ -1,9 +1,19 @@
+import("Sql_lib");
 import("system.logging");
 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))
-    result.string(vars.get("$param.ContactId_param"));
+{
+    var isPersonContact = newSelect("PERSON.PERSONID").from("PERSON")
+        .join("CONTACT", "PERSON.PERSONID = CONTACT.PERSON_ID")
+        .where("CONTACT.CONTACTID", vars.get("$param.ContactId_param")).cell()
+
+    if(isPersonContact)
+        result.string(vars.get("$param.ContactId_param"));
+}    
 
 
diff --git a/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/stateProcess.js b/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/stateProcess.js
deleted file mode 100644
index 832f94c08c..0000000000
--- a/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/stateProcess.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import("system.logging");
-import("system.neon");
-import("system.result");
-import("system.vars");
-
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value") == null 
-    && vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param"))
-{
-    result.string(neon.COMPONENTSTATE_INVISIBLE);
-}
\ No newline at end of file
diff --git a/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/valueProcess.js b/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/valueProcess.js
index 8e22e5c11f..2b90b66856 100644
--- a/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/valueProcess.js
+++ b/entity/VisitPlanEntry_entity/entityfields/organisation_contact_id/valueProcess.js
@@ -1,3 +1,4 @@
+import("Sql_lib");
 import("system.neon");
 import("system.result");
 import("system.vars");
@@ -5,5 +6,15 @@ import("system.vars");
 if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value") == null 
     && vars.exists("$param.OrganisationId_param") && vars.get("$param.OrganisationId_param"))
 {
-    result.string(vars.get("$param.OrganisationId_param"));
+    
+    var OrgId = newSelect("CONTACT.ORGANISATION_ID").from("CONTACT")
+        .where("CONTACT.CONTACTID", vars.get("$param.OrganisationId_param"))
+        .cell()
+    
+    var contactIdWithoutPerson = newSelect("CONTACT.CONTACTID").from("CONTACT")
+        .where("CONTACT.ORGANISATION_ID", OrgId)
+        .and("CONTACT.PERSON_ID is null")
+        .cell()
+        
+    result.string(contactIdWithoutPerson);
 }
\ No newline at end of file
-- 
GitLab