diff --git a/entity/Communication_entity/Communication_entity.aod b/entity/Communication_entity/Communication_entity.aod index 06cb4ddca331f8e1e21604233486d20652098924..fb11fd640a7db55e72b75cb3aa736d43c63d05b6 100644 --- a/entity/Communication_entity/Communication_entity.aod +++ b/entity/Communication_entity/Communication_entity.aod @@ -125,7 +125,7 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact <entityParameter> <name>CommCategory_param</name> <valueProcess>%aditoprj%/entity/Communication_entity/entityfields/phonecommunications/children/commcategory_param/valueProcess.js</valueProcess> - <expose v="true" /> + <expose v="false" /> <description>TODO: expose auf false. aktuell wird der Code nicht ausgeführt, wenn Expose false ist.</description> </entityParameter> <entityParameter> @@ -162,8 +162,9 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact <children> <entityParameter> <name>CommCategory_param</name> + <title></title> <valueProcess>%aditoprj%/entity/Communication_entity/entityfields/emailcommunications/children/commcategory_param/valueProcess.js</valueProcess> - <expose v="true" /> + <expose v="false" /> <description>TODO: expose auf false. aktuell wird der Code nicht ausgeführt, wenn Expose false ist.</description> </entityParameter> <entityParameter> diff --git a/entity/DSGVO_entity/DSGVO_entity.aod b/entity/DSGVO_entity/DSGVO_entity.aod index 3dc0b06c7c3ac2bf01d500a65ffefe37e16edd4d..2b33298ac54de52e762264f7ec4f880b1c785750 100644 --- a/entity/DSGVO_entity/DSGVO_entity.aod +++ b/entity/DSGVO_entity/DSGVO_entity.aod @@ -104,6 +104,7 @@ <children> <entityParameter> <name>ContainerName_param</name> + <title></title> <valueProcess>%aditoprj%/entity/DSGVO_entity/entityfields/keyworddsgvopurpose/children/containername_param/valueProcess.js</valueProcess> </entityParameter> </children> diff --git a/entity/Offer_entity/entityfields/lettersalutation/valueProcess.js b/entity/Offer_entity/entityfields/lettersalutation/valueProcess.js index 0dd257f7f36ea76b1dea44e0405d5105a408a75d..2c0266cbac1c8c8e575ade5d92b84fba9d7c474a 100644 --- a/entity/Offer_entity/entityfields/lettersalutation/valueProcess.js +++ b/entity/Offer_entity/entityfields/lettersalutation/valueProcess.js @@ -1,4 +1,3 @@ -import("system.logging"); import("system.result"); import("system.neon"); import("system.vars"); @@ -6,7 +5,6 @@ import("Address_lib"); if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && !vars.get("$this.value")) { - logging.log(vars.get("$field.CONTACT_ID")) var addrobj = new AddrObject(vars.get("$field.CONTACT_ID")); var salutation = addrobj.getFormattedAddress(false, "{letter_salutation},"); if (salutation != "Err.,") diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod index af151b8b0e5e49bdb85dafd201a5653824fad601..131f57a342976a436e6c5f6f6e0d870ab166f993 100644 --- a/entity/Person_entity/Person_entity.aod +++ b/entity/Person_entity/Person_entity.aod @@ -908,6 +908,10 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact </entityParameter> </children> </entityConsumer> + <entityActionField> + <name>lokl</name> + <onActionProcess>%aditoprj%/entity/Person_entity/entityfields/lokl/onActionProcess.js</onActionProcess> + </entityActionField> </entityFields> <recordContainers> <dbRecordContainer> diff --git a/entity/Person_entity/entityfields/lokl/onActionProcess.js b/entity/Person_entity/entityfields/lokl/onActionProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..b9da4051c335783febe37c3f97bf04f5ee561423 --- /dev/null +++ b/entity/Person_entity/entityfields/lokl/onActionProcess.js @@ -0,0 +1,3 @@ +import("system.vars"); +import("Contact_lib"); +ContactUtils.getPrivateContact(vars.get("$field.PERSONID")) \ No newline at end of file diff --git a/entity/Person_entity/recordcontainers/db/conditionProcess.js b/entity/Person_entity/recordcontainers/db/conditionProcess.js index 2678fdab9c1337a75e2f06a34ac456384daa8c66..ea9ed9c1ed9d69004d4832ee258b00fdc1e1fce8 100644 --- a/entity/Person_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Person_entity/recordcontainers/db/conditionProcess.js @@ -22,3 +22,4 @@ if (vars.exists("$param.ExcludedContactIds_param") && vars.get("$param.ExcludedC //TODO: use a preparedCondition when available #1030812 #1034026 result.string(db.translateCondition(cond.build("1 = 1"))); +logging.log(JSON.stringify(vars.get("$sys.filter"), null, "\t")) \ No newline at end of file diff --git a/entity/Person_entity/recordcontainers/db/fromClauseProcess.js b/entity/Person_entity/recordcontainers/db/fromClauseProcess.js index ee43318317813db5384c2a13bba96181b447a6be..c8caaf3874ed3ee8cfa40da0fb0d57d72f998f02 100644 --- a/entity/Person_entity/recordcontainers/db/fromClauseProcess.js +++ b/entity/Person_entity/recordcontainers/db/fromClauseProcess.js @@ -5,4 +5,4 @@ import("system.result"); result.string("PERSON \n\ join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID) \n\ join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID) \n\ - left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"); \ No newline at end of file + left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"); diff --git a/entity/Person_entity/recordcontainers/db/onDBUpdate.js b/entity/Person_entity/recordcontainers/db/onDBUpdate.js index 042bca7423fa3cc756efa399d3c8ba702797c17b..530c2f5d46b93d85f6ee09373a336219671aad49 100644 --- a/entity/Person_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Person_entity/recordcontainers/db/onDBUpdate.js @@ -34,4 +34,4 @@ vars.get("$local.changed").forEach(function(fieldName) { } }) -DataPrivacyUtils.notifyNeedDataPrivacyUpdate(vars.get("$field.CONTACT_ID")); \ No newline at end of file +DataPrivacyUtils.notifyNeedDataPrivacyUpdate(vars.get("$field.CONTACTID")); \ No newline at end of file diff --git a/process/Address_lib/process.js b/process/Address_lib/process.js index a694f7a3d47e8cb06566318eb06dc133ea98b302..d1a52330e8fe3d954177ceac9b77440b70d3ae4b 100644 --- a/process/Address_lib/process.js +++ b/process/Address_lib/process.js @@ -121,6 +121,7 @@ function getAddressData( pCondition, pConfig, AddressID ) */ function fetchAddressData( pCondition, pConfig, AddressID, pPerson ) { + // TODO: load entity? if ( typeof(pCondition) == "object") pCondition = "CONTACT.CONTACTID in ('" + pCondition.join("','") + "')"; if ( pConfig.length > 0 ) { @@ -325,6 +326,7 @@ function _getAddrData( pData ) pData[23] = salutation; pData[24] = lettersalutation; pData[25] = _getCountryName(pData[5]); + logging.log(JSON.stringify(pData, null, "\t")) return pData; } diff --git a/process/DataPrivacy_lib/process.js b/process/DataPrivacy_lib/process.js index e2d5450fa9724f318c47f86169632a010d5c4fa7..15d99fb1f8b377835429752c256ac5c55e293bf0 100644 --- a/process/DataPrivacy_lib/process.js +++ b/process/DataPrivacy_lib/process.js @@ -15,6 +15,7 @@ import("system.entities"); import("system.datetime"); import("Report_lib"); import("Contact_lib"); +import("Address_lib"); /** * @@ -62,57 +63,100 @@ DataPrivacyType.get = function(pKey) /** * Helper function to get personal data. */ - function _selectPersonal(pContactId, pPersonId, fields) + function _selectPersonal(pContactId, pContactIdSaved, fields) { - // Use PersonId as ID, since the data comes from the person - - // TODO: with loadEntity - var persData = db.array(db.ROW, SqlCondition.begin() - .andPrepareIfSet("CONTACT.CONTACTID", pContactId) - .andPrepareIfSet("PERSON.PERSONID", pPersonId) - .buildSql("select PERSONID, " + fields.join(",") - + (pContactId ? " from CONTACT left join PERSON on PERSONID = PERSON_ID" : "PERSON"), // use only CONTACT, if contactid is given else use PERSON directly - "1 = 0")); - return persData; + fields.push("CONTACTID"); + + if (pContactIdSaved) + pContactId = pContactIdSaved; + + var entityConfig = entities.createConfigForLoadingRows() + .entity("Person_entity") + .provider("Contact") + .uid(pContactId) + .fields(fields); + return entities.getRow(entityConfig); } - function _getName(pContactId, pPersonId) + function _getName(pContactId, pContactIdSaved) { // Use PersonId as ID, since the data comes from the person - - var persData = _selectPersonal(pContactId, pPersonId, ["SALUTATION", "TITLE", "TITLESUFFIX", "FIRSTNAME", "MIDDLENAME", "LASTNAME"]); + + var persData = _selectPersonal(pContactId, pContactIdSaved, ["SALUTATION", "TITLE", "TITLESUFFIX", "FIRSTNAME", "MIDDLENAME", "LASTNAME"]); // TODO format correctly (with lib?) - var names = persData.slice(1).join(" "); + + var contact = new Contact(); + contact.salutation = persData.SALUTATION; + contact.title = persData.TITLE; + contact.firstname= persData.FIRSTNAME; + contact.middlename = persData.MIDDLENAME; + contact.lastname = persData.LASTNAME; + contact.suffix = persData.TITLESUFFIX; + + var renderer = new ContactTitleRenderer(contact); + var names = renderer.asString() return [{ value: names, - id: persData[0] + id: persData.CONTACTID }] } - function _getBirthday(pContactId, pPersonId) - { - // Use PersonId as ID, since the data comes from the person - + function _getBirthday(pContactId, pContactIdSaved) + { // Todo Format or set content type - var persData = _selectPersonal(pContactId, pPersonId, ["DATEOFBIRTH"]); + var persData = _selectPersonal(pContactId, pContactIdSaved, ["DATEOFBIRTH"]); return [{ - value: persData[1], - id: persData[0] + value: persData.DATEOFBIRTH, + id: persData.CONTACTID }] } function _getAddress(pContactId, pAddressId) { - // TODO: with loadEntity + var addrIds + if (pAddressId) + { + addrIds = [{ + ADDRESSID: pAddressId + }] + } + else + { + var entityConfig = entities.createConfigForLoadingRows() + .entity("Address_entity") + .provider("ContactAddresses") + .addParameter("ContactId_param", pContactId) + .fields(["ADDRESSID"]); + addrIds = entities.getRows(entityConfig); + + } + + + + // Todo: Address_lib doesn't use loadEntity... + for (addrId in addrIds) + { + addrId = addrId.ADDRESSID + var addrobj = new AddrObject(pContactId, true, addrId); + + var addr = addrobj.getFormattedAddress(false); + logging.log(JSON.stringify(addr, null, "\t")) + } + + + // if (addr != "Err.") + + + /* var addrData = db.table(SqlCondition.begin() .andPrepareIfSet("ADDRESS.ADDRESSID", pAddressId) .andPrepareIfSet("ADDRESS.CONTACT_ID", pContactId) .buildSql("select ADDRESSID, ADDRESS, ADDRESSADDITION, ADDRIDENTIFIER, " + "BUILDINGNO, CITY, COUNTRY, DISTRICT, REGION, STATE, ZIP, ADDR_TYPE " + "from ADDRESS", "1 = 0")); - +*/ return addrData.map(function(pAddr) { // TODO Addresse formatieren diff --git a/process/PostalAddress_lib/process.js b/process/PostalAddress_lib/process.js index 757eed6adaa34dd390c1584e4686863d3866e03b..de5ac3dcd8e6fb96c2e975543aed2f8c589bf468 100644 --- a/process/PostalAddress_lib/process.js +++ b/process/PostalAddress_lib/process.js @@ -1,271 +1,271 @@ -import("KeywordRegistry_basic"); -import("system.db"); -import("Sql_lib"); -import("Contact_lib"); -import("Keyword_lib"); -import("Util_lib"); -/** - * Methods for addresses. - * Todo: evtl. übernahme / anpassung der Adresslib aus altem Basic. 1030856 - * - * Do not create an instance of this! - * - * @class - */ -function AddressUtils(){} - -/** - * format the Address in one line - * - * @param {String} pCountry - * @param {String} pAddressLine - * @param {String} pBuildingNo - * @param {String} pZipCode - * @param {String} pCity - * @param {String} pAddressIdentifier - * - * @return {String} - */ -AddressUtils.formatOneline = function (pCountry, pAddressLine, pBuildingNo, pZipCode, pCity, pAddressIdentifier) -{ - //request (and resulting change) was made here to NOT include Country int othe title - return StringUtils.concat(", ", [pAddressLine, pBuildingNo, pZipCode, pCity, pAddressIdentifier]); -}; - -/** - * format the Address in one line as a sql statement - * - * @return {String} sql expression that can be used within a select statement - */ -AddressUtils.formatOnelineSql = function () -{ - //request (and resulting change) was made here to NOT include Country int othe title - var maskingHelper = new SqlMaskingUtils(); - var sqlExpression = maskingHelper.concat(["ADDRESS.ADDRESS", "ADDRESS.BUILDINGNO", "ADDRESS.ZIP", "ADDRESS.CITY", "ADDRESS.ADDRIDENTIFIER"], ", "); - return sqlExpression; -}; - - -/** - * returns the formatted address by the ADDRESSID as one line - * - * TODO: Dummy method! Übernahme der Adresslib aus altem Basic - * - * @params {String} pAddressId ADDRESSID of the address which shall be loaded - * - * @return {String} formatted address - */ -AddressUtils.getFormattedOnlineAddressById = function(pAddressId) -{ - var addrId = pAddressId; - var addr = ""; - if (addrId) - { - var select = "select ADDRESS.COUNTRY, ADDRESS.ADDRESS, ADDRESS.BUILDINGNO, ADDRESS.ZIP, ADDRESS.CITY, ADDRESS.ADDRIDENTIFIER from ADDRESS "; - var addrData = db.array(db.ROW, - SqlCondition.begin() - .andPrepare("ADDRESS.ADDRESSID", addrId) - .buildSql(select)); - - addr = AddressUtils.formatOneline.apply(this, addrData); - } - return addr; -} - -/** - * Returns the formatted standard address for the contact. - * - * TODO: Dummy method! Übernahme der Adresslib aus altem Basic - * - * @return {String} - */ -AddressUtils.getAddress = function(pContactId) { - var address = db.array(db.ROW, SqlCondition.begin().andPrepare("CONTACT.CONTACTID", pContactId).buildSql('select CONTACTID, ADDRESS, BUILDINGNO, ZIP, CITY, "NAME", FIRSTNAME, LASTNAME, TITLE from' + ContactUtils.getFullContactString(), "1=0")); - - // TODO: currently there are some relations without standard address. Use Hardcoded one. - if (!address[1]) { - var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSql('select ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0")); - address[1] = dummyAddress[0]; - address[2] = dummyAddress[1]; - address[3] = dummyAddress[2]; - address[4] = dummyAddress[3]; - - } - var type = ContactUtils.getContactTypeByContactId(pContactId); - - return AddressUtils.formatAddress(type, address[1], address[2], address[3], address[4], address[5], address[6], address[7], address[8]); -} - -/** - * Returns the formatted address. - * - * TODO: Dummy method! Übernahme der Adresslib aus altem Basic - * - * @return {String} - */ -AddressUtils.getAddressById = function(pAddressId) { - var address = db.array(db.ROW, SqlCondition.begin() - .andPrepare("ADDRESS.ADDRESSID", pAddressId) - .buildSql("select CONTACT_ID, ADDRESS, BUILDINGNO, ZIP, CITY from " - + "ADDRESS", "1=0")); - - // TODO: currently there are some relations without standard address. Use Hardcoded one. - if (!address[1]) { - var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSql('select CONTACT_ID, ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0")); - address[0] = dummyAddress[0]; - address[1] = dummyAddress[1]; - address[2] = dummyAddress[2]; - address[3] = dummyAddress[3]; - address[4] = dummyAddress[4]; - - } - var type = ContactUtils.getContactTypeByContactId(address[0]); - - if (address[0]) - { - var names = db.array(db.ROW, SqlCondition.begin() - .andPrepare("CONTACT.CONTACTID", address[0]) - .buildSql("select ORGANISATION.NAME, FIRSTNAME, LASTNAME, TITLE from CONTACT left join PERSON on PERSONID = PERSON_ID left join ORGANISATION on ORGANISATIONID = ORGANISATION_ID" - , "1=0")); - return AddressUtils.formatAddress(type, address[1], address[2], address[3], address[4], names[0], names[1], names[2], names[3]); - } - - return ""; -} - -/** - * TODO: Dummy method! - * - * Returns the formatted address. - * - * TODO: Dummy method! Übernahme der Adresslib aus altem Basic und Nutzung von den Platzhaltern in Zukunft! - * - * @return {String} - */ -AddressUtils.formatAddress = function(pAddrType, pAddress, pBuildingno, pZip, pCity, pOrgname, pFirstname, pLastname, pTitle) { - var resultAddr = ""; - - // 1 if organisation <br> - // 2 if privat person <br> - // 3 if person of an organisation <br> - switch (pAddrType) - { - case 1: - resultAddr = pOrgname + "\n" + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity; - break; - case 2: - resultAddr = pTitle + " " + pFirstname + " " + pLastname + "\n" + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity; - break; - case 3: - resultAddr = pOrgname + "\n" + (pTitle && pFirstname && pLastname ? pTitle + " " + pFirstname + " " + pLastname + "\n" : "") + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity; - break; - } - - return resultAddr; -} - -/** - * Returns the formatted addresses for the contact. - * - * TODO: Dummy method! Übernahme der Adresslib aus altem Basic - * - * @return {String} - */ -AddressUtils.getAllPossibleAddresses = function(pRelationId) { - var addresses = db.table(SqlCondition.begin().andPrepare("CONTACT.CONTACTID", pRelationId) - .buildSql("select ADDRESSID, ADDR_TYPE, ADDRIDENTIFIER from ADDRESS join CONTACT on CONTACTID = CONTACT_ID or CONTACT_ID = ORGANISATION_ID", "1=0")); - - return addresses.map(function(pAddress) { - return [pAddress[0], KeywordUtils.getViewValue($KeywordRegistry.addressType(), pAddress[1]) + ": " + pAddress[2]]; - }); -} - -/** - * Returns a letter salutation. - * - * TODO: Dummy method! Übernahme der Adresslib aus altem Basic - * - * @return {String} - */ -AddressUtils.getLetterSalutation = function() { - return "Sehr geehrte Damen und Herren"; -} - -/** - * Methods for validating addresses. - * - * Do not create an instance of this! - * - * @class - */ -function AddressValidationUtils(){} - -/** - * loads AB_COUNTRYINFO.REQUIRED_FIELDS from db - * - * @param {String} countryCode - * - * @return {String} A string containing all mandatory fieldCodes - * - * @ignore - */ -AddressValidationUtils._getRequiredFields = function(countryCode) -{ - if (!countryCode) - return ""; - var requiredFields = db.cell(SqlCondition.begin().andPrepare("AB_COUNTRYINFO.ISO2", countryCode) - .buildSql("select AB_COUNTRYINFO.REQUIRED_FIELDS from AB_COUNTRYINFO")); - return requiredFields; -}; - -/** - * check if the requested field is a mandatory field - * - * @param {String} countryCode - * @param {String} fieldCode - * - * @return {Boolean} - */ -AddressValidationUtils.isMandatoryField = function(countryCode, fieldCode) -{ - var requiredFields = this._getRequiredFields(countryCode); - return requiredFields == "" || requiredFields.search(fieldCode) != -1; -}; - -/** - * load the regexp for zip validation from the database - * - * @param {String} countryCode - * - * @return {String} the regexp - */ -AddressValidationUtils._getZipValidationRegEx = function(countryCode) -{ - if (!countryCode) - return ""; - var cond = new SqlCondition(); - cond.andPrepare("AB_COUNTRYINFO.ISO2", countryCode ); - var stmt = cond.buildSql("select AB_COUNTRYINFO.ZIP_REGEX from AB_COUNTRYINFO"); - return db.cell(stmt); -}; - -/** - * check if the zip code is valid - * - * @param {String} countryCode - * @param {String} zipCode - * - * return {Boolean} - */ -AddressValidationUtils.isValidZip = function(countryCode, zipCode) -{ - if (zipCode == "") - return true;//if ZIP is a required field has to be checked in a separate mandatory-field-check -> do not check this here - var regExpVal = this._getZipValidationRegEx(countryCode); - if (regExpVal == "") - return true; - //only an exact match is a correct one -> specify being and end anchors - regExpVal = "^" + regExpVal + "$"; - var regExp = new RegExp(regExpVal); - return regExp.test(zipCode); +import("KeywordRegistry_basic"); +import("system.db"); +import("Sql_lib"); +import("Contact_lib"); +import("Keyword_lib"); +import("Util_lib"); +/** + * Methods for addresses. + * Todo: evtl. übernahme / anpassung der Adresslib aus altem Basic. 1030856 + * + * Do not create an instance of this! + * + * @class + */ +function AddressUtils(){} + +/** + * format the Address in one line + * + * @param {String} pCountry + * @param {String} pAddressLine + * @param {String} pBuildingNo + * @param {String} pZipCode + * @param {String} pCity + * @param {String} pAddressIdentifier + * + * @return {String} + */ +AddressUtils.formatOneline = function (pCountry, pAddressLine, pBuildingNo, pZipCode, pCity, pAddressIdentifier) +{ + //request (and resulting change) was made here to NOT include Country int othe title + return StringUtils.concat(", ", [pAddressLine, pBuildingNo, pZipCode, pCity, pAddressIdentifier]); +}; + +/** + * format the Address in one line as a sql statement + * + * @return {String} sql expression that can be used within a select statement + */ +AddressUtils.formatOnelineSql = function () +{ + //request (and resulting change) was made here to NOT include Country int othe title + var maskingHelper = new SqlMaskingUtils(); + var sqlExpression = maskingHelper.concat(["ADDRESS.ADDRESS", "ADDRESS.BUILDINGNO", "ADDRESS.ZIP", "ADDRESS.CITY", "ADDRESS.ADDRIDENTIFIER"], ", "); + return sqlExpression; +}; + + +/** + * returns the formatted address by the ADDRESSID as one line + * + * TODO: Dummy method! Übernahme der Adresslib aus altem Basic + * + * @params {String} pAddressId ADDRESSID of the address which shall be loaded + * + * @return {String} formatted address + */ +AddressUtils.getFormattedOnlineAddressById = function(pAddressId) +{ + var addrId = pAddressId; + var addr = ""; + if (addrId) + { + var select = "select ADDRESS.COUNTRY, ADDRESS.ADDRESS, ADDRESS.BUILDINGNO, ADDRESS.ZIP, ADDRESS.CITY, ADDRESS.ADDRIDENTIFIER from ADDRESS "; + var addrData = db.array(db.ROW, + SqlCondition.begin() + .andPrepare("ADDRESS.ADDRESSID", addrId) + .buildSql(select)); + + addr = AddressUtils.formatOneline.apply(this, addrData); + } + return addr; +} + +/** + * Returns the formatted standard address for the contact. + * + * TODO: Dummy method! Übernahme der Adresslib aus altem Basic + * + * @return {String} + */ +AddressUtils.getAddress = function(pContactId) { + var address = db.array(db.ROW, SqlCondition.begin().andPrepare("CONTACT.CONTACTID", pContactId).buildSql('select CONTACTID, ADDRESS, BUILDINGNO, ZIP, CITY, "NAME", FIRSTNAME, LASTNAME, TITLE from' + ContactUtils.getFullContactString(), "1=0")); + + // TODO: currently there are some relations without standard address. Use Hardcoded one. + if (!address[1]) { + var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSql('select ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0")); + address[1] = dummyAddress[0]; + address[2] = dummyAddress[1]; + address[3] = dummyAddress[2]; + address[4] = dummyAddress[3]; + + } + var type = ContactUtils.getContactTypeByContactId(pContactId); + + return AddressUtils.formatAddress(type, "DUMMYADDR - (no standard addr set)" + address[1], address[2], address[3], address[4], address[5], address[6], address[7], address[8]); +} + +/** + * Returns the formatted address. + * + * TODO: Dummy method! Übernahme der Adresslib (jetzt Address_lib) aus altem Basic + * + * @return {String} + */ +AddressUtils.getAddressById = function(pAddressId) { + var address = db.array(db.ROW, SqlCondition.begin() + .andPrepare("ADDRESS.ADDRESSID", pAddressId) + .buildSql("select CONTACT_ID, ADDRESS, BUILDINGNO, ZIP, CITY from " + + "ADDRESS", "1=0")); + + // TODO: currently there are some relations without standard address. Use Hardcoded one. + if (!address[1]) { + var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSql('select CONTACT_ID, ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0")); + address[0] = dummyAddress[0]; + address[1] = dummyAddress[1]; + address[2] = dummyAddress[2]; + address[3] = dummyAddress[3]; + address[4] = dummyAddress[4]; + + } + var type = ContactUtils.getContactTypeByContactId(address[0]); + + if (address[0]) + { + var names = db.array(db.ROW, SqlCondition.begin() + .andPrepare("CONTACT.CONTACTID", address[0]) + .buildSql("select ORGANISATION.NAME, FIRSTNAME, LASTNAME, TITLE from CONTACT left join PERSON on PERSONID = PERSON_ID left join ORGANISATION on ORGANISATIONID = ORGANISATION_ID" + , "1=0")); + return AddressUtils.formatAddress(type, address[1], address[2], address[3], address[4], names[0], names[1], names[2], names[3]); + } + + return ""; +} + +/** + * TODO: Dummy method! + * + * Returns the formatted address. + * + * TODO: Dummy method! Übernahme der Adresslib (jetzt Address_lib) aus altem Basic und Nutzung von den Platzhaltern in Zukunft! + * + * @return {String} + */ +AddressUtils.formatAddress = function(pAddrType, pAddress, pBuildingno, pZip, pCity, pOrgname, pFirstname, pLastname, pTitle) { + var resultAddr = ""; + + // 1 if organisation <br> + // 2 if privat person <br> + // 3 if person of an organisation <br> + switch (pAddrType) + { + case 1: + resultAddr = pOrgname + "\n" + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity; + break; + case 2: + resultAddr = pTitle + " " + pFirstname + " " + pLastname + "\n" + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity; + break; + case 3: + resultAddr = pOrgname + "\n" + (pTitle && pFirstname && pLastname ? pTitle + " " + pFirstname + " " + pLastname + "\n" : "") + pAddress + " " + pBuildingno + "\n" + pZip + " " + pCity; + break; + } + + return resultAddr; +} + +/** + * Returns the formatted addresses for the contact. + * + * TODO: Dummy method! Übernahme der Adresslib (jetzt Address_lib) aus altem Basic + * + * @return {String} + */ +AddressUtils.getAllPossibleAddresses = function(pRelationId) { + var addresses = db.table(SqlCondition.begin().andPrepare("CONTACT.CONTACTID", pRelationId) + .buildSql("select ADDRESSID, ADDR_TYPE, ADDRIDENTIFIER from ADDRESS join CONTACT on CONTACTID = CONTACT_ID or CONTACT_ID = ORGANISATION_ID", "1=0")); + + return addresses.map(function(pAddress) { + return [pAddress[0], KeywordUtils.getViewValue($KeywordRegistry.addressType(), pAddress[1]) + ": " + pAddress[2]]; + }); +} + +/** + * Returns a letter salutation. + * + * TODO: Dummy method! Übernahme der Adresslib (jetzt Address_lib) aus altem Basic + * + * @return {String} + */ +AddressUtils.getLetterSalutation = function() { + return "Sehr geehrte Damen und Herren"; +} + +/** + * Methods for validating addresses. + * + * Do not create an instance of this! + * + * @class + */ +function AddressValidationUtils(){} + +/** + * loads AB_COUNTRYINFO.REQUIRED_FIELDS from db + * + * @param {String} countryCode + * + * @return {String} A string containing all mandatory fieldCodes + * + * @ignore + */ +AddressValidationUtils._getRequiredFields = function(countryCode) +{ + if (!countryCode) + return ""; + var requiredFields = db.cell(SqlCondition.begin().andPrepare("AB_COUNTRYINFO.ISO2", countryCode) + .buildSql("select AB_COUNTRYINFO.REQUIRED_FIELDS from AB_COUNTRYINFO")); + return requiredFields; +}; + +/** + * check if the requested field is a mandatory field + * + * @param {String} countryCode + * @param {String} fieldCode + * + * @return {Boolean} + */ +AddressValidationUtils.isMandatoryField = function(countryCode, fieldCode) +{ + var requiredFields = this._getRequiredFields(countryCode); + return requiredFields == "" || requiredFields.search(fieldCode) != -1; +}; + +/** + * load the regexp for zip validation from the database + * + * @param {String} countryCode + * + * @return {String} the regexp + */ +AddressValidationUtils._getZipValidationRegEx = function(countryCode) +{ + if (!countryCode) + return ""; + var cond = new SqlCondition(); + cond.andPrepare("AB_COUNTRYINFO.ISO2", countryCode ); + var stmt = cond.buildSql("select AB_COUNTRYINFO.ZIP_REGEX from AB_COUNTRYINFO"); + return db.cell(stmt); +}; + +/** + * check if the zip code is valid + * + * @param {String} countryCode + * @param {String} zipCode + * + * return {Boolean} + */ +AddressValidationUtils.isValidZip = function(countryCode, zipCode) +{ + if (zipCode == "") + return true;//if ZIP is a required field has to be checked in a separate mandatory-field-check -> do not check this here + var regExpVal = this._getZipValidationRegEx(countryCode); + if (regExpVal == "") + return true; + //only an exact match is a correct one -> specify being and end anchors + regExpVal = "^" + regExpVal + "$"; + var regExp = new RegExp(regExpVal); + return regExp.test(zipCode); }; \ No newline at end of file