Skip to content
Snippets Groups Projects
Commit eb6a4681 authored by Jessica Luginger's avatar Jessica Luginger
Browse files

Merge branch '1066188_gb_2020.2.0_Betreuung_HamaDSG' into '2020.2.0_Betreuung_HamaDSG'

1066188: Serienaktion Gebiet zuordnen

See merge request xrm/basic!464
parents 2b7694f2 bb5afd92
No related branches found
No related tags found
No related merge requests found
......@@ -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>
......
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
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);
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);
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);
......@@ -12,6 +12,7 @@
<treeTableViewTemplate>
<name>treetableViewTemplate</name>
<parentField>PARENTDISTRICT_DISTRICTID</parentField>
<favoriteActionGroup1>ActionGroup</favoriteActionGroup1>
<hideContentSearch v="false" />
<showChildrenCount v="false" />
<entityField>#ENTITY</entityField>
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment