diff --git a/process/VisitPlanning_lib/process.js b/process/VisitPlanning_lib/process.js index d4619f0c366d2cb34c0406f2cad49a4e98f45236..4ddfce5a1a315d12ae139795752114affe35ce97 100644 --- a/process/VisitPlanning_lib/process.js +++ b/process/VisitPlanning_lib/process.js @@ -1,3 +1,4 @@ +import("Organisation_lib"); import("system.entities"); import("AttributeRegistry_basic"); import("Util_lib"); @@ -63,10 +64,12 @@ VisitPlanningUtils.openRoute = function (pIsDayRoute) } var childAddresses = newSelect(["ADDRESS", "BUILDINGNO", "ZIP", "CITY", "COUNTRY"]) - .from("ADDRESS") - .leftJoin("VISITPLANENTRY", newWhere("ADDRESS.ADDRESSID", newSelect("ADDRESS_ID") - .from("CONTACT") - .where("CONTACT.CONTACTID = VISITPLANENTRY.ORGANISATION_CONTACT_ID"))) + .from("VISITPLANENTRY") + .join("CONTACT", newWhere("VISITPLANENTRY.CONTACT_ID = CONTACT.CONTACTID") + .and("VISITPLANENTRY.ORGANISATION_CONTACT_ID", OrgUtils.getPrivateOrganisationId()) + .or(newWhere("VISITPLANENTRY.ORGANISATION_CONTACT_ID = CONTACT.CONTACTID") + .and("VISITPLANENTRY.ORGANISATION_CONTACT_ID", OrgUtils.getPrivateOrganisationId(), SqlBuilder.NOT_EQUAL()))) + .join("ADDRESS", "CONTACT.ADDRESS_ID = ADDRESS.ADDRESSID") .where(cond) .orderBy("VISITPLANENTRY.BEGIN_TIME ASC") .table();