From 121abf0208f43114c61bbfc8c686634c82199a43 Mon Sep 17 00:00:00 2001
From: Daniel Tran <d.tran@adito.de>
Date: Thu, 8 Apr 2021 10:13:44 +0000
Subject: [PATCH] [Projekt: xRM-ContactManagement][TicketNr.:
 1077138][Firma/Kontakt - neuer Termin Fehlermeldung] - Removed useless
 vars.exist.

---
 .../recordcontainers/jdito/contentProcess.js       |  4 ++--
 entity/Organisation_entity/Organisation_entity.aod |  1 +
 entity/Person_entity/Person_entity.aod             |  1 +
 .../VisitPlanEntry_entity.aod                      |  2 +-
 entity/VisitPlanEntry_entity/afterSave.js          | 14 +++++++-------
 .../children/newappointment/onActionProcess.js     |  1 +
 process/Calendar_lib/process.js                    |  2 +-
 7 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/entity/Appointment_entity/recordcontainers/jdito/contentProcess.js b/entity/Appointment_entity/recordcontainers/jdito/contentProcess.js
index 709bfac8d0..9e3b631b9d 100644
--- a/entity/Appointment_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Appointment_entity/recordcontainers/jdito/contentProcess.js
@@ -18,12 +18,12 @@ var appointmentUids;
 /**
  * Will be used, if the user is operating the calendar.
  */
