diff --git a/entity/Salesproject_entity/Salesproject_entity.aod b/entity/Salesproject_entity/Salesproject_entity.aod index f4603f8af45ec19aa7cb4b13d28c7e4552c80e8a..970e68b2e4fb6c103a3c33196f4186c9006c6617 100644 --- a/entity/Salesproject_entity/Salesproject_entity.aod +++ b/entity/Salesproject_entity/Salesproject_entity.aod @@ -1165,6 +1165,10 @@ <useConsumer v="true" /> <consumer>Contacts</consumer> <filterConditionProcess>%aditoprj%/entity/Salesproject_entity/recordcontainers/db/filterextensions/responsible_filter/filterConditionProcess.js</filterConditionProcess> + <groupedRecordField>OBJECTMEMBER.CONTACT_ID</groupedRecordField> + <titleRecordField>$$$TITLERECORDFIELD_PLACEHOLDER$$$</titleRecordField> + <isGroupable v="true" /> + <groupQueryProcess>%aditoprj%/entity/Salesproject_entity/recordcontainers/db/filterextensions/responsible_filter/groupQueryProcess.js</groupQueryProcess> <filtertype>BASIC</filtertype> </filterExtension> <filterExtension> diff --git a/entity/Salesproject_entity/recordcontainers/db/filterextensions/responsible_filter/groupQueryProcess.js b/entity/Salesproject_entity/recordcontainers/db/filterextensions/responsible_filter/groupQueryProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..ae312c407b3821a214ec84d0be07a0fe95cc778d --- /dev/null +++ b/entity/Salesproject_entity/recordcontainers/db/filterextensions/responsible_filter/groupQueryProcess.js @@ -0,0 +1,4 @@ +import("Salesproject_lib"); +import("system.result"); + +result.string(Salesproject.responsibleGroupQueryProcess()); \ No newline at end of file diff --git a/process/Person_lib/process.js b/process/Person_lib/process.js index 1b32bd44ec0ebc5ceab3ab8843d51a253e64c8e0..e297a0c89f1e7fea3089fe3d1bdae6597ee9d197 100644 --- a/process/Person_lib/process.js +++ b/process/Person_lib/process.js @@ -74,13 +74,20 @@ PersUtils.getResolvingDisplaySubSql = function(pRelationIdField, pResponsible) /** * creates a sql-part for resolving a person into one string of text (for example the name of a person) * useful for example in an displayValue-expression to resolave a references which is already joined within the record-container - + * + * @param {String} [pOptions] additional options for rendering; use values of ContactTitleRenderer.OPTIONS and pass them by bitwise OR concatination; e.g.: OPTION_1 | OPTION_2 | OPTION_5 + * * @return {String} a sql-part that can be placed within an SQL */ -PersUtils.getDisplaySqlExpression = function() +PersUtils.getDisplaySqlExpression = function(pOptions) { var contact = Contact.createWithColumnPreset(); - var renderer = new ContactTitleRenderer(contact, null); + var options = null; + if(pOptions) + { + options = pOptions; + } + var renderer = new ContactTitleRenderer(contact, options); var expression = renderer.asSql(); return expression; } \ No newline at end of file diff --git a/process/Salesproject_lib/process.js b/process/Salesproject_lib/process.js index d08cc206010cdb3dad364606ff30ed0acc7fa76b..79246a7b3dc35d3602432b0e8ff70fd87dd2e4b8 100644 --- a/process/Salesproject_lib/process.js +++ b/process/Salesproject_lib/process.js @@ -1,3 +1,5 @@ +import("Contact_lib"); +import("Person_lib"); import("system.datetime"); import("system.logging"); import("Sql_lib"); @@ -154,6 +156,48 @@ Salesproject.updateSalesprojectPhase = function(pSalesprojectId, pPhase) .updateData(true, "SALESPROJECT", ["PHASE"], null, [pPhase]); } +/** + * Returns the groupQueryProcess for Responsible_filter + */ +Salesproject.responsibleGroupQueryProcess = function() +{ + var condition = vars.get("$local.condition"); + var stmt = new SqlBuilder() + .from("SALESPROJECT") + .leftJoin("OBJECTMEMBER", newWhere("OBJECTMEMBER.OBJECT_ROWID = SALESPROJECT.SALESPROJECTID") + .and("OBJECTMEMBER.RESPONSIBLE", "1")) + .leftJoin("CONTACT", "OBJECTMEMBER.CONTACT_ID = CONTACT.CONTACTID") + .leftJoin("ORGANISATION", "CONTACT.ORGANISATION_ID = ORGANISATION.ORGANISATIONID") + .leftJoin("PERSON", "PERSON.PERSONID = CONTACT.PERSON_ID"); + + if(Utils.isNotNullOrEmptyString(condition.trim())) + { + stmt.where(condition); + } + stmt.groupBy(["OBJECTMEMBER.CONTACT_ID", PersUtils.getDisplaySqlExpression(ContactTitleRenderer.OPTIONS.IncludeOrganisation)]) + .orderBy(SqlBuilder.caseWhen("OBJECTMEMBER.CONTACT_ID is not null") + .then("OBJECTMEMBER.CONTACT_ID") + .elseString(translate.text("unassigned"))); + + if (vars.get("$local.count")) // TRUE if the count of the records is needed + { + stmt.select("1"); + } + else + { + var caseWhen = SqlBuilder.caseWhen("OBJECTMEMBER.CONTACT_ID is not null") + .then(PersUtils.getDisplaySqlExpression(ContactTitleRenderer.OPTIONS.IncludeOrganisation)) + .elseString(translate.text("unassigned")); + + var columnlist = vars.get("$local.columnlist"); + + columnlist = StringUtils.replaceAll(columnlist, "$$$TITLERECORDFIELD_PLACEHOLDER$$$", caseWhen.toString()); + stmt.select([columnlist]); + } + + return stmt.toString(); +} + /** * Methods used by the SalesprojectConversionRate. * Do not create an instance of this!