From d21bc1e46525eeac263dd5a2397ba171958f8b68 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Tue, 15 Jan 2019 13:48:13 +0100
Subject: [PATCH] [Projekt: Entwicklung - Neon][TicketNr.:
 1030899][Adressselektion in Angebot und Beleg]

---
 entity/Address_entity/Address_entity.aod      |  1 +
 .../addr_type/possibleItemsProcess.js         | 12 +--
 .../entityfields/address/valueProcess.js      |  0
 .../entityfields/relation_id/valueProcess.js  |  7 +-
 entity/Offer_entity/Offer_entity.aod          | 13 +++-
 .../entityfields/address/documentation.adoc   |  3 +
 .../chosenaddress/onValueChange.js            | 11 +++
 .../chosenaddress/possibleItemsProcess.js     |  5 ++
 .../possibleaddresses/possibleItemsProcess.js |  4 -
 .../AddressList_view/AddressList_view.aod     |  1 +
 neonView/OfferEdit_view/OfferEdit_view.aod    |  8 ++
 .../OfferPreview_view/OfferPreview_view.aod   |  4 +
 others/db_changes/data/PERS_data.xml          | 24 ------
 others/db_changes/data/PERS_extendeddata.xml  | 21 ------
 .../1535612802325_addresses.xml               | 27 -------
 .../data/example_comm/1535614428250_comm.xml  | 24 ------
 others/db_changes/data/example_org.xml        | 67 -----------------
 .../data/example_pers/PERS_leicht.xml         | 40 ++++++++++
 others/db_changes/masterChangelog.xml         |  1 -
 process/PostalAddress_lib/process.js          | 74 +++++++++++++++++--
 20 files changed, 164 insertions(+), 183 deletions(-)
 create mode 100644 entity/Address_entity/entityfields/address/valueProcess.js
 create mode 100644 entity/Offer_entity/entityfields/address/documentation.adoc
 create mode 100644 entity/Offer_entity/entityfields/chosenaddress/onValueChange.js
 create mode 100644 entity/Offer_entity/entityfields/chosenaddress/possibleItemsProcess.js
 delete mode 100644 entity/Offer_entity/entityfields/possibleaddresses/possibleItemsProcess.js
 delete mode 100644 others/db_changes/data/PERS_data.xml
 delete mode 100644 others/db_changes/data/PERS_extendeddata.xml
 delete mode 100644 others/db_changes/data/example_address/1535612802325_addresses.xml
 delete mode 100644 others/db_changes/data/example_comm/1535614428250_comm.xml
 delete mode 100644 others/db_changes/data/example_org.xml

diff --git a/entity/Address_entity/Address_entity.aod b/entity/Address_entity/Address_entity.aod
index f3b70c507fa..f5f260207f5 100644
--- a/entity/Address_entity/Address_entity.aod
+++ b/entity/Address_entity/Address_entity.aod
@@ -11,6 +11,7 @@
       <name>ADDRESS</name>
       <title>Address</title>
       <mandatoryProcess>%aditoprj%/entity/Address_entity/entityfields/address/mandatoryProcess.js</mandatoryProcess>
+      <valueProcess>%aditoprj%/entity/Address_entity/entityfields/address/valueProcess.js</valueProcess>
     </entityField>
     <entityField>
       <name>ADDRESSADDITION</name>
diff --git a/entity/Address_entity/entityfields/addr_type/possibleItemsProcess.js b/entity/Address_entity/entityfields/addr_type/possibleItemsProcess.js
index 9b37906c7bd..018ea70fb3e 100644
--- a/entity/Address_entity/entityfields/addr_type/possibleItemsProcess.js
+++ b/entity/Address_entity/entityfields/addr_type/possibleItemsProcess.js
@@ -16,12 +16,14 @@ switch (type) {
         break;
 }
 
