From c0638744ee93ab64b40367e08714b1456122ff6a Mon Sep 17 00:00:00 2001 From: "j.goderbauer" <j.goderbauer@adito.de> Date: Mon, 4 Nov 2019 15:26:29 +0100 Subject: [PATCH] fix when creating a new offer that the wrong salesprojects are listed --- .../children/contactid_param/valueProcess.js | 12 +++-- process/Contact_lib/process.js | 46 +++++++++++++++---- process/Organisation_lib/process.js | 15 +++++- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/entity/Offer_entity/entityfields/objects/children/contactid_param/valueProcess.js b/entity/Offer_entity/entityfields/objects/children/contactid_param/valueProcess.js index 7b92c1bb14..38069f3801 100644 --- a/entity/Offer_entity/entityfields/objects/children/contactid_param/valueProcess.js +++ b/entity/Offer_entity/entityfields/objects/children/contactid_param/valueProcess.js @@ -1,10 +1,14 @@ +import("Organisation_lib"); import("system.result"); import("system.vars"); import("Contact_lib"); -if (vars.get("$field.CONTACT_ID")) +var anyContactId = vars.get("$field.CONTACT_ID") +if (anyContactId) { - var ids = ContactUtils.getPersOrgIds(vars.getString("$field.CONTACT_ID")); - if (ids.length >= 3 && ids[2]) - result.string(ids[2]); + //when a person is selected list the salesproject of the persons organisation + //when a organisation is selected list the organisations salesprojects + var organisationContactId = ContactUtils.getOrganisationContactId(anyContactId); + if (organisationContactId && !OrgUtils.isPrivateOrganisationContactId(organisationContactId)) + result.string(organisationContactId); } \ No newline at end of file diff --git a/process/Contact_lib/process.js b/process/Contact_lib/process.js index fe11f0c530..6f799eec31 100644 --- a/process/Contact_lib/process.js +++ b/process/Contact_lib/process.js @@ -16,7 +16,7 @@ import("Context_lib"); * Do not create an instance of this! * @class */ -function OrganisationUtils() {} +function OrganisationUtils() {}//TODO: there exsits a OrgUtils and OrganisationUtils, this is inconvenient /* * retrieves the name of an organisation with a select statement @@ -289,17 +289,45 @@ ContactUtils.getPersOrgIds = function(pContactId) return persOrgIds; } -ContactUtils.getPersId = function(pContactId) + +/** + * get the person- and org-id from a contact as array + * + * @param {String} pContactId + * @return {String[]} result as [contactid, persid, orgid] if one of them is null in the db, "" will be returned as the id. if Contactid is empty -> [] is returned + */ +ContactUtils.getPersOrgIds = function(pContactId) { - persId = ContactUtils.getPersOrgIds(pContactId) - if (persId.length > 0) - { - persId = persId[1]; + if (pContactId) { + return db.array(db.ROW, + SqlCondition.begin() + .andPrepare("CONTACT.CONTACTID", pContactId) + .buildSql("select CONTACTID, PERSON_ID, ORGANISATION_ID from CONTACT", "1=0")); } - else - persId = ""; - return persId ; + return []; +} + +/** + * automatically determines the organisations contactid by specifying a person-contactid (or organisation-contactid) + * this is done with a sql statement, so this will only affect to the db commited data + * + * @param {String} pAnyContactId a person-contactid or organisation-contactid + * @return {String} the contactId of the organisation or "" + */ +ContactUtils.getOrganisationContactId = function(pAnyContactId) +{ + if (!pAnyContactId) + return ""; + + var idSql = SqlCondition.begin() + .andPrepare("anyContact.CONTACTID", pAnyContactId, null, SqlUtils.getSingleColumnType("CONTACT", "CONTACTID")) + .and("CONTACT.PERSON_ID is null") + .buildSql("select CONTACT.CONTACTID \n\ + from CONTACT\n\ + join CONTACT anyContact on anyContact.ORGANISATION_ID = CONTACT.ORGANISATION_ID"); + var id = db.cell(idSql); + return id; } /** diff --git a/process/Organisation_lib/process.js b/process/Organisation_lib/process.js index 5ca14d0407..187622e897 100644 --- a/process/Organisation_lib/process.js +++ b/process/Organisation_lib/process.js @@ -18,7 +18,7 @@ import("KeywordRegistry_basic"); * Do not create an instance of this! * @class */ -function OrgUtils() {} +function OrgUtils() {}//TODO: there exsits a OrgUtils and OrganisationUtils, this is inconvenient /** * checks if a organisationid is the id of the dummy organisation "private" @@ -33,6 +33,19 @@ OrgUtils.isPrivateOrganisationId = function(pOrganisationId) return pOrganisationId.trim() == OrgUtils.getPrivateOrganisationId(); } +/** + * checks if a organsations contactid is the id of the dummy organisation "private" + * + * @param {String} pOrganisationContactId the id that shall be checked + * + * @return {boolean} true if passed contactid is the contactid of the dummy organisation "private" + */ +OrgUtils.isPrivateOrganisationContactId = function(pOrganisationContactId) +{ + //contactid and organisationid in private dummy are equal, so it's okay to check the orgnisation-contactid against the orgnisationid + return pOrganisationContactId.trim() == OrgUtils.getPrivateOrganisationId(); +} + /** * returns the image for a organisation * -- GitLab