diff --git a/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod b/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod index 71c8af2723ad8ee5c8cee8a99fe9cc4740d47e51..ea28eb64265345721c84653b28b76cc702c108aa 100644 --- a/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod +++ b/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod @@ -31,11 +31,15 @@ <mandatory v="true" /> <state>EDITABLE</state> <displayValueProcess>%aditoprj%/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/displayValueProcess.js</displayValueProcess> + <onValueChange>%aditoprj%/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/onValueChange.js</onValueChange> </entityField> <entityField> <name>campaignParticipantMessage</name> <state>READONLY</state> <valueProcess>%aditoprj%/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js</valueProcess> + <onValueChangeTypes> + <element>PROCESS</element> + </onValueChangeTypes> </entityField> <entityParameter> <name>campaignParticipantsRowIds_param</name> diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js index e26b93f07ea4d621a85dbcf66f85ebdfdf0622a3..b4015c595144d461b0e4661bccb1e5d79721a06f 100644 --- a/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js +++ b/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js @@ -1,12 +1,88 @@ +import("Campaign_lib"); import("system.logging"); import("system.result"); import("system.translate"); import("system.vars"); -//logging.log(" -> " + JSON.stringify(vars.getString("$param.campaignParticipantsRowIds_param"))); -//var test = vars.getString("$param.campaignParticipantsRowIds_param"); -//var campaignParticipantsAmount = JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param")).length; -//var informationText = translate.text("participants will be added to the selected campaign step"); +//logging.log("campaignParticipantsRowIds_param -> " + vars.get("$param.campaignParticipantsRowIds_param")); +//logging.log("campaignParticipantsRowIds_param -> " + JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param")).length); +//logging.log("campaignParticipantsRowIds_param -> " + vars.getString("$param.campaignParticipantsRowIds_param")); +//logging.log("campaignParticipantsCondition_param -> " + vars.getString("$param.campaignParticipantsCondition_param")); -//result.string(campaignParticipantsAmount + " " + informationText); -result.string("Message"); \ No newline at end of file +var campaignParticipantsAmount = 0; +var informationText = translate.text("participants will be added to the selected campaign step"); + +var targetTable = vars.get("$param.dataSourceTableName_param"); +var selectionRowIds = JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param")); +var selectedCampaignId = vars.get("$field.CAMPAIGN_ID"); +var selectedCampaignStepId = vars.get("$field.CAMPAIGNSTEP_ID"); + + +var participantCondition = ""; +var resultString = ""; +//logging.log("selectedCampaignId -> " + selectedCampaignId); + +if(selectedCampaignId == '') + result.string(resultString); +else +{ + /* + * First determines how many of the selected are already in the campaign + * If there are no valid participants at all or too many in respect of the + * selected steps max number of participants, nothing will be added. + * A message describing this situation will be written. + * + * If none of those criteria match, all participants are good to be added. + */ + var countParticipantsAlreadyInCampaign = 0; + var countParticipantsToAdd = 0; + var countValidParticipantsToAdd = 0; + //if theres a selection, we have to use it, otherwise use the condition + if(selectionRowIds != null && selectionRowIds.length > 0) + { + countParticipantsToAdd = selectionRowIds.length; + logging.log("selectedCampaignId -> " + selectedCampaignId); + countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyInStepCountByRowId(selectedCampaignId, selectionRowIds); + } + else + { + logging.log("campaignParticipantsCondition_param -> " + vars.getString("$param.campaignParticipantsCondition_param")); + participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param")).condition; + countParticipantsToAdd = CampaignUtils.GetContactCountByCondition(participantCondition); + countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyInStepCountByCondition(selectedCampaignId, targetTable, participantCondition); + } + countValidParticipantsToAdd = countParticipantsToAdd - countParticipantsAlreadyInCampaign; + + logging.log("countParticipantsToAdd -> " + countParticipantsToAdd); + logging.log("countParticipantsAlreadyInCampaign -> " + countParticipantsAlreadyInCampaign); + logging.log("countValidParticipantsToAdd -> " + countValidParticipantsToAdd); + + if(countValidParticipantsToAdd <= 0) + { + resultString = "Alle selektierten Teilnehmer befinden sich bereits in der Stufe"; + } + else if(hasStepEnoughSlots(countValidParticipantsToAdd)) + { + resultString = countValidParticipantsToAdd + "/" + countParticipantsToAdd + " " + informationText; + + } + else + { + resultString = "Nicht genug Teilnehmerplätze für " + + countValidParticipantsToAdd + "/" + countParticipantsToAdd + + " Teilnehmern vorhanden"; + } + + result.string(resultString); +} + +function hasStepEnoughSlots(pCountToAdd) +{ +// logging.log(" selectedCampaignStepId-> " + selectedCampaignStepId); + let currentParticipants = CampaignUtils.getParticipantCountForStep(selectedCampaignStepId) + let maxParticipants = CampaignUtils.getMaxParticipantCountForStep(selectedCampaignStepId) +// logging.log(" currentParticipants + pCountToAdd-> " + (parseInt(currentParticipants) + parseInt(pCountToAdd))); +// logging.log(" maxParticipants-> " + maxParticipants); +// logging.log(" (currentParticipants + pCountToAdd) <= maxParticipants-> " + ((currentParticipants + pCountToAdd) <= maxParticipants)); + return (parseInt(currentParticipants) + parseInt(pCountToAdd)) <= maxParticipants; +} \ No newline at end of file diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/onValueChange.js b/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/onValueChange.js new file mode 100644 index 0000000000000000000000000000000000000000..20f59c4bac6dd3416e26c27959f49ce0be78d680 --- /dev/null +++ b/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/onValueChange.js @@ -0,0 +1,2 @@ +import("system.neon"); +neon.refresh(["$field.campaignParticipantMessage"]) \ No newline at end of file diff --git a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js index f0581e865d29f31a75da823f24821c2739e22a9d..6eeacc6b47775eef8154ec127cb50a0c3c62bd85 100644 --- a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js +++ b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js @@ -7,7 +7,7 @@ import("Campaign_lib"); var cols = []; var participantRowIds = JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param")); -var participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param")); +var participantCondition = ""; var conditionSourceTableName = vars.getString("$param.dataSourceTableName_param"); var campaignId = vars.getString("$field.CAMPAIGN_ID"); @@ -16,18 +16,40 @@ var isUpdate = vars.get("$field.isUpdate"); var colNamesCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumnNames(); -if(participantRowIds.length > 0) +if(participantRowIds != null && participantRowIds.length > 0) { - _handleRowIds(participantRowIds); + let contactIdsToHandle = participantRowIds; + if(isUpdate == "false") + contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByRowIds(campaignId, participantRowIds); + logging.log("contactIdsToHandle by rowIds -> " + contactIdsToHandle); + _handleRowIds(contactIdsToHandle); } else { - _handleCondition(participantCondition, conditionSourceTableName) + participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param")).condition; + _handleCondition(campaignId, conditionSourceTableName, participantCondition); } -function _handleCondition(pCondition, pSourceTableName) +function _handleCondition(pCampaignId, pTargetTableName, pCondition) { - //( UPPER( PERSON.SALUTATION ) = UPPER( 'Frau' ) + let contactIdsToHandle = []; + + /* + * If it's an update of participants, get the participants defined by the condition in the selected campaign + * Because they already are participants, no restrictions apply to the affected IDs. + * + * Otherwise the participants ought to be inserted. The only restriction right now is, hat the participants to be inserted + * musn't already be in this specific campaign. Therefore all IDs hat are defined by the condition and not in the campaign are selected. + */ + if(isUpdate == "true") + { + contactIdsToHandle = CampaignUtils.GetContactIdsInCampaignByCondition(pCampaignId, pCondition) + } + else + contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByCondition(pCampaignId, pCondition); + + logging.log("contactIdsToHandle -> " + contactIdsToHandle); + _handleRowIds(contactIdsToHandle); } function _handleRowIds(pParticipantRowIds) @@ -52,6 +74,7 @@ function _handleRowIds(pParticipantRowIds) let statementArray = []; let logArray = []; + logging.log("pParticipantRowIds -> " + pParticipantRowIds); for (participant in pParticipantRowIds) { let campaignParticipantLogId = util.getNewUUID(); diff --git a/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod b/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod index eb8230095d5203a023c26aa8c03fc1a5db7604b8..311b171cc9178dc8d6e363e1ff9a99c77adcd5fc 100644 --- a/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod +++ b/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod @@ -165,7 +165,7 @@ <title>Set campaign step</title> <onActionProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js</onActionProcess> <isObjectAction v="false" /> - <isSelectionAction v="true" /> + <isSelectionAction v="false" /> <iconId>NEON:GROUP_APPOINTMENT</iconId> </entityActionField> </children> @@ -181,40 +181,40 @@ <displayValueProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/campaignstepmaxparticipantcount/displayValueProcess.js</displayValueProcess> </entityField> <entityField> - <name>ADVERTISINGBAN_ICON</name> - <colorProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/advertisingban_icon/colorProcess.js</colorProcess> - <contentType>IMAGE</contentType> - <stateProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/advertisingban_icon/stateProcess.js</stateProcess> - <valueProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/advertisingban_icon/valueProcess.js</valueProcess> - </entityField> - <entityConsumer> - <name>ParticipantsCommRestiction</name> - <dependency> - <name>dependency</name> - <entityName>CommRestriction_Entity</entityName> - <fieldName>PersonsCommRestriction</fieldName> - </dependency> - <children> - <entityParameter> - <name>ContactId_param</name> - <valueProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/participantscommrestiction/children/contactid_param/valueProcess.js</valueProcess> - </entityParameter> - </children> - </entityConsumer> - <entityConsumer> - <name>CommRestrictionIcon</name> - <dependency> - <name>dependency</name> - <entityName>KeywordAttribute_entity</entityName> - <fieldName>SpecificContainerKeyword</fieldName> - </dependency> - <children> - <entityParameter> - <name>ContainerName_param</name> - <valueProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/commrestrictionicon/children/containername_param/valueProcess.js</valueProcess> - </entityParameter> - </children> - </entityConsumer> + <name>ADVERTISINGBAN_ICON</name> + <colorProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/advertisingban_icon/colorProcess.js</colorProcess> + <contentType>IMAGE</contentType> + <stateProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/advertisingban_icon/stateProcess.js</stateProcess> + <valueProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/advertisingban_icon/valueProcess.js</valueProcess> + </entityField> + <entityConsumer> + <name>ParticipantsCommRestiction</name> + <dependency> + <name>dependency</name> + <entityName>CommRestriction_Entity</entityName> + <fieldName>PersonsCommRestriction</fieldName> + </dependency> + <children> + <entityParameter> + <name>ContactId_param</name> + <valueProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/participantscommrestiction/children/contactid_param/valueProcess.js</valueProcess> + </entityParameter> + </children> + </entityConsumer> + <entityConsumer> + <name>CommRestrictionIcon</name> + <dependency> + <name>dependency</name> + <entityName>KeywordAttribute_entity</entityName> + <fieldName>SpecificContainerKeyword</fieldName> + </dependency> + <children> + <entityParameter> + <name>ContainerName_param</name> + <valueProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/commrestrictionicon/children/containername_param/valueProcess.js</valueProcess> + </entityParameter> + </children> + </entityConsumer> </entityFields> <recordContainers> <dbRecordContainer> diff --git a/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js b/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js index 737946e0696b69ba103881e97d54428362a2cfbc..e1e625b019bc758a7be7d5fb065beaa8e482edd1 100644 --- a/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js +++ b/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js @@ -1,3 +1,4 @@ +import("system.logging"); import("system.util"); import("system.db"); import("system.result"); diff --git a/entity/CampaignStep_entity/CampaignStep_entity.aod b/entity/CampaignStep_entity/CampaignStep_entity.aod index 9c9867bd3fdcd968c535551bca1bb18e2d0d4031..5ac18577c7654e60734f15e98e20b5f272489dce 100644 --- a/entity/CampaignStep_entity/CampaignStep_entity.aod +++ b/entity/CampaignStep_entity/CampaignStep_entity.aod @@ -7,6 +7,7 @@ <siblings> <element>CampaignPlanning_entity</element> <element>CampaignParticipantChart_entity</element> + <element>Campaign_entity</element> </siblings> <contentTitleProcess>%aditoprj%/entity/CampaignStep_entity/contentTitleProcess.js</contentTitleProcess> <onValidation>%aditoprj%/entity/CampaignStep_entity/onValidation.js</onValidation> diff --git a/entity/Campaign_entity/Campaign_entity.aod b/entity/Campaign_entity/Campaign_entity.aod index 522a89efa0a2aca818f1c886199ce9a453c60378..c4b80061c6532d48d0c6c824a61d970937e0d1aa 100644 --- a/entity/Campaign_entity/Campaign_entity.aod +++ b/entity/Campaign_entity/Campaign_entity.aod @@ -6,6 +6,7 @@ <title>Campaign</title> <siblings> <element>CampaignPlanning_entity</element> + <element>CampaignStep_entity</element> </siblings> <contentTitleProcess>%aditoprj%/entity/Campaign_entity/contentTitleProcess.js</contentTitleProcess> <afterUiInit>%aditoprj%/entity/Campaign_entity/afterUiInit.js</afterUiInit> diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod index 9ff8eb12e7b3f4d66756a99de97e3b5452ceb956..c5ded0f7c52daaa979807c110ea24ba1375a8625 100644 --- a/entity/Person_entity/Person_entity.aod +++ b/entity/Person_entity/Person_entity.aod @@ -835,7 +835,7 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact <onActionProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js</onActionProcess> <isMenuAction v="true" /> <isObjectAction v="false" /> - <isSelectionAction v="true" /> + <isSelectionAction v="false" /> <iconId>NEON:GROUP_APPOINTMENT</iconId> <tooltip>Add the selection to a campaign</tooltip> <tooltipProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/tooltipProcess.js</tooltipProcess> diff --git a/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js b/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js index 7be2f554b74e0286efb82bc177ce1dcc1e84fb39..e6a1e385e5f8ac4559b6388933cc9099d0f3daff 100644 --- a/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js +++ b/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js @@ -1,3 +1,4 @@ +import("system.logging"); import("system.vars"); import("system.neon"); import("Campaign_lib"); @@ -8,14 +9,18 @@ import("Campaign_lib"); * is used to determine the objects to be added. * If no selection has been set, all objects will be added. */ -var sysSelection = vars.getString("$sys.selection"); +var sysSelection = vars.get("$sys.selection"); if(sysSelection.length > 0) //selektierte IDs als Array { - CampaignUtils.addParticipantsByRowIds(sysSelection, "PERSON"); + logging.log("sysSelection -> " + sysSelection); + CampaignUtils.addParticipantsByRowIds(JSON.stringify(sysSelection), "PERSON"); } else { let sysFilter = vars.get("$sys.filter");//todo change name - CampaignUtils.addParticipantsByCondition(sysFilter.condition, "PERSON"); + logging.log("sysFilter -> " + sysFilter); + logging.log("asdasd sysFilter.condition -> " + sysFilter.condition); + + CampaignUtils.addParticipantsByCondition(JSON.stringify(sysFilter), "PERSON"); } \ No newline at end of file diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js index ce5c72318714a7bd154fe7356448eae7d897d33e..5fe24b9887212895ce04451e867a0e619cdce93b 100644 --- a/process/Campaign_lib/process.js +++ b/process/Campaign_lib/process.js @@ -43,6 +43,7 @@ CampaignUtils.addParticipantsByRowIds = function(pRowIds, pSourceTableName) */ CampaignUtils.addParticipantsByCondition = function(pCondition, pSourceTableName) { + logging.log(" asdf-> " + pCondition); _CampaignUtils._openAddParticipantContext("CampaignAddParticipants", pCondition, "campaignParticipantsCondition_param", "CampaignAddParticipantsEdit_view", pSourceTableName); } @@ -309,7 +310,117 @@ CampaignUtils.checkforCommRestrictions = function() .buildSql("select MEDIUM from CAMPAIGNSTEP join COMMRESTRICTION on MEDIUM = STEPMEDIUM", "1=2")); } +//CampaignUtils.GetContactIdsNotInStepByRowIds = function(pCampaignId, pParticipantRowIds) +//{ +// //SELECT CAMPAIGNPARTICIPANTID FROM CAMPAIGNPARTICIPANT +// //WHERE CAMPAIGNPARTICIPANT.CONTACT_ID +// //IN ('4cc98357-25f3-462b-898c-440f9faf4b97','d5a2dc64-e503-4aed-a0c6-d54f49b8db87','45635aca-7971-43df-a683-c80c86cb58cc','1a67eaa7-21da-4a18-97ab-755ac5cb74f7') +// +// let rowIdsAsRay = _CampaignUtils._convertToSqlValuesList(pParticipantRowIds); +// +// let query = "SELECT CAMPAIGNPARTICIPANTID FROM CAMPAIGNPARTICIPANT" +// + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "' AND" +// + " CAMPAIGNPARTICIPANT.CONTACT_ID NOT IN " + rowIdsAsRay; +// +// return db.array(db.COLUMN, query) +//} + +CampaignUtils.GetParticipantsAlreadyInStepCountByRowId = function(pCampaignId, pParticipantRowIds) +{ + let rowIdsAsRay = _CampaignUtils._convertToSqlValuesList(pParticipantRowIds); + + let query = "SELECT COUNT(*) FROM CAMPAIGNPARTICIPANT" + + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "' AND" + + " CAMPAIGNPARTICIPANT.CONTACT_ID IN " + rowIdsAsRay; + + logging.log("GetParticipantsAlreadyInStepCountByRowId query -> " + query); + + return db.cell(query) +} + +CampaignUtils.GetParticipantsAlreadyInStepCountByCondition = function(pCampaignId, pTargetTableName, pCondition) +{ + let targetIdField = "CONTACT.CONTACTID"; + + var joinCondition = ""; + if(pTargetTableName == "PERSON") + { + joinCondition = "PERSONID = PERSON_ID"; + } + else + { + joinCondition = "ORGANISATIONID = ORGANISATION_ID"; + } + + //select PERSON.* + //from CONTACT + //join PERSON on PERSONID = PERSON_ID + //where CONTACT.CONTACTID in ('d5a2dc64-e503-4aed-a0c6-d54f49b8db87','45635aca-7971-43df-a683-c80c86cb58cc','1a67eaa7-21da-4a18-97ab-755ac5cb74f7') + + let query = "select count(*) from CAMPAIGNPARTICIPANT" + + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "' AND" + + " CAMPAIGNPARTICIPANT.CONTACT_ID in" + + " (" + _CampaignUtils._selectFromContactWithJoin(targetIdField, pTargetTableName, joinCondition, pCondition) + + ")"; + + logging.log("query -> " + query); + + return db.cell(query) +} + +CampaignUtils.GetContactIdsNotInCampaignByRowIds = function(pCampaignId, pParticipantRowIds) +{ + let rowIdsAsRay = _CampaignUtils._convertToSqlValuesList(pParticipantRowIds); + + let query = "select CONTACT.CONTACTID from CONTACT" + + " where CONTACT.CONTACTID in " + rowIdsAsRay + + " and CONTACT.CONTACTID not in" + + " (select CAMPAIGNPARTICIPANT.CONTACT_ID from CAMPAIGNPARTICIPANT" + + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')"; + + return db.array(db.COLUMN, query) +} + +CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCondition) +{ + let query = "select CONTACT.CONTACTID from PERSON" + + " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)" + + " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)" + + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)" + + " where " + pCondition + + " and CONTACT.CONTACTID not in" + + " (select CAMPAIGNPARTICIPANT.CONTACT_ID from CAMPAIGNPARTICIPANT where" + + " CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')"; + + return db.array(db.COLUMN, query); +} + +CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondition) +{ + let query = "select CONTACT.CONTACTID, person.FIRSTNAME from PERSON" + + " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)" + + " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)" + + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)" + + " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID" + + " where " + pCondition + + " and CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')"; + + return db.array(db.COLUMN, query); +} +CampaignUtils.GetContactCountByCondition = function(pCondition) +{ + let query = "select count(*) from PERSON" + + " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)" + + " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)" + + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"; + + if(pCondition != "") + query += " where " + pCondition; + + logging.log("GetContactCountByCondition -> " + query); + return db.cell(query); +} /** * Methods for campaignmanagement. @@ -320,6 +431,28 @@ CampaignUtils.checkforCommRestrictions = function() */ function _CampaignUtils() {} +_CampaignUtils._selectFromContactWithJoin = function(pSelectFields, pCampaignId, pWhereCondition) +{ + let query = "select " + pSelectFields + " from PERSON" + + " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)" + + " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)" + + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"; + + if(pWhereCondition != "") + { + query += " where " + pWhereCondition; + query += " and CONTACT.CONTACTID not in" + + " (select CONTACT_ID from CAMPAIGNPARTICIPANT" + + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')"; + } + else + query += " where CONTACT.CONTACTID not in" + + " (select CONTACT_ID from CAMPAIGNPARTICIPANT" + + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')"; + + return query; +} + /** * Open EditView to Add Participants to a Campaignstep * @@ -343,6 +476,21 @@ _CampaignUtils._openAddParticipantContext = function(pContext, pTargetDataExpres neon.openContext(pContext, null, null, neon.OPERATINGSTATE_NEW, params); } +/** + * todo + */ +_CampaignUtils._convertToSqlValuesList = function(pValuesArray) +{ + let rowIds = "("; + for (i = 0; i < pValuesArray.length; i++) + { + rowIds += "'" + pValuesArray[i] + "'"; + if(i < pValuesArray.length-1) + rowIds += ","; + } + rowIds += ")"; + return rowIds; +} /** * todo