-result.object(KeywordUtils.getStandardArrayProps("ADDRESS.TYPE").filter(function (pKeyword) {       
+var resultKeywords = [];
+KeywordUtils.getStandardArrayProps("ADDRESS.TYPE").forEach(function(pKeyword) {
     for (let i = 0; i < fields.length; i++) {
         if (pKeyword[2][fields[i]]) {
-            return true;
+            resultKeywords.push([pKeyword[0], pKeyword[1]]);
+            break;
         }
     }
-    
-    return false;
-}));
\ No newline at end of file
+});
+
+result.object(resultKeywords);
\ No newline at end of file
diff --git a/entity/Address_entity/entityfields/address/valueProcess.js b/entity/Address_entity/entityfields/address/valueProcess.js
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/entity/Address_entity/entityfields/relation_id/valueProcess.js b/entity/Address_entity/entityfields/relation_id/valueProcess.js
index 61a5ce97dd4..d2e1b432aef 100644
--- a/entity/Address_entity/entityfields/relation_id/valueProcess.js
+++ b/entity/Address_entity/entityfields/relation_id/valueProcess.js
@@ -1,9 +1,12 @@
+import("system.logging");
 import("system.result");
 import("system.neon");
 import("system.vars");
 
-if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW)
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
 {
     if(vars.exists("$param.RelId_param") && vars.getString("$param.RelId_param"))
+    {
         result.string(vars.getString("$param.RelId_param"));    
-}
\ No newline at end of file
+    }
+}
diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod
index 78334abd582..883ea09314d 100644
--- a/entity/Offer_entity/Offer_entity.aod
+++ b/entity/Offer_entity/Offer_entity.aod
@@ -329,10 +329,19 @@
     </entityOutgoingField>
     <entityField>
       <name>ADDRESS</name>
+      <documentation>%aditoprj%/entity/Offer_entity/entityfields/address/documentation.adoc</documentation>
+      <title>address</title>
+      <description></description>
+      <contentType>LONG_TEXT</contentType>
     </entityField>
     <entityField>
-      <name>PossibleAddresses</name>
-      <possibleItemsProcess>%aditoprj%/entity/Offer_entity/entityfields/possibleaddresses/possibleItemsProcess.js</possibleItemsProcess>
+      <name>ChosenAddress</name>
+      <title>Choose address</title>
+      <possibleItemsProcess>%aditoprj%/entity/Offer_entity/entityfields/chosenaddress/possibleItemsProcess.js</possibleItemsProcess>
+      <onValueChange>%aditoprj%/entity/Offer_entity/entityfields/chosenaddress/onValueChange.js</onValueChange>
+      <onValueChangeTypes>
+        <element>MASK</element>
+      </onValueChangeTypes>
     </entityField>
   </entityFields>
   <recordContainers>
diff --git a/entity/Offer_entity/entityfields/address/documentation.adoc b/entity/Offer_entity/entityfields/address/documentation.adoc
new file mode 100644
index 00000000000..25ac2910909
--- /dev/null
+++ b/entity/Offer_entity/entityfields/address/documentation.adoc
@@ -0,0 +1,3 @@
+The Address is a free text field, because it should not be connected to the original address.
+
+The field is set also by the ChosenAddress field
\ No newline at end of file
diff --git a/entity/Offer_entity/entityfields/chosenaddress/onValueChange.js b/entity/Offer_entity/entityfields/chosenaddress/onValueChange.js
new file mode 100644
index 00000000000..e27804413bf
--- /dev/null
+++ b/entity/Offer_entity/entityfields/chosenaddress/onValueChange.js
@@ -0,0 +1,11 @@
+import("system.vars");
+import("system.neon");
+import("PostalAddress_lib");
+import("Entity_lib");
+
+var newAddressId = ProcessHandlingUtils.getOnValidationValue(vars.get("$field.ChosenAddress"));
+
+if (newAddressId)
+{
+    neon.setFieldValue("$field.ADDRESS", AddressUtils.getAddressById(newAddressId));
+}
\ No newline at end of file
diff --git a/entity/Offer_entity/entityfields/chosenaddress/possibleItemsProcess.js b/entity/Offer_entity/entityfields/chosenaddress/possibleItemsProcess.js
new file mode 100644
index 00000000000..5672ce8b163
--- /dev/null
+++ b/entity/Offer_entity/entityfields/chosenaddress/possibleItemsProcess.js
@@ -0,0 +1,5 @@
+import("system.vars");
+import("system.result");
+import("PostalAddress_lib");
+
+result.object(AddressUtils.getAllPossibleAddresses(vars.get("$field.RELATION_ID")));
\ No newline at end of file
diff --git a/entity/Offer_entity/entityfields/possibleaddresses/possibleItemsProcess.js b/entity/Offer_entity/entityfields/possibleaddresses/possibleItemsProcess.js
deleted file mode 100644
index fbbb4f0c71b..00000000000
--- a/entity/Offer_entity/entityfields/possibleaddresses/possibleItemsProcess.js
+++ /dev/null
@@ -1,4 +0,0 @@
-import("system.result");
-import("Keyword_lib");
-
-result.object(KeywordUtils.getStandardArray("ADDRESS.TYPE"));
\ No newline at end of file
diff --git a/neonView/AddressList_view/AddressList_view.aod b/neonView/AddressList_view/AddressList_view.aod
index 83e0b2e6bd8..e947fb863fe 100644
--- a/neonView/AddressList_view/AddressList_view.aod
+++ b/neonView/AddressList_view/AddressList_view.aod
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.0.1">
   <name>AddressList_view</name>
+  <description>Org addresses</description>
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <layout>
     <noneLayout>
diff --git a/neonView/OfferEdit_view/OfferEdit_view.aod b/neonView/OfferEdit_view/OfferEdit_view.aod
index e8f8de7cf5a..5c83f5e936d 100644
--- a/neonView/OfferEdit_view/OfferEdit_view.aod
+++ b/neonView/OfferEdit_view/OfferEdit_view.aod
@@ -56,6 +56,14 @@
           <name>c4b3c8ed-4625-4785-abc6-c726171ff7f4</name>
           <entityField>FOOTER</entityField>
         </entityFieldLink>
+        <entityFieldLink>
+          <name>833e6193-fde6-4990-8a26-eaeb0f60de48</name>
+          <entityField>ChosenAddress</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>930dc6e3-a19f-4780-9553-9cfd4a158fd5</name>
+          <entityField>ADDRESS</entityField>
+        </entityFieldLink>
       </fields>
     </genericViewTemplate>
     <neonViewReference>
diff --git a/neonView/OfferPreview_view/OfferPreview_view.aod b/neonView/OfferPreview_view/OfferPreview_view.aod
index f01c49bdfa8..1186c654358 100644
--- a/neonView/OfferPreview_view/OfferPreview_view.aod
+++ b/neonView/OfferPreview_view/OfferPreview_view.aod
@@ -34,6 +34,10 @@
           <name>49e446b5-015e-45ad-9417-c5c50f9756f1</name>
           <entityField>LANGUAGE</entityField>
         </entityFieldLink>
+        <entityFieldLink>
+          <name>447f5c6e-3653-49dd-ba8b-18c21a9bd6f9</name>
+          <entityField>ADDRESS</entityField>
+        </entityFieldLink>
       </fields>
     </genericViewTemplate>
     <genericViewTemplate>
