From 0fe7a724b0604a3ca03654e76ef5978aba31c877 Mon Sep 17 00:00:00 2001
From: "a.schindlbeck" <a.schindlbeck@adito.de>
Date: Fri, 29 Mar 2019 10:53:01 +0100
Subject: [PATCH] Rabatt und UmsSt auf 2 Kommastellen erweitert

---
 entity/Offeritem_entity/Offeritem_entity.aod       |  2 +-
 .../entityfields/discount/onValidation.js          |  8 +++-----
 .../entityfields/vat/onValidation.js               |  2 +-
 process/Util_lib/process.js                        | 14 +++++++++++---
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/entity/Offeritem_entity/Offeritem_entity.aod b/entity/Offeritem_entity/Offeritem_entity.aod
index ec65a90423..0185cc75e4 100644
--- a/entity/Offeritem_entity/Offeritem_entity.aod
+++ b/entity/Offeritem_entity/Offeritem_entity.aod
@@ -17,7 +17,7 @@
       <name>DISCOUNT</name>
       <title>Discount %</title>
       <contentType>NUMBER</contentType>
-      <outputFormat>#,##0</outputFormat>
+      <outputFormat>#,##0.00</outputFormat>
       <onValidation>%aditoprj%/entity/Offeritem_entity/entityfields/discount/onValidation.js</onValidation>
     </entityField>
     <entityField>
diff --git a/entity/Offeritem_entity/entityfields/discount/onValidation.js b/entity/Offeritem_entity/entityfields/discount/onValidation.js
index 18bd49fe0d..a929b1d08a 100644
--- a/entity/Offeritem_entity/entityfields/discount/onValidation.js
+++ b/entity/Offeritem_entity/entityfields/discount/onValidation.js
@@ -1,13 +1,11 @@
+import("system.logging");
 import("system.result");
 import("system.vars");
 import("Util_lib");
 import("Entity_lib");
 
 var value = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.DISCOUNT"));
-
-var validationResult = NumberUtils.validateIsInside("Discount", value, 0, 100);
+var validationResult = NumberUtils.validateIsBetweenFloat("Discount", value, 0, 100);
 
 if (validationResult)
-{
-    result.string(validationResult);
-}
\ No newline at end of file
+    result.string(validationResult);
\ No newline at end of file
diff --git a/entity/Productprice_entity/entityfields/vat/onValidation.js b/entity/Productprice_entity/entityfields/vat/onValidation.js
index 974d4c311f..463ab50e20 100644
--- a/entity/Productprice_entity/entityfields/vat/onValidation.js
+++ b/entity/Productprice_entity/entityfields/vat/onValidation.js
@@ -5,7 +5,7 @@ import("Entity_lib");
 
 var value = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.VAT"));
 
-var validationResult = NumberUtils.validateIsInside("VAT", value, 0, 100);
+var validationResult = NumberUtils.validateIsBetweenFloat("VAT", value, 0, 100);
 
 if (validationResult)
 {
diff --git a/process/Util_lib/process.js b/process/Util_lib/process.js
index 82af36de2b..d6cde464c4 100644
--- a/process/Util_lib/process.js
+++ b/process/Util_lib/process.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("system.neon");
 import("system.project");
 import("system.process");
@@ -80,16 +81,23 @@ NumberUtils.isInside = function(pValue, pMin, pMax, pIgnoreNull)
  * @example
  *  var value = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.DISCOUNT")); <br>
  *   <br>
- *  var validationResult = NumberUtils.validateIsInside("Discount", value, 0, 100); <br>
+ *  var validationResult = NumberUtils.validateIsBetweenFloat("Discount", value, 0, 100); <br>
  *   <br>
  *  if (validationResult) <br>
  *  { <br>
  *      result.string(validationResult); <br>
  *  } <br>
  */
-NumberUtils.validateIsInside = function(pTitle, pValue, pMin, pMax, pIgnoreNull)
+NumberUtils.validateIsBetweenFloat = function(pTitle, pValue, pMin, pMax, pIgnoreNull)
 {
-    var discount = parseInt(pValue);
+    if(pValue.includes(","))
+        pValue = pValue.replace(",", ".");
+    
+    var discount = parseFloat(pValue);
+    
+    if(isNaN(discount))
+        return false;
+    
     if (!NumberUtils.isInside(discount, 0, 100, pIgnoreNull))
     {
         return (translate.withArguments("${MIN_MAX_ERROR} field: %0, value: %1, min: %2, max: %3", [translate.text(pTitle), discount, pMin, pMax]));
-- 
GitLab