From fe38daee372e804d1a3e4ed3ef76ef093ea46256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Schr=C3=B6ger?= <m.schroeger@adito.de> Date: Fri, 26 Oct 2018 17:05:54 +0200 Subject: [PATCH] Util_lib erweitert um Klasse CopyModuleUtils - Implementierung: Neue Angebotsversion --- entity/Offer_entity/Offer_entity.aod | 16 + entity/Offer_entity/conditionProcess.js | 0 .../newofferversion/onActionProcess.js | 22 + .../children/offerid_param/code.js | 4 + entity/Offeritem_entity/Offeritem_entity.aod | 4 +- entity/Offeritem_entity/conditionProcess.js | 8 + .../_____LANGUAGE_EXTRA.aod | 3 + .../_____LANGUAGE_de/_____LANGUAGE_de.aod | 4 + .../_____LANGUAGE_en/_____LANGUAGE_en.aod | 3 + neonContext/Offer_context/Offer_context.aod | 1 + .../_____PREFERENCES_PROJECT.aod | 2 +- process/Util_lib/process.js | 394 ++++++++++++++++++ 12 files changed, 459 insertions(+), 2 deletions(-) create mode 100644 entity/Offer_entity/conditionProcess.js create mode 100644 entity/Offer_entity/entityfields/newofferversion/onActionProcess.js create mode 100644 entity/Offer_entity/entityfields/offerofferitem_dfo/children/offerid_param/code.js create mode 100644 entity/Offeritem_entity/conditionProcess.js diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod index f18450b286..4ab172e44a 100644 --- a/entity/Offer_entity/Offer_entity.aod +++ b/entity/Offer_entity/Offer_entity.aod @@ -4,6 +4,7 @@ <title>Offer</title> <majorModelMode>DISTRIBUTED</majorModelMode> <alias>Data_alias</alias> + <conditionProcess>%aditoprj%/entity/Offer_entity/conditionProcess.js</conditionProcess> <recordContainerType>DB</recordContainerType> <caption>Offer</caption> <entityFields> @@ -144,7 +145,22 @@ <entityName>Offeritem_entity</entityName> <fieldName>#INCOMING</fieldName> </dependency> + <children> + <entityParameter> + <name>OfferId_param</name> + <code>%aditoprj%/entity/Offer_entity/entityfields/offerofferitem_dfo/children/offerid_param/code.js</code> + <expose v="true" /> + <triggerRecalculation v="true" /> + <mandatory v="true" /> + </entityParameter> + </children> </entityOutgoingField> + <entityActionField> + <name>newOfferVersion</name> + <fieldType>ACTION</fieldType> + <onActionProcess>%aditoprj%/entity/Offer_entity/entityfields/newofferversion/onActionProcess.js</onActionProcess> + <caption>New offer verison</caption> + </entityActionField> </entityFields> <linkInformation> <linkInformation> diff --git a/entity/Offer_entity/conditionProcess.js b/entity/Offer_entity/conditionProcess.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/entity/Offer_entity/entityfields/newofferversion/onActionProcess.js b/entity/Offer_entity/entityfields/newofferversion/onActionProcess.js new file mode 100644 index 0000000000..c08e236d13 --- /dev/null +++ b/entity/Offer_entity/entityfields/newofferversion/onActionProcess.js @@ -0,0 +1,22 @@ +import("system.logging"); +import("system.vars"); +import("system.neon"); +import("Util_lib"); + +var CMUtils = new CopyModuleUtils(); + +var InputMapping = { + + "OFFER": { + condition: "OFFERID = '" + vars.get("$field.OFFERID") + "'" + , SubModules:{ + "OFFERITEM": { + condition: "OFFER_ID = '" + vars.get("$field.OFFERID") + "' order by ITEMSORT" + } + } + } +} + +var ModulesMapping = CMUtils.copyModule(InputMapping); + +CMUtils.openNewModules("Offer_context", ModulesMapping); \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/offerofferitem_dfo/children/offerid_param/code.js b/entity/Offer_entity/entityfields/offerofferitem_dfo/children/offerid_param/code.js new file mode 100644 index 0000000000..5e2ebc73ab --- /dev/null +++ b/entity/Offer_entity/entityfields/offerofferitem_dfo/children/offerid_param/code.js @@ -0,0 +1,4 @@ +import("system.vars"); +import("system.result"); + +result.string(vars.get("$field.OFFERID")); \ No newline at end of file diff --git a/entity/Offeritem_entity/Offeritem_entity.aod b/entity/Offeritem_entity/Offeritem_entity.aod index 31c42f1dd7..e79df8ba11 100644 --- a/entity/Offeritem_entity/Offeritem_entity.aod +++ b/entity/Offeritem_entity/Offeritem_entity.aod @@ -4,6 +4,7 @@ <title>Offeritem</title> <majorModelMode>DISTRIBUTED</majorModelMode> <alias>Data_alias</alias> + <conditionProcess>%aditoprj%/entity/Offeritem_entity/conditionProcess.js</conditionProcess> <recordContainerType>DB</recordContainerType> <caption>Offeritem</caption> <entityFields> @@ -48,7 +49,7 @@ <name>DISCOUNT</name> <tableName>OFFERITEM</tableName> <columnName>DISCOUNT</columnName> - <caption>Rabatt</caption> + <caption>Discount</caption> </entityField> <entityField> <name>GROUPCODEID</name> @@ -136,6 +137,7 @@ <name>OfferId_param</name> <expose v="true" /> <triggerRecalculation v="true" /> + <mandatory v="true" /> <description>PARAMETER</description> </entityParameter> </entityFields> diff --git a/entity/Offeritem_entity/conditionProcess.js b/entity/Offeritem_entity/conditionProcess.js new file mode 100644 index 0000000000..904a7b5517 --- /dev/null +++ b/entity/Offeritem_entity/conditionProcess.js @@ -0,0 +1,8 @@ +import("system.logging"); +import("system.result"); +import("system.vars"); + +if(vars.exists("$param.OfferId_param") && vars.get("$param.OfferId_param") != "") + result.string("OFFERITEM.OFFER_ID = ('" + vars.get("$param.OfferId_param") + "')"); +else + result.string("1 = 2"); \ No newline at end of file diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod index d8e5298e71..b792b08850 100644 --- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod +++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod @@ -693,6 +693,9 @@ <entry> <key>Offeritem</key> </entry> + <entry> + <key>New offer verison</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> <sqlModels> diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod index 833f8d7e1f..2befe9354a 100644 --- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod +++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod @@ -905,6 +905,10 @@ <key>Offeritem</key> <value>Angebotsposten</value> </entry> + <entry> + <key>New offer verison</key> + <value>Neue Angebotsversion</value> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod index 5ca99d946d..88547b9265 100644 --- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod +++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod @@ -701,6 +701,9 @@ <entry> <key>Offeritem</key> </entry> + <entry> + <key>New offer verison</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/neonContext/Offer_context/Offer_context.aod b/neonContext/Offer_context/Offer_context.aod index 77b1dfe024..37a7a890e1 100644 --- a/neonContext/Offer_context/Offer_context.aod +++ b/neonContext/Offer_context/Offer_context.aod @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.0.0"> <name>Offer_context</name> + <title>Offer</title> <majorModelMode>DISTRIBUTED</majorModelMode> <mainview>OfferMain_view</mainview> <filterview>OfferFilter_view</filterview> diff --git a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod index b0f2142f63..6342decac5 100644 --- a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod +++ b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod @@ -2,7 +2,7 @@ <preferences xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="3.0.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/preferences/3.0.1"> <name>_____PREFERENCES_PROJECT</name> <majorModelMode>DISTRIBUTED</majorModelMode> - <projectName>xRM-Basic-5</projectName> + <projectName>xRM-Basic</projectName> <jditoMaxContentSize v="57671680" /> <calendarCategoriesEvent> <entry> diff --git a/process/Util_lib/process.js b/process/Util_lib/process.js index 406f2120f8..71cd86700d 100644 --- a/process/Util_lib/process.js +++ b/process/Util_lib/process.js @@ -1,3 +1,4 @@ +import("system.neon"); import("system.project"); import("system.logging"); import("system.process"); @@ -10,6 +11,8 @@ import("system.swing"); import("system.question"); import("system.eMath"); import("system.datetime"); +import("Offer_lib"); +import("Date_lib"); /** * Class containing utility functions for images @@ -1055,3 +1058,394 @@ function JSONUtils() return parse; } } + +/** + * Class containing utility functions for copying modules + * @class + */ +function CopyModuleUtils() +{ + var that = this; + + /** + * opens the new created modules in neonClient + * + * @param {String} pNeonContext req Name of the neon context that should be opened + * @param {Object} pModulesMapping req ModulesMapping object created by method copyModule + * + * @example var ModulesMapping = CMUtils.copyModule(InputMapping); + * + * CMUtils.openNewModules("Offer_context", ModulesMapping); + */ + this.openNewModules = function(pNeonContext, pModulesMapping) + { + if(pModulesMapping != undefined) + { + var rootModule = Object.keys(pModulesMapping)[0]; + if(pModulesMapping[rootModule].DataRows != undefined) + { + var newids = []; + + for(var row in pModulesMapping[rootModule].DataRows) + { + newids.push(pModulesMapping[rootModule].DataRows[row].newPrimaryKey); + } + + if(newids.length > 0) + neon.openContext(pNeonContext, newids, neon.OPERATINGSTATE_VIEW, null); + } + } + } + + /** + * Creates a copy of a specified module together with specified subordinated modules. <br> + * The structure of the input mapping object is the following: <br> + * pInputMapping { + * (only one rootModule allowed) + * $rootModule$: { + * condition: "sqlWhereCondition" + * , ValueMapping: {$colName$: "value"} + * , destinationModuleName: "destinationModuleName" + * , DestinationColumnMapping: { $sourceColName$ : "destinationColName" } + * , SubModules: { + * $Module$:{ + * condition: "sqlWhereCondition" + * , ValueMapping: {$colName$: "value"} + * , destinationModuleName: "destinationModuleName" + * , DestinationColumnMapping: { $sourceColName$ : "destinationColName" } + * , SubModules: {...} + * } + * } + * } + * } + * + * @param {Object} pInputMapping + * + * @example var CMUtils = new CopyModuleUtils(); + * + * var InputMapping = { + * + * "OFFER": { + * condition: "OFFERID = '" + vars.get("$field.OFFERID") + "'" + * ,SubModules:{ + * "OFFERITEM": { + * condition: "OFFER_ID = '" + vars.get("$field.OFFERID") + "' order by ITEMSORT" + * } + * } + * } + * } + * + * CMUtils.copyModule(InputMapping); + */ + this.copyModule = function(pInputMapping) + { + var AliasDefinitionStructure = project.getAliasDefinitionStructure("Data_alias", null); + var ModulesMapping = {}; + var statements = []; + + buildMapping( pInputMapping ); + buildStatements( ModulesMapping ); + + if(statements.length > 0) + db.inserts( statements ); + + return ModulesMapping; + + /** + * Builds a mapping Object for the copyModule Method. <br> + * The structure of the Object is the following: <br> + * ModulesMapping = { + * + * $rootModule$: { ($$ marks an object property) + * + * (ModuleMapping) + * name: "moduleName" + * , destinationModuleName: "destinationModuleName" + * , DestinationColumnMapping: { $sourceColName$ : "destinationColName" } + * , ValueMapping: {$colName$: "value"} + * , dataRows:{ + * (ModuleRowMapping) + * $rowid$: { + * name: "moduleName" + * , oldPrimaryKey: "oldPrimaryKeyValue" + * , newPrimaryKey: "newPrimaryKeyValue" + * , ColumnMapping: { $colName$: { newValue: "newValue", oldValue: "oldValue", destinationColumn: "destinationColumn" } } + * , ModuleMapping: object reference to ModuleMapping object that contains ModuleRowMapping objects + * , ParentModuleMapping: object reference to supervised ModuleMapping object (at this point "null" because there is no supervised object) + * } + * } + * , SubModules: { + * (ModuleMapping) + * $moduleName$: { + * name: "moduleName" + * , destinationModuleName: "destinationModuleName" + * , DestinationColumnMapping: { $sourceColName$ : "destinationColName" } + * , ValueMapping: {$colName$: "value"} + * , dataRows:{ + * (ModuleRowMapping) + * $rowid$: { + * name: "moduleName" + * , oldPrimaryKey: "oldPrimaryKeyValue" + * , newPrimaryKey: "newPrimaryKeyValue" + * , ColumnMapping: { $colName$: { newValue: "newValue", oldValue: "oldValue", destinationColumn: "destinationColumn" } } + * , ModuleMapping: + * , ParentModuleMapping: object reference to supervised ModuleMapping object (at this point "null" because there is no supervised object) + * } + * } + * , SubModules: {...} + * } + * } + * + * } + * + *} + * + * @param {Object} pInputMapping InputMapping + */ + function buildMapping(pInputMapping) + { + //root mapping + var rootModule = Object.keys(pInputMapping)[0]; + var ModuleMapping = _ModuleMapping(rootModule, pInputMapping[rootModule]); + var ModuleData = _getModuleData(rootModule, pInputMapping[rootModule].condition); + + for(var row in ModuleData) + { + var ModuleRowMapping = _ModuleRowMapping(ModuleMapping, null, ModuleData[row]); + + ModuleMapping.DataRows[ModuleRowMapping.oldPrimaryKey] = ModuleRowMapping; + } + + ModulesMapping[rootModule] = ModuleMapping; + + //recursive subordinated modules mapping + _buildSubordinatedMapping(pInputMapping, ModuleMapping); + + + //delivers stored data for module in Database with condition + function _getModuleData(pModule, pCondition) + { + if(pModule == undefined) return {}; + + var ModuleColumnsStructure = AliasDefinitionStructure.tables[pModule].columns; + var cols = Object.keys(ModuleColumnsStructure); + + var condition = "1=1"; + if(pCondition != undefined) + condition = pCondition; + + var dbData = db.table("select " + cols.join(", ") + " from " + pModule + " where " + condition); + + //map 2d-Array to Object { $rowNumber$: { $columnName$: { value: "valueInDB" } } } + var DataObj = {}; + for(var row = 0; row < dbData.length; row++) + { + DataObj[row] = {}; + for(var col = 0; col < dbData[row].length; col++) + { + DataObj[row][cols[col]] = { + value: dbData[row][col] + }; + } + } + + return DataObj; + } + + + //recursive: ModuleMapping and ModuleRowMapping for subordinated modules + function _buildSubordinatedMapping(pInputMapping, pParentModuleMapping) + { + var SubModules = pInputMapping[pParentModuleMapping.name].SubModules; + if(SubModules == undefined) + return; + + for(var subModuleName in SubModules) + { + var ModuleMapping = _ModuleMapping(subModuleName, SubModules[subModuleName]); + ModuleData = _getModuleData(subModuleName, SubModules[subModuleName].condition); + for(var row in ModuleData) + { + ModuleRowMapping = _ModuleRowMapping(ModuleMapping, pParentModuleMapping, ModuleData[row]); + ModuleMapping.DataRows[ModuleRowMapping.oldPrimaryKey] = ModuleRowMapping; + } + + ModulesMapping[pParentModuleMapping.name].SubModules[subModuleName] = ModuleMapping; + + _buildSubordinatedMapping(SubModules, ModuleMapping); + } + } + + function _ModuleMapping( pModuleName, pInputModuleMapping ) + { + return { + name: pModuleName, + destinationModuleName: pInputModuleMapping.destinationModuleName == undefined ? pModuleName : pInputModuleMapping.destinationModuleName, + DestinationColumnMapping: pInputModuleMapping.DestinationColumnMapping == undefined ? {} : pInputModuleMapping.DestinationColumnMapping, + ValueMapping: pInputModuleMapping.ValueMapping == undefined ? {} : pInputModuleMapping.ValueMapping, + DataRows:{}, + SubModules: {} + }; + } + + function _ModuleRowMapping(pModuleMapping, pParentModuleMapping, pDataRow) + { + var ModuleRowMapping = { + name: pModuleMapping.name, + oldPrimaryKey: null, + newPrimaryKey: null, + ColumnMapping: {}, + ModuleMapping: pModuleMapping, + ParentModuleMapping: pParentModuleMapping + }; + + var ModuleColumnsStructure = AliasDefinitionStructure.tables[ModuleRowMapping.name].columns; + + //build ColumnMapping + for(var col in ModuleColumnsStructure) + { + //set defined columns from InputMapping -> if not defined, use the same column + var destinationColumn = ModuleRowMapping.ModuleMapping.DestinationColumnMapping[col]; + if(destinationColumn == undefined) + destinationColumn = col; + + //set defined values from InputMapping -> if not defined, use the value from DB + var oldValue = pDataRow[col].value; + var newValue = newValue = ModuleRowMapping.ModuleMapping.ValueMapping[col]; + if(newValue == undefined) + newValue = oldValue; + + //set new primary key + if(ModuleColumnsStructure[col].primaryKey) + { + ModuleRowMapping.oldPrimaryKey = ModuleRowMapping.ColumnMapping[col] = oldValue; + newValue = util.getNewUUID(); + ModuleRowMapping.newPrimaryKey = newValue; + } + + ModuleRowMapping.ColumnMapping[col] = _columnMapping(newValue, oldValue, destinationColumn); + } + + switch(ModuleRowMapping.name) + { + case "OFFER": + { + //andere Values setzen + var offUtils = new OfferUtils(); + var dtUtils = new DateUtils(); + + ModuleRowMapping.ColumnMapping["OFFERCODE"].newValue = offUtils.getNextOfferNumber(); + ModuleRowMapping.ColumnMapping["OFFERDATE"].newValue = dtUtils.getTodayUTC(); + } + break; + case "OFFERITEM": + { + //OFFER_ID mappen + if(ModuleRowMapping.ParentModuleMapping.name == "OFFER") + { + ModuleRowMapping.ColumnMapping["OFFER_ID"].newValue = ModulesMapping[ModuleRowMapping.ParentModuleMapping.name].DataRows[ModuleRowMapping.ColumnMapping["OFFER_ID"].oldValue].newPrimaryKey; + } + //ASSIGNEDTO mappen + if(ModuleRowMapping.ColumnMapping["ASSIGNEDTO"].oldValue != "") + { + if(ModuleRowMapping.ParentModuleMapping == null) + { + ModuleRowMapping.ColumnMapping["ASSIGNEDTO"].newValue = ModulesMapping["OFFERITEM"].DataRows[ModuleRowMapping.ColumnMapping["ASSIGNEDTO"].oldValue].newPrimaryKey; + } + else + { + ModuleRowMapping.ColumnMapping["ASSIGNEDTO"].newValue = ModuleRowMapping.ModuleMapping.DataRows[ModuleRowMapping.ColumnMapping["ASSIGNEDTO"].oldValue].newPrimaryKey; + } + } + } + break; + case "OFFERLINK": + { + + } + default: + { + + } + + + } + + //Spezialbehandlung USER_NEW DATENEW.... + if(ModuleRowMapping.ColumnMapping["DATE_NEW"] != undefined) ModuleRowMapping.ColumnMapping["DATE_NEW"].newValue = datetime.date(); + if(ModuleRowMapping.ColumnMapping["USER_NEW"] != undefined) ModuleRowMapping.ColumnMapping["USER_NEW"].newValue = vars.get("$sys.user"); + if(ModuleRowMapping.ColumnMapping["DATE_EDIT"] != undefined) ModuleRowMapping.ColumnMapping["DATE_EDIT"].newValue = ""; + if(ModuleRowMapping.ColumnMapping["USER_EDIT"] != undefined) ModuleRowMapping.ColumnMapping["USER_EDIT"].newValue = ""; + + return ModuleRowMapping; + } + + + + + function _columnMapping(pNewValue, pOldValue, pDestinationColumn) + { + return { + newValue: pNewValue, + oldValue: pOldValue, + destinationColumn: pDestinationColumn + }; + } + + } + + /** + * Builds the insert statements for passed ModulesMapping + * + * @param {Object} pModulesMapping ModulesMapping from buildMapping() + */ + function buildStatements(pModulesMapping) + { + var rootModule = Object.keys(pModulesMapping)[0]; + + for(var row in pModulesMapping[rootModule].DataRows) + { + //buildInsertStatement + statements.push(_statement(pModulesMapping[rootModule].DataRows[row])); + } + + _subordinatedStatements(pModulesMapping[rootModule]); + + function _subordinatedStatements(pMapping) + { + if(pMapping.SubModules == undefined) + return; + + for(var subModule in pMapping.SubModules) + { + + for(var row in pMapping.SubModules[subModule].DataRows) + { + statements.push(_statement(pMapping.SubModules[subModule].DataRows[row])); + } + + _subordinatedStatements(pMapping.SubModules[subModule]); + } + + } + + function _statement(pRowMapping) + { + var cols = []; + var vals = []; + var destTable = pRowMapping.ModuleMapping.destinationModuleName; + var colMapping = pRowMapping.ColumnMapping; + + for(var col in colMapping) + { + cols.push(colMapping[col].destinationColumn); + vals.push(colMapping[col].newValue.toString()); + } + + var colTypes = db.getColumnTypes(destTable, cols) + + return [destTable, cols, colTypes, vals]; + } + } + } +} \ No newline at end of file -- GitLab