From 5b8bdc5562736c9eb8889227a3390c067bcfc043 Mon Sep 17 00:00:00 2001
From: "d.lechner" <d.lechner@adito.de>
Date: Wed, 24 Apr 2019 12:57:26 +0200
Subject: [PATCH] Use documenttemplate in offer

---
 .../DocumentTemplate_entity.aod                        |  1 -
 .../recordcontainers/db/conditionProcess.js            | 10 +++++++---
 .../recordcontainers/db/fromClauseProcess.js           |  0
 entity/Offer_entity/Offer_entity.aod                   |  2 +-
 .../Offer_entity/entityfields/header/valueProcess.js   |  8 ++++++++
 5 files changed, 16 insertions(+), 5 deletions(-)
 create mode 100644 entity/DocumentTemplate_entity/recordcontainers/db/fromClauseProcess.js

diff --git a/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod b/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod
index c9f0f90cd7..920c99b2fd 100644
--- a/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod
+++ b/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod
@@ -4,7 +4,6 @@
   <title>Document Template</title>
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <icon>VAADIN:FILE_FONT</icon>
-  <titleProcess>%aditoprj%/entity/DocumentTemplate_entity/titleProcess.js</titleProcess>
   <recordContainer>db</recordContainer>
   <entityFields>
     <entityProvider>
diff --git a/entity/DocumentTemplate_entity/recordcontainers/db/conditionProcess.js b/entity/DocumentTemplate_entity/recordcontainers/db/conditionProcess.js
index 96bac18a05..2478d8b4cf 100644
--- a/entity/DocumentTemplate_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/DocumentTemplate_entity/recordcontainers/db/conditionProcess.js
@@ -4,11 +4,15 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-var docTemplateType = vars.get("$param.DocumentTemplateType_param").trim();
-var docTemplateTypeClassification = vars.get("$param.DocumentTemplateTypeClassification_param").trim();
+var docTemplateType = vars.get("$param.DocumentTemplateType_param");
+var docTemplateTypeClassification = vars.get("$param.DocumentTemplateTypeClassification_param");
 
-if(docTemplateType != "" && docTemplateTypeClassification != "")
+
+if(docTemplateType != null && docTemplateType != "" && docTemplateTypeClassification != null && docTemplateTypeClassification != "")
 {
+    docTemplateType = docTemplateType.trim();
+    docTemplateTypeClassification = docTemplateTypeClassification.trim();
+    
     var cond = SqlCondition.begin()
                            .andPrepare("DOCUMENTTEMPLATE.TYPE", docTemplateType)
                            .andPrepare("DOCUMENTTEMPLATE.CLASSIFICATION", docTemplateTypeClassification)
diff --git a/entity/DocumentTemplate_entity/recordcontainers/db/fromClauseProcess.js b/entity/DocumentTemplate_entity/recordcontainers/db/fromClauseProcess.js
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod
index 7d2f77f09b..29aee8674e 100644
--- a/entity/Offer_entity/Offer_entity.aod
+++ b/entity/Offer_entity/Offer_entity.aod
@@ -106,7 +106,6 @@
     </entityField>
     <entityField>
       <name>HEADER</name>
-      <title>Cover letter</title>
       <contentType>LONG_TEXT</contentType>
       <valueProcess>%aditoprj%/entity/Offer_entity/entityfields/header/valueProcess.js</valueProcess>
     </entityField>
@@ -741,6 +740,7 @@
     </entityConsumer>
     <entityField>
       <name>chooseTEXHeader</name>
+      <title>Cover letter</title>
       <consumer>DocumentTemplateText</consumer>
     </entityField>
   </entityFields>
diff --git a/entity/Offer_entity/entityfields/header/valueProcess.js b/entity/Offer_entity/entityfields/header/valueProcess.js
index 54affd8d1d..508e3cb15b 100644
--- a/entity/Offer_entity/entityfields/header/valueProcess.js
+++ b/entity/Offer_entity/entityfields/header/valueProcess.js
@@ -1,6 +1,8 @@
 import("system.result");
 import("system.vars");
 import("system.neon");
+import("system.db");
+import("system.util");
 
 if(vars.exists("$param.OfferHeader_param") && vars.get("$param.OfferHeader_param")) 
     result.string(vars.get("$param.OfferHeader_param"));
@@ -10,3 +12,9 @@ else if(vars.get("$this.value"))
 
 else if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
     result.string("gerne bieten wir Ihnen wie folgt an:")
+
+if (vars.get("$field.chooseTEXHeader") != "")
+{
+    var binaryId      = db.cell("select ID from ASYS_BINARIES where ROW_ID = '" + vars.get("$field.chooseTEXHeader") + "'", "_____SYSTEMALIAS");
+    result.string(util.decodeBase64String(db.getBinaryContent(binaryId, "_____SYSTEMALIAS")));
+}
\ No newline at end of file
-- 
GitLab