diff --git a/entity/District_entity/District_entity.aod b/entity/District_entity/District_entity.aod index fa41a81526f5375212d0744b02a25651701dee16..e45c83db3f6cdb87fac6c0dfec0a96d0df6685b2 100644 --- a/entity/District_entity/District_entity.aod +++ b/entity/District_entity/District_entity.aod @@ -263,6 +263,17 @@ <title>Assign district</title> <onActionProcess>%aditoprj%/entity/District_entity/entityfields/assigndistrict/onActionProcess.js</onActionProcess> </entityActionField> + <entityActionGroup> + <name>ActionGroup</name> + <children> + <entityActionField> + <name>assignAllActiveDistricts</name> + <title>Assign all selected districts</title> + <onActionProcess>%aditoprj%/entity/District_entity/entityfields/actiongroup/children/assignallactivedistricts/onActionProcess.js</onActionProcess> + <isObjectAction v="false" /> + </entityActionField> + </children> + </entityActionGroup> </entityFields> <recordContainers> <dbRecordContainer> diff --git a/entity/District_entity/entityfields/actiongroup/children/assignallactivedistricts/onActionProcess.js b/entity/District_entity/entityfields/actiongroup/children/assignallactivedistricts/onActionProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..59461e56b39556b3fdcc50ed9e2257df8d240631 --- /dev/null +++ b/entity/District_entity/entityfields/actiongroup/children/assignallactivedistricts/onActionProcess.js @@ -0,0 +1,9 @@ +import("system.vars"); +import("system.question"); +import("system.translate"); +import("District_lib"); + +var arrDistrictIds = vars.get("$sys.selection"); +question.showMessage(translate.text("Assignment for all selected districts will start now!")); + +DistrictUtils.assignDistrictOnServer(arrDistrictIds); \ No newline at end of file diff --git a/entity/District_entity/entityfields/appliedfilter/valueProcess.js b/entity/District_entity/entityfields/appliedfilter/valueProcess.js index 253bd0712af0b47b35aaa72b8d027fc9d053526d..b4542e7e2d01943cfe47e2aa1364e5be3b411753 100644 --- a/entity/District_entity/entityfields/appliedfilter/valueProcess.js +++ b/entity/District_entity/entityfields/appliedfilter/valueProcess.js @@ -1,37 +1,7 @@ +import("District_lib"); import("system.result"); import("system.vars"); -var parentFilter = vars.get("$field.parentFilter"); -var districtFilter = vars.get("$field.DISTRICT_FILTER"); - -var appliedFilter = { - entity: "Organisation_entity", - filter: { - type: "group", - operator: "AND", - childs: [] -}}; - -if (parentFilter) -{ - appliedFilter.filter.childs.push(JSON.parse(parentFilter).filter); -} -if (districtFilter) -{ - //appliedFilter = _getApplicableFilter(appliedFilter, districtFilter); - appliedFilter.filter.childs.push(JSON.parse(districtFilter).filter); -} - -result.string(JSON.stringify(appliedFilter)); - -filterArray = []; - -function _getApplicableFilter(pFilter, pAppendFilter){ - - var applicableFilter = ""; - var childFilter = JSON.parse(pFilter).filter; - - - - return applicableFilter; -} \ No newline at end of file +//Aufbau des kompletten Filters über alle Hierarchie-Ebenen hinweg +var appliedFilter = DistrictUtils.getAppliedFilter(vars.get("$field.DISTRICT_FILTER"), vars.get("$field.PARENTDISTRICT_DISTRICTID")); +result.string(appliedFilter); diff --git a/entity/District_entity/entityfields/assigndistrict/onActionProcess.js b/entity/District_entity/entityfields/assigndistrict/onActionProcess.js index 301a4faa165f45602f002d29390ecc7d2a11ec6a..f556ead9f64e28f01568cdff1828907b9db2dc14 100644 --- a/entity/District_entity/entityfields/assigndistrict/onActionProcess.js +++ b/entity/District_entity/entityfields/assigndistrict/onActionProcess.js @@ -1,13 +1,10 @@ import("system.question"); -import("system.util"); -import("system.notification"); import("system.translate"); import("District_lib"); import("system.vars"); -var districtId = vars.get("$field.DISTRICTID"); -var appliedFilter = vars.get("$field.appliedFilter"); +var arrDistrictId = [vars.get("$field.DISTRICTID")]; -question.showMessage(translate.text("District assignment will start now!")) +question.showMessage(translate.text("District assignment will start now!")); -DistrictUtils.assignDistrictOnServer(districtId, appliedFilter); +DistrictUtils.assignDistrictOnServer(arrDistrictId); diff --git a/entity/District_entity/entityfields/parentfilter/valueProcess.js b/entity/District_entity/entityfields/parentfilter/valueProcess.js index e1c0dfd89d6d147325bc77eb3fe1e1b452c6793e..7dd066de7e904e7528f28d0e03c65b459b534579 100644 --- a/entity/District_entity/entityfields/parentfilter/valueProcess.js +++ b/entity/District_entity/entityfields/parentfilter/valueProcess.js @@ -1,64 +1,7 @@ +import("District_lib"); import("system.result"); import("system.vars"); -import("system.neon"); -import("Sql_lib"); -var res = ""; -var parentDistrictId = vars.get("$field.PARENTDISTRICT_DISTRICTID"); - -if (parentDistrictId) -{ - var completeParentFilter = _getParentFilter(parentDistrictId, null); - completeParentFilter.entity = "Organisation_entity"; - res = completeParentFilter; -} -else -{ - var entity = "Organisation_entity"; - var emptyFilter = { - entity: entity, - filter: { - type: "group", - operator: "AND", - childs: [] - } - }; - - res = emptyFilter; -} - -result.string(JSON.stringify(res)); - - -function _getParentFilter(pParentDistrictId, pPreviousFilter) -{ - var resFilter; - - if (pPreviousFilter != null) - { - resFilter = pPreviousFilter; - } - - if (pParentDistrictId) - { - var parentDistrictFilter, grandParentDistrict; - [parentDistrictFilter, grandParentDistrict] = newSelect(["DISTRICT.DISTRICT_FILTER", "DISTRICT.PARENTDISTRICT_DISTRICTID"]) - .from("DISTRICT") - .where("DISTRICT.DISTRICTID", pParentDistrictId) - .arrayRow(); - - parentDistrictFilter = JSON.parse(parentDistrictFilter); - - if (pPreviousFilter) - parentDistrictFilter.filter.childs.push(resFilter.filter);//todo: kommentar ergänzen was wir heir eigentlcih machen - - resFilter = parentDistrictFilter; - - if (grandParentDistrict.length > 0) - { - resFilter = _getParentFilter(grandParentDistrict, resFilter); - } - } - - return resFilter; -} \ No newline at end of file +//Aufbau des übergeordneten Filters +var res = DistrictUtils.getParentFilter(vars.get("$field.PARENTDISTRICT_DISTRICTID")); +result.string(res); diff --git a/neonView/DistrictFilter_view/DistrictFilter_view.aod b/neonView/DistrictFilter_view/DistrictFilter_view.aod index 336fe50e56e4434e8bd00034d3dd3277034c7fad..8dfc3b2f7c38ada2eb67f1b3c2ddbc804af584ec 100644 --- a/neonView/DistrictFilter_view/DistrictFilter_view.aod +++ b/neonView/DistrictFilter_view/DistrictFilter_view.aod @@ -12,6 +12,7 @@ <treeTableViewTemplate> <name>treetableViewTemplate</name> <parentField>PARENTDISTRICT_DISTRICTID</parentField> + <favoriteActionGroup1>ActionGroup</favoriteActionGroup1> <hideContentSearch v="false" /> <showChildrenCount v="false" /> <entityField>#ENTITY</entityField> diff --git a/others/language_DE.txt b/others/language_DE.txt index 7d3a7923a6bf19f212e11be043b80193707f9d8f..e21ad1cb8b6eb4c6aae186be2a34d464ffb35148 100644 --- a/others/language_DE.txt +++ b/others/language_DE.txt @@ -51,10 +51,22 @@ <value>Zuordnung des Gebietes \"%0\" ist abgeschlossen!</value> </entry> <entry> - <key>%0 companies were newley assigned to this district. \n %1 companies are no longer assigned to this district (these assignments got the status 'review'). \n %2 valid assignments were unchanged. \n The Process took %3 seconds. </key> - <value>%0 Firmen wurden dem Gebiet neu hinzugefügt. \n %1 Firmen sind diesem Gebiet nicht länger zugeordnet (diese Zuordnungen wurden auf den Status 'zur Prüfung' gesetzt). \n %2 gültige Zuordnungen blieben unverändert. \n Der Prozess dauert %3 Sekunden. </value> + <key>%0 companies were newley assigned. \n%1 companies are no longer assigned (these assignments got the status 'review'). \n%2 valid assignments were unchanged.\nThe Process took %3 seconds.</key> + <value>%0 Firmen wurden neu hinzugefügt. \n %1 Firmen sind nicht länger zugeordnet (diese Zuordnungen wurden auf den Status 'zur Prüfung' gesetzt). \n %2 gültige Zuordnungen blieben unverändert. \n Der Prozess dauert %3 Sekunden. </value> </entry> <entry> <key>District assignment status</key> <value>Gebietzuordnungstatus</value> + </entry> + <entry> + <key>Assign all selected districts</key> + <value>Zuordnung für alle selektierten Gebiete</value> + </entry> + <entry> + <key>Assignment for all selected districts will start now!</key> + <value>Zuordnung für alle selektierten Gebiete wird jetzt gestartet</value> + </entry> + <entry> + <key>Assignment of all selected districts is completed!</key> + <value>Zuordnung für alle selektierten Gebiete abgeschlossen</value> </entry> \ No newline at end of file diff --git a/others/language_EN.txt b/others/language_EN.txt index 7a6da3e4bef09597d2498d577104d3d2b89bf315..64983f276c87d57079e98f1f2899620e996db567 100644 --- a/others/language_EN.txt +++ b/others/language_EN.txt @@ -38,8 +38,17 @@ <key>Assignment of district \"%0\" is completed!</key> </entry> <entry> - <key>%0 companies were newley assigned to this district. \n %1 companies are no longer assigned to this district (these assignments got the status 'review'). \n %2 valid assignments were unchanged. \n The Process took %3 seconds. </key> + <key>%0 companies were newley assigned. \n%1 companies are no longer assigned (these assignments got the status 'review'). \n%2 valid assignments were unchanged.\nThe Process took %3 seconds.</key> </entry> <entry> <key>District assignment status</key> + </entry> + <entry> + <key>Assign all selected districts</key> + </entry> + <entry> + <key>Assignment for all selected districts will start now!</key> + </entry> + <entry> + <key>Assignment of all selected districts is completed!</key> </entry> \ No newline at end of file diff --git a/process/District_lib/process.js b/process/District_lib/process.js index 03abf8d35d1f5bee408a4c4cff09182fbcad1a67..8e3a1b061af45e34afa1f66ce2f860fc71112977 100644 --- a/process/District_lib/process.js +++ b/process/District_lib/process.js @@ -34,7 +34,25 @@ DistrictUtils.getDistrictName = function (pDistrictId) } /** - * Gets the id of a district + * Get data from district + * + * @param {String} pDistrictId <p> + * ID of a district<br> + * @return {Array} <p> + * array of data from a district <br> + */ +DistrictUtils.getDataFromDistrict = function (pDistrictId) +{ + var districtData = newSelect("DISTRICT_FILTER, PARENTDISTRICT_DISTRICTID") + .from("DISTRICT") + .where("DISTRICT.DISTRICTID", pDistrictId) + .arrayRow(); + return(districtData); +} + + +/** + * Get data from a special district * * @param {String} pDistrictContactId <p> * Id of the districtcontact.<br> @@ -55,25 +73,22 @@ DistrictUtils.getDataFromDistrictContact = function (pDistrictContactId) /** * Executes a process to assign districts on the server and creates a notification when finished. * - * @param {String} pDistrictId <p> - * Id of the district.<br> - * @param {String} pAppliedFilter <p> - * Filter condition to get the assigned companies.<br> + * @param {Array} pArrDistrictIds <p> + * Array of district-IDs.<br> * @param {String} pUser=currentUser (optional) <p> * User that will get the notification, <br> * if null (not undefined!), no notification<br> * will be created.<br> */ -DistrictUtils.assignDistrictOnServer = function (pDistrictId, pAppliedFilter, pUser) +DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser) { //pUser hat folgendes Format: _____USER_bcdfb521-c7d0-4ef1-8916-78e7d3232046 if (pUser === undefined) - pUser = EmployeeUtils.getCurrentUserId(); + pUser = EmployeeUtils.getCurrentUserId(); var processConfig = process.createStartAsyncConfig() .setName("assignDistrict_serverProcess") .setLocalVariables({ - districtId : pDistrictId, - appliedFilter : pAppliedFilter, + arrDistrictIds : pArrDistrictIds.join(";"), user : pUser || "" }) .setUser(pUser) @@ -119,7 +134,7 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter) var appliedFilterCondition = JSON.parse(pAppliedFilter).filter; appliedFilterCondition = JSON.stringify(appliedFilterCondition); var sqlCondition = db.toFilterCondition(appliedFilterCondition, "Organisation_entity") - + //Einlesen der Contact-IDs zu den Firmen, die gemäß Filter diesem Gebiet zugeordnet sind var arrOrgContactIds = new SqlBuilder() .selectDistinct("CONTACT.CONTACTID") @@ -173,6 +188,10 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter) //Firmen-Betreuer-Datensatz existiert noch nicht -> Insert if (found == 'N') { + //Falls Status null, dann auf active setzen + if (Utils.isNullOrEmpty(arrResponsibleIds[j][2])) + arrResponsibleIds[j][2] = $KeywordRegistry.contactStatus$active(); + var valsInsert = [ util.getNewUUID(), arrOrgContactIds[i], @@ -217,3 +236,115 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter) unchanged : unchanged }; } + + +/** + * Get the complete hierarchical filter + * + * @param {JSON-String} pDistrictFilter <p> + * The filter of the current level<br> + * @param {String} pParentDistrict_DistrictId <p> + * District-ID of the parent district<br>* + * @return {JSON-String} <p> + * JSON-String of the complete filter (all levels) <br> + */ +DistrictUtils.getAppliedFilter = function (pDistrictFilter, pParentDistrict_DistrictId) +{ + var parentFilter = DistrictUtils.getParentFilter(pParentDistrict_DistrictId); + + var appliedFilter = { + entity: "Organisation_entity", + filter: { + type: "group", + operator: "AND", + childs: [] + }}; + + if (parentFilter) + { + appliedFilter.filter.childs.push(JSON.parse(parentFilter).filter); + } + if (pDistrictFilter) + { + appliedFilter.filter.childs.push(JSON.parse(pDistrictFilter).filter); + } + + return JSON.stringify(appliedFilter); +} + +/** + * Get the filter starting with the parent level + * @param {String} pParentDistrict_DistrictId <p> + * District-ID of the parent district<br> + * @return {JSON-String} <p> + * JSON-String of the filter starting with the parent<br> + */ +DistrictUtils.getParentFilter = function (pParentDistrict_DistrictId) +{ + var res = ""; + + if (pParentDistrict_DistrictId) + { + var completeParentFilter = DistrictUtils._getParentFilter(pParentDistrict_DistrictId, null); + completeParentFilter.entity = "Organisation_entity"; + res = completeParentFilter; + } + else + { + var entity = "Organisation_entity"; + var emptyFilter = { + entity: entity, + filter: { + type: "group", + operator: "AND", + childs: [] + } + }; + + res = emptyFilter; + } + + return JSON.stringify(res); +} + +/** + * This function will recursively go through each filter level up to the root. + * @param {String} pParentDistrict_DistrictId <p> + * District-ID of the parent district<br> + * @param {JSON} pPreviousFilter <p> + * Collected filters so far<br> + * @return {JSON} <p> + * JSON-Object of the collected filters<br> + */ +DistrictUtils._getParentFilter = function (pParentDistrict_DistrictId, pPreviousFilter) +{ + var resFilter; + + if (pPreviousFilter != null) + { + resFilter = pPreviousFilter; + } + + if (pParentDistrict_DistrictId) + { + var parentDistrictFilter, grandParentDistrict; + [parentDistrictFilter, grandParentDistrict] = newSelect(["DISTRICT.DISTRICT_FILTER", "DISTRICT.PARENTDISTRICT_DISTRICTID"]) + .from("DISTRICT") + .where("DISTRICT.DISTRICTID", pParentDistrict_DistrictId) + .arrayRow(); + + parentDistrictFilter = JSON.parse(parentDistrictFilter); + + if (pPreviousFilter) + parentDistrictFilter.filter.childs.push(resFilter.filter); + + resFilter = parentDistrictFilter; + + if (grandParentDistrict.length > 0) + { + resFilter = DistrictUtils._getParentFilter(grandParentDistrict, resFilter); + } + } + + return resFilter; +} \ No newline at end of file diff --git a/process/assignDistrict_serverProcess/process.js b/process/assignDistrict_serverProcess/process.js index e3b3c34b56550d6518ef5f64ad166d762ee3ec8f..48f1e807144572e80847b1bb4603fd9051dc50a7 100644 --- a/process/assignDistrict_serverProcess/process.js +++ b/process/assignDistrict_serverProcess/process.js @@ -7,20 +7,46 @@ import("system.vars"); import("system.notification"); import("District_lib"); +var res; +var message; +var description; + +var newAssigned = 0; +var unchanged = 0; +var invalid = 0; + var startTime = datetime.date(); -var appliedFilter = vars.get("$local.appliedFilter") var user = vars.get("$local.user"); -var districtId = vars.get("$local.districtId"); -var districtName = DistrictUtils.getDistrictName(districtId); +var arrDistrictIds = vars.get("$local.arrDistrictIds").split(";"); + +//Alle übergebenen Gebiete bearbeiten +for (var i=0; i<arrDistrictIds.length; i++) +{ + //Pro Gebiet den kompletten hierarchieschen Filter aufbauen + var districtData = DistrictUtils.getDataFromDistrict(arrDistrictIds[i]); + var completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1]) + + //Automatische Zuordnung + res = DistrictUtils.assignDistrict(arrDistrictIds[i], completeFilter); + + newAssigned += res.newAssigned; + unchanged += res.unchanged; + invalid += res.invalid; +} -//Automatische Zuordnung -var res = DistrictUtils.assignDistrict(districtId, appliedFilter); +if (arrDistrictIds.length == 1) +{ + var districtName = DistrictUtils.getDistrictName(arrDistrictIds[0]); + message = translate.withArguments("Assignment of district \"%0\" is completed!", [districtName]); +} +else + message = translate.text("Assignment of all selected districts is completed!"); -// Benachrichtigung am Ende der Zuordnung -var message = translate.withArguments("Assignment of district \"%0\" is completed!", [districtName]); -var description = translate.withArguments("%0 companies were newley assigned to this district. \n " + - "%1 companies are no longer assigned to this district (these assignments got the status 'review'). \n " + - "%2 valid assignments were unchanged. \n " + - "The Process took %3 seconds. ", - [res.newAssigned, res.invalid, res.unchanged, Math.round((datetime.date() - startTime) / datetime.ONE_SECOND)]) -notification.addNotification(util.getNewUUID(), null, null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user], message, description); +// Benachrichtigung am Ende der Zuordnungen +description = translate.withArguments("%0 companies were newley assigned. \n" + + "%1 companies are no longer assigned (these assignments got the status 'review'). \n" + + "%2 valid assignments were unchanged.\n" + + "The Process took %3 seconds.", + [newAssigned, invalid, unchanged, Math.round((datetime.date() - startTime) / datetime.ONE_SECOND)]) +notification.addNotification(util.getNewUUID(), null, null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user], message, description); + \ No newline at end of file