diff --git a/others/db_changes/data/PERS_data.xml b/others/db_changes/data/PERS_data.xml
deleted file mode 100644
index 75d901d6354..00000000000
--- a/others/db_changes/data/PERS_data.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.1" encoding="UTF-8" standalone="no"?>
-<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
-<changeSet author="e.pollinger" id="efc45d88-a40d-49e0-a24c-afcb6095d1cb">
-	<insert tableName="PERS">
-		<column name="PERSID" value="efc45d88-a40d-49e0-a24c-afcb6095d1cb"/>
-		<column name="DATE_NEW" valueDate="2018-07-02T00:00:00"/>
-		<column name="DATEOFBIRTH" valueDate="1991-02-01"/>
-		<column name="USER_NEW" value="admin"/>
-		<column name="FIRSTNAME" value="Heribert"/>
-		<column name="MIDDLENAME" value="Anton"/>
-		<column name="LASTNAME" value="Untermeier"/>
-		<column name="GENDER" value="m"/>
-		<column name="SALUTATION" value="Herr"/>
-	</insert>
-        <rollback>
-            <delete tableName="PERS">
-                <where>PERSID = ?</where>
-                <whereParams>
-                    <param value="efc45d88-a40d-49e0-a24c-afcb6095d1cb" />
-                </whereParams>
-            </delete>
-        </rollback>
-</changeSet>
-</databaseChangeLog>
\ No newline at end of file
diff --git a/others/db_changes/data/PERS_extendeddata.xml b/others/db_changes/data/PERS_extendeddata.xml
deleted file mode 100644
index 03ae509a346..00000000000
--- a/others/db_changes/data/PERS_extendeddata.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.1" encoding="UTF-8" standalone="no"?>
-<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
-	<changeSet author="j.goderbauer" id="bcd51581-424d-40c0-b060-5abe8fe1efb2">
-		<insert tableName="RELATION">
-			<column name="RELATIONID" value="a8e084e2-d68a-4f1e-a7bb-f8d46ad6293d"/>
-			<column name="PERS_ID" value="efc45d88-a40d-49e0-a24c-afcb6095d1cb"/>
-			<column name="ORG_ID" value="29990305-4ac6-4876-94b9-0300ce5cefaa"/>
-			<column name="DATE_NEW" valueDate="2018-07-02T00:00:00"/>
-			<column name="USER_NEW" value="Lisa Sommer"/>
-			<column name="STATUS" valueNumeric="1"/>
-		</insert>
-            <rollback>
-                <delete tableName="RELATION">
-                    <where>RELATIONID = ?</where>
-                    <whereParams>
-                        <param value="a8e084e2-d68a-4f1e-a7bb-f8d46ad6293d" />
-                    </whereParams>
-                </delete>
-            </rollback>
-	</changeSet>
-</databaseChangeLog>
\ No newline at end of file
diff --git a/others/db_changes/data/example_address/1535612802325_addresses.xml b/others/db_changes/data/example_address/1535612802325_addresses.xml
deleted file mode 100644
index 711d28a71b8..00000000000
--- a/others/db_changes/data/example_address/1535612802325_addresses.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.1" encoding="UTF-8" standalone="no"?>
-<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
-    <changeSet author="j.goderbauer" id="b77db18b-ecc9-439b-a0bd-df86e63a413f">
-        <insert tableName="ADDRESS">
-            <column name="ADDRESSID" value="97d37aea-d7f8-4436-bb31-875439f5f7f1"/>
-            <column name="USER_NEW" value="Raphael"/>
-            <column name="DATE_NEW" valueDate="2018-08-13T02:06:43"/>
-            <column name="RELATION_ID" value="bdb6e38a-b227-455b-ae48-f8febd622e03"/>
- 
-            <column name="ADDR_TYPE" valueNumeric="1"/>
-            <column name="ADDRESS" value="Musterstraße"/>
-            <column name="BUILDINGNO" value="9"/>
-            <column name="ZIP" value="5018"/>
-            <column name="CITY" value="Bergen"/>
-            <column name="COUNTRY" value="DE"/>
-        </insert>
-        
-        <rollback>
-            <delete tableName="ADDRESS">
-                <where>ADDRESSID = ?</where>
-                <whereParams>
-                    <param value="97d37aea-d7f8-4436-bb31-875439f5f7f1"/>
-                </whereParams>
-            </delete>
-        </rollback>
-    </changeSet>
-</databaseChangeLog>
\ No newline at end of file
diff --git a/others/db_changes/data/example_comm/1535614428250_comm.xml b/others/db_changes/data/example_comm/1535614428250_comm.xml
deleted file mode 100644
index cd8636d1163..00000000000
--- a/others/db_changes/data/example_comm/1535614428250_comm.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.1" encoding="UTF-8" standalone="no"?>
-<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
-    <changeSet author="j.goderbauer" id="e452c5ee-dfe5-4aee-9eec-c3a397fa2ab2">
-        <insert tableName="COMM">
-            <column name="COMMID" value="cdd02d37-845d-40be-9b8c-08f99afa985f"/>
-            <column name="USER_NEW" value="Raphael"/>
-            <column name="DATE_NEW" valueDate="2018-08-13T03:14:22"/>
-            <column name="RELATION_ID" value="bdb6e38a-b227-455b-ae48-f8febd622e03"/>
- 
-            <column name="MEDIUM_ID" valueNumeric="3"/>
-            <column name="STANDARD" valueNumeric="1"/>
-            <column name="ADDR" value="http://www.brod-bergen.no/"/>
-        </insert>
-        
-        <rollback>
-            <delete tableName="COMM">
-                <where>COMMID = ?</where>
-                <whereParams>
-                    <param value="cdd02d37-845d-40be-9b8c-08f99afa985f"/>
-                </whereParams>
-            </delete>
-        </rollback>
-    </changeSet>
-</databaseChangeLog>
\ No newline at end of file
diff --git a/others/db_changes/data/example_org.xml b/others/db_changes/data/example_org.xml
deleted file mode 100644
index b2d8f2b8ca6..00000000000
--- a/others/db_changes/data/example_org.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.1" encoding="UTF-8" standalone="no"?>
-<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
-    <changeSet author="j.goderbauer" id="1528875814543-1">
-        <insert tableName="ORG">
-            <column name="ORGID" value="198b8a8b-c053-447a-bc69-17965b6a60ae"/>
-            <column name="USER_NEW" value="Gwendoline"/>
-            <column name="DATE_NEW" valueDate="2018-06-13T09:03:43"/>
-            <column name="NAME" value="Bitfox Ltd."/>
-            <column name="CUSTOMERCODE" value="01189998819991197253"/>
-            <column name="TYPE" valueNumeric="0"/>
-        </insert>
-        <insert tableName="RELATION">
-            <column name="RELATIONID" value="a589b58a-f120-42d8-9a64-0b176501eac7"/>
-            <column name="USER_NEW" value="Gwendoline"/>
-            <column name="DATE_NEW" valueDate="2018-06-13T09:03:43"/>
-            <column name="ORG_ID" value="198b8a8b-c053-447a-bc69-17965b6a60ae"/>
-            <column name="LANGUAGE" value="en-GB"/>
-            <column name="STATUS" valueNumeric="0"/>
-        </insert>
-        <rollback>
-            <delete tableName="RELATION">
-                <where>RELATIONID = ?</where>
-                <whereParams>
-                    <param value="a589b58a-f120-42d8-9a64-0b176501eac7" />
-                </whereParams>
-            </delete>
-            <delete tableName="ORG">
-                <where>ORGID = ?</where>
-                <whereParams>
-                    <param value="198b8a8b-c053-447a-bc69-17965b6a60ae" />
-                </whereParams>
-            </delete>
-
-        </rollback>
-    </changeSet>
-    <changeSet author="j.goderbauer" id="1528875814543-2">
-        <insert tableName="ORG">
-            <column name="ORGID" value="29990305-4ac6-4876-94b9-0300ce5cefaa"/>
-            <column name="USER_NEW" value="Gwendoline"/>
-            <column name="DATE_NEW" valueDate="2018-06-13T14:02:53"/>
-            <column name="NAME" value="Brød og mer &#x16D7; AS"/>
-            <column name="TYPE" valueNumeric="0"/>
-        </insert>
-        <insert tableName="RELATION">
-            <column name="RELATIONID" value="bdb6e38a-b227-455b-ae48-f8febd622e03"/>
-            <column name="USER_NEW" value="Gwendoline"/>
-            <column name="DATE_NEW" valueDate="2018-06-13T14:02:54"/>
-            <column name="ORG_ID" value="29990305-4ac6-4876-94b9-0300ce5cefaa"/>
-            <column name="LANGUAGE" value="no-NO"/>
-            <column name="STATUS" valueNumeric="0"/>
-        </insert>
-        <rollback>
-            <delete tableName="RELATION">
-                <where>RELATIONID = ?</where>
-                <whereParams>
-                    <param value="bdb6e38a-b227-455b-ae48-f8febd622e03" />
-                </whereParams>
-            </delete>
-            <delete tableName="ORG">
-                <where>ORGID = ?</where>
-                <whereParams>
-                    <param value="29990305-4ac6-4876-94b9-0300ce5cefaa" />
-                </whereParams>
-            </delete>
-        </rollback>
-    </changeSet>
-</databaseChangeLog>
\ No newline at end of file
diff --git a/others/db_changes/data/example_pers/PERS_leicht.xml b/others/db_changes/data/example_pers/PERS_leicht.xml
index ad4e5664ec8..bcc0d96c585 100644
--- a/others/db_changes/data/example_pers/PERS_leicht.xml
+++ b/others/db_changes/data/example_pers/PERS_leicht.xml
@@ -22,6 +22,40 @@
 		<column name="USER_NEW" value="admin"/>
 		<column name="STATUS" valueNumeric="1"/>
 	</insert>
+        <insert tableName="ADDRESS">
+                <column name="STATE" value="Bayern"/>
+                <column name="ADDR_TYPE" valueNumeric="2"/>
+                <column name="DATE_NEW" valueDate="2018-07-02T00:00:00"/>
+                <column name="CITY" value="Landshut"/>
+                <column name="COUNTRY" value="DE"/>
+                <column name="RELATION_ID" value="73d72f18-e7f5-11e8-9f32-f2801f1b9fd1"/>
+                <column name="USER_NEW" value="admin"/>
+                <column name="ADDRIDENTIFIER" value=""/>
+                <column name="REGION" value="Niederbayern"/>
+                <column name="ADDRESSID" value="ce990566-3b86-48fe-bd0c-1167142e584b"/>
+                <column name="BUILDINGNO" value="12"/>
+                <column name="ADDRESSADDITION"/>
+                <column name="ZIP" value="84034"/>
+                <column name="ADDRESS" value="Neustadt"/>
+                <column name="DISTRICT" value="Niederbayern"/>
+	</insert>
+        <insert tableName="ADDRESS">
+                <column name="STATE" value="Bayern"/>
+                <column name="ADDR_TYPE" valueNumeric="3"/>
+                <column name="DATE_NEW" valueDate="2018-07-02T00:00:00"/>
+                <column name="CITY" value="Landshut"/>
+                <column name="COUNTRY" value="DE"/>
+                <column name="RELATION_ID" value="73d72f18-e7f5-11e8-9f32-f2801f1b9fd1"/>
+                <column name="USER_NEW" value="admin"/>
+                <column name="ADDRIDENTIFIER" value=""/>
+                <column name="REGION" value="Niederbayern"/>
+                <column name="ADDRESSID" value="43b8aea1-2444-448f-87c5-f12fe1ef4ca0"/>
+                <column name="BUILDINGNO" value="13"/>
+                <column name="ADDRESSADDITION"/>
+                <column name="ZIP" value="84034"/>
+                <column name="ADDRESS" value="Neustadt"/>
+                <column name="DISTRICT" value="Niederbayern"/>
+	</insert>
 	<rollback>
 		<delete tableName="RELATION">
 			<where>RELATIONID = ?</where>
