Commit 4ae41d17 authored by Frank Bergmann's avatar Frank Bergmann

-- extended 'Add topic staff' with employees working for a company a user is...

-- extended 'Add topic staff' with employees working for a company a user is related to key/accounting contact
-- example: Creating a task task in a user forum. User is a customer and assigned to customer company ABC.
--          Assignees list will now show employees that are key account, accounting contact and members of ABC
--          This extension supports CRM processes
parent d972a599
...@@ -217,69 +217,69 @@ ad_proc -public im_forum_potential_asignees {user_id object_id} { ...@@ -217,69 +217,69 @@ ad_proc -public im_forum_potential_asignees {user_id object_id} {
# ----------------------- Start building the SQL Query ---------- # ----------------------- Start building the SQL Query ----------
# #
set object_admin_sql "( set object_admin_sql "(
-- object_admin_sql -- object_admin_sql
select distinct select distinct
u.user_id, u.user_id,
im_name_from_user_id(u.user_id) as user_name im_name_from_user_id(u.user_id) as user_name
from from
users u users u
where where
user_id in ($object_admins_commalist) user_id in ($object_admins_commalist)
)" )"
set object_group_sql "( set object_group_sql "(
select distinct select distinct
u.user_id, u.user_id,
im_name_from_user_id(u.user_id) as user_name im_name_from_user_id(u.user_id) as user_name
from from
users u users u
where where
user_id in ($object_members_commalist) user_id in ($object_members_commalist)
)" )"
# If the user can talk to the public (probably a SenMan # If the user can talk to the public (probably a SenMan
# or SysAdmin), he can also assign the task to everybody. # or SysAdmin), he can also assign the task to everybody.
# ToDo: This may cause problems with large installations # ToDo: This may cause problems with large installations
set public_sql "( set public_sql "(
-- public_sql -- public_sql
select distinct select distinct
u.user_id, u.user_id,
im_name_from_user_id(u.user_id) as user_name im_name_from_user_id(u.user_id) as user_name
from from
users u users u
)" )"
# Add the objects customers to the list # Add the objects customers to the list
set object_customer_sql "( set object_customer_sql "(
-- object_customer_sql -- object_customer_sql
select distinct select distinct
u.user_id, u.user_id,
im_name_from_user_id(u.user_id) as user_name im_name_from_user_id(u.user_id) as user_name
from from
acs_rels r, acs_rels r,
group_member_map m, group_member_map m,
membership_rels mr, membership_rels mr,
users u users u
where where
r.object_id_one = :object_id r.object_id_one = :object_id
and r.object_id_two = u.user_id and r.object_id_two = u.user_id
and m.rel_id = mr.rel_id and m.rel_id = mr.rel_id
and mr.member_state = 'approved' and mr.member_state = 'approved'
and m.member_id = u.user_id and m.member_id = u.user_id
and m.group_id = :customer_group_id and m.group_id = :customer_group_id
)" )"
# Add all object members to the list who are # Add all object members to the list who are
# not customers # not customers
set object_non_customer_sql "( set object_non_customer_sql "(
-- object_non_customer_sql -- object_non_customer_sql
select distinct select distinct
u.user_id, u.user_id,
im_name_from_user_id(u.user_id) as user_name im_name_from_user_id(u.user_id) as user_name
from from
acs_rels r, acs_rels r,
users u users u
where where
r.object_id_one = :object_id r.object_id_one = :object_id
and r.object_id_two = u.user_id and r.object_id_two = u.user_id
and u.user_id not in ( and u.user_id not in (
...@@ -291,26 +291,26 @@ where ...@@ -291,26 +291,26 @@ where
and mr.member_state = 'approved' and mr.member_state = 'approved'
and m.group_id = :customer_group_id and m.group_id = :customer_group_id
) )
)" )"
set object_staff_sql "( set object_staff_sql "(
-- object_staff_sql -- object_staff_sql
select distinct select distinct
u.user_id, u.user_id,
im_name_from_user_id(u.user_id) as user_name im_name_from_user_id(u.user_id) as user_name
from from
acs_rels r, acs_rels r,
group_member_map m, group_member_map m,
membership_rels mr, membership_rels mr,
users u users u
where where
r.object_id_one = :object_id r.object_id_one = :object_id
and r.object_id_two = u.user_id and r.object_id_two = u.user_id
and m.rel_id = mr.rel_id and m.rel_id = mr.rel_id
and mr.member_state = 'approved' and mr.member_state = 'approved'
and m.member_id = u.user_id and m.member_id = u.user_id
and m.group_id = :employee_group_id and m.group_id = :employee_group_id
)" )"
set primary_accounting_contact_client_sql "( set primary_accounting_contact_client_sql "(
...@@ -318,8 +318,8 @@ where ...@@ -318,8 +318,8 @@ where
select distinct select distinct
user_id, user_id,
im_name_from_user_id(user_id) as user_name im_name_from_user_id(user_id) as user_name
from from (
(select select
primary_contact_id as user_id primary_contact_id as user_id
from from
im_companies c, im_companies c,
...@@ -350,6 +350,62 @@ where ...@@ -350,6 +350,62 @@ where
im_companies im_companies
where where
company_id = :object_id company_id = :object_id
-- Get Primary/Accounting user is a employee of
UNION
select distinct
primary_contact_id as user_id
from
im_companies c
where
c.company_id in (
select
object_id_one
from
acs_rels
where
object_id_two = :object_id and
rel_type = 'im_company_employee_rel'
)
UNION
select distinct
accounting_contact_id as user_id
from
im_companies c
where
c.company_id in (
select
object_id_one
from
acs_rels
where
object_id_two = :object_id and
rel_type = 'im_company_employee_rel'
)
) tt
)"
set im_company_rel_sql "(
-- get company employees of companies user has a im_company_rel with
select distinct
user_id,
im_name_from_user_id(user_id) as user_name
from (
select distinct
object_id_two as user_id
from
acs_rels r
where
rel_type = 'im_key_account_rel' and
object_id_one in (
select
object_id_one
from
acs_rels
where
object_id_two = :object_id and
rel_type = 'im_company_employee_rel'
)
) tt ) tt
)" )"
...@@ -357,9 +413,9 @@ where ...@@ -357,9 +413,9 @@ where
# Don't enable the list of the entire public - # Don't enable the list of the entire public -
# too many users in large installations # too many users in large installations
# if {[im_permission $user_id add_topic_public]} { # if {[im_permission $user_id add_topic_public]} {
# lappend sql_list $public_sql # lappend sql_list $public_sql
# } # }
if {[im_permission $user_id add_topic_group]} { if {[im_permission $user_id add_topic_group]} {
...@@ -368,6 +424,7 @@ where ...@@ -368,6 +424,7 @@ where
if {[im_permission $user_id add_topic_staff]} { if {[im_permission $user_id add_topic_staff]} {
lappend sql_list $object_staff_sql lappend sql_list $object_staff_sql
lappend sql_list $primary_accounting_contact_client_sql lappend sql_list $primary_accounting_contact_client_sql
lappend sql_list $im_company_rel_sql
} }
if {[im_permission $user_id add_topic_client]} { if {[im_permission $user_id add_topic_client]} {
lappend sql_list $object_customer_sql lappend sql_list $object_customer_sql
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment