From dc854ef642fea05a20bd736d58c140076793d7e6 Mon Sep 17 00:00:00 2001
From: Tobias Feldmann <t.feldmann@adito.de>
Date: Wed, 19 Dec 2018 15:13:04 +0100
Subject: [PATCH] Salesproject integration in offer

---
 entity/Offer_entity/Offer_entity.aod                | 12 ++++++++++++
 .../entityfields/relation_id/valueProcess.js        |  4 ++--
 .../salesproject_id/displayValueProcess.js          |  5 +++++
 .../entityfields/newoffer/onActionProcess.js        |  4 ++++
 entity/Salesproject_entity/Salesproject_entity.aod  |  9 +++++++++
 entity/Salesproject_entity/titleProcess.js          |  4 ++++
 process/Offer_lib/process.js                        |  2 +-
 process/Salesproject_lib/process.js                 | 13 +++++++++++++
 8 files changed, 50 insertions(+), 3 deletions(-)
 create mode 100644 entity/Offer_entity/entityfields/salesproject_id/displayValueProcess.js
 create mode 100644 entity/Pers_entity/entityfields/newoffer/onActionProcess.js
 create mode 100644 entity/Salesproject_entity/titleProcess.js

diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod
index 6c22346f3ab..7e1f94098ab 100644
--- a/entity/Offer_entity/Offer_entity.aod
+++ b/entity/Offer_entity/Offer_entity.aod
@@ -72,10 +72,13 @@
     <entityField>
       <name>SALESPROJECT_ID</name>
       <title>Salesproject</title>
+      <linkedContext>Salesproject_context</linkedContext>
       <mandatory v="true" />
+      <outgoingField>OfferSalesproject_dfo</outgoingField>
       <state>INVISIBLE</state>
       <stateProcess>%aditoprj%/entity/Offer_entity/entityfields/salesproject_id/stateProcess.js</stateProcess>
       <valueProcess>%aditoprj%/entity/Offer_entity/entityfields/salesproject_id/valueProcess.js</valueProcess>
+      <displayValueProcess>%aditoprj%/entity/Offer_entity/entityfields/salesproject_id/displayValueProcess.js</displayValueProcess>
     </entityField>
     <entityField>
       <name>STATUS</name>
@@ -325,6 +328,15 @@
     <entityField>
       <name>ORG_NAME</name>
     </entityField>
+    <entityOutgoingField>
+      <name>OfferSalesproject_dfo</name>
+      <fieldType>DEPENDENCY_OUT</fieldType>
+      <dependency>
+        <name>dependency</name>
+        <entityName>Salesproject_entity</entityName>
+        <fieldName>#INCOMING</fieldName>
+      </dependency>
+    </entityOutgoingField>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
diff --git a/entity/Offer_entity/entityfields/relation_id/valueProcess.js b/entity/Offer_entity/entityfields/relation_id/valueProcess.js
index 250a8378a04..3e39bab540d 100644
--- a/entity/Offer_entity/entityfields/relation_id/valueProcess.js
+++ b/entity/Offer_entity/entityfields/relation_id/valueProcess.js
@@ -1,7 +1,7 @@
 import("system.result");
 import("system.vars");
 
-if (vars.exists("$param.RelationId_param"))
+if (vars.exists("$param.RelationId_param")) 
 {
-    result.string(vars.get("$param.RelationId_param"))
+    result.string(vars.get("$param.RelationId_param"));
 }
