Skip to content
Snippets Groups Projects
Commit a6e86218 authored by David Büchler's avatar David Büchler
Browse files

Condition + Selektion Serienaktion funktioniert nun auch bei ORGANISATION

Um eine Firma ermitteln zu können muss die CONTACT Tabelle per right join hinzugefügt werden. Dies ist benötigt, weil eine Firma keine PersonenId hat, die Contacts aber über die PersonId gejoint werden. Bei normalen Datensätzen reicht normales joinen.
parent 350534ed
No related branches found
No related tags found
No related merge requests found
......@@ -69,7 +69,12 @@ if(selectedCampaignId != '')
{
participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param")).condition;
logging.log("im isOperationValid -> ");
countParticipantsToAdd = CampaignUtils.GetContactCountByCondition(participantCondition, isUpdate);
let useRightJoinToGetOrgs = "false";
if(targetTable == "ORGANISATION")
useRightJoinToGetOrgs = "true";
countParticipantsToAdd = CampaignUtils.GetContactCountByCondition(participantCondition, isUpdate, useRightJoinToGetOrgs);
logging.log("countParticipantsToAdd -> " + countParticipantsToAdd);
/*
......@@ -84,7 +89,7 @@ if(selectedCampaignId != '')
else
whereCondition = "CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + selectedCampaignId + "'";
countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyAddedCountByCondition(whereCondition, participantCondition);
countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyAddedCountByCondition(whereCondition, participantCondition, useRightJoinToGetOrgs);
//CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "'"
}
countValidParticipantsToAdd = countParticipantsToAdd - countParticipantsAlreadyInCampaign;
......
......@@ -38,6 +38,10 @@ function _handleCondition(pCampaignId, pTargetTableName, pCondition)
{
let contactIdsToHandle = [];
let useRightJoinToGetOrgs = "false";
if(pTargetTableName == "ORGANISATION")
useRightJoinToGetOrgs = "true";
/*
* 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.
......@@ -47,10 +51,10 @@ function _handleCondition(pCampaignId, pTargetTableName, pCondition)
*/
if(isUpdate == "true")
{
contactIdsToHandle = CampaignUtils.GetContactIdsInCampaignByCondition(pCampaignId, pCondition)
contactIdsToHandle = CampaignUtils.GetContactIdsInCampaignByCondition(pCampaignId, pCondition, useRightJoinToGetOrgs)
}
else
contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByCondition(pCampaignId, pCondition);
contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByCondition(pCampaignId, pCondition, useRightJoinToGetOrgs);
logging.log("contactIdsToHandle -> " + contactIdsToHandle);
_handleRowIds(contactIdsToHandle);
......
......@@ -335,10 +335,14 @@ CampaignUtils.GetParticipantsAlreadyAddedCountByRowId = function(pWhereCondition
return db.cell(query)
}
CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondition, pCondition)
CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondition, pCondition, pRightJoinContacts)
{
let query = "select count(*) from PERSON"
+ " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
if(pRightJoinContacts == "true")
query += " right"
query += " 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"
......@@ -365,10 +369,14 @@ CampaignUtils.GetContactIdsNotInCampaignByRowIds = function(pCampaignId, pPartic
return db.array(db.COLUMN, query)
}
CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCondition)
CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCondition, pRightJoinContacts)
{
let query = "select CONTACT.CONTACTID from PERSON"
+ " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
if(pRightJoinContacts == "true")
query += " right"
query += " 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 CONTACT.CONTACTID not in"
......@@ -377,29 +385,37 @@ CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCon
if(pCondition != "")
query += " and " + pCondition;
logging.log("GetContactIdsNotInCampaignByCondition -> " + query);
return db.array(db.COLUMN, query);
}
CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondition)
CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondition, pRightJoinContacts)
{
let query = "select CONTACT.CONTACTID from PERSON"
+ " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
if(pRightJoinContacts == "true")
query += " right"
query += " 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 + "'";
logging.log("GetContactIdsInCampaignByCondition -> " + GetContactIdsInCampaignByCondition);
return db.array(db.COLUMN, query);
}
CampaignUtils.GetContactCountByCondition = function(pCondition, pLookInCampaignOnly)
CampaignUtils.GetContactCountByCondition = function(pCondition, pLookInCampaignOnly, pRightJoinContacts)
{
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(pRightJoinContacts == "true")
query += " right"
query += " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
query += " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
query += " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"
if(pLookInCampaignOnly == "true")
query += " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment