From 9345b7a2577010a81c907dd199e61a10bcbfe11e Mon Sep 17 00:00:00 2001
From: "c.wimmer" <c.wimmer@cwimmer-nb.aditosoftware.local>
Date: Fri, 18 Dec 2020 15:51:41 +0100
Subject: [PATCH] [Projekt: Crowd-Development / Besuch vor Ort][TicketNr.:
 1068901][[Bug] Mainview Wochenplan - Neuer Wochenplaneintrag  Datum
 vorbelegen]

---
 .../VisitPlanEntry_entity.aod                      |  1 +
 entity/VisitPlanEntry_entity/onValidation.js       | 14 ++++++++++++++
 .../recordcontainers/jdito/onUpdate.js             |  6 +-----
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod b/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
index f35469b6006..56d2b015d25 100644
--- a/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
+++ b/entity/VisitPlanEntry_entity/VisitPlanEntry_entity.aod
@@ -57,6 +57,7 @@
         <element>PROCESS_SETVALUE</element>
         <element>RECORD</element>
       </onValueChangeTypes>
+      <onValidation>%aditoprj%/entity/VisitPlanEntry_entity/entityfields/entrydate/onValidation.js</onValidation>
     </entityField>
     <entityField>
       <name>END_TIME</name>
diff --git a/entity/VisitPlanEntry_entity/onValidation.js b/entity/VisitPlanEntry_entity/onValidation.js
index 0cdee16cc3f..2b341575427 100644
--- a/entity/VisitPlanEntry_entity/onValidation.js
+++ b/entity/VisitPlanEntry_entity/onValidation.js
@@ -1,3 +1,4 @@
+import("system.neon");
 import("system.eMath");
 import("Sql_lib");
 import("system.logging");
@@ -13,3 +14,16 @@ var begin_time = eMath.absInt(vars.get("$field.BEGIN_TIME"));
 if (endTime != "" && begin_time != "" && endTime < begin_time)
     result.string(translate.text("The endtime can't be before begintime!"));
 
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && !vars.get("$param.NoVisitPlanEmployeeWeek_param"))
+{
+
+    var week = newSelect("VISITPLAN_WEEK") 
+                                .from("VISITPLANEMPLOYEEWEEK")
+                                .where("VISITPLANEMPLOYEEWEEK.VISITPLANEMPLOYEEWEEKID", vars.get("$field.VISITPLANEMPLOYEEWEEK_ID"))
+                                .cell();                
+    weekEntrydate = eMath.absInt(datetime.toDate(vars.get("$field.ENTRYDATE"), "w"))
+
+    if(week != weekEntrydate)
+        result.string(translate.text("Entrydate has to be in the selected calendar week!"));
+    
+}
diff --git a/entity/VisitPlanEntry_entity/recordcontainers/jdito/onUpdate.js b/entity/VisitPlanEntry_entity/recordcontainers/jdito/onUpdate.js
index 29f1c3c50f9..d5c991243c8 100644
--- a/entity/VisitPlanEntry_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/VisitPlanEntry_entity/recordcontainers/jdito/onUpdate.js
@@ -17,10 +17,6 @@ var weekId = newSelect("VISITPLANEMPLOYEEWEEKID")
                         .and("VISITPLANEMPLOYEEWEEK.VISITPLAN_YEAR", calendarYear)
                         .and("VISITPLANEMPLOYEEWEEK.CONTACT_ID", user)
                         .cell();
-                        
-logging.log(rowData["ENTRYDATE.value"])
-logging.log(datetime.toDate(rowData["ENTRYDATE.value"], "w"))
-logging.log(datetime.toDate(rowData["ENTRYDATE.value"], "yyyy"))
 
 if(weekId)
     visitPlanEmployeeWeekID = weekId;
@@ -66,7 +62,7 @@ var columns = [
     "STATUS_APPOINTMENT",
     "VISITPLANEMPLOYEEWEEK_ID"
 ];
-logging.log(visitPlanEmployeeWeekID)
+
 var cond = newWhere("VISITPLANENTRY.VISITPLANENTRYID", vars.get("$field.UID")).toString();
 
 db.updateData("VISITPLANENTRY", columns, null, values, cond);
-- 
GitLab