-if(vars.exists("$param.Entry_param") && vars.get("$param.Entry_param"))
+if(vars.get("$param.Entry_param"))
 {
     var entry = JSON.parse(vars.getString("$param.Entry_param"));
 
     var masterEntry = null;
-    if (vars.exists("$param.MasterEntry_param") && vars.get("$param.MasterEntry_param") != "") {
+    if (vars.get("$param.MasterEntry_param") != "") {
         masterEntry = JSON.parse(vars.getString("$param.MasterEntry_param"));
     }
 
diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod
index a1c9dc5748..94a9a3b2fd 100644
--- a/entity/Organisation_entity/Organisation_entity.aod
+++ b/entity/Organisation_entity/Organisation_entity.aod
@@ -1418,6 +1418,7 @@
       <title>New appointment</title>
       <onActionProcess>%aditoprj%/entity/Organisation_entity/entityfields/newappointment/onActionProcess.js</onActionProcess>
       <iconId>VAADIN:CALENDAR</iconId>
+      <state>INVISIBLE</state>
       <stateProcess>%aditoprj%/entity/Organisation_entity/entityfields/newappointment/stateProcess.js</stateProcess>
       <tooltip>New Appointment</tooltip>
     </entityActionField>
diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod
index f294673d39..e4191e1d78 100644
--- a/entity/Person_entity/Person_entity.aod
+++ b/entity/Person_entity/Person_entity.aod
@@ -1453,6 +1453,7 @@
       <title>New appointment</title>
       <onActionProcess>%aditoprj%/entity/Person_entity/entityfields/newappointment/onActionProcess.js</onActionProcess>
       <iconId>VAADIN:CALENDAR</iconId>
+      <state>INVISIBLE</state>
       <stateProcess>%aditoprj%/entity/Person_entity/entityfields/newappointment/stateProcess.js</stateProcess>
       <tooltip>New Appointment</tooltip>
     </entityActionField>
diff --git a/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod b/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
index acc3d4d6af..28198aeea3 100644
--- a/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
+++ b/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
@@ -111,7 +111,7 @@
           <title>New Appointment</title>
           <onActionProcess>%aditoprj%/entity/VisitPlanEntry_entity/entityfields/entityactiongroup/children/newappointment/onActionProcess.js</onActionProcess>
           <iconId>VAADIN:CALENDAR</iconId>
-          <state>EDITABLE</state>
+          <state>INVISIBLE</state>
           <stateProcess>%aditoprj%/entity/VisitPlanEntry_entity/entityfields/entityactiongroup/children/newappointment/stateProcess.js</stateProcess>
           <tooltip>Create new Appointment</tooltip>
           <tooltipProcess>%aditoprj%/entity/VisitPlanEntry_entity/entityfields/entityactiongroup/children/newappointment/tooltipProcess.js</tooltipProcess>
diff --git a/entity/VisitPlanEntry_entity/afterSave.js b/entity/VisitPlanEntry_entity/afterSave.js
index a244a88b30..fb0d5e8e2f 100644
--- a/entity/VisitPlanEntry_entity/afterSave.js
+++ b/entity/VisitPlanEntry_entity/afterSave.js
@@ -26,11 +26,12 @@ if(savedData["STATUS_APPOINTMENT"] == "VISITSTATUSAPPOINTMENTCONFIRMED")
     var description = savedData["CONTACT_ID.displayValue"];
     var standardMail = CommUtil.getStandardMail(savedData["CONTACT_ID"]); 
     
-    var entryDate = datetime.toLocaleDate(savedData["ENTRYDATE"], "dd-MM-yyyy");
-    var startTime = entryDate + " " + datetime.toLocaleDate(savedData["BEGIN_TIME"], "HH:mm:ss.S");
-        startTime = datetime.toLong(startTime, "dd-MM-yyyy HH:mm:ss.S", "UTC"); // #1076044 set tz to prevent time gaps.
-    var endTime = savedData["END_TIME"];
-    var duration = eMath.subInt(endTime, startTime);
+    //1077138, 1074419 customized code to match, new CalendarUtil.createEntry()/newSilentEvent() and work without misbehaviour.
+    var entryDateLocalTime = parseInt(datetime.toLong(datetime.toLocaleDate(parseInt(savedData["ENTRYDATE"]), "dd-MM-yyyy"), "dd-MM-yyyy", 
+                                                                                        vars.get("$sys.timezone")));
+
+    var start = new Date(entryDateLocalTime+Number(savedData["BEGIN_TIME"]));
+    var end = new Date(entryDateLocalTime+Number(savedData["END_TIME"]));
     
     var links = [
         {
@@ -45,8 +46,7 @@ if(savedData["STATUS_APPOINTMENT"] == "VISITSTATUSAPPOINTMENTCONFIRMED")
     
     var params = {
         "Entry_param" : JSON.stringify(CalendarUtil.createEntry(summary, description, links, undefined, undefined, 
-                                            Date(Date.toExponential(startTime)), Date(Date.toExponential(endTime)), 
-                                            undefined, undefined, undefined, [standardMail], undefined, undefined, undefined))
+                                            start, end, undefined, undefined, undefined, [standardMail], undefined, undefined, undefined))
     };
     
     neon.openContext("Appointment", "AppointmentEdit_view", [vars.get("$field.UID")], neon.OPERATINGSTATE_NEW, params, null);
diff --git a/entity/VisitPlanEntry_entity/entityfields/entityactiongroup/children/newappointment/onActionProcess.js b/entity/VisitPlanEntry_entity/entityfields/entityactiongroup/children/newappointment/onActionProcess.js
index b760e1613d..e4ce657061 100644
--- a/entity/VisitPlanEntry_entity/entityfields/entityactiongroup/children/newappointment/onActionProcess.js
+++ b/entity/VisitPlanEntry_entity/entityfields/entityactiongroup/children/newappointment/onActionProcess.js
@@ -25,6 +25,7 @@ var summary = translate.text("Site visit") + " || " + fullName;
 var description = fullName;
 var standardMail = CommUtil.getStandardMail(selectionRowData[0].CONTACT_ID); 
 
+//1077138, 1074419 customized code to match, new CalendarUtil.createEntry()/newSilentEvent() and work without misbehaviour.
 var startTime = selectionRowData[0].BEGIN_TIME;
 var endTime = selectionRowData[0].END_TIME;
 var duration = eMath.subInt(endTime, startTime);
diff --git a/process/Calendar_lib/process.js b/process/Calendar_lib/process.js
index 455b28d263..cf037ba7e0 100644
--- a/process/Calendar_lib/process.js
+++ b/process/Calendar_lib/process.js
@@ -391,7 +391,7 @@ CalendarUtil.createEntry = function(pSummary, pDescription, pLinks, pOwner, pAff
         pStatus = calendars.STATUS_CONFIRMED;
     }
     
-    if(!pReminder)
+    if(pReminder)
     {
         entry[calendars.HASREMINDER] = "true";
         entry[calendars.REMINDER_DURATION] = pReminder.getTime().toString();
-- 
GitLab