x
1
-- File: trig_i_d_syst_owners.eex.sql
2
-- Location: musebms/database/components/system/mscmp_syst_instance/ms_syst/api_views/syst_owners/trig_i_d_syst_owners.eex.sql
3
-- Project: Muse Systems Business Management System
4
--
5
-- Copyright © Lima Buttgereit Holdings LLC d/b/a Muse Systems
6
-- This file may include content copyrighted and licensed from third parties.
7
--
8
-- See the LICENSE file in the project root for license terms and conditions.
9
-- See the NOTICE file in the project root for copyright ownership information.
10
--
11
-- muse.information@musesystems.com :: https://muse.systems
12
13
BEGIN
14
15
IF
16
exists( SELECT
17
TRUE
18
FROM ms_syst_data.syst_enum_functional_types seft
19
WHERE
20
seft.enum_id = old.owner_state_id
21
AND seft.internal_name != 'owner_states_purge_eligible' )
22
THEN
23
24
RAISE EXCEPTION
25
USING
26
MESSAGE = 'You cannot delete an owner that is not in a purge ' ||
27
'eligible owner state using this API view.',
28
DETAIL = ms_syst_priv.get_exception_details(
29
p_proc_schema => 'ms_syst'
30
,p_proc_name => 'trig_i_d_syst_owners'
31
,p_exception_name => 'invalid_api_view_call'
32
,p_errcode => 'PM008'
33
,p_param_data => to_jsonb(old)
34
,p_context_data =>
35
jsonb_build_object(
36
'tg_op', tg_op
37
,'tg_when', tg_when
38
,'tg_schema', tg_table_schema
39
,'tg_table_name', tg_table_name)),
40
ERRCODE = 'PM008',
41
SCHEMA = tg_table_schema,
42
TABLE = tg_table_name;
43
44
END IF;
45
46
DELETE FROM ms_syst_data.syst_owners WHERE id = old.id RETURNING * INTO old;
47
48
RETURN old;
49
50
END;