@@ -35,6 +69,12 @@
 				<param value="73d72bf8-e7f5-11e8-9f32-f2801f1b9fd1" />
 			</whereParams>
 		</delete>
+                <delete tableName="ADDRESS">
+			<where>RELATION_ID = ?</where>
+			<whereParams>
+				<param value="73d72bf8-e7f5-11e8-9f32-f2801f1b9fd1" />
+			</whereParams>
+		</delete>
 	</rollback>
 </changeSet>
 
diff --git a/others/db_changes/masterChangelog.xml b/others/db_changes/masterChangelog.xml
index 4059bb9fac5..17b5f69cde5 100644
--- a/others/db_changes/masterChangelog.xml
+++ b/others/db_changes/masterChangelog.xml
@@ -25,7 +25,6 @@
     <include file="struct/create_salesorderitem.xml"/>
     <include file="struct/create_countryinfo.xml"/>
     <include file="struct/create_timetracking.xml"/>
-    <include file="data/example_address/1535612802325_addresses.xml"/>
     <include file="data/example_org/ORG_privat.xml"/>
     <include file="data/example_org/ORG_gfk.xml"/>
     <include file="data/example_org/ORG_mnf.xml"/>
diff --git a/process/PostalAddress_lib/process.js b/process/PostalAddress_lib/process.js
index d3e6ed3ff18..394f05bac8a 100644
--- a/process/PostalAddress_lib/process.js
+++ b/process/PostalAddress_lib/process.js
@@ -1,7 +1,7 @@
 import("system.db");
 import("Sql_lib");
 import("Relation_lib");
-
+import("Keyword_lib");
 /**
  * Methods for addresses.
  * Todo: evtl. übernahme / anpassung der Adresslib aus altem Basic. 1030856
@@ -59,26 +59,88 @@ AddressUtils.getAddress = function(pRelationId) {
     }
     var type = RelationUtils.getRelationTypeByRelation(pRelationId);
     
+    return AddressUtils.formatAddress(type, address[1], address[2], address[3], address[4], address[5], address[6], address[7], address[8]);
+}
+
+/**
+ * Returns the formatted address.
+ * 
+ * TODO: Dummy method! Ãœbernahme der Adresslib aus altem Basic
+ * 
+ * @return {String}
+ */
+AddressUtils.getAddressById = function(pAddressId) {
+    var address = db.array(db.ROW, SqlCondition.begin()
+                                               .andPrepare("ADDRESS.ADDRESSID", pAddressId)
+                                               .buildSelect("select RELATION_ID, ADDRESS, BUILDINGNO, ZIP, CITY from "
+                                                          + "ADDRESS", "1=0"));
+    
+    // TODO: currently there are some relations without standard address. Use Hardcoded one.
+    if (!address[1]) {
+        var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSelect('select RELATION_ID, ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0"));
+        address[0] = dummyAddress[0];
+        address[1] = dummyAddress[1];
+        address[2] = dummyAddress[2];
+        address[3] = dummyAddress[3];
+        address[4] = dummyAddress[4];
+        
+    }
+    var type = RelationUtils.getRelationTypeByRelation(address[0]);   
+
+    var names = db.array(db.ROW, SqlCondition.begin()
+                                             .andPrepare("RELATION.RELATIONID", address[0])
+                                             .buildSelect("select ORG.NAME, FIRSTNAME, LASTNAME, TITLE from RELATION left join PERS on PERSID = PERS_ID left join ORG on ORGID = ORG_ID"
+                                                            , "1=0"));
+    return AddressUtils.formatAddress(type, address[1], address[2], address[3], address[4], names[0], names[1], names[2], names[3]);
+}
+
+/**
+ * TODO: Dummy method!
+ *
+ * Returns the formatted address.
+ * 
+ * TODO: Dummy method! Ãœbernahme der Adresslib aus altem Basic und Nutzung von den Platzhaltern in Zukunft!
+ * 
+ * @return {String}
+ */
+AddressUtils.formatAddress = function(pAddrType, pAddress, pBuildingno, pZip, pCity, pOrgname, pFirstname, pLastname, pTitle) {
     var resultAddr = "";
+        
     // 1 if organisation <br>
     // 2 if privat person <br>
-    // 3 if person of an organisation <br>*/
-    switch (type) 
+    // 3 if person of an organisation <br>
+    switch (pAddrType) 
     {
         case 1:
-            resultAddr = address[5] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
+            resultAddr = pOrgname + "\n" + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity;
             break;
         case 2:
-            resultAddr = address[8] + " " + address[6] + " " + address[7] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
+            resultAddr = pTitle + " " + pFirstname + " " + pLastname + "\n" + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity;
             break;
         case 3:
-            resultAddr = address[5] + "\n" + address[6] + " " + address[7] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
+            resultAddr = pOrgname + "\n" + (pTitle && pFirstname && pLastname ? pTitle + " " + pFirstname + " " + pLastname + "\n" : "") + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity;
             break;
     }
     
     return resultAddr;
 }
 
+/**
+ * Returns the formatted addresses for the relation.
+ * 
+ * TODO: Dummy method! Ãœbernahme der Adresslib aus altem Basic
+ * 
+ * @return {String}
+ */
+AddressUtils.getAllPossibleAddresses = function(pRelationId) {
+    var addresses = db.table(SqlCondition.begin().andPrepare("RELATION.RELATIONID", pRelationId)
+                                                     .buildSelect("select ADDRESSID, ADDR_TYPE, ADDRIDENTIFIER from ADDRESS join RELATION on RELATIONID = RELATION_ID or RELATION_ID = ORG_ID", "1=0"));
+                                                     
+    return addresses.map(function(pAddress) {
+        return [pAddress[0], KeywordUtils.get("ADDRESS.TYPE", pAddress[1])[1] + " " + pAddress[2]]
+    });
+}
+
 /**
  * Returns a letter salutation.
  * 
-- 
GitLab