\ No newline at end of file
diff --git a/entity/Offer_entity/entityfields/salesproject_id/displayValueProcess.js b/entity/Offer_entity/entityfields/salesproject_id/displayValueProcess.js
new file mode 100644
index 00000000000..65afbf6e950
--- /dev/null
+++ b/entity/Offer_entity/entityfields/salesproject_id/displayValueProcess.js
@@ -0,0 +1,5 @@
+import("system.vars");
+import("system.result");
+import("Salesproject_lib");
+
+result.string(Salesproject.getSalesProjectTitleById(vars.getString("$field.SALESPROJECT_ID")));
\ No newline at end of file
diff --git a/entity/Pers_entity/entityfields/newoffer/onActionProcess.js b/entity/Pers_entity/entityfields/newoffer/onActionProcess.js
new file mode 100644
index 00000000000..fdee58dbfa8
--- /dev/null
+++ b/entity/Pers_entity/entityfields/newoffer/onActionProcess.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("Offer_lib");
+
+OfferUtils.createNewOffer(null, vars.getString("$field.RELATIONID"));
\ No newline at end of file
diff --git a/entity/Salesproject_entity/Salesproject_entity.aod b/entity/Salesproject_entity/Salesproject_entity.aod
index bcb7ba7ea9d..3b218bb0a58 100644
--- a/entity/Salesproject_entity/Salesproject_entity.aod
+++ b/entity/Salesproject_entity/Salesproject_entity.aod
@@ -4,10 +4,19 @@
   <title>Salesproject</title>
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <iconId>VAADIN:BOOK_DOLLAR</iconId>
+  <titleProcess>%aditoprj%/entity/Salesproject_entity/titleProcess.js</titleProcess>
   <recordContainer>db</recordContainer>
   <entityFields>
     <entityIncomingField>
       <name>#INCOMING</name>
+      <dependencies>
+        <entityDependency>
+          <name>525fd920-ea50-45d6-97a8-20e0aaaa830c</name>
+          <entityName>Offer_entity</entityName>
+          <fieldName>OfferSalesproject_dfo</fieldName>
+          <isOutgoing v="false" />
+        </entityDependency>
+      </dependencies>
     </entityIncomingField>
     <entityField>
       <name>DATE_EDIT</name>
diff --git a/entity/Salesproject_entity/titleProcess.js b/entity/Salesproject_entity/titleProcess.js
new file mode 100644
index 00000000000..96a0a030e21
--- /dev/null
+++ b/entity/Salesproject_entity/titleProcess.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("system.result");
+
+result.string(vars.get("$field.PROJECTTITLE"));
\ No newline at end of file
diff --git a/process/Offer_lib/process.js b/process/Offer_lib/process.js
index 3143c1b695f..a84bde50803 100644
--- a/process/Offer_lib/process.js
+++ b/process/Offer_lib/process.js
@@ -74,7 +74,7 @@ OfferUtils.createNewOffer = function(pSalesprojectId, pRelationId)
     if (pRelationId)
         params["RelationId_param"] = pRelationId;
     
-    neon.openContext("Offer_context", null, neon.OPERATINGSTATE_NEW, params);
+    neon.openContext("Offer_context", null, null, neon.OPERATINGSTATE_NEW, params);
 }
 
 
diff --git a/process/Salesproject_lib/process.js b/process/Salesproject_lib/process.js
index a7a26eb60f3..2b50b3b61d1 100644
--- a/process/Salesproject_lib/process.js
+++ b/process/Salesproject_lib/process.js
@@ -66,4 +66,17 @@ Salesproject.insertMilestone = function(salesprojectId, type, value, notifyForec
 Salesproject.notifyToUpdateForecast = function() {
     // TODO: logging.show durch sinnvolle Meldung ersetzen oder ähnlich...
     logging.show(translate.text("Please update the forecast."));
+}
+
+/**
+ * get the title of a salesproject by id
+ * @param {String} pSalesProjectId
+ * <br>
+ * @return {String} title of the salesproject
+ */
+Salesproject.getSalesProjectTitleById = function(pSalesProjectId)
+{
+    return db.cell( SqlCondition.begin()
+                        .andPrepare("SALESPROJECT.SALESPROJECTID", pSalesProjectId)
+                        .buildSelect("select PROJECTTITLE from SALESPROJECT", "1=0"));
 }
\ No newline at end of file
-- 
GitLab