diff --git a/entity/Person_entity/grantDeleteProcess.js b/entity/Person_entity/grantDeleteProcess.js index 7b130d228f43287df7b16ee2f16acc9f7f43c009..2c8fe13800c8f755557466f0ba55164897abd1e6 100644 --- a/entity/Person_entity/grantDeleteProcess.js +++ b/entity/Person_entity/grantDeleteProcess.js @@ -1,20 +1,34 @@ +import("Sql_lib"); import("Entity_lib"); import("Employee_lib"); import("Context_lib"); import("system.vars"); import("system.result"); -var contactId = vars.get("$field.CONTACTID"); -var currentContext = ContextUtils.getCurrentContextId(); +var canDelete = false; +var personId = vars.get("$field.PERSONID"); +var personCount = newSelect("count(*)") + .from("CONTACT") + .join("PERSON", "PERSON.PERSONID = CONTACT.PERSON_ID") + .where("PERSON.PERSONID", personId) + .cell() +//only delete when the contact doesnt have any functions, because that would currently lead to the person and all his functions being deleted, +// since there is only one person contact behind all the contacts. +//ToDo: come back to this and implement the solution for deleting a function (#1059167) once it'S decided how that's being implemented +if(personCount == 1) +{ + var contactId = vars.get("$field.CONTACTID"); + var currentContext = ContextUtils.getCurrentContextId(); -var canDelete = new HasLinkedObjectTester() - .andNoEntityRows("Activity_entity", "LinkedObjects", {ObjectId_param : currentContext, RowId_param : contactId}) //Activities - .andNoEntityRows("Task_entity", "Tasks", {ObjectId_param : currentContext, RowId_param : contactId}) //Tasks - .andNoEntityRows("Document_entity", "Documents", {AssignmentTable_param : "CONTACT", AssignmentRowId_param : contactId}) //Documents - .and(function () {return !EmployeeUtils.isUser(contactId);}) - .andNoEntityRows("Offer_entity", "ContactOffers", {ContactId_param : contactId}) //Offers - .andNoEntityRows("Contract_entity", "Contracts", {ContactId_param : contactId}) //Contracts - .andNoEntityRows("ObjectTree_entity", "TreeProvider", {ObjectIds_param : JSON.stringify([contactId, vars.get("$field.PERSON_ID")]), ObjectTypes_param : JSON.stringify([currentContext, "PrivatePerson"])}) - .validate(); + canDelete = new HasLinkedObjectTester() + .andNoEntityRows("Activity_entity", "LinkedObjects", {ObjectId_param : currentContext, RowId_param : contactId}) //Activities + .andNoEntityRows("Task_entity", "Tasks", {ObjectId_param : currentContext, RowId_param : contactId}) //Tasks + .andNoEntityRows("Document_entity", "Documents", {AssignmentTable_param : "CONTACT", AssignmentRowId_param : contactId}) //Documents + .and(function () {return !EmployeeUtils.isUser(contactId);}) + .andNoEntityRows("Offer_entity", "ContactOffers", {ContactId_param : contactId}) //Offers + .andNoEntityRows("Contract_entity", "Contracts", {ContactId_param : contactId}) //Contracts + .andNoEntityRows("ObjectTree_entity", "TreeProvider", {ObjectIds_param : JSON.stringify([contactId, vars.get("$field.PERSON_ID")]), ObjectTypes_param : JSON.stringify([currentContext, "PrivatePerson"])}) + .validate(); +} result.string(canDelete);