diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod index fc1d8d175ff4c2c473d855cc124c8342bd165afe..0182f22693d7d081143409f74d41c329992df5cb 100644 --- a/aliasDefinition/Data_alias/Data_alias.aod +++ b/aliasDefinition/Data_alias/Data_alias.aod @@ -214,9 +214,9 @@ <columnType v="1" /> <size v="36" /> <scale v="0" /> - <notNull v="true" /> + <notNull v="false" /> <isUnique v="false" /> - <index v="true" /> + <index v="false" /> <title></title> <description></description> </entityFieldDb> @@ -1394,19 +1394,6 @@ <syncIds></syncIds> </auditSyncConfig> <entityFields> - <entityFieldDb> - <name>ORG_ID</name> - <dbName></dbName> - <primaryKey v="false" /> - <columnType v="1" /> - <size v="36" /> - <scale v="0" /> - <notNull v="false" /> - <isUnique v="false" /> - <index v="false" /> - <title></title> - <description></description> - </entityFieldDb> <entityFieldDb> <name>UNIT</name> <dbName></dbName> @@ -1576,6 +1563,20 @@ <title></title> <description></description> </entityFieldDb> + <entityFieldDb> + <name>RELATION_ID</name> + <dbName></dbName> + <primaryKey v="false" /> + <columnType v="1" /> + <size v="36" /> + <scale v="0" /> + <notNull v="false" /> + <isUnique v="false" /> + <index v="false" /> + <documentation></documentation> + <title></title> + <description></description> + </entityFieldDb> </entityFields> </entityDb> <entityDb> @@ -1765,7 +1766,7 @@ <columnType v="4" /> <size v="10" /> <scale v="0" /> - <notNull v="false" /> + <notNull v="true" /> <isUnique v="false" /> <index v="false" /> <title></title> @@ -2535,7 +2536,7 @@ <scale v="0" /> <notNull v="false" /> <isUnique v="false" /> - <index v="true" /> + <index v="false" /> <documentation></documentation> <title></title> <description></description> @@ -2645,9 +2646,9 @@ <columnType v="1" /> <size v="36" /> <scale v="0" /> - <notNull v="true" /> + <notNull v="false" /> <isUnique v="false" /> - <index v="true" /> + <index v="false" /> <title></title> <description></description> </entityFieldDb> diff --git a/entity/Org_entity/Org_entity.aod b/entity/Org_entity/Org_entity.aod index 0b483c0f1988d50a73318957b6391a2e04f45d13..112ead0c4cec30426edfce1328e4f71b137ef541 100644 --- a/entity/Org_entity/Org_entity.aod +++ b/entity/Org_entity/Org_entity.aod @@ -374,8 +374,8 @@ </dependency> <children> <entityParameter> - <name>OrgId_param</name> - <code>%aditoprj%/entity/Org_entity/entityfields/orgproduct_dfo/children/orgid_param/code.js</code> + <name>relationId_param</name> + <code>%aditoprj%/entity/Org_entity/entityfields/orgproduct_dfo/children/relationid_param/code.js</code> </entityParameter> </children> </entityOutgoingField> diff --git a/entity/Org_entity/entityfields/orgproduct_dfo/children/orgid_param/code.js b/entity/Org_entity/entityfields/orgproduct_dfo/children/relationid_param/code.js similarity index 52% rename from entity/Org_entity/entityfields/orgproduct_dfo/children/orgid_param/code.js rename to entity/Org_entity/entityfields/orgproduct_dfo/children/relationid_param/code.js index 43a0099996b20b6781091de4a333fa1c8f28056f..aa257b8b78ed72ce888626a9fa22a890e3c9bf17 100644 --- a/entity/Org_entity/entityfields/orgproduct_dfo/children/orgid_param/code.js +++ b/entity/Org_entity/entityfields/orgproduct_dfo/children/relationid_param/code.js @@ -1,4 +1,4 @@ import("system.result"); import("system.vars"); -result.string(vars.get("$field.ORGID")); \ No newline at end of file +result.string(vars.get("$field.RELATIONID")); \ No newline at end of file diff --git a/entity/Product_entity/Product_entity.aod b/entity/Product_entity/Product_entity.aod index e73c1a6a9548eedd229795c3b5911a76a7d9b239..73e5daa061e4a4637ee6ec8c549a27ea258a96a2 100644 --- a/entity/Product_entity/Product_entity.aod +++ b/entity/Product_entity/Product_entity.aod @@ -63,13 +63,6 @@ <contentType>NUMBER</contentType> <outputFormat>#,##0.##</outputFormat> </entityField> - <entityField> - <name>ORG_ID</name> - <title>Developer</title> - <tableName>PRODUCT</tableName> - <columnName>ORG_ID</columnName> - <valueProcess>%aditoprj%/entity/Product_entity/entityfields/org_id/valueProcess.js</valueProcess> - </entityField> <entityField> <name>PRODUCTCODE</name> <documentation>%aditoprj%/entity/Product_entity/entityfields/productcode/documentation.adoc</documentation> @@ -167,7 +160,7 @@ </dependencies> </entityIncomingField> <entityParameter> - <name>OrgId_param</name> + <name>relationId_param</name> <expose v="true" /> <triggerRecalculation v="true" /> <mandatory v="false" /> @@ -278,21 +271,51 @@ </entityParameter> </children> </entityOutgoingField> + <entityField> + <name>RELATION_ID</name> + <title>Developer</title> + <tableName>PRODUCT</tableName> + <columnName>RELATION_ID</columnName> + <linkedContextProcess>%aditoprj%/entity/Product_entity/entityfields/relation_id/linkedContextProcess.js</linkedContextProcess> + <outgoingField>ProductOrg_dfo</outgoingField> + <valueProcess>%aditoprj%/entity/Product_entity/entityfields/relation_id/valueProcess.js</valueProcess> + </entityField> + <entityField> + <name>RELATION_ORG_ID</name> + </entityField> + <entityField> + <name>RELATION_PERS_ID</name> + </entityField> </entityFields> <recordContainers> <dbRecordContainer> <name>db</name> <alias>Data_alias</alias> <maximumDbRows v="0" /> + <fromClauseProcess>%aditoprj%/entity/Product_entity/recordcontainers/db/fromClauseProcess.js</fromClauseProcess> <onDBDelete>%aditoprj%/entity/Product_entity/recordcontainers/db/onDBDelete.js</onDBDelete> <linkInformation> <linkInformation> - <name>c1012dc4-2126-433f-aacd-ce8f25e96f42</name> + <name>219bb2ab-3c6f-475f-a2b4-0d3e48b16b8f</name> <tableName>PRODUCT</tableName> <primaryKey>PRODUCTID</primaryKey> <isUIDTable v="true" /> <readonly v="false" /> </linkInformation> + <linkInformation> + <name>478598a4-3130-4b0c-ba8d-14b67f003ee5</name> + <tableName>RELATION</tableName> + <primaryKey>RELATIONID</primaryKey> + <isUIDTable v="false" /> + <readonly v="true" /> + </linkInformation> + <linkInformation> + <name>3800cc08-4ab5-4b9a-a200-993c990b7906</name> + <tableName>ORG</tableName> + <primaryKey>ORGID</primaryKey> + <isUIDTable v="false" /> + <readonly v="true" /> + </linkInformation> </linkInformation> <recordFieldMappings> <dbRecordFieldMapping> @@ -316,8 +339,8 @@ <value>PRODUCT.MINSTOCK</value> </dbRecordFieldMapping> <dbRecordFieldMapping> - <name>ORG_ID.value</name> - <value>PRODUCT.ORG_ID</value> + <name>RELATION_ID.value</name> + <value>PRODUCT.RELATION_ID</value> </dbRecordFieldMapping> <dbRecordFieldMapping> <name>PRODUCTCODE.value</name> @@ -351,6 +374,18 @@ <name>USER_NEW.value</name> <value>PRODUCT.USER_NEW</value> </dbRecordFieldMapping> + <dbRecordFieldMapping> + <name>RELATION_ORG_ID.value</name> + <value>RELATION.ORG_ID</value> + </dbRecordFieldMapping> + <dbRecordFieldMapping> + <name>RELATION_PERS_ID.value</name> + <value>RELATION.PERS_ID</value> + </dbRecordFieldMapping> + <dbRecordFieldMapping> + <name>RELATION_ID.displayValue</name> + <value>ORG.NAME</value> + </dbRecordFieldMapping> </recordFieldMappings> </dbRecordContainer> </recordContainers> diff --git a/entity/Product_entity/entityfields/org_id/valueProcess.js b/entity/Product_entity/entityfields/org_id/valueProcess.js deleted file mode 100644 index de32e15c56f4743946b19f2cd9b7383df46b1c37..0000000000000000000000000000000000000000 --- a/entity/Product_entity/entityfields/org_id/valueProcess.js +++ /dev/null @@ -1,11 +0,0 @@ -import("system.vars"); -import("system.result"); -import("system.neon"); - -if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW) -{ - if(vars.exists("$param.OrgId_param") && vars.get("$param.OrgId_param") != null) - result.string(vars.getString("$param.OrgId_param")); -} -else - result.string(vars.get("$this.value")); diff --git a/entity/Product_entity/entityfields/relation_id/linkedContextProcess.js b/entity/Product_entity/entityfields/relation_id/linkedContextProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..bd698d1aca9e1c515735c58137858371efbd24df --- /dev/null +++ b/entity/Product_entity/entityfields/relation_id/linkedContextProcess.js @@ -0,0 +1,14 @@ +import("system.result"); +import("system.vars"); +import("Relation_lib") + +switch (RelationUtils.getRelationTypeByPersOrg(vars.get("$field.RELATION_PERS_ID"), vars.get("$field.RELATION_ORG_ID"))) +{ + case 1: // Org + result.string("Org_context") + break; + case 2: // private Pers + case 3: // Pers + result.string("Pers_context") + default: +} \ No newline at end of file diff --git a/entity/Product_entity/entityfields/relation_id/valueProcess.js b/entity/Product_entity/entityfields/relation_id/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..7e309f23c0b812ae56fb35abe46a40245c5bb0f6 --- /dev/null +++ b/entity/Product_entity/entityfields/relation_id/valueProcess.js @@ -0,0 +1,9 @@ +import("system.vars"); +import("system.result"); +import("system.neon"); + +if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW) +{ + if(vars.exists("$param.relationId_param") && vars.get("$param.relationId_param")) + result.string(vars.getString("$param.relationId_param")); +} diff --git a/entity/Product_entity/recordcontainers/db/fromClauseProcess.js b/entity/Product_entity/recordcontainers/db/fromClauseProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..7bfbd0635acff5460cb5991a0fd5eb0908528818 --- /dev/null +++ b/entity/Product_entity/recordcontainers/db/fromClauseProcess.js @@ -0,0 +1,3 @@ +import("system.result"); + +result.string("PRODUCT left join RELATION on RELATIONID = RELATION_ID left join ORG on ORGID = ORG_ID"); \ No newline at end of file diff --git a/neonView/ProductPreview_view/ProductPreview_view.aod b/neonView/ProductPreview_view/ProductPreview_view.aod index c1f1fa217d9ae38c855ec48f00c106d248e519bf..03fea1d033d1ddb20e4e581c68b89a51d1790419 100644 --- a/neonView/ProductPreview_view/ProductPreview_view.aod +++ b/neonView/ProductPreview_view/ProductPreview_view.aod @@ -25,8 +25,8 @@ <entityField>PRODUCTNAME</entityField> </entityFieldLink> <entityFieldLink> - <name>7074979a-a2fc-4a57-98ad-3d8e98fde37a</name> - <entityField>ORG_ID</entityField> + <name>bd8e7e33-6fc6-48fe-b9be-931383f4d859</name> + <entityField>RELATION_ID</entityField> </entityFieldLink> <entityFieldLink> <name>a5a3ecee-059d-4bf2-9654-abe3efd58510</name> diff --git a/others/db_changes/struct/create_product.xml b/others/db_changes/struct/create_product.xml index 685984f4d1c041aac1ac7ed1a3319fde5773e5c3..03301c76b78e28c69a855027347f9e3597edf518 100644 --- a/others/db_changes/struct/create_product.xml +++ b/others/db_changes/struct/create_product.xml @@ -8,7 +8,7 @@ <column name="ADVERTISING" type="CHAR(1)"/> <column name="GROUPCODEID" type="INTEGER"/> <column name="MINSTOCK" type="NUMERIC(14,2)"/> - <column name="ORG_ID" type="CHAR(36)"/> + <column name="RELATION_ID" type="CHAR(36)"/> <column name="PRODUCTCODE" type="VARCHAR(50)"> <constraints nullable="false" unique="true" uniqueConstraintName="UNIQUE_PRODUCT_PRODUCTCODE"/> </column> diff --git a/process/Relation_lib/Relation_lib.aod b/process/Relation_lib/Relation_lib.aod new file mode 100644 index 0000000000000000000000000000000000000000..3871a31e6ae3cf4368651d326487f1eef1ed9287 --- /dev/null +++ b/process/Relation_lib/Relation_lib.aod @@ -0,0 +1,6 @@ +<?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>Relation_lib</name> + <majorModelMode>DISTRIBUTED</majorModelMode> + <process>%aditoprj%/process/Relation_lib/process.js</process> +</process> diff --git a/process/Relation_lib/process.js b/process/Relation_lib/process.js new file mode 100644 index 0000000000000000000000000000000000000000..6b6e3829fedfb5c7761eaed65ed15ca7a00bbb87 --- /dev/null +++ b/process/Relation_lib/process.js @@ -0,0 +1,77 @@ +import("system.db"); +import("Sql_lib"); + +/** + * a static Utility class for relations + * + * Do not create an instance of this! + * @class + */ +function RelationUtils() {} + +/** + * get the type of relation for a relationId <br> + * If you already have persId and orgId from the RELATION table, use getRelationTypeByPersOrg() <br> + * @param {String} pRelationId + * <br> + * @return {String} 0 if relationId not found <br> + * 1 if organisation <br> + * 2 if privat person <br> + * 3 if person of an organisation <br> + */ +RelationUtils.getRelationTypeByRelation = function(pRelationId) +{ + var relationData = db.array(db.ROW, + SqlCondition.begin() + .andPrepare("RELATION.RELATIONID", pRelationId) + .buildSelect("select RELATIONID, PERS_ID, ORG_ID from RELATION", "1=0")); + + if (relationData[0]) + { + return this.getRelationTypeByPersOrg(relationData[1], relationData[2]); + } + else + { + return 0; + } +} + +/** + * Get the type of relation. <br> + * It only checks if the parameters are not empty. <br> + * Based on which parameter is empty / not empty it return s the type of the relation. <br> + * <br> + * !!It does not check if the pers / org ids really exist!! <br> + * !!And it does not check if really any relation with this pers / org ids exist!! <br> + * <br> + * This function is more performant than getRelationTypeByRelation, <br> + * because it doesn't load something from the db. <br> + * <br> + * It is meant to be used by entitys, where you can load pers and org with the DataRecord. <br> + * This saves an extra select from RELATION. <br> + * <br> + * @param {String} pPersId selected from the RELATION table + * @param {String} pOrgId selected from the RELATION table + * <br> + * @return {String} <br>1 if organisation <br> + * 2 if privat person <br> + * 3 if person of an organisation <br> + */ +RelationUtils.getRelationTypeByPersOrg = function(pPersId, pOrgId) +{ + if (!pPersId) + { + return 1; // Organisation da PERS_ID leer + } + else + { + if (pOrgId.replace(/\s/g,"") == "0" ) + { + return 2; // Privatperson da PERS_ID nicht leer und ORG_ID.trim() = '0' + } + else + { + return 3; // Person einer Organisation da PERS_ID nicht leer und ORG_ID nicht '0' + } + } +} \ No newline at end of file diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js index 6d270c9c0d5faf915789220e5a78ede0dd80b2f1..56217a25382fcfa130177e7b79524b737a5db9c9 100644 --- a/process/Sql_lib/process.js +++ b/process/Sql_lib/process.js @@ -38,7 +38,7 @@ function SqlCondition(alias) { * See Examples! * * @param {String} [alias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements) - * @return {Object} the new SqlCondition-object + * @return {SqlCondition} the new SqlCondition-object * * @example * vars mySelect = SqlCondition.begin(alias) @@ -61,7 +61,7 @@ SqlCondition.begin = function(alias) { /** * append with SQL-and; no paranthesize of existing conditions is done * @param {String} cond the condition string which shall be appended - * @return {Object} current SqlCondition-object + * @return {SqlCondition} current SqlCondition-object */ SqlCondition.prototype.and = function(cond) { if (!cond) @@ -84,7 +84,7 @@ SqlCondition.prototype.and = function(cond) { * for (...) { * cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?") * } - * @return {Object} current SqlCondition-object + * @return {SqlCondition} current SqlCondition-object */ SqlCondition.prototype.andPrepare = function(field, value, cond, fieldType) { cond = this._prepare(field, value, cond, fieldType); @@ -94,7 +94,7 @@ SqlCondition.prototype.andPrepare = function(field, value, cond, fieldType) { /** * append with SQL-or; Also paranthesize the existing conditions * @param {String} cond the condition string which shall be appended - * @return {Object} current SqlCondition-object + * @return {SqlCondition} current SqlCondition-object */ SqlCondition.prototype.or = function(cond) { if (!cond) @@ -117,9 +117,9 @@ SqlCondition.prototype.or = function(cond) { /** * append another condition with SQL-or; Also paranthesize the existing conditions * - * @param {Object} cond the condition which shall be appended + * @param {SqlCondition} cond the condition which shall be appended * @param {String} [alternativeCond=""] condition if the given SqlCondition has none - * @return {Object} current SqlCondition-object + * @return {SqlCondition} current SqlCondition-object */ SqlCondition.prototype.orSqlCondition = function(cond, alternativeCond) { this.or(" ( " + cond.toString(alternativeCond) + " ) "); @@ -132,9 +132,9 @@ SqlCondition.prototype.orSqlCondition = function(cond, alternativeCond) { /** * append another condition with SQL-and * - * @param {Object} cond the condition which shall be appended + * @param {SqlCondition} cond the condition which shall be appended * @param {String} [alternativeCond=""] condition if the given SqlCondition has none - * @return {Object} current SqlCondition-object + * @return {SqlCondition} current SqlCondition-object */ SqlCondition.prototype.andSqlCondition = function(cond, alternativeCond) { this.and(" ( " + cond.toString(alternativeCond) + " ) "); @@ -156,7 +156,7 @@ SqlCondition.prototype.andSqlCondition = function(cond, alternativeCond) { * for (...) { * cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?") * } - * @return {Object} current SqlCondition-object + * @return {SqlCondition} current SqlCondition-object */ SqlCondition.prototype.orPrepare = function(field, value, cond, fieldType) { cond = this._prepare(field, value, cond, fieldType); @@ -175,7 +175,7 @@ SqlCondition.prototype.orPrepare = function(field, value, cond, fieldType) { * for (...) { * cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?") * } - * @return {Object} current SqlCondition-object + * @return {SqlCondition} current SqlCondition-object */ SqlCondition.prototype.andPrepareVars = function(field, variable, cond, fieldType) { variable = this._checkVars(variable) @@ -197,7 +197,7 @@ SqlCondition.prototype.andPrepareVars = function(field, variable, cond, fieldTyp * for (...) { * cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?") * } - * @return {Object} current SqlCondition-object + * @return {SqlCondition} current SqlCondition-object */ SqlCondition.prototype.orPrepareVars = function(field, variable, cond, fieldType) { variable = this._checkVars(variable) @@ -222,7 +222,7 @@ SqlCondition.prototype.toString = function(alternativeCond) { /** * ready to use string; does contain a where keyword at the beginning * @param {String} [alternativeCond=""] condition that is returned when nothing has been appended. - * @return {String} concatenated SQL-condition; empty string if nothing has been appended or - if passed - the alternativeCond + * @return {SqlCondition} concatenated SQL-condition; empty string if nothing has been appended or - if passed - the alternativeCond */ SqlCondition.prototype.toWhereString = function(alternativeCond) { var cond = this.toString(alternativeCond);