From 32e1f514027f68acf66a54ecbb5d5c1c37ea9580 Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Thu, 2 May 2019 11:11:32 +0200
Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Neon][TicketNr.:?=
 =?UTF-8?q?=201036415][=C3=9Cbernahme=20AUDIT=20und=20Logging=20aus=20best?=
 =?UTF-8?q?ehendem=20xRM-Basic=20f=C3=BCr=20ADITO=202019]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 aliasDefinition/Data_alias/Data_alias.aod      | 10 ++++++++++
 .../customproperties/translate4log/property.js |  5 +++--
 .../customproperties/translate4log/property.js |  7 +++++++
 .../customproperties/translate4log/property.js |  2 +-
 .../customproperties/translate4log/property.js |  9 +++++++--
 entity/Offer_entity/Offer_entity.aod           |  4 ++--
 neonView/OfferMain_view/OfferMain_view.aod     |  5 +++++
 process/Contact_lib/process.js                 | 18 ++++++++++++++++--
 process/Loghistory_lib/process.js              | 13 +++++++++----
 9 files changed, 60 insertions(+), 13 deletions(-)
 create mode 100644 aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/language/customproperties/translate4log/property.js

diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod
index 61811a2b9a..cbd4aa22e7 100644
--- a/aliasDefinition/Data_alias/Data_alias.aod
+++ b/aliasDefinition/Data_alias/Data_alias.aod
@@ -2641,6 +2641,11 @@
                     <global v="false" />
                     <property v="true" />
                   </customBooleanProperty>
+                  <customJDitoProperty>
+                    <name>translate4Log</name>
+                    <global v="false" />
+                    <property>%aditoprj%/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/language/customproperties/translate4log/property.js</property>
+                  </customJDitoProperty>
                 </customProperties>
               </entityFieldDb>
               <entityFieldDb>
@@ -2784,6 +2789,11 @@
                     <global v="false" />
                     <property v="true" />
                   </customBooleanProperty>
+                  <customStringProperty>
+                    <name>keyword</name>
+                    <global v="false" />
+                    <property>OfferStatus</property>
+                  </customStringProperty>
                 </customProperties>
               </entityFieldDb>
               <entityFieldDb>
diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/contact_id/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/contact_id/customproperties/translate4log/property.js
index 704213fe86..f35d37ab09 100644
--- a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/contact_id/customproperties/translate4log/property.js
+++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/contact_id/customproperties/translate4log/property.js
@@ -1,6 +1,7 @@
+import("Contact_lib");
 import("system.result");
-import("Address_lib");
 import("Loghistory_lib");
 
 var params = Translate4LogParams.load();
-result.string(new AddrObject(params.value).getFormattedAddress());
\ No newline at end of file
+var res = ContactUtils.getFullTitleByContactId(params.value);
+result.string(res);
\ No newline at end of file
diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/language/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/language/customproperties/translate4log/property.js
new file mode 100644
index 0000000000..51a8cec57a
--- /dev/null
+++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/language/customproperties/translate4log/property.js
@@ -0,0 +1,7 @@
+import("system.result");
+import("Loghistory_lib");
+import("Keyword_lib");
+
+var params = Translate4LogParams.load();
+var res = LanguageKeywordUtils.getViewValue(params.value, params.locale);
+result.string(res);
\ No newline at end of file
diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/salesproject_id/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/salesproject_id/customproperties/translate4log/property.js
index a179e03370..e6c0e291bc 100644
--- a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/salesproject_id/customproperties/translate4log/property.js
+++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/offer/entityfields/salesproject_id/customproperties/translate4log/property.js
@@ -7,5 +7,5 @@ var params = Translate4LogParams.load();
 
 var res = db.cell(SqlCondition.begin()
                               .andPrepare("SALESPROJECT.SALESPROJECTID", params.value)
-                              .buildSql("select " + concat(["PROJECTTITLE", "'/'", "cast( PROJECTNUMBER as char(5))"]) + " from SALESPROJECT"));
+                              .buildSql("select PROJECTTITLE from SALESPROJECT"));
 result.string(res);
\ No newline at end of file
diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/salesproject/entityfields/contact_id/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/salesproject/entityfields/contact_id/customproperties/translate4log/property.js
index 9e1763cfe8..eeae5a1612 100644
--- a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/salesproject/entityfields/contact_id/customproperties/translate4log/property.js
+++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/salesproject/entityfields/contact_id/customproperties/translate4log/property.js
@@ -1,4 +1,9 @@
-import("system.result");
+import("Contact_lib");
 import("system.db");
+import("system.result");
+import("Loghistory_lib");
+import("Sql_lib");
 
-result.string(db.cell("select ORGNAME from RELATION left join ORG on ORG_ID = ORGID where RELATIONID = '{value}'")); 
\ No newline at end of file
+var params = Translate4LogParams.load();
+var res = OrganisationUtils.getNameByContactId(params.value);
+result.string(res);
diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod
index 755f0ba735..9178937f1f 100644
--- a/entity/Offer_entity/Offer_entity.aod
+++ b/entity/Offer_entity/Offer_entity.aod
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.2">
   <name>Offer_entity</name>
-  <title>Offer</title>
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <documentation>%aditoprj%/entity/Offer_entity/documentation.adoc</documentation>
+  <title>Offer</title>
   <afterUiInit>%aditoprj%/entity/Offer_entity/afterUiInit.js</afterUiInit>
   <iconId>VAADIN:CART</iconId>
   <titleProcess>%aditoprj%/entity/Offer_entity/titleProcess.js</titleProcess>
@@ -386,7 +386,7 @@
         <entityParameter>
           <name>ContainerName_param</name>
           <valueProcess>%aditoprj%/entity/Offer_entity/entityfields/keywordofferstates/children/containername_param/valueProcess.js</valueProcess>
-          <expose v="false" />
+          <expose v="true" />
         </entityParameter>
       </children>
     </entityConsumer>
diff --git a/neonView/OfferMain_view/OfferMain_view.aod b/neonView/OfferMain_view/OfferMain_view.aod
index 47f2a91194..fbc90aac96 100644
--- a/neonView/OfferMain_view/OfferMain_view.aod
+++ b/neonView/OfferMain_view/OfferMain_view.aod
@@ -44,5 +44,10 @@
       <entityField>Documents</entityField>
       <view>DocumentFilter_view</view>
     </neonViewReference>
+    <neonViewReference>
+      <name>d79a0304-4106-4749-b2e1-c5ba005b4448</name>
+      <entityField>LogHistoryConsumer</entityField>
+      <view>LogHistoryFilter_view</view>
+    </neonViewReference>
   </children>
 </neonView>
diff --git a/process/Contact_lib/process.js b/process/Contact_lib/process.js
index f533b09e7c..e8b2c9e47b 100644
--- a/process/Contact_lib/process.js
+++ b/process/Contact_lib/process.js
@@ -21,8 +21,22 @@ OrganisationUtils.getNameByOrganisationId = function(pOrganisationId)
     if (pOrganisationId)
     {
         orgname = db.cell(SqlCondition.begin()
-                                  .andPrepare("ORGANISATION.ORGANISATIONID", pOrganisationId)
-                                  .buildSql("select ORGANISATION.NAME from ORGANISATION"));
+                                      .andPrepare("ORGANISATION.ORGANISATIONID", pOrganisationId)
+                                      .buildSql("select ORGANISATION.NAME from ORGANISATION"));
+    }
+    return orgname;
+};
+
+OrganisationUtils.getNameByContactId = function(pContactId)
+{
+    var orgname = "";
+    if (pContactId)
+    {
+        orgname = db.cell(SqlCondition.begin()
+            .andPrepare("CONTACT.CONTACT", pContactId)
+            .buildSql("select ORGANISATION.NAME \n\
+                            from ORGANISATION \n\
+                            join CONTACT on (CONTACT.ORGANISATION_ID = ORGANISATION.ORGANISATIONID and CONTACT.PERSON_ID is null)"));
     }
     return orgname;
 };
diff --git a/process/Loghistory_lib/process.js b/process/Loghistory_lib/process.js
index 6e2c450766..3b5c791ae3 100644
--- a/process/Loghistory_lib/process.js
+++ b/process/Loghistory_lib/process.js
@@ -173,8 +173,10 @@ LogHistoryExecutor.prototype.execute = function ()
             var logfield = columnStructure[this.columns[i]];
             if (logfield && logfield.log)
             {
-                if (this.sqlAction != 'I' && this.oldValues[i] != "") this.oldValues[i] = this._getFormattedValue(logfield, this.oldValues[i], this.translationLanguage);
-                if (this.sqlAction != 'D' && this.newValues[i] != "") this.newValues[i] = this._getFormattedValue(logfield, this.newValues[i], this.translationLanguage);
+                if (this.sqlAction != 'I' && this.oldValues[i] != "") 
+                    this.oldValues[i] = this._getFormattedValue(this.columns[i], logfield, this.oldValues[i]);
+                if (this.sqlAction != 'D' && this.newValues[i] != "") 
+                    this.newValues[i] = this._getFormattedValue(this.columns[i], logfield, this.newValues[i]);
                 
                 var logfieldTitle = (logfield.title ? translate.text(logfield.title, this.translationLanguage) : translate.text("Value", this.translationLanguage));
                 if (this.sqlAction == 'U' && this.oldValues[i] != this.newValues[i])
@@ -314,11 +316,12 @@ LogHistoryExecutor.prototype._getCalendarDescription = function (pIndex)
 * - the field is a TIMESTAMP field the raw long-value will be formatted
 * 
 * @param {Object} pDescription the structureConfig of one specific field which is logged
+* @param {String} pColumnName name of the column whoes value shall be formatted
 * @param {String} pValue raw value that shall be formatted
 *
 * @return {String} if necessary the formattedValue otherwise the original value
 */
-LogHistoryExecutor.prototype._getFormattedValue = function (pDescription, pValue)
+LogHistoryExecutor.prototype._getFormattedValue = function (pColumnName, pDescription, pValue)
 {
     if (pDescription.keyword != null && pDescription.keyword != "")
     {
@@ -336,7 +339,9 @@ LogHistoryExecutor.prototype._getFormattedValue = function (pDescription, pValue
     else if (pDescription.translate4Log != null && pDescription.translate4Log != "") 
     {
         var params = Translate4LogParams.generateParams(this.idValue, pValue.toString(), this.sqlAction, this.translationLanguage);
-        pValue = process.executeScript("LogHistoryExecutor._getFormattedValue ", pDescription.translate4Log, params, vars.get("$sys.dbalias"));
+        var scriptId = "LogHistoryExecutor._getFormattedValue." 
+            + this.structureDefinitionAlias + "." + this.affectedTable + "." +  pColumnName + ".translate4Log";
+        pValue = process.executeScript(scriptId, pDescription.translate4Log, params, vars.get("$sys.dbalias"));
     }
     else if (pDescription.columnType == String(SQLTYPES.TIMESTAMP)) 
         pValue = datetime.toDate(pValue, translate.text("dd.MM.yyyy", this.translationLanguage), "Europe/Berlin");//TODO: timezone?
-- 
GitLab