From b2948b2e099eda88064cd2d659c214e767badd31 Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Tue, 12 Feb 2019 13:47:10 +0100
Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Neon][TicketNr.:?=
 =?UTF-8?q?=201033739][Vertriebsprojekt=20-=20Aktion=20"Zeit=20eintragen"?=
 =?UTF-8?q?=20in=20Aktionsmen=C3=BC]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Salesproject_entity.aod                   |  8 ++++
 .../newtimetracking/onActionProcess.js        |  4 ++
 .../timetrackingsum/valueProcess.js           | 11 ++---
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     |  5 ++
 process/Salesproject_lib/process.js           | 19 +-------
 process/Timetracking_lib/Timetracking_lib.aod |  9 ++++
 process/Timetracking_lib/process.js           | 47 +++++++++++++++++++
 7 files changed, 78 insertions(+), 25 deletions(-)
 create mode 100644 entity/Salesproject_entity/entityfields/newtimetracking/onActionProcess.js
 create mode 100644 process/Timetracking_lib/Timetracking_lib.aod
 create mode 100644 process/Timetracking_lib/process.js

diff --git a/entity/Salesproject_entity/Salesproject_entity.aod b/entity/Salesproject_entity/Salesproject_entity.aod
index 8332d804d9..85832cea86 100644
--- a/entity/Salesproject_entity/Salesproject_entity.aod
+++ b/entity/Salesproject_entity/Salesproject_entity.aod
@@ -306,6 +306,7 @@
     <entityField>
       <name>TIMETRACKINGSUM</name>
       <title>Time expenses</title>
+      <description>the total hours of all time trackings related to the salesproject</description>
       <state>READONLY</state>
       <valueProcess>%aditoprj%/entity/Salesproject_entity/entityfields/timetrackingsum/valueProcess.js</valueProcess>
     </entityField>
@@ -362,6 +363,13 @@
         </entityParameter>
       </children>
     </entityConsumer>
+    <entityActionField>
+      <name>newTimetracking</name>
+      <fieldType>ACTION</fieldType>
+      <title>New time tracking</title>
+      <description>Opens the time tracking context in new-mode for the selected salesproject</description>
+      <onActionProcess>%aditoprj%/entity/Salesproject_entity/entityfields/newtimetracking/onActionProcess.js</onActionProcess>
+    </entityActionField>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
diff --git a/entity/Salesproject_entity/entityfields/newtimetracking/onActionProcess.js b/entity/Salesproject_entity/entityfields/newtimetracking/onActionProcess.js
new file mode 100644
index 0000000000..2f991c1b2c
--- /dev/null
+++ b/entity/Salesproject_entity/entityfields/newtimetracking/onActionProcess.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("Timetracking_lib");
+
+Timetracking.createNewTimeTracking(vars.getString("$field.SALESPROJECTID"));
\ No newline at end of file
diff --git a/entity/Salesproject_entity/entityfields/timetrackingsum/valueProcess.js b/entity/Salesproject_entity/entityfields/timetrackingsum/valueProcess.js
index 91a3e076d0..e3ef687794 100644
--- a/entity/Salesproject_entity/entityfields/timetrackingsum/valueProcess.js
+++ b/entity/Salesproject_entity/entityfields/timetrackingsum/valueProcess.js
@@ -1,13 +1,10 @@
-import("system.eMath");
+import("system.text");
 import("system.translate");
 import("system.result");
 import("system.vars");
-import("Salesproject_lib");
+import("Timetracking_lib");
 
-var objectId = ContextUtils.getCurrentContextId();
-var rowId = vars.getString("$field.SALESPROJECTID");
-
-var hrs = Salesproject.getTotalTrackingTime(objectId, rowId) / 60;
-hrs = eMath.roundDec(hrs, 2, eMath.ROUND_HALF_UP);
+var hrs = Timetracking.getTotalTrackingTime(vars.getString("$field.SALESPROJECTID")) / 60;
+hrs = text.formatDouble(hrs, "0.00");
 
 result.string(hrs + " " + translate.text("hrs"));
\ No newline at end of file
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index 59cd2ccf51..9b057dd5bf 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -58,6 +58,10 @@
       <key>Austria</key>
       <value>Österreich</value>
     </entry>
+    <entry>
+      <key>New time tracking</key>
+      <value>Neuer Zeiteintrag</value>
+    </entry>
     <entry>
       <key>Customercode</key>
       <value>Kundennummer</value>
@@ -1344,6 +1348,7 @@
     </entry>
     <entry>
       <key>New receipt version</key>
+      <value></value>
     </entry>
     <entry>
       <key>Orderitems</key>
diff --git a/process/Salesproject_lib/process.js b/process/Salesproject_lib/process.js
index 393cc72188..acbb272a3e 100644
--- a/process/Salesproject_lib/process.js
+++ b/process/Salesproject_lib/process.js
@@ -1,3 +1,4 @@
+import("system.neon");
 import("system.vars");
 import("system.util");
 import("system.translate");
@@ -82,21 +83,3 @@ Salesproject.getSalesProjectTitleById = function(pSalesProjectId)
                         .andPrepare("SALESPROJECT.SALESPROJECTID", pSalesProjectId)
                         .buildSql("select PROJECTTITLE from SALESPROJECT", "1=0"));
 }
-
-/**
- * calculates the total time of all time trackings of the object
- * 
- * @param {String} pObjectId the objectId
- * @param {String} pRowId the rowId
- * 
- * @return {Number} total time in minutes
- */
-Salesproject.getTotalTrackingTime = function (pObjectId, pRowId)
-{
-    var totalMinutes = db.cell(SqlCondition.begin()
-        .andPrepare("TIMETRACKING.OBJECT_ID", pObjectId)
-        .andPrepare("TIMETRACKING.ROW_ID", pRowId)
-        .buildSql("select sum(MINUTES) from TIMETRACKING", "1=0"));
-    
-    return Number(totalMinutes);
-}
\ No newline at end of file
diff --git a/process/Timetracking_lib/Timetracking_lib.aod b/process/Timetracking_lib/Timetracking_lib.aod
new file mode 100644
index 0000000000..305c323c6e
--- /dev/null
+++ b/process/Timetracking_lib/Timetracking_lib.aod
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.7" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.1.7">
+  <name>Timetracking_lib</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <process>%aditoprj%/process/Timetracking_lib/process.js</process>
+  <variants>
+    <element>LIBRARY</element>
+  </variants>
+</process>
diff --git a/process/Timetracking_lib/process.js b/process/Timetracking_lib/process.js
new file mode 100644
index 0000000000..2a540245b6
--- /dev/null
+++ b/process/Timetracking_lib/process.js
@@ -0,0 +1,47 @@
+import("system.db");
+import("system.neon");
+import("Context_lib");
+
+/**
+ * Methods used for time tracking.
+ * Do not create an instance of this!
+ * 
+ * @class
+ */
+function Timetracking() {}
+   
+/**
+ * calculates the total time of all time trackings of the object
+ * 
+ * @param {String} pRowId the rowId
+ * 
+ * @return {Number} total time in minutes
+ */
+Timetracking.getTotalTrackingTime = function (pRowId)
+{
+    var objectId = ContextUtils.getCurrentContextId();
+    var totalMinutes = db.cell(SqlCondition.begin()
+        .andPrepare("TIMETRACKING.OBJECT_ID", objectId)
+        .andPrepare("TIMETRACKING.ROW_ID", pRowId)
+        .buildSql("select sum(MINUTES) from TIMETRACKING", "1=0"));
+    
+    return Number(totalMinutes);
+}
+
+/**
+ * Create a new time tracking
+ * 
+ * @param {String} pRowId the rowId
+ * 
+ * @return {Number} total time in minutes
+ */
+Timetracking.createNewTimeTracking = function (pRowId)
+{
+    var objectId = ContextUtils.getCurrentContextId();
+    var params = {
+        "ObjectId_param" : objectId,
+        "RowId_param" : pRowId
+    };
+    
+    neon.openContext("Timetracking_context", null, null, neon.OPERATINGSTATE_NEW, params);
+}
\ No newline at end of file
-- 
GitLab