Skip to content
Snippets Groups Projects
Commit aa30a97f authored by dsg03695's avatar dsg03695
Browse files

Ticket #1066033: first audit process done after assigning a new district...

Ticket #1066033: first audit process done after assigning a new district contact to a organisation the employee needs to be notified.
parent 772ae952
No related branches found
No related tags found
No related merge requests found
import("system.text");
import("system.datetime");
import("system.notification");
import("system.translate");
import("system.logging"); import("system.logging");
import("Contact_lib"); import("Contact_lib");
import("KeywordRegistry_basic"); import("KeywordRegistry_basic");
...@@ -28,9 +32,9 @@ function DistrictUtils () {} ...@@ -28,9 +32,9 @@ function DistrictUtils () {}
DistrictUtils.getDistrictName = function (pDistrictId) DistrictUtils.getDistrictName = function (pDistrictId)
{ {
var districtName = newSelect("DISTRICT_NAME") var districtName = newSelect("DISTRICT_NAME")
.from("DISTRICT") .from("DISTRICT")
.where("DISTRICT.DISTRICTID", pDistrictId) .where("DISTRICT.DISTRICTID", pDistrictId)
.cell(true); .cell(true);
return(districtName) return(districtName)
} }
...@@ -46,9 +50,9 @@ DistrictUtils.getDistrictName = function (pDistrictId) ...@@ -46,9 +50,9 @@ DistrictUtils.getDistrictName = function (pDistrictId)
DistrictUtils.getDataFromDistrict = function (pDistrictId) DistrictUtils.getDataFromDistrict = function (pDistrictId)
{ {
var districtData = newSelect("DISTRICT_FILTER, PARENTDISTRICT_DISTRICTID") var districtData = newSelect("DISTRICT_FILTER, PARENTDISTRICT_DISTRICTID")
.from("DISTRICT") .from("DISTRICT")
.where("DISTRICT.DISTRICTID", pDistrictId) .where("DISTRICT.DISTRICTID", pDistrictId)
.arrayRow(); .arrayRow();
return(districtData); return(districtData);
} }
...@@ -63,10 +67,10 @@ DistrictUtils.getDataFromDistrict = function (pDistrictId) ...@@ -63,10 +67,10 @@ DistrictUtils.getDataFromDistrict = function (pDistrictId)
*/ */
DistrictUtils.getDataFromDistrictContact = function (pDistrictContactId) DistrictUtils.getDataFromDistrictContact = function (pDistrictContactId)
{ {
var arrData = newSelect("DISTRICT_ID, ADVISER_CONTACT_ID") var arrData = newSelect("DISTRICT_ID, ADVISER_CONTACT_ID, CONTACT_ID")
.from("DISTRICTCONTACT") .from("DISTRICTCONTACT")
.where("DISTRICTCONTACT.DISTRICTCONTACTID", pDistrictContactId) .where("DISTRICTCONTACT.DISTRICTCONTACTID", pDistrictContactId)
.arrayRow(); .arrayRow();
return(arrData); return(arrData);
} }
...@@ -88,12 +92,12 @@ DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser) ...@@ -88,12 +92,12 @@ DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser)
if (pUser === undefined) if (pUser === undefined)
pUser = EmployeeUtils.getCurrentUserId(); pUser = EmployeeUtils.getCurrentUserId();
var processConfig = process.createStartAsyncConfig() var processConfig = process.createStartAsyncConfig()
.setName("assignDistrict_serverProcess") .setName("assignDistrict_serverProcess")
.setLocalVariables({ .setLocalVariables({
arrDistrictIds : pArrDistrictIds.join(";"), arrDistrictIds : pArrDistrictIds.join(";"),
user : pUser || "" user : pUser || ""
}) })
.setUser(pUser) .setUser(pUser)
process.startAsync(processConfig); process.startAsync(processConfig);
} }
...@@ -126,21 +130,21 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId ...@@ -126,21 +130,21 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
if (!pContactId) if (!pContactId)
{ {
arrExistingIds = new SqlBuilder() arrExistingIds = new SqlBuilder()
.select("DISTRICTCONTACT.DISTRICTCONTACTID, DISTRICTCONTACT.CONTACT_ID, DISTRICTCONTACT.ADVISER_CONTACT_ID") .select("DISTRICTCONTACT.DISTRICTCONTACTID, DISTRICTCONTACT.CONTACT_ID, DISTRICTCONTACT.ADVISER_CONTACT_ID")
.from("DISTRICTCONTACT") .from("DISTRICTCONTACT")
.where("DISTRICTCONTACT.DISTRICT_ID", pDistrictId) .where("DISTRICTCONTACT.DISTRICT_ID", pDistrictId)
.and ("DISTRICTCONTACT.ORIGIN", $KeywordRegistry.districtOrigin$auto()) .and ("DISTRICTCONTACT.ORIGIN", $KeywordRegistry.districtOrigin$auto())
.and ("DISTRICTCONTACT.STATUS", $KeywordRegistry.contactStatus$inReview(), SqlBuilder.NOT_EQUAL()) .and ("DISTRICTCONTACT.STATUS", $KeywordRegistry.contactStatus$inReview(), SqlBuilder.NOT_EQUAL())
.table(); .table();
} }
//Einlesen aller Betreuer, die dem übergebenen Gebiet zugeordnet sind //Einlesen aller Betreuer, die dem übergebenen Gebiet zugeordnet sind
var arrResponsibleIds = new SqlBuilder() var arrResponsibleIds = new SqlBuilder()
.select("DISTRICTRESPONSIBLE.EMPLOYEE_CONTACT_ID, DISTRICTRESPONSIBLE.ADVISER_ROLE, " + .select("DISTRICTRESPONSIBLE.EMPLOYEE_CONTACT_ID, DISTRICTRESPONSIBLE.ADVISER_ROLE, " +
"DISTRICTRESPONSIBLE.ADVISER_STATUS, DISTRICTRESPONSIBLE.VALID_FROM, DISTRICTRESPONSIBLE.VALID_UNTIL") "DISTRICTRESPONSIBLE.ADVISER_STATUS, DISTRICTRESPONSIBLE.VALID_FROM, DISTRICTRESPONSIBLE.VALID_UNTIL")
.from("DISTRICTRESPONSIBLE") .from("DISTRICTRESPONSIBLE")
.where("DISTRICTRESPONSIBLE.DISTRICT_ID", pDistrictId) .where("DISTRICTRESPONSIBLE.DISTRICT_ID", pDistrictId)
.table(); .table();
//Aufbereiten des im JSON-Format übergebenen Filters in eine SQL-Condition //Aufbereiten des im JSON-Format übergebenen Filters in eine SQL-Condition
var appliedFilterCondition = JSON.parse(pAppliedFilter).filter; var appliedFilterCondition = JSON.parse(pAppliedFilter).filter;
...@@ -150,35 +154,35 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId ...@@ -150,35 +154,35 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
logging.log("sqlCondition: " + sqlCondition) logging.log("sqlCondition: " + sqlCondition)
//Einlesen der Contact-IDs zu den Firmen, die gemäß Filter diesem Gebiet zugeordnet sind //Einlesen der Contact-IDs zu den Firmen, die gemäß Filter diesem Gebiet zugeordnet sind
var arrOrgContactIds = new SqlBuilder() var arrOrgContactIds = new SqlBuilder()
.selectDistinct("CONTACT.CONTACTID") .selectDistinct("CONTACT.CONTACTID")
.from("ORGANISATION") .from("ORGANISATION")
.join("CONTACT", newWhere("ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID").and("CONTACT.PERSON_ID is null")) .join("CONTACT", newWhere("ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID").and("CONTACT.PERSON_ID is null"))
.leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID") .leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID")
.leftJoin("CLASSIFICATIONSTORAGE", "CLASSIFICATIONSTORAGE.OBJECT_ROWID = CONTACT.CONTACTID") .leftJoin("CLASSIFICATIONSTORAGE", "CLASSIFICATIONSTORAGE.OBJECT_ROWID = CONTACT.CONTACTID")
.whereIfSet(sqlCondition) .whereIfSet(sqlCondition)
.andIfSet("CONTACT.CONTACTID", pContactId) .andIfSet("CONTACT.CONTACTID", pContactId)
.arrayColumn(); .arrayColumn();
logging.log("arrOrgContactIds.length: " + arrOrgContactIds.length) logging.log("arrOrgContactIds.length: " + arrOrgContactIds.length)
var insertArray = []; var insertArray = [];
var colsInsert = [ var colsInsert = [
"DISTRICTCONTACTID", "DISTRICTCONTACTID",
"CONTACT_ID", "CONTACT_ID",
"DISTRICT_ID", "DISTRICT_ID",
"ADVISER_CONTACT_ID", "ADVISER_CONTACT_ID",
"ADVISER_ROLE", "ADVISER_ROLE",
"STATUS", "STATUS",
"VALID_FROM", "VALID_FROM",
"VALID_UNTIL", "VALID_UNTIL",
"ORIGIN", "ORIGIN",
"USER_NEW", "USER_NEW",
"DATE_NEW" "DATE_NEW"
]; ];
var updateArray = []; var updateArray = [];
var colsUpdate = [ var colsUpdate = [
"STATUS", "STATUS",
"USER_EDIT", "USER_EDIT",
"DATE_EDIT" "DATE_EDIT"
]; ];
//Anlegen der Firmen-Betreuer-Datensätze in der Tabelle DISTRICTCONTACT //Anlegen der Firmen-Betreuer-Datensätze in der Tabelle DISTRICTCONTACT
for (var i=0; i<arrOrgContactIds.length; i++) for (var i=0; i<arrOrgContactIds.length; i++)
...@@ -207,17 +211,17 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId ...@@ -207,17 +211,17 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
arrResponsibleIds[j][2] = $KeywordRegistry.contactStatus$active(); arrResponsibleIds[j][2] = $KeywordRegistry.contactStatus$active();
var valsInsert = [ var valsInsert = [
util.getNewUUID(), util.getNewUUID(),
arrOrgContactIds[i], arrOrgContactIds[i],
pDistrictId, pDistrictId,
arrResponsibleIds[j][0], arrResponsibleIds[j][0],
arrResponsibleIds[j][1], arrResponsibleIds[j][1],
arrResponsibleIds[j][2], arrResponsibleIds[j][2],
arrResponsibleIds[j][3], arrResponsibleIds[j][3],
arrResponsibleIds[j][4], arrResponsibleIds[j][4],
$KeywordRegistry.districtOrigin$auto(), $KeywordRegistry.districtOrigin$auto(),
vars.get("$sys.user"), vars.get("$sys.user"),
vars.get("$sys.date") vars.get("$sys.date")
]; ];
insertArray.push(["DISTRICTCONTACT", colsInsert, null, valsInsert]); insertArray.push(["DISTRICTCONTACT", colsInsert, null, valsInsert]);
} }
...@@ -233,9 +237,9 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId ...@@ -233,9 +237,9 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
for (var l=0; l<arrExistingIds.length; l++) for (var l=0; l<arrExistingIds.length; l++)
{ {
var valsUpdate = [ var valsUpdate = [
$KeywordRegistry.contactStatus$inReview(), $KeywordRegistry.contactStatus$inReview(),
vars.get("$sys.user"), vars.get("$sys.user"),
vars.get("$sys.date") vars.get("$sys.date")
]; ];
var condition = newWhere("DISTRICTCONTACT.DISTRICTCONTACTID", arrExistingIds[l][0]); var condition = newWhere("DISTRICTCONTACT.DISTRICTCONTACTID", arrExistingIds[l][0]);
updateArray.push(["DISTRICTCONTACT", colsUpdate, null, valsUpdate, condition.build()]); updateArray.push(["DISTRICTCONTACT", colsUpdate, null, valsUpdate, condition.build()]);
...@@ -267,12 +271,13 @@ DistrictUtils.getAppliedFilter = function (pDistrictFilter, pParentDistrict_Dist ...@@ -267,12 +271,13 @@ DistrictUtils.getAppliedFilter = function (pDistrictFilter, pParentDistrict_Dist
var parentFilter = DistrictUtils.getParentFilter(pParentDistrict_DistrictId); var parentFilter = DistrictUtils.getParentFilter(pParentDistrict_DistrictId);
var appliedFilter = { var appliedFilter = {
entity: "Organisation_entity", entity: "Organisation_entity",
filter: { filter: {
type: "group", type: "group",
operator: "AND", operator: "AND",
childs: [] childs: []
}}; }
};
if (parentFilter) if (parentFilter)
{ {
...@@ -343,9 +348,9 @@ DistrictUtils._getParentFilter = function (pParentDistrict_DistrictId, pPrevious ...@@ -343,9 +348,9 @@ DistrictUtils._getParentFilter = function (pParentDistrict_DistrictId, pPrevious
{ {
var parentDistrictFilter, grandParentDistrict; var parentDistrictFilter, grandParentDistrict;
[parentDistrictFilter, grandParentDistrict] = newSelect(["DISTRICT.DISTRICT_FILTER", "DISTRICT.PARENTDISTRICT_DISTRICTID"]) [parentDistrictFilter, grandParentDistrict] = newSelect(["DISTRICT.DISTRICT_FILTER", "DISTRICT.PARENTDISTRICT_DISTRICTID"])
.from("DISTRICT") .from("DISTRICT")
.where("DISTRICT.DISTRICTID", pParentDistrict_DistrictId) .where("DISTRICT.DISTRICTID", pParentDistrict_DistrictId)
.arrayRow(); .arrayRow();
parentDistrictFilter = JSON.parse(parentDistrictFilter); parentDistrictFilter = JSON.parse(parentDistrictFilter);
...@@ -381,9 +386,9 @@ DistrictUtils.assignOrganisationToDistrict = function (pOrganisationId, pUserLog ...@@ -381,9 +386,9 @@ DistrictUtils.assignOrganisationToDistrict = function (pOrganisationId, pUserLog
//alle Filter ermitteln, die auf auto-assignment gleich true gesetzt sind //alle Filter ermitteln, die auf auto-assignment gleich true gesetzt sind
var allAutoDistricts = newSelect("DISTRICTID") var allAutoDistricts = newSelect("DISTRICTID")
.from("DISTRICT") .from("DISTRICT")
.where("DISTRICT.DISTRICT_AUTOADD", 1) .where("DISTRICT.DISTRICT_AUTOADD", 1)
.arrayColumn(); .arrayColumn();
//TODO: pUserLogin noch bis zum Schreiben von date_new durchschleusen //TODO: pUserLogin noch bis zum Schreiben von date_new durchschleusen
logging.log("pUerLogin: " + pUserLogin) logging.log("pUerLogin: " + pUserLogin)
...@@ -404,8 +409,32 @@ DistrictUtils.assignOrganisationToDistrict = function (pOrganisationId, pUserLog ...@@ -404,8 +409,32 @@ DistrictUtils.assignOrganisationToDistrict = function (pOrganisationId, pUserLog
} }
//Variante 2: Aufruf des Server-Prozessen mit allen Gebieten mit Auto-Zuordnung gleich true //Variante 2: Aufruf des Server-Prozessen mit allen Gebieten mit Auto-Zuordnung gleich true
//Wirft den gleichen Fehler wie Variante 1 //Wirft den gleichen Fehler wie Variante 1
//TODO: Aus dem pUserLogin noch die Employee-ID ermitteln //TODO: Aus dem pUserLogin noch die Employee-ID ermitteln
//DistrictUtils.assignDistrictOnServer(allAutoDistricts, pUserLogin); //DistrictUtils.assignDistrictOnServer(allAutoDistricts, pUserLogin);
}
/**
* This function will notificate the district contact that he/she was assigned
*
* @param {String} pDistrictContactId <p>
* DistrictContact-ID of the new Dataset<br>
* @return <none> <p>
*/
DistrictUtils.notificateNewDistrictContact = function(pDistrictContactId){
logging.log(pDistrictContactId);
message = translate.text("Assignment to a new district/company!");
//[0]: DISTRICT_ID, [1]: ADVISER_CONTACT_ID, [2]: CONTACT_ID
var arrayDistrictContact = DistrictUtils.getDataFromDistrictContact(pDistrictContactId);
logging.log(arrayDistrictContact.length);
var districtName = DistrictUtils.getDistrictName(arrayDistrictContact[0]);
logging.log(districtName);
var organisationName = ContactUtils.getFullTitleByContactId(arrayDistrictContact[2]);
logging.log(arrayDistrictContact + districtName + organisationName);
// Benachrichtigung am Ende der Zuordnungen
description = translate.withArguments("You were assigned as new district contact to district %0 and organisation %1.",
[districtName, organisationName])
notification.addNotification(util.getNewUUID(), text.encodeMS(["Organisation", arrayDistrictContact[2]]), null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user, arrayDistrictContact[1]], message, description);
} }
\ No newline at end of file
import("system.logging");
import("District_lib"); import("District_lib");
import("Loghistory_lib"); import("Loghistory_lib");
import("system.vars"); import("system.vars");
...@@ -21,4 +22,9 @@ if (sqlAction != 'X') ...@@ -21,4 +22,9 @@ if (sqlAction != 'X')
//if (sqlAction == 'I' && tableName == 'ORGANISATION') //if (sqlAction == 'I' && tableName == 'ORGANISATION')
//{ //{
// DistrictUtils.assignOrganisationToDistrict(id, userLogin); // DistrictUtils.assignOrganisationToDistrict(id, userLogin);
//} //}
\ No newline at end of file
if(sqlAction == 'I' && tableName == 'DISTRICTCONTACT'){
logging.log("audit");
DistrictUtils.notificateNewDistrictContact(id);
}
\ 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