Commit ec148ce0 authored by Frank Bergmann's avatar Frank Bergmann

Added two new unassigned callbacks

parent 9d920305
......@@ -295,7 +295,6 @@ begin
end;$$ language 'plpgsql';
-- ------------------------------------------------------
-- Unassigned callback that assigns the transition to the group in the custom_arg
--
......@@ -516,6 +515,158 @@ BEGIN
END; $BODY$ LANGUAGE 'plpgsql' VOLATILE;
-- Unassigned callback for financial documents to assign the projects supervisor
CREATE OR REPLACE FUNCTION im_workflow__assign_to_findoc_project_supervisor(integer, text)
RETURNS integer AS $BODY$
DECLARE
p_task_id alias for $1;
p_custom_arg alias for $2;
v_transition_key varchar;
v_object_type varchar;
v_case_id integer;
v_object_id integer;
v_creation_user integer;
v_creation_ip varchar;
v_supervisor_id integer;
v_supervisor_name varchar;
v_journal_id integer;
BEGIN
-- Get information about the transition and the 'environment'
select tr.transition_key, t.case_id, c.object_id, o.creation_user, o.creation_ip, o.object_type
into v_transition_key, v_case_id, v_object_id, v_creation_user, v_creation_ip, v_object_type
from wf_tasks t, wf_cases c, wf_transitions tr, acs_objects o
where t.task_id = p_task_id and
t.case_id = c.case_id and
o.object_id = t.case_id and
t.workflow_key = tr.workflow_key and
t.transition_key = tr.transition_key;
-- From the financial document get the task and from there get
-- the main_projects and extract its supervisor_id
select main_p.supervisor_id, im_name_from_id(main_p.supervisor_id)
into v_supervisor_id, v_supervisor_name -- take the supervisor from the main project
from im_costs c,
im_projects p,
im_projects main_p
where c.cost_id = v_object_id and -- the WF is attached to a financial document
c.project_id = p.project_id and -- the cost is attached to a task
main_p.tree_sortkey = tree_root_key(p.tree_sortkey); -- Get the main_project from any sub-level
RAISE NOTICE 'The supervisor for % is % and called %', v_object_id, v_supervisor_id, v_supervisor_name;
IF v_supervisor_id is not null THEN
v_journal_id := journal_entry__new(
null, v_case_id,
v_transition_key || ' assign_to_supervisor ' || v_supervisor_name,
v_transition_key || ' assign_to_supervisor ' || v_supervisor_name,
now(), v_creation_user, v_creation_ip,
'Assigning to user ' || v_supervisor_name || ', the supervisor of ' ||
acs_object__name(v_object_id) || '.'
);
PERFORM workflow_case__add_task_assignment(p_task_id, v_supervisor_id, 'f');
PERFORM workflow_case__notify_assignee (p_task_id, v_supervisor_id, null, null,
'wf_' || v_object_type || '_assignment_notif');
ELSE
-- IF the supervisor_id is NULL, then we will get 'stuck' workflows.
-- However, these WFs are shown to the admin who can fix them.
v_journal_id := journal_entry__new(
null, v_case_id,
v_transition_key || ' assign_to_supervisor ' || v_supervisor_name,
v_transition_key || ' assign_to_supervisor ' || v_supervisor_name,
now(), v_creation_user, v_creation_ip,
'NOT assigning to any user, because there is no supervisor_id for project ' ||
acs_object__name(v_object_id) || '.'
);
END IF;
return 0;
END; $BODY$ LANGUAGE 'plpgsql' VOLATILE;
-- Unassigned callback for a financial document to assign a random senior manager who is not the project supervisor
CREATE OR REPLACE FUNCTION im_workflow__assign_to_findoc_project_non_supervising_senior_manager(integer, text)
RETURNS integer AS $BODY$
DECLARE
p_task_id alias for $1;
p_custom_arg alias for $2;
v_transition_key varchar;
v_object_type varchar;
v_case_id integer;
v_object_id integer;
v_creation_user integer;
v_creation_ip varchar;
v_supervisor_id integer;
v_supervisor_name varchar;
v_non_supervisor_id integer;
v_non_supervisor_name varchar;
v_journal_id integer;
BEGIN
-- Get information about the transition and the 'environment'
select tr.transition_key, t.case_id, c.object_id, o.creation_user, o.creation_ip, o.object_type
into v_transition_key, v_case_id, v_object_id, v_creation_user, v_creation_ip, v_object_type
from wf_tasks t, wf_cases c, wf_transitions tr, acs_objects o
where t.task_id = p_task_id and
t.case_id = c.case_id and
o.object_id = t.case_id and
t.workflow_key = tr.workflow_key and
t.transition_key = tr.transition_key;
-- From the financial document get the task and from there get
-- the main_projects and extract its supervisor_id
select main_p.supervisor_id, im_name_from_id(main_p.supervisor_id)
into v_supervisor_id, v_supervisor_name -- take the supervisor from the main project
from im_costs c,
im_projects p,
im_projects main_p
where c.cost_id = v_object_id and -- the WF is attached to a financial document
c.project_id = p.project_id and -- the cost is attached to a task
main_p.tree_sortkey = tree_root_key(p.tree_sortkey); -- Get the main_project from any sub-level
-- Pick a random senior manager who is not the supervisor
select max(gdmm.member_id), acs_object__name(max(gdmm.member_id))
into v_non_supervisor_id, v_non_supervisor_name
from group_distinct_member_map gdmm
where gdmm.group_id in (select group_id from groups where group_name = 'Senior Managers') and
gdmm.member_id != v_supervisor_id; -- !!! What if supervisor is NULL???
RAISE NOTICE 'The non-supervisor for % is % and called %', v_object_id, v_non_supervisor_id, v_non_supervisor_name;
IF v_non_supervisor_id is not null THEN
v_journal_id := journal_entry__new(
null, v_case_id,
v_transition_key || ' assign_to_non_supervisor ' || v_non_supervisor_name,
v_transition_key || ' assign_to_non_supervisor ' || v_non_supervisor_name,
now(), v_creation_user, v_creation_ip,
'Assigning to user' || v_non_supervisor_name || ', the non_supervisor of ' ||
acs_object__name(v_object_id) || '.'
);
PERFORM workflow_case__add_task_assignment(p_task_id, v_non_supervisor_id, 'f');
PERFORM workflow_case__notify_assignee (p_task_id, v_non_supervisor_id, null, null,
'wf_' || v_object_type || '_assignment_notif');
ELSE
-- IF the non_supervisor_id is NULL, then we will get 'stuck' workflows.
-- However, these WFs are shown to the admin who can fix them.
v_journal_id := journal_entry__new(
null, v_case_id,
v_transition_key || ' assign_to_non_supervisor ' || v_non_supervisor_name,
v_transition_key || ' assign_to_non_supervisor ' || v_non_supervisor_name,
now(), v_creation_user, v_creation_ip,
'NOT assigning to any user, because there is no non_supervisor_id for project ' ||
acs_object__name(v_object_id) || ' with supervisor ' || v_supervisor_name || '.'
);
END IF;
return 0;
END; $BODY$ LANGUAGE 'plpgsql' VOLATILE;
create or replace function im_workflow__assign_to_project_admins (integer, text)
returns integer as $$
......
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