Skip to content
Snippets Groups Projects
Commit c0638744 authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

fix when creating a new offer that the wrong salesprojects are listed

parent e906373f
No related branches found
No related tags found
No related merge requests found
import("Organisation_lib");
import("system.result");
import("system.vars");
import("Contact_lib");
if (vars.get("$field.CONTACT_ID"))
var anyContactId = vars.get("$field.CONTACT_ID")
if (anyContactId)
{
var ids = ContactUtils.getPersOrgIds(vars.getString("$field.CONTACT_ID"));
if (ids.length >= 3 && ids[2])
result.string(ids[2]);
//when a person is selected list the salesproject of the persons organisation
//when a organisation is selected list the organisations salesprojects
var organisationContactId = ContactUtils.getOrganisationContactId(anyContactId);
if (organisationContactId && !OrgUtils.isPrivateOrganisationContactId(organisationContactId))
result.string(organisationContactId);
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ import("Context_lib");
* Do not create an instance of this!
* @class
*/
function OrganisationUtils() {}
function OrganisationUtils() {}//TODO: there exsits a OrgUtils and OrganisationUtils, this is inconvenient
/*
* retrieves the name of an organisation with a select statement
......@@ -289,17 +289,45 @@ ContactUtils.getPersOrgIds = function(pContactId)
return persOrgIds;
}
ContactUtils.getPersId = function(pContactId)
/**
* get the person- and org-id from a contact as array
*
* @param {String} pContactId
* @return {String[]} result as [contactid, persid, orgid] if one of them is null in the db, "" will be returned as the id. if Contactid is empty -> [] is returned
*/
ContactUtils.getPersOrgIds = function(pContactId)
{
persId = ContactUtils.getPersOrgIds(pContactId)
if (persId.length > 0)
{
persId = persId[1];
if (pContactId) {
return db.array(db.ROW,
SqlCondition.begin()
.andPrepare("CONTACT.CONTACTID", pContactId)
.buildSql("select CONTACTID, PERSON_ID, ORGANISATION_ID from CONTACT", "1=0"));
}
else
persId = "";
return persId ;
return [];
}
/**
* automatically determines the organisations contactid by specifying a person-contactid (or organisation-contactid)
* this is done with a sql statement, so this will only affect to the db commited data
*
* @param {String} pAnyContactId a person-contactid or organisation-contactid
* @return {String} the contactId of the organisation or ""
*/
ContactUtils.getOrganisationContactId = function(pAnyContactId)
{
if (!pAnyContactId)
return "";
var idSql = SqlCondition.begin()
.andPrepare("anyContact.CONTACTID", pAnyContactId, null, SqlUtils.getSingleColumnType("CONTACT", "CONTACTID"))
.and("CONTACT.PERSON_ID is null")
.buildSql("select CONTACT.CONTACTID \n\
from CONTACT\n\
join CONTACT anyContact on anyContact.ORGANISATION_ID = CONTACT.ORGANISATION_ID");
var id = db.cell(idSql);
return id;
}
/**
......
......@@ -18,7 +18,7 @@ import("KeywordRegistry_basic");
* Do not create an instance of this!
* @class
*/
function OrgUtils() {}
function OrgUtils() {}//TODO: there exsits a OrgUtils and OrganisationUtils, this is inconvenient
/**
* checks if a organisationid is the id of the dummy organisation "private"
......@@ -33,6 +33,19 @@ OrgUtils.isPrivateOrganisationId = function(pOrganisationId)
return pOrganisationId.trim() == OrgUtils.getPrivateOrganisationId();
}
/**
* checks if a organsations contactid is the id of the dummy organisation "private"
*
* @param {String} pOrganisationContactId the id that shall be checked
*
* @return {boolean} true if passed contactid is the contactid of the dummy organisation "private"
*/
OrgUtils.isPrivateOrganisationContactId = function(pOrganisationContactId)
{
//contactid and organisationid in private dummy are equal, so it's okay to check the orgnisation-contactid against the orgnisationid
return pOrganisationContactId.trim() == OrgUtils.getPrivateOrganisationId();
}
/**
* returns the image for a organisation
*
......
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