From 382fffbd45f619d2634663d3a46b583b9c1afc0a Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Mon, 20 May 2019 14:59:49 +0200
Subject: [PATCH] fix productprice date validation

---
 entity/Contract_entity/onValidation.js        |  2 +-
 .../Productprice_entity.aod                   |  3 +--
 .../entityfields/valid_from/onValidation.js   |  9 ---------
 .../entityfields/valid_from/valueProcess.js   | 20 +++++++++----------
 .../entityfields/valid_to/onValidation.js     |  9 ---------
 entity/Productprice_entity/onValidation.js    |  9 +++++++++
 entity/Salesproject_entity/onValidation.js    |  2 +-
 process/Date_lib/process.js                   |  4 +++-
 8 files changed, 24 insertions(+), 34 deletions(-)
 delete mode 100644 entity/Productprice_entity/entityfields/valid_from/onValidation.js
 delete mode 100644 entity/Productprice_entity/entityfields/valid_to/onValidation.js
 create mode 100644 entity/Productprice_entity/onValidation.js

diff --git a/entity/Contract_entity/onValidation.js b/entity/Contract_entity/onValidation.js
index e072305a2e..77648d0168 100644
--- a/entity/Contract_entity/onValidation.js
+++ b/entity/Contract_entity/onValidation.js
@@ -9,7 +9,7 @@ var endDate = vars.get("$field.CONTRACTEND");
 
 var errorMessage = "";
 
-if (DateUtils.validateBeginnBeforeEnd(startDate, endDate) === false)
+if (!DateUtils.validateBeginnBeforeEnd(startDate, endDate))
     errorMessage = DateUtils.getValidationFailString();
 
 // check Duedate
diff --git a/entity/Productprice_entity/Productprice_entity.aod b/entity/Productprice_entity/Productprice_entity.aod
index cd09e9a74c..bb04523c57 100644
--- a/entity/Productprice_entity/Productprice_entity.aod
+++ b/entity/Productprice_entity/Productprice_entity.aod
@@ -4,6 +4,7 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <documentation>%aditoprj%/entity/Productprice_entity/documentation.adoc</documentation>
   <title>Prices</title>
+  <onValidation>%aditoprj%/entity/Productprice_entity/onValidation.js</onValidation>
   <afterOperatingState>%aditoprj%/entity/Productprice_entity/afterOperatingState.js</afterOperatingState>
   <recordContainer>db</recordContainer>
   <entityFields>
@@ -70,7 +71,6 @@
       <inputFormat>dd.MM.yyyy</inputFormat>
       <mandatory v="true" />
       <valueProcess>%aditoprj%/entity/Productprice_entity/entityfields/valid_from/valueProcess.js</valueProcess>
-      <onValidation>%aditoprj%/entity/Productprice_entity/entityfields/valid_from/onValidation.js</onValidation>
     </entityField>
     <entityField>
       <name>VALID_TO</name>
@@ -79,7 +79,6 @@
       <resolution>DAY</resolution>
       <outputFormat>dd.MM.yyyy</outputFormat>
       <inputFormat>dd.MM.yyyy</inputFormat>
-      <onValidation>%aditoprj%/entity/Productprice_entity/entityfields/valid_to/onValidation.js</onValidation>
     </entityField>
     <entityField>
       <name>VAT</name>
diff --git a/entity/Productprice_entity/entityfields/valid_from/onValidation.js b/entity/Productprice_entity/entityfields/valid_from/onValidation.js
deleted file mode 100644
index 5ce849d2e8..0000000000
--- a/entity/Productprice_entity/entityfields/valid_from/onValidation.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import("system.result");
-import("system.vars");
-import("Date_lib");
-import("Entity_lib");
-
-var cStart = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.VALID_FROM"));
-
-if (DateUtils.validateBeginnBeforeEnd(cStart, vars.get("$field.VALID_TO")) === false)
-    result.string(DateUtils.getValidationFailString());
\ No newline at end of file
diff --git a/entity/Productprice_entity/entityfields/valid_from/valueProcess.js b/entity/Productprice_entity/entityfields/valid_from/valueProcess.js
index e2eb1642a6..fde00cab2a 100644
--- a/entity/Productprice_entity/entityfields/valid_from/valueProcess.js
+++ b/entity/Productprice_entity/entityfields/valid_from/valueProcess.js
@@ -1,11 +1,9 @@
-import("system.result");
-import("system.vars");
-import("system.neon");
-import("Date_lib");
-
-if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && !vars.get("$this.value"))
-{
-    result.string(DateUtils.getTodayUTC());
-}
-else
-    result.string(vars.get("$this.value"));
\ No newline at end of file
+import("system.result");
+import("system.vars");
+import("system.neon");
+import("Date_lib");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && !vars.get("$this.value"))
+{
+    result.string(DateUtils.getTodayUTC());
+}
\ No newline at end of file
diff --git a/entity/Productprice_entity/entityfields/valid_to/onValidation.js b/entity/Productprice_entity/entityfields/valid_to/onValidation.js
deleted file mode 100644
index a25d6a1147..0000000000
--- a/entity/Productprice_entity/entityfields/valid_to/onValidation.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import("system.result");
-import("system.vars");
-import("Date_lib");
-import("Entity_lib");
-
-var cEnd = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.VALID_TO"));
-
-if (DateUtils.validateBeginnBeforeEnd(vars.get("$field.VALID_FROM"), cEnd) === false)
-    result.string(DateUtils.getValidationFailString());
\ No newline at end of file
diff --git a/entity/Productprice_entity/onValidation.js b/entity/Productprice_entity/onValidation.js
new file mode 100644
index 0000000000..6e3b8b5612
--- /dev/null
+++ b/entity/Productprice_entity/onValidation.js
@@ -0,0 +1,9 @@
+import("system.result");
+import("Date_lib");
+import("system.vars");
+
+var startDate = vars.get("$field.VALID_FROM");
+var endDate = vars.get("$field.VALID_TO");
+
+if (!DateUtils.validateBeginnBeforeEnd(startDate, endDate))
+    result.string(DateUtils.getValidationFailString());
\ No newline at end of file
diff --git a/entity/Salesproject_entity/onValidation.js b/entity/Salesproject_entity/onValidation.js
index de8d3eaf90..e0b1e589a7 100644
--- a/entity/Salesproject_entity/onValidation.js
+++ b/entity/Salesproject_entity/onValidation.js
@@ -5,5 +5,5 @@ import("system.vars");
 var startDate = vars.get("$field.STARTDATE");
 var endDate = vars.get("$field.ENDDATE");
 
-if (DateUtils.validateBeginnBeforeEnd(startDate, endDate) === false)
+if (!DateUtils.validateBeginnBeforeEnd(startDate, endDate))
     result.string(DateUtils.getValidationFailString());
\ No newline at end of file
diff --git a/process/Date_lib/process.js b/process/Date_lib/process.js
index f4121551b8..7173ddf876 100644
--- a/process/Date_lib/process.js
+++ b/process/Date_lib/process.js
@@ -18,7 +18,9 @@ function DateUtils() {}
  * @result {Boolean|null} Boolean if it was able to check smth or null if the input values were not valid
  */
 DateUtils.validateBeginnBeforeEnd = function(pStart, pEnd) {
-    if (pStart == "" || pStart == null || pEnd == "" || pEnd == null) return null;
+    if (!pStart || !pEnd) 
+        return null;
+    
     return pStart <= pEnd;
 }
 
-- 
GitLab