diff --git a/process/Org_lib/process.js b/process/Org_lib/process.js index 3a6930658bc75dad763c10e8d535490f8c20d6ef..b9c5d9e734bd63542d3e8e09cb211804b72c9e17 100644 --- a/process/Org_lib/process.js +++ b/process/Org_lib/process.js @@ -65,11 +65,12 @@ OrgUtils.openOrgReport = function(pOrgId) .buildSelect("select ORG.INFO from ORG")); //communication data of the organization - var commSelect = "select MEDIUM_ID, ADDR from COMM"; - var commCond = SqlCondition.begin() + var commSql = "select MEDIUM_ID, ADDR from COMM"; + commSql = SqlCondition.begin() .andPrepare("COMM.RELATION_ID", relationId) - .and("STANDARD = 1"); - var commData = db.table(commCond.buildSelect(commSelect)); + .and("STANDARD = 1") + .buildSelect(commSql); + var commData = db.table(commSql); //resolve keyword commData.forEach(function (row) @@ -80,13 +81,15 @@ OrgUtils.openOrgReport = function(pOrgId) //select people from the organization //TODO: Position und Abteilung fehlen noch - var persSelect = "select SALUTATION, TITLE, FIRSTNAME, LASTNAME, '', '', '', ORG_ID, RELATIONID" + var persSql = "select SALUTATION, TITLE, FIRSTNAME, LASTNAME, '', '', '', ORG_ID, RELATIONID" + " from PERS join RELATION on PERSID = PERS_ID"; - var persCond = SqlCondition.begin() + persSql = SqlCondition.begin() .andPrepare("RELATION.ORG_ID", pOrgId) - .and("RELATION.STATUS = 1"); - var persData = db.table(persCond.buildSelect(persSelect, "", " order by PERS.LASTNAME asc")); - + .and("RELATION.STATUS = 1") + .buildSelect(persSql, "", " order by PERS.LASTNAME asc"); + var persData = db.table(persSql); + + //TODO: get the keywords in another way when keywords are entitys var mediumIds = []; var mediums = KeywordUtils.getStandardArrayProps("COMM.MEDIUM"); for (let i = 0; i < mediums.length; i++) @@ -96,14 +99,18 @@ OrgUtils.openOrgReport = function(pOrgId) for (let i = 0; i < persData.length; i++) { - _joinArrayVals(persData[i], 0, 4); - var persCommSelect = "select MEDIUM_ID, ADDR from COMM"; - var persCommCond = SqlCondition.begin() + _joinArrayVals(persData[i], 0, 4); //join the full name together + + //select the contact info for every person for phone and mail + var persCommSql = "select MEDIUM_ID, ADDR from COMM"; + persCommSql = SqlCondition.begin() .andPrepare("COMM.RELATION_ID", persData[i][5]) .and("MEDIUM_ID in (" + mediumIds + ")") - .and("STANDARD = 1"); - var persDataComm = db.table(persCommCond.buildSelect(persCommSelect)); + .and("STANDARD = 1") + .buildSelect(persCommSql); + var persDataComm = db.table(persCommSql); + //resolve keyword persData[i][3] = persDataComm.map(function (row) { return KeywordUtils.getViewValue("COMM.MEDIUM", row[0]) + ": " + row[1]; @@ -112,12 +119,14 @@ OrgUtils.openOrgReport = function(pOrgId) } persData = ReportData.begin(["PERSNAMECOMPLETE", "PERSFUNCTION", "PERSDEPARTMENT", "PERSCOMM", "ORG_ID", "RELATION_ID"]).add(persData); - var histSelect = "select ENTRYDATE, CATEGORY, FIRSTNAME, LASTNAME, INFO from ACTIVITY " + var histSql = "select ENTRYDATE, CATEGORY, FIRSTNAME, LASTNAME, INFO from ACTIVITY " + " join ACTIVITYLINK on ACTIVITYLINK.ACTIVITY_ID = ACTIVITYID " + " join RELATION on ACTIVITYLINK.ROW_ID = RELATIONID" + " left join PERS on RELATION.PERS_ID = PERSID"; - var histCond = SqlCondition.begin().andPrepare("RELATION.ORG_ID", pOrgId); - var histData = db.table(histCond.buildSelect(histSelect, "", "order by ENTRYDATE desc")); + histSql = SqlCondition.begin() + .andPrepare("RELATION.ORG_ID", pOrgId) //= all activities linked to the organization or an employee + .buildSelect(histSql, "", "order by ENTRYDATE desc"); + var histData = db.table(histSql); var dateFormat = translate.text("dd.MM.yyyy"); histData.forEach(function (row) @@ -129,18 +138,31 @@ OrgUtils.openOrgReport = function(pOrgId) histData = ReportData.begin(["ENTRYDATE", "MEDIUM", "LOGIN", "INFO"]).add(histData); var attr = ""; //TODO: this should be a string with the attributes - - var taskData = ReportData.begin(["SUBJECT", "INFOTEXT", "STATUS", "RESPONSIBLE"]).add([]); //TODO: get tasks for this org - + + + //tasks + var taskSql = "select TASK.SUBJECT, TASK.DESCRIPTION, TASK.STATUS, FIRSTNAME, LASTNAME from TASK" + + " join RELATION on EDITOR_RELATION_ID = RELATIONID" + + " left join PERS on RELATION.PERS_ID = PERSID"; + taskSql = SqlCondition.begin() + .andPrepare("RELATION.ORG_ID", pOrgId) + .buildSelect(taskSql); + var taskData = db.table(taskSql); + + taskData.forEach(function (row) + { + row[2] = KeywordUtils.getViewValue("TASK.STATUS", 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(relationId).toString(), //TODO: use new address logic when available "ORGAttr" : attr, - "RELID" : relationId, - "ORGID" : pOrgId, "INFO" : info }; - var orgReport = new Report("RPTJ_ORG"); + var orgReport = new Report("RPTJ_ORG", params); //add subreport data orgReport.addSubReportData("subdataComm", commData); @@ -157,11 +179,11 @@ OrgUtils.openOrgReport = function(pOrgId) params["myAddr"] = imgData[0]; orgReport.addImage("myLogo", imgData[1]); - orgReport.addReportParams(params); - orgReport.setReportData(ReportData.begin(["e"]).add([["d"]])); - orgReport.openReport(); + /* + * merges multiple columns in an two-dimensional array into one + */ function _joinArrayVals (pArr, pIndex, pHowMany) { pArr.splice(pIndex, pHowMany,