From d3ff2a2b6acc43e58f98a87e821e1cb5839a9186 Mon Sep 17 00:00:00 2001 From: Andre Loreth <a.loreth@adito.de> Date: Wed, 27 Mar 2019 13:30:13 +0100 Subject: [PATCH] #1035771 Standard address/communication --- .../recordcontainers/db/onDBUpdate.js | 4 ++ process/StandardObject_lib/process.js | 40 +++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/entity/Person_entity/recordcontainers/db/onDBUpdate.js b/entity/Person_entity/recordcontainers/db/onDBUpdate.js index c1aaada594..4e3598b753 100644 --- a/entity/Person_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Person_entity/recordcontainers/db/onDBUpdate.js @@ -2,6 +2,7 @@ import("system.vars"); import("Person_lib"); import("Communication_lib"); import("Entity_lib"); +import("StandardObject_lib"); // TODO: this is a workaround for missing possibility to react on changes of fields not connected to record Contqainer #1030023 FieldChanges.assimilateChangeAndDispose("$field.IMAGE", function(state, value){ @@ -20,3 +21,6 @@ FieldChanges.assimilateChangeAndDispose("$field.STANDARD_EMAIL_COMMUNICATION", f FieldChanges.assimilateChangeAndDispose("$field.STANDARD_PHONE_COMMUNICATION", function(state, value){ CommUtil.setStandardPhone(uid, value); }); + +new StandardObject("Address", vars.get("$field.ADDRESS_ID"), "Person", vars.get("$field.CONTACTID")) + .onPersonUpdate(vars.get("$field.ORGANISATION_ID")); \ No newline at end of file diff --git a/process/StandardObject_lib/process.js b/process/StandardObject_lib/process.js index 28c728cd76..52d5ba43de 100644 --- a/process/StandardObject_lib/process.js +++ b/process/StandardObject_lib/process.js @@ -2,6 +2,7 @@ import("system.logging"); import("system.db"); import("Keyword_lib"); import("KeywordRegistry_basic"); +import("Contact_lib"); function StandardObject (pObjectType, pObjectID, pScopeType, pScopeID) { if (!this._isValidType("object", pObjectType)) @@ -114,9 +115,9 @@ StandardObject.prototype.onObjectInsert = function () { this._assertScopeIdNotNull(); if (this.objectType === StandardObject.CONST_OBJECT_ADDRESS()) { - this._onAddressInsert() + this._onAddressInsert(); } else if (this.objectType === StandardObject.CONST_OBJECT_COMMUNICATION) { - this._onCommunicationInsert() + this._onCommunicationInsert(); } } @@ -130,7 +131,21 @@ StandardObject.prototype._onAddressInsert = function () { this._assertObjectType(StandardObject.CONST_OBJECT_ADDRESS()); if (!this._hasContactStandardAddress(this.scopeID)) { - this._setContactStandardAddress(this.objectID, this.scopeID) + this._setContactStandardAddress(this.objectID, this.scopeID); + } +} + +StandardObject.prototype.onPersonUpdate = function (pOrganisationID) { + // Assert + this._assertScopeType(StandardObject.CONST_SCOPE_PERSON()); + + var isOrganisationAddress = this._isOrganisationAddress(this.scopeID); + + if (isOrganisationAddress) { + // Update to new address of org + var addressID = this._getCompanyStandardAddress(pOrganisationID); + + this._setContactStandardAddress(addressID, this.scopeID); } } @@ -199,7 +214,7 @@ StandardObject.prototype._setContactStandardAddress = function (pAddressID, pCon ["ADDRESS_ID"], db.getColumnTypes("CONTACT", ["ADDRESS_ID"]), [pAddressID], - "CONTACTID = '" + pContactID + "'") + "CONTACTID = '" + pContactID + "'"); } /** @@ -231,7 +246,7 @@ StandardObject.prototype._hasStandardCommunicationByMedium = function (pContactI var dbResult = db.array(db.COLUMN, "select CHAR_VALUE from COMMUNICATION" + " left join AB_KEYWORD_ENTRY on KEYID = MEDIUM_ID" + " left join AB_KEYWORD_ATTRIBUTERELATION on AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRYID and AB_KEYWORD_ATTRIBUTE_ID = '7250ff28-1d48-41cc-bb36-8c33ace341bb'" - + " where STANDARD = 1 and CONTACT_ID = '" + pContactID + "'") + + " where STANDARD = 1 and CONTACT_ID = '" + pContactID + "'"); return dbResult.indexOf(pMediumCategory) !== -1; } @@ -265,7 +280,7 @@ StandardObject.prototype._setStandardCommunication = function (pCommunicationID, ["STANDARD"], db.getColumnTypes("COMMUNICATION", ["STANDARD"]), [pValue], - "COMMUNICATIONID = '" + pCommunicationID + "'") + "COMMUNICATIONID = '" + pCommunicationID + "'"); } /** @@ -275,5 +290,16 @@ StandardObject.prototype._setStandardCommunication = function (pCommunicationID, * @return The contact ID. */ StandardObject.prototype._getContactIdByCommunication = function (pCommunicationID) { - return db.cell("select CONTACT_ID from COMMUNICATION where COMMUNICATIONID = '" + pCommunicationID + "'") + return db.cell("select CONTACT_ID from COMMUNICATION where COMMUNICATIONID = '" + pCommunicationID + "'"); +} + +StandardObject.prototype._isOrganisationAddress = function (pAddressID) { + var contactID = db.cell("select CONTACTID from CONTACT where ADDRESS_ID = '" + pAddressID + "'"); + + if (contactID === "") + return false; + + var contactType = ContactUtils.getContactTypeByContactId(contactID); + + return contactType === 1; } \ No newline at end of file -- GitLab