Skip to content
Snippets Groups Projects
Commit 40a352dd authored by Benjamin Ulrich's avatar Benjamin Ulrich :speech_balloon: Committed by Sebastian Pongratz
Browse files

[Projekt: xRM-Sales][TicketNr.: 1086776][Zuordnung Betreuer - Status in...

[Projekt: xRM-Sales][TicketNr.: 1086776][Zuordnung Betreuer - Status in Betreuer wird von zur Prüfung auf aktiv gesetzt, wenn bei verantwortlcihen was geändert und gebiet neu gesetzt wird]
parent 82159be7
No related branches found
No related tags found
No related merge requests found
...@@ -139,15 +139,23 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId ...@@ -139,15 +139,23 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
.where("DISTRICTRESPONSIBLE.DISTRICT_ID", pDistrictId) .where("DISTRICTRESPONSIBLE.DISTRICT_ID", pDistrictId)
.table(); .table();
var arrOrgContactIds = new SqlBuilder() var arrOrgContactIdsAndStatus = new SqlBuilder()
.selectDistinct("CONTACT.CONTACTID") .selectDistinct("CONTACT.CONTACTID, CONTACT.STATUS")
.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(); .table();
var arrOrgContactIds = [];
var orgContactStatusObj = {};
for (let i = 0; i < arrOrgContactIdsAndStatus.length; i++)
{
arrOrgContactIds.push(arrOrgContactIdsAndStatus[i][0]);
orgContactStatusObj[arrOrgContactIdsAndStatus[i][0]] = arrOrgContactIdsAndStatus[i][1];
}
var colsInsert = [ var colsInsert = [
"DISTRICTCONTACTID", "DISTRICTCONTACTID",
...@@ -190,6 +198,7 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId ...@@ -190,6 +198,7 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
.from("DISTRICTCONTACT") .from("DISTRICTCONTACT")
.where("DISTRICTCONTACT.DISTRICT_ID", pDistrictId) .where("DISTRICTCONTACT.DISTRICT_ID", pDistrictId)
.and("DISTRICTCONTACT.ADVISER_CONTACT_ID", resContactId) .and("DISTRICTCONTACT.ADVISER_CONTACT_ID", resContactId)
.and("DISTRICTCONTACT.ORIGIN", $KeywordRegistry.districtOrigin$auto())
.table(); .table();
} }
...@@ -206,6 +215,8 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId ...@@ -206,6 +215,8 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
for (var i = 0; i < arrOrgContactIds.length; i++) for (var i = 0; i < arrOrgContactIds.length; i++)
{ {
resStatus = orgContactStatusObj[arrOrgContactIds[i]] == $KeywordRegistry.contactStatus$inactive() ? $KeywordRegistry.contactStatus$inReview() : resStatus;//set to in review if org is inactive
//insert new assignments //insert new assignments
var valsInsert = [ var valsInsert = [
util.getNewUUID(), util.getNewUUID(),
...@@ -225,19 +236,18 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId ...@@ -225,19 +236,18 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
//association = DISTRICT_ID + CONTACT_ID + ADVISER_CONTACT_ID //association = DISTRICT_ID + CONTACT_ID + ADVISER_CONTACT_ID
var existingEntryAssoz = pDistrictId + arrOrgContactIds[i] + arrResponsibleIds[j][0]; var existingEntryAssoz = pDistrictId + arrOrgContactIds[i] + arrResponsibleIds[j][0];
var checkexistingEntry = existingEnriesObject[existingEntryAssoz]; //existingEnriesObject[pDistrictId + arrOrgContactIds[i] + arrResponsibleIds[j][0]] var checkexistingEntry = existingEnriesObject[existingEntryAssoz]; //existingEnriesObject[pDistrictId + arrOrgContactIds[i] + arrResponsibleIds[j][0]]
//check associative Array //check associative Array
if (checkexistingEntry == undefined) { //insert missing entries if (checkexistingEntry == undefined) { //insert missing entries
newAssigned++ newAssigned++
insertArray.push(["DISTRICTCONTACT", colsInsert, null, valsInsert]); insertArray.push(["DISTRICTCONTACT", colsInsert, null, valsInsert]);
} }
else if (checkexistingEntry != undefined && else if (checkexistingEntry != undefined && checkexistingEntry["status"] != $KeywordRegistry.contactStatus$inReview() &&
(checkexistingEntry["status"] != resStatus || checkexistingEntry["role"] != resRole (checkexistingEntry["status"] != resStatus || checkexistingEntry["role"] != resRole
|| checkexistingEntry["validFrom"] != resValidFrom || checkexistingEntry["validUntil"] != resValidUntil || checkexistingEntry["validFrom"] != resValidFrom || checkexistingEntry["validUntil"] != resValidUntil
|| checkexistingEntry["visitFrequency"] != resVisitFrequency))// value changed -> update this dataset || checkexistingEntry["visitFrequency"] != resVisitFrequency))// value changed -> update this dataset
{ {
updated++; updated++;
updateStatements.push(newWhere("DISTRICTCONTACT.DISTRICTCONTACTID", checkexistingEntry["districtContactId"]).buildUpdateStatement({ updateStatements.push(newWhere("DISTRICTCONTACT.DISTRICTCONTACTID", checkexistingEntry["districtContactId"]).buildUpdateStatement({
"ADVISER_ROLE": resRole, "ADVISER_ROLE": resRole,
"STATUS": resStatus, "STATUS": resStatus,
......
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