diff --git a/process/Organisation_lib/process.js b/process/Organisation_lib/process.js index ac47bd040093fc70ec5f37b2f68fc68de61a50e9..fcba728823650949bd9fb79ca13dcfa8bb8dc918 100644 --- a/process/Organisation_lib/process.js +++ b/process/Organisation_lib/process.js @@ -1,3 +1,4 @@ +import("system.neon"); import("Util_lib"); import("system.datetime"); import("system.translate"); @@ -14,7 +15,7 @@ import("KeywordRegistry_basic"); /** * a static Utility class for the Org context. - * + * * Do not create an instance of this! * @class */ @@ -22,7 +23,7 @@ function OrgUtils() {}//TODO: there exsits a OrgUtils and OrganisationUtils, thi /** * checks if a organisationid is the id of the dummy organisation "private" - * + * * @param {String} pOrganisationId the id that shall be checked * * @return {boolean} true if passed organisationid is organisationid of the dummy organisation "private" @@ -35,7 +36,7 @@ OrgUtils.isPrivateOrganisationId = function(pOrganisationId) /** * 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" @@ -48,7 +49,7 @@ OrgUtils.isPrivateOrganisationContactId = function(pOrganisationContactId) /** * returns the image for a organisation - * + * * @return {String} hard coded organisationid of the dummy organisation "private" */ OrgUtils.getPrivateOrganisationId = function() @@ -59,7 +60,7 @@ OrgUtils.getPrivateOrganisationId = function() /** * returns the image for a organisation - * + * * @param {String} pOrgId the id of the organisation. * @param {String} pDefaultText the text, to use for default image generation. * @return {String} base64 coded String of the image. If none existed, the given String is used to create an image. @@ -71,7 +72,7 @@ OrgUtils.getImage = function(pOrgId, pDefaultText) /** * sets the image of a organisation - * + * * @param {String} pOrgId the id of the organisation. * @param {String} pImageDateBase64 base64 coded String of the image. * @return {Boolean} if image could be set @@ -83,7 +84,7 @@ OrgUtils.setImage = function(pOrgId, pImageDateBase64) /** * deletes the image of a organisation - * + * * @param {String} pOrgId the id of the organisation. * @return {Boolean} if image could be removed */ @@ -93,33 +94,33 @@ OrgUtils.removeImage = function(pOrgId) } /** - * opens the org-report - * + * Builds the Organisation report. + * * @param {String} pOrgId the id of the organization * @param {String} pContactId the OrganisationContactId */ -OrgUtils.openOrgReport = function(pOrgId, pContactId) +OrgUtils.buildOrgReport = function(pOrgId, pContactId) { //org info var info = newSelect("ORGANISATION.INFO") .from("ORGANISATION") .where("ORGANISATION.ORGANISATIONID", pOrgId) .cell(); - + //communication data of the organization var commData = newSelect("MEDIUM_ID, ADDR") .from("COMMUNICATION") .where("COMMUNICATION.CONTACT_ID", pContactId) .and("ISSTANDARD = 1") .table(); - + //resolve keyword commData.forEach(function (row) { row[0] = KeywordUtils.getViewValue($KeywordRegistry.communicationMedium(), row[0]); }); commData = ReportData.begin(["KINDOFCOMM", "COMMVALUE"]).add(commData); - + //select people from the organization var persData = newSelect("SALUTATION, TITLE, FIRSTNAME, LASTNAME " + ",CONTACTROLE as PERSFUNCITON, DEPARTMENT as PERSDEPARTMENT " @@ -129,10 +130,10 @@ OrgUtils.openOrgReport = function(pOrgId, pContactId) .from("PERSON") .join("CONTACT", "PERSONID = PERSON_ID") .where("CONTACT.ORGANISATION_ID", pOrgId) - .and("CONTACT.STATUS", $KeywordRegistry.contactStatus$active()) + .and("CONTACT.STATUS", $KeywordRegistry.contactStatus$active()) .orderBy("PERSON.LASTNAME asc") .table(); - + for (let i = 0; i < persData.length; i++) { _joinArrayVals(persData[i], 0, 4); //join the full name together @@ -148,28 +149,28 @@ OrgUtils.openOrgReport = function(pOrgId, pContactId) .where("ACTIVITYLINK.OBJECT_ROWID", pContactId) .and("ACTIVITYLINK.OBJECT_TYPE", "Organisation") .orderBy("ENTRYDATE desc"); - + var activityData = activityQuery.table() - + var dateFormat = translate.text("dd.MM.yyyy"); - activityData.forEach(function (row) + activityData.forEach(function (row) { row[0] = datetime.toDate(row[0], dateFormat); // convert html to text row[4] = text.html2text(row[4]); - + row[1] = KeywordUtils.getViewValue($KeywordRegistry.activityCategory(), row[1]); _joinArrayVals(row, 2, 2); }); activityData = ReportData.begin(["ENTRYDATE", "MEDIUM", "LOGIN", "INFO"]).add(activityData); - + var attr = new AttributeRelationQuery(pOrgId) .includeDisplayValue() .includeFullAttributeName() .getAttributes() .map(function (row) {return row.value ? row.fullAttributeName + ": " + row.displayValue : row.fullAttributeName}) .join("\n"); - + //tasks var taskData = newSelect("TASK.SUBJECT, TASK.DESCRIPTION, TASK.STATUS, FIRSTNAME, LASTNAME") .from("TASK") @@ -177,28 +178,28 @@ var activityData = activityQuery.table() .leftJoin("PERSON", "CONTACT.PERSON_ID = PERSONID") .where("CONTACT.ORGANISATION_ID", pOrgId) .table(); - - taskData.forEach(function (row) + + taskData.forEach(function (row) { row[2] = KeywordUtils.getViewValue($KeywordRegistry.taskStatus(), row[2]); _joinArrayVals(row, 3, 2); //join FIRSTNAME and LASTNAME together }); taskData = ReportData.begin(["SUBJECT", "INFOTEXT", "STATUS", "RESPONSIBLE"]).add(taskData); - + var params = { "ORGAddr" : AddressUtils.getAddress(pContactId).toString(), //TODO: use new address logic when available "ORGAttr" : attr, "INFO" : info }; - + var orgReport = new Report("Organisation_report", params); - + //add subreport data orgReport.addSubReportData("subdataComm", commData); orgReport.addSubReportData("subdataPers", persData); orgReport.addSubReportData("subdataHist", activityData); orgReport.addSubReportData("subdataTask", taskData); - + //add logo //TODO: use an function to get the image when available var imgData = [ @@ -207,9 +208,10 @@ var activityData = activityQuery.table() ]; params["myAddr"] = imgData[0]; orgReport.addImage("myLogo", imgData[1]); - - orgReport.openReport(); - + + + return orgReport.exportReport(); + /* * merges multiple columns in an two-dimensional array into one */ @@ -221,4 +223,14 @@ var activityData = activityQuery.table() pArr.slice(pIndex, pIndex + pHowMany), pJoinSeparator) ); } -} \ No newline at end of file +} + +/** + * opens the org-report + * + * @param {String} pOrgId the id of the organization + */ +OrgUtils.openOrgReport = function(pOrgId) +{ + neon.openContext("Organisation", "OrganisationReport_view", [pOrgId], neon.OPERATINGSTATE_VIEW, null); +}