diff --git a/entity/DistrictContact_entity/DistrictContact_entity.aod b/entity/DistrictContact_entity/DistrictContact_entity.aod index f44080dab0120f8d4b84e5ed04ceb3773537566c..f8cc0892b0c741a7957c015de990b41ea62d43e8 100644 --- a/entity/DistrictContact_entity/DistrictContact_entity.aod +++ b/entity/DistrictContact_entity/DistrictContact_entity.aod @@ -23,6 +23,8 @@ <consumer>Organisations</consumer> <groupable v="true" /> <linkedContext>Person</linkedContext> + <state>READONLY</state> + <valueProcess>%aditoprj%/entity/DistrictContact_entity/entityfields/contact_id/valueProcess.js</valueProcess> <displayValueProcess>%aditoprj%/entity/DistrictContact_entity/entityfields/contact_id/displayValueProcess.js</displayValueProcess> </entityField> <entityField> @@ -142,6 +144,12 @@ <entityName>DistrictResponsible_entity</entityName> <fieldName>DistrictResponsibleAdvisers</fieldName> </dependency> + <children> + <entityParameter> + <name>DistrictId_param</name> + <valueProcess>%aditoprj%/entity/DistrictContact_entity/entityfields/advisers/children/districtid_param/valueProcess.js</valueProcess> + </entityParameter> + </children> </entityConsumer> <entityConsumer> <name>Districts</name> @@ -176,6 +184,14 @@ <name>currentOrganisationId_param</name> <expose v="true" /> </entityParameter> + <entityParameter> + <name>ObjectId_param</name> + <expose v="true" /> + </entityParameter> + <entityParameter> + <name>RowId_param</name> + <expose v="true" /> + </entityParameter> <entityActionGroup> <name>setStatus</name> <children> diff --git a/entity/DistrictContact_entity/entityfields/advisers/children/districtid_param/valueProcess.js b/entity/DistrictContact_entity/entityfields/advisers/children/districtid_param/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..a13a013fadcab4a35ad6a795015276b1fd16be0e --- /dev/null +++ b/entity/DistrictContact_entity/entityfields/advisers/children/districtid_param/valueProcess.js @@ -0,0 +1,4 @@ +import("system.vars"); +import("system.result"); + +result.string(vars.get("$field.DISTRICT_ID")); \ No newline at end of file diff --git a/entity/DistrictContact_entity/entityfields/contact_id/valueProcess.js b/entity/DistrictContact_entity/entityfields/contact_id/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..bd8d4f8447e67f798cc0b1429919e71dec4401ad --- /dev/null +++ b/entity/DistrictContact_entity/entityfields/contact_id/valueProcess.js @@ -0,0 +1,4 @@ +import("system.result"); +import("system.vars"); + +result.string(vars.get("$param.currentOrganisationId_param")); \ No newline at end of file diff --git a/entity/DistrictContact_entity/recordcontainers/db/conditionProcess.js b/entity/DistrictContact_entity/recordcontainers/db/conditionProcess.js index f9e0b80adf18420f7f8acf47539c268adeccda6b..2847b1e2b17599d13ff5d26a5602608adfc20fbe 100644 --- a/entity/DistrictContact_entity/recordcontainers/db/conditionProcess.js +++ b/entity/DistrictContact_entity/recordcontainers/db/conditionProcess.js @@ -6,6 +6,13 @@ import("Sql_lib"); var organisationID = vars.get("$param.currentOrganisationId_param"); var cond = newWhere(); +if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param")) +{ + cond.and("DISTRICTCONTACT.ADVISER_CONTACT_ID", newSelect("DISTRICTRESPONSIBLE.EMPLOYEE_CONTACT_ID") + .from("DISTRICTRESPONSIBLE") + .where("DISTRICTRESPONSIBLE.DISTRICTRESPONSIBLEID", "$param.RowId_param") + , SqlBuilder.IN()); +} if (organisationID) { cond.and("DISTRICTCONTACT.CONTACT_ID", organisationID); diff --git a/entity/DistrictResponsible_entity/DistrictResponsible_entity.aod b/entity/DistrictResponsible_entity/DistrictResponsible_entity.aod index ad1bbffb6bf0fe57bf17b54b8776ce01a0828c88..245c9ebe4dd7b0cba759977f90ee40f454697f03 100644 --- a/entity/DistrictResponsible_entity/DistrictResponsible_entity.aod +++ b/entity/DistrictResponsible_entity/DistrictResponsible_entity.aod @@ -5,6 +5,7 @@ <documentation>%aditoprj%/entity/DistrictResponsible_entity/documentation.adoc</documentation> <icon>VAADIN:GLOBE</icon> <title>District Responsible</title> + <grantDeleteProcess>%aditoprj%/entity/DistrictResponsible_entity/grantDeleteProcess.js</grantDeleteProcess> <contentTitleProcess>%aditoprj%/entity/DistrictResponsible_entity/contentTitleProcess.js</contentTitleProcess> <iconIdProcess>%aditoprj%/entity/DistrictResponsible_entity/iconIdProcess.js</iconIdProcess> <image>VAADIN:GLOBE</image> @@ -21,6 +22,7 @@ <linkedContext>Person</linkedContext> <mandatory v="true" /> <selectionMode>SINGLE</selectionMode> + <stateProcess>%aditoprj%/entity/DistrictResponsible_entity/entityfields/employee_contact_id/stateProcess.js</stateProcess> <displayValueProcess>%aditoprj%/entity/DistrictResponsible_entity/entityfields/employee_contact_id/displayValueProcess.js</displayValueProcess> </entityField> <entityField> @@ -209,6 +211,10 @@ <valueProcess>%aditoprj%/entity/DistrictResponsible_entity/entityfields/adviserstates/children/containername_param/valueProcess.js</valueProcess> <expose v="true" /> </entityParameter> + <entityParameter> + <name>ExcludedKeyIdsSubquery_param</name> + <valueProcess>%aditoprj%/entity/DistrictResponsible_entity/entityfields/adviserstates/children/excludedkeyidssubquery_param/valueProcess.js</valueProcess> + </entityParameter> </children> </entityConsumer> <entityField> diff --git a/entity/DistrictResponsible_entity/entityfields/adviserstates/children/excludedkeyidssubquery_param/valueProcess.js b/entity/DistrictResponsible_entity/entityfields/adviserstates/children/excludedkeyidssubquery_param/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..15b73f9705dc456af35c5d5e144cf88c436a79eb --- /dev/null +++ b/entity/DistrictResponsible_entity/entityfields/adviserstates/children/excludedkeyidssubquery_param/valueProcess.js @@ -0,0 +1,10 @@ +import("system.result"); +import("KeywordRegistry_basic"); +import("Sql_lib"); + +var cond = newSelect("AB_KEYWORD_ENTRY.KEYID") +.from("AB_KEYWORD_ENTRY") +.where("AB_KEYWORD_ENTRY.CONTAINER", $KeywordRegistry.contactStatus()) +.and("AB_KEYWORD_ENTRY.KEYID", $KeywordRegistry.contactStatus$inReview(), SqlBuilder.LIKE()); + +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/DistrictResponsible_entity/entityfields/employee_contact_id/stateProcess.js b/entity/DistrictResponsible_entity/entityfields/employee_contact_id/stateProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..b3376f73e33c298d8cefd14c9098bd6a64f62b38 --- /dev/null +++ b/entity/DistrictResponsible_entity/entityfields/employee_contact_id/stateProcess.js @@ -0,0 +1,20 @@ +import("system.neon"); +import("system.vars"); +import("system.result"); +import("Sql_lib"); +import("system.db"); + +var cond = newWhere(); + +var test = newSelect("COUNT(*)") +.from("DISTRICTCONTACT") +.join("DISTRICTRESPONSIBLE", "DISTRICTCONTACT.ADVISER_CONTACT_ID = DISTRICTRESPONSIBLE.EMPLOYEE_CONTACT_ID") +.where("DISTRICTRESPONSIBLE.EMPLOYEE_CONTACT_ID", vars.get("$field.EMPLOYEE_CONTACT_ID")) +.arrayColumn()[0]; + +if(test.toString() == 0){ + result.string(neon.COMPONENTSTATE_EDITABLE); +} +else{ + result.string(neon.COMPONENTSTATE_READONLY); +} \ No newline at end of file diff --git a/entity/DistrictResponsible_entity/grantDeleteProcess.js b/entity/DistrictResponsible_entity/grantDeleteProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..7039de6df63613d5985e26ef10ab10e90161e5c9 --- /dev/null +++ b/entity/DistrictResponsible_entity/grantDeleteProcess.js @@ -0,0 +1,13 @@ +import("Context_lib"); +import("system.vars"); +import("system.result"); +import("Entity_lib"); + +var rowId = vars.get("$field.DISTRICTRESPONSIBLEID"); +var currentContext = ContextUtils.getCurrentContextId(); + +var canDelete = new HasLinkedObjectTester() + .andNoEntityRows("DistrictContact_entity", "DistrictContacts", {ObjectId_param : currentContext, RowId_param : rowId}) //District Contact + .validate(); + +result.string(canDelete); \ No newline at end of file diff --git a/process/District_lib/process.js b/process/District_lib/process.js index d6143110e5168727ba442a533248d29c2805698b..2811473806a364c43b06bafba27198df0ab39e04 100644 --- a/process/District_lib/process.js +++ b/process/District_lib/process.js @@ -1,3 +1,5 @@ +import("system.logging"); +import("Contact_lib"); import("KeywordRegistry_basic"); import("system.vars"); import("system.util"); @@ -103,25 +105,35 @@ DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser) * Id of the district.<br> * @param {String} pAppliedFilter <p> * Filter condition to get the assigned companies.<br> + * @param {String} pContactId (opt) <p> + * Only filled when a special contact-ID should assigned to a district.<br>* * @return {Object} <p> * Count of new assigned companies and no longer assigned companies.<br> */ -DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter) +DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId) { + if (pContactId == undefined) + pContactId = null; + var newAssigned = 0; var unchanged = 0; var invalid = 0; //Einlesen von allen bereits existierenden automatischen Zuordnungen, - //die nicht auf Status 'zur Prüfung' sthen - var arrExistingIds = new SqlBuilder() - .select("DISTRICTCONTACT.DISTRICTCONTACTID, DISTRICTCONTACT.CONTACT_ID, DISTRICTCONTACT.ADVISER_CONTACT_ID") - .from("DISTRICTCONTACT") - .where("DISTRICTCONTACT.DISTRICT_ID", pDistrictId) - .and ("DISTRICTCONTACT.ORIGIN", $KeywordRegistry.districtOrigin$auto()) - .and ("DISTRICTCONTACT.STATUS", $KeywordRegistry.contactStatus$inReview(), SqlBuilder.NOT_EQUAL()) - .table(); - + //die nicht auf Status 'zur Prüfung' stehen + //Nur notwendig, wenn pContactId leer ist. Ansonsten soll ja gezielt ein neuer Datensatz angelegt werden + var arrExistingIds = [] + if (!pContactId) + { + arrExistingIds = new SqlBuilder() + .select("DISTRICTCONTACT.DISTRICTCONTACTID, DISTRICTCONTACT.CONTACT_ID, DISTRICTCONTACT.ADVISER_CONTACT_ID") + .from("DISTRICTCONTACT") + .where("DISTRICTCONTACT.DISTRICT_ID", pDistrictId) + .and ("DISTRICTCONTACT.ORIGIN", $KeywordRegistry.districtOrigin$auto()) + .and ("DISTRICTCONTACT.STATUS", $KeywordRegistry.contactStatus$inReview(), SqlBuilder.NOT_EQUAL()) + .table(); + } + //Einlesen aller Betreuer, die dem übergebenen Gebiet zugeordnet sind var arrResponsibleIds = new SqlBuilder() .select("DISTRICTRESPONSIBLE.EMPLOYEE_CONTACT_ID, DISTRICTRESPONSIBLE.ADVISER_ROLE, " + @@ -129,12 +141,13 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter) .from("DISTRICTRESPONSIBLE") .where("DISTRICTRESPONSIBLE.DISTRICT_ID", pDistrictId) .table(); - + //Aufbereiten des im JSON-Format übergebenen Filters in eine SQL-Condition var appliedFilterCondition = JSON.parse(pAppliedFilter).filter; - appliedFilterCondition = JSON.stringify(appliedFilterCondition); + appliedFilterCondition = JSON.stringify(appliedFilterCondition); + logging.log("appliedFilterCondition: " + appliedFilterCondition); var sqlCondition = db.toFilterCondition(appliedFilterCondition, "Organisation_entity") - + logging.log("sqlCondition: " + sqlCondition) //Einlesen der Contact-IDs zu den Firmen, die gemäß Filter diesem Gebiet zugeordnet sind var arrOrgContactIds = new SqlBuilder() .selectDistinct("CONTACT.CONTACTID") @@ -143,8 +156,9 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter) .leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID") .leftJoin("CLASSIFICATIONSTORAGE", "CLASSIFICATIONSTORAGE.OBJECT_ROWID = CONTACT.CONTACTID") .whereIfSet(sqlCondition) + .andIfSet("CONTACT.CONTACTID", pContactId) .arrayColumn(); - + logging.log("arrOrgContactIds.length: " + arrOrgContactIds.length) var insertArray = []; var colsInsert = [ "DISTRICTCONTACTID", @@ -370,4 +384,51 @@ DistrictUtils.setDistrictContactStatus = function (pArrIds, pStatus) updateArray.push(["DISTRICTCONTACT", colsUpdate, null, valsUpdate, condition.build()]); } db.updates(updateArray); +} + + +/** + * This function will assign a new organisation to all districts, which + * - have the property "auto assignment" + * - and are part of the regarding filter + * @param {String} pOrganisationId <p> + * Organisation-ID of the new Organisation<br> + * @param {String} pUserLogin <p> + * login,who created the new organistion<br> + * @return <none> <p> + */ +DistrictUtils.assignOrganisationToDistrict = function (pOrganisationId, pUserLogin) +{ + //contactid zur organisationid ermitteln + var contactId = ContactUtils.getOrgContactId(pOrganisationId); + + //alle Filter ermitteln, die auf auto-assignment gleich true gesetzt sind + var allAutoDistricts = newSelect("DISTRICTID") + .from("DISTRICT") + .where("DISTRICT.DISTRICT_AUTOADD", 1) + .arrayColumn(); + + //TODO: pUserLogin noch bis zum Schreiben von date_new durchschleusen + logging.log("pUerLogin: " + pUserLogin) + + + //Variante 1 + for (var i=0; i<allAutoDistricts.length; i++) + { + logging.log("allAutoDistricts[i]: " + allAutoDistricts[i]); + //pro District den kompletten Filter ermitteln + var districtData = DistrictUtils.getDataFromDistrict(allAutoDistricts[i]); + var completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1]) + //logging.log("completeFilter: " + completeFilter) + //prüfen, ob die neue contactid im filter enthalten wäre + //und im Erfolgsfall die Daten in der districtcontact anlegen + //TODO: pUserLogin als 4ten Parameter übergeben. Wenn gefüllt, diesen als USER_NEW/EDIT setzen, sonst den sys.user verwenden + var res = DistrictUtils.assignDistrict(allAutoDistricts[i], completeFilter, contactId); + } + + + //Variante 2: Aufruf des Server-Prozessen mit allen Gebieten mit Auto-Zuordnung gleich true + //Wirft den gleichen Fehler wie Variante 1 + //TODO: Aus dem pUserLogin noch die Employee-ID ermitteln + //DistrictUtils.assignDistrictOnServer(allAutoDistricts, pUserLogin); } \ No newline at end of file diff --git a/process/process_audit/process.js b/process/process_audit/process.js index 023a6e0dbf0888fc4021b7aef9e215dd0a5e4879..b91b948b6dfc3b680015966c5c3024e3e04d76ed 100644 --- a/process/process_audit/process.js +++ b/process/process_audit/process.js @@ -1,3 +1,4 @@ +import("District_lib"); import("Loghistory_lib"); import("system.vars"); import("system.process"); @@ -15,3 +16,9 @@ if (sqlAction != 'X') { (new LogHistoryExecutor(tableName, userLogin, columns, newvalues, oldvalues, timestamp, sqlAction, id)).execute(); } + +//Ticketnummer: 1066031 +//if (sqlAction == 'I' && tableName == 'ORGANISATION') +//{ +// DistrictUtils.assignOrganisationToDistrict(id, userLogin); +//} \ No newline at end of file