Härzlig willkome zue minere Bocksnip Code-Gallerie um alli Arte vo Code z'teile.

Collection Library

Avaloq · October 20, 2016 3:35 pm

0 0 543

En Library um en Collection z'erstelle

[Script 1.0]

script package rbsc$collect_lib
/*
-------------------------------------------------------------------------------------------------------------
Bank : Coutts & Co Ltd.
Business Area : Static/Dynamic Collections
Description : Library to create, modify, and access Static and Dynamic Collections
Owner : Coutts & Co Ltd.
-------------------------------------------------------------------------------------------------------------
ID Date Name, Company Issue Change Log or Description
-------------------------------------------------------------------------------------------------------------
001
*/

is

import err;
import text_list;
import util;
import rbsc$pfm_lib;
import native rbsc$collect_lib#;

-- TODO
-- Remove, once Avq CR delivered DDIC enhancement:
import native doc_tab_collect_stat#;


c_open_new_wfc_action_id constant number := 1100;
c_open_mdf_wfc_action_id constant number := 2100;
c_verify_direct_wfc_action_id constant number := 10190;
c_verify_no_doc_wfc_action_id constant number := 10191;

c_open_new_cc_wfc_action_id constant number := 701100;
c_verify_cc_wfc_action_id constant number := 704090;

c_collection_type_cc constant number := 8493;

l_order_new text := '-';
l_mem_doc_collect_id id mem_doc_obj_collect;

l_orig_bu_id number := session.bu_id;

-- TODO
-- Disable debugging once tested...
DO_DEBUG constant boolean := FALSE;

--------------------------------------------------------------------------------
---- Returns the Avaloq MinDate ------------------------------------------------
--------------------------------------------------------------------------------
l_mindate constant date := lookup.date('MinDate');
function C_MINDATE
return date
is
begin
return l_mindate;
end C_MINDATE;


--------------------------------------------------------------------------------
---- New Collection order (WFC Action: NEW or MODIFY) --------------------------
---- Don't use directly --------------------------------------------------------
--------------------------------------------------------------------------------
procedure make_new_doc(i_bu_id number
,i_key_sym text
,i_obj_type_id number
,i_collect_type_id number := null
)
is
t_collect_id id obj_collect := null;
l_wfc_action_open_id number := c_open_new_wfc_action_id;
l_form_id number := null;
begin
-- Change session BU (and remember current BU to change back):
l_orig_bu_id := session.bu_id;
if i_bu_id <> 0 then
session.bu_id := i_bu_id;
end if;
-- Lookup if collection already exists in that BU:
if (i_key_sym is not null) and (i_bu_id <> 0) then
t_collect_id := lookup.collect_id(key_val=>i_key_sym, bu_id=>i_bu_id, restr_bu=>'+', eff_date=>session.today);
end if;
if coalesce(i_collect_type_id,0) = c_collection_type_cc then
l_wfc_action_open_id := c_open_new_cc_wfc_action_id;
l_form_id := 7010 -- Client Connection Form
end if;
-- Create new, or modify existing collection:
if t_collect_id is null then
l_order_new := '+';
with new mem_doc_collect(l_wfc_action_open_id) as d do
d.item_obj_type_id := i_obj_type_id;
d.is_manual_mdf := '+';
d.key('collect_sym') := i_key_sym;
if l_form_id is not null then
d.form_id := l_form_id;
end if;
l_mem_doc_collect_id := d.id;
end with;
else
l_order_new := '-';
with new mem_doc_collect(c_open_mdf_wfc_action_id, t_collect_id) as d do
if l_form_id is not null then
d.form_id := l_form_id;
end if;
l_mem_doc_collect_id := d.id;
end with;
end if;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.make_new_doc');
end make_new_doc;


--------------------------------------------------------------------------------
---- Checks if an item (object) is in the collection ---------------------------
--------------------------------------------------------------------------------
function is_item_in_collect(i_collect_id number := null -- obj_id of the collection
,i_collect_key_sym text := '' -- or key of the collection
,i_bu_id number := null -- BU of the collection (only used if i_collect_key_sym set)
,i_item_id number -- obj-ID of the item to check
,i_eff_date date := session.today -- Effective date
,i_expd number := 0 -- 0: just look in top-level (std. stat. coll., very fast);
-- >0: expand static collection (fast), if collection is a stat. coll. of std. objects and/or collections;
-- <0: expand static collection, force obj_list-loop (down to all levels! slow = same as dyn.), if coll. contains std. objects and/or collections, which may contain other stat/dyn collections
) return text
is
t_collect_id id obj_collect;
begin
if i_collect_id is not null then
t_collect_id := i_collect_id;
elsif i_collect_key_sym is not null then
t_collect_id := lookup.collect_id(key_val=>i_collect_key_sym, bu_id=>coalesce(i_bu_id, session.bu_id), restr_bu=>'+');
else
return '-';
end if;
if (t_collect_id is null) or (i_item_id is null) then
return '-';
end if;

with obj_collect(t_collect_id) as coll do
if (coll.obj_sub_type_id = 60) and (i_expd >= 0) then -- collect_stat
-- Static collection (faster):
if coll.item(i_item_id, i_eff_date) is not null then
return '+';
end if;

-- Static collection of collections:
if i_expd > 0 then
if rbsc$collect_lib#.is_item_in_stat_expd(i_collect_id, i_item_id, i_eff_date) = true then
return '+';
end if;
end if;

else
-- Dyn. collection / Stat. collection (expand all collections inside) (slower):
for obj in coll.obj_list(i_eff_date) loop
if obj.id = i_item_id then
return '+';
end if;
end loop;
end if;
end with;

return '-';

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.is_item_in_collect');
end is_item_in_collect;


--------------------------------------------------------------------------------
---- Add item to static collection in memory -----------------------------------
--------------------------------------------------------------------------------
procedure add_item_to_stat(i_mem_doc_collect_id id mem_doc_obj_collect
,i_item_id id obj
,i_not_check_duplicate text := '-'
,i_delete_items text := '-'
)
is
begin
with mem_doc_collect(i_mem_doc_collect_id) as d do
if i_item_id is not null then
-- first, clear item list if wished:
if i_delete_items = '+' then
d.item_list.clear;
end if;
-- add item:
if i_not_check_duplicate = '+' then -- much faster! Duplicates will be checked anyway by verify-WFC
-- TODO
-- Using underlying native package procedure until Avq CR is delivered to give option in DDIC method add_item:
--> d.add_item(i_item_id, i_chk_dupl => '-');
doc_tab_collect_stat#.doc#add_item(i_doc => d.id
,i_obj_id => i_item_id
,i_chk_dupl => false);
else -- slow!
-- Check duplicates: check manually, otherwise an error message would appear:
if d.item(obj_id => i_item_id) is null then
-- TODO
-- Don't check again for duplicates by add_item, because already done manually:
-- Change when Avq CR is delivered to give option i_chk_dupl in DDIC method add_item:
--> d.add_item(i_item_id, i_chk_dupl => '-');
doc_tab_collect_stat#.doc#add_item(i_doc => d.id
,i_obj_id => i_item_id
,i_chk_dupl => false);
end if;
end if;
end if;
end with;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.add_item_to_stat');
end add_item_to_stat;



--------------------------------------------------------------------------------
---- Remove item from static collection in memory -----------------------------------
--------------------------------------------------------------------------------
procedure remv_item_from_stat(i_mem_doc_collect_id id mem_doc_obj_collect
,i_item_id id obj := null
,i_delete_all text := '-'
)
is
i number := 0;
begin
with mem_doc_collect(i_mem_doc_collect_id) as d do
if i_item_id is not null then
for item in d.item_list loop
i := i+1;
if item.item_id = i_item_id then
--d.item_list.remv(seq_nr => i);
d.remv_item(seq_nr => i);
exit;
end if;
end loop;
elsif i_delete_all = '+' then
d.item_list.clear;
end if;
end with;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.remv_item_from_stat');
end remv_item_from_stat;


--------------------------------------------------------------------------------
---- Add classes to collection in memory ---------------------------------------
--------------------------------------------------------------------------------
procedure set_classes(i_mem_doc_collect_id id mem_doc_obj_collect
,i_class_id number := null
,i_classif_id number := null
,i_class_list text := '' -- mult. classes ('classif_1:class_1;classif_2:class_2;...')
)
is
t_item_list_cnt number := 0;
t_list_item text := '';
t_class text := '';
t_classif text := '';
t_class_id number := 0;
t_classif_id number := 0;
begin
with mem_doc_collect(i_mem_doc_collect_id) as d do
if (i_class_id is not null) and (i_classif_id is not null) then
d.class_id(obj_classif_id => i_classif_id) := i_class_id;
end if;
if i_class_list is not null then
t_item_list_cnt := util.item_count(i_class_list, ';');
for i in 1..t_item_list_cnt loop
t_list_item := util.item(i_class_list, i, ';');
t_classif := util.item(t_list_item, 1, ':');
t_class := util.item(t_list_item, 2, ':');
t_class_id := lookup.code('code_obj_class', t_class);
t_classif_id := lookup.code('code_obj_classif', t_classif);--lookup.class(t_classif, t_class).obj_classif_id;
d.class_id(obj_classif_id => t_classif_id) := t_class_id;
end loop;
end if;
end with;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.set_classes');
end set_classes;


--------------------------------------------------------------------------------
---- Add keys to collection in memory ------------------------------------------
--------------------------------------------------------------------------------
procedure set_keys(i_mem_doc_collect_id id mem_doc_obj_collect
,i_key_list text -- mult. keys ('key_1:val_1;key_2:val_2;...')
)
is
t_item_list_cnt number := 0;
t_list_item text := '';
t_key text := '';
t_val text := '';
t_key_id number := 0;
begin
with mem_doc_collect(i_mem_doc_collect_id) as d do
if i_key_list is not null then
t_item_list_cnt := util.item_count(i_key_list, ';');
for i in 1..t_item_list_cnt loop
t_list_item := util.item(i_key_list, i, ';');
t_key := util.item(t_list_item, 1, ':');
t_val := util.item(t_list_item, 2, ':');
d.key(t_key) := t_val;
end loop;
end if;
end with;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.set_keys');
end set_keys;


--------------------------------------------------------------------------------
---- Modify Static Collection - Sets classes on object -----------
--------------------------------------------------------------------------------
procedure set_class_stat(i_bu_id number
,i_obj_type_id number
,i_key_sym text
,i_collect_type_id number := 1837 -- collect_stat
,i_open_date date := null
,i_eff_date date := null
,i_class_list text := '' -- mult. items text_list key-val
,i_classif_list text := '' -- mult. items text_list key-id
,i_gui text := '-' -- open GUI instead of verify order
,i_remark text := ''
,i_collect_owner_id number := null -- collection owner for access security
,i_obj_ref_id number := null -- reference object
)
is
t_class_list_cnt number := 0;
t_class text := '';
t_classif text := '';
t_class_id number := 0;
t_classif_id number := 0;
begin
-- New/Modify Collection (these three parameters can't be modified, only set when new):
make_new_doc(i_bu_id => i_bu_id
,i_key_sym => i_key_sym
,i_obj_type_id => i_obj_type_id
,i_collect_type_id => i_collect_type_id);

-- set/modify remaining parameters:
with mem_doc_collect(l_mem_doc_collect_id) as d do
d.collect_type_id := i_collect_type_id;
if i_open_date is not null then
d.open_date := i_open_date;
end if;
d.remark := i_remark;
if i_collect_owner_id is not null then
d.obj_extn.collect_owner_id := i_collect_owner_id;
end if;
if i_obj_ref_id is not null then
d.ref_obj_id := i_obj_ref_id;
end if;
end with;
-- Add new objects from l_item_key_list text-list (key_id from l_item_key_id_list):
if i_class_list is not null then
t_class_list_cnt := text_list.item_cnt(i_class_list);
for i in 1..t_class_list_cnt loop
t_class := text_list.item(i_class_list, i);
t_classif := text_list.item(i_classif_list, i);
t_class_id := lookup.class_id(t_classif, t_class);
t_classif_id := lookup.code('CODE_OBJ_CLASSIF', t_classif);
set_classes(i_mem_doc_collect_id => l_mem_doc_collect_id
,i_class_id => t_class_id
,i_classif_id => t_classif_id);

end loop;
end if;

if i_gui = '+' then
session.ui_mgr.open_doc(l_mem_doc_collect_id);
elsif i_collect_type_id = c_collection_type_cc then
mem_doc_collect(l_mem_doc_collect_id).do_wfc_action(c_verify_cc_wfc_action_id);
else
mem_doc_collect(l_mem_doc_collect_id).do_wfc_action(c_verify_direct_wfc_action_id);
end if;

-- Change back to current session BU:
session.bu_id := l_orig_bu_id;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.set_class_stat');
end set_class_stat;


--------------------------------------------------------------------------------
---- New/Modify Static Collection (fast, useful for bulk operations) -----------
---- Adds multiple items (given in text-lists or up to 2 single items) ---------
--------------------------------------------------------------------------------
procedure new_mod_static (i_bu_id number
,i_obj_type_id number
,i_name text := ''
,i_key_sym text
,i_abbr text := ''
,i_name_long text := ''
,i_name_intl_sec text := '' -- dummy parameter for compatibility (name_intl_sec can't be set manually)
,i_collect_type_id number := 1837 -- collect_stat
,i_incl_closed_obj text := '-' -- incl. closed objects
,i_open_date date := null
,i_delete_items text := '-'
,i_item_key_list text := '' -- mult. items text_list key-val
,i_item_key_id_list text := '' -- mult. items text_list key-id
,i_item_key_1 text := '' -- single item 1 key
,i_item_key_id_1 number := null -- single item 1 key-id
,i_item_key_2 text := '' -- single item 2 key
,i_item_key_id_2 number := null -- single item 2 key-id
,i_item_id_list text := '' -- mult. items text_list obj_id
,i_item_id_obj_list number := null -- mult. items number_list id
,i_gui text := '-' -- open GUI instead of verify order
,i_close_date date := null
,i_remark text := ''
,i_collect_owner_id number := null -- collection owner for access security
,i_obj_ref_id number := null -- reference object
,i_class_list text := '' -- mult. classes ('classif_1:class_1;classif_2:class_2;...')
,i_key_list text := '' -- mult. keys ('key_1:val_1;key_2:val_2;...')
)
is
t_item_list_cnt number := 0;
t_item_key text := '';
t_item_key_id number := 0;
t_item_id id obj;
t_delete_items text := i_delete_items;
begin
-- New/Modify Collection (these three parameters can't be modified, only set when new):
make_new_doc(i_bu_id => i_bu_id
,i_key_sym => i_key_sym
,i_obj_type_id => i_obj_type_id
,i_collect_type_id => i_collect_type_id);

-- set/modify remaining parameters:
with mem_doc_collect(l_mem_doc_collect_id) as d do
if i_name is not null then
d.name := i_name;
end if;
if i_abbr is not null then
d.abbr := i_abbr;
end if;
if i_name_long is not null then
d.name_long := i_name_long;
end if;
d.collect_type_id := i_collect_type_id;
if i_open_date is not null then
d.open_date := i_open_date;
end if;
if i_close_date is not null then
d.close_date := i_close_date;
end if;
d.incl_closed_obj := i_incl_closed_obj;
d.remark := i_remark;
if i_collect_owner_id is not null then
d.obj_extn.collect_owner_id := i_collect_owner_id;
end if;
if i_obj_ref_id is not null then
d.ref_obj_id := i_obj_ref_id;
end if;
end with;

-- Add new objects from l_item_key_list text-list (key_id from l_item_key_id_list):
if i_item_key_list is not null then
t_item_list_cnt := text_list.item_cnt(i_item_key_list);
for i in 1..t_item_list_cnt loop
t_item_key := text_list.item(i_item_key_list, i);
t_item_key_id := text_list.item(i_item_key_id_list, i);
t_item_id := lookup.obj_id(t_item_key, t_item_key_id);
add_item_to_stat(i_mem_doc_collect_id => l_mem_doc_collect_id
,i_item_id => t_item_id
,i_delete_items => t_delete_items);
t_delete_items := '-'; -- delete first time only if wished
end loop;
end if;

-- Add new objects from i_item_id_list text-list:
if i_item_id_list is not null then
t_item_list_cnt := text_list.item_cnt(i_item_id_list);
for i in 1..t_item_list_cnt loop
t_item_id := text_list.item(i_item_id_list, i);
add_item_to_stat(i_mem_doc_collect_id => l_mem_doc_collect_id
,i_item_id => t_item_id
,i_delete_items => t_delete_items);
t_delete_items := '-'; -- delete first time only if wished
end loop;
end if;

-- Add new objects from i_item_nr_list_id number-list:
if i_item_id_obj_list is not null then
with new mem_db_list_nr(i_item_id_obj_list) as mem_list do
for t_item_id in mem_list.item_list loop
add_item_to_stat(i_mem_doc_collect_id => l_mem_doc_collect_id
,i_item_id => t_item_id
,i_delete_items => t_delete_items);
t_delete_items := '-'; -- delete first time only if wished
end loop;
end with;
end if;

-- Add single items:
if i_item_key_1 is not null then
-- first item:
t_item_id := lookup.obj_id(i_item_key_1, i_item_key_id_1);
add_item_to_stat(i_mem_doc_collect_id => l_mem_doc_collect_id
,i_item_id => t_item_id
,i_delete_items => i_delete_items); -- delete first time only if wished
-- second item:
if i_item_key_2 is not null then
t_item_id := lookup.obj_id(i_item_key_2, i_item_key_id_2);
add_item_to_stat(i_mem_doc_collect_id => l_mem_doc_collect_id
,i_item_id => t_item_id
,i_delete_items => '-'); -- don't delete (because it's the second item)
end if;
end if;

-- Set classes:
if i_class_list is not null then
set_classes(i_mem_doc_collect_id => l_mem_doc_collect_id, i_class_list => i_class_list);
end if;

-- Set keys:
if i_key_list is not null then
set_keys(l_mem_doc_collect_id, i_key_list);
end if;

if i_gui = '+' then
session.ui_mgr.open_doc(l_mem_doc_collect_id);
elsif i_collect_type_id = c_collection_type_cc then
mem_doc_collect(l_mem_doc_collect_id).do_wfc_action(c_verify_cc_wfc_action_id);
else
mem_doc_collect(l_mem_doc_collect_id).do_wfc_action(c_verify_direct_wfc_action_id);
end if;

-- Change back to current session BU:
session.bu_id := l_orig_bu_id;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.new_mod_static');
end new_mod_static;


--------------------------------------------------------------------------------
---- New/Modify Dynamic Collection (fast, useful for bulk operations) ----------
--------------------------------------------------------------------------------
procedure new_mod_dynamic(i_bu_id number
,i_obj_type_id number
,i_name text := ''
,i_key_sym text
,i_abbr text := ''
,i_name_long text := ''
,i_name_intl_sec text := '' -- dummy parameter for compatibility (name_intl_sec can't be set manually)
,i_collect_type_id number := 1838 -- collect_dyn
,i_decl_clause text := ''
,i_sel_stmt text
,i_from_stmt text
,i_where_stmt text
,i_incl_closed_obj text := '-'
,i_open_date date := null
,i_close_date date := null
,i_remark text := ''
,i_collect_owner_id number := null -- collection owner for access security
,i_ref_obj_id number := null -- reference object
,i_class_list text := '' -- mult. classes ('classif_1:class_1;classif_2:class_2;...')
,i_key_list text := '' -- mult. keys ('key_1:val_1;key_2:val_2;...')
)
is
t_item_id id obj;
begin
-- New/Modify Collection (these three parameters can't be modified, only set when new):
make_new_doc(i_bu_id => i_bu_id
,i_key_sym => i_key_sym
,i_obj_type_id => i_obj_type_id);

-- set/modify remaining parameters:
with mem_doc_collect(l_mem_doc_collect_id) as d do
if i_name is not null then
d.name := i_name;
end if;
if i_abbr is not null then
d.abbr := i_abbr;
end if;
if i_name_long is not null then
d.name_long := i_name_long;
end if;
d.collect_type_id := i_collect_type_id;
if i_open_date is not null then
d.open_date := i_open_date;
end if;
if i_close_date is not null then
d.close_date := i_close_date;
end if;
d.decl_clause := i_decl_clause;
d.sel_stmt := i_sel_stmt;
d.from_stmt := i_from_stmt;
d.where_stmt := i_where_stmt;
d.incl_closed_obj := i_incl_closed_obj;
d.remark := i_remark;
if i_collect_owner_id is not null then
d.obj_extn.collect_owner_id := i_collect_owner_id;
end if;
if i_ref_obj_id is not null then
d.ref_obj_id := i_ref_obj_id;
end if;
end with;

-- Set classes:
if i_class_list is not null then
set_classes(i_mem_doc_collect_id => l_mem_doc_collect_id, i_class_list => i_class_list);
end if;

-- Set keys:
if i_key_list is not null then
set_keys(l_mem_doc_collect_id, i_key_list);
end if;

mem_doc_collect(l_mem_doc_collect_id).do_wfc_action(c_verify_direct_wfc_action_id);

-- Change back to current session BU:
session.bu_id := l_orig_bu_id;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.new_mod_dynamic');
end new_mod_dynamic;


--------------------------------------------------------------------------------
---- Add/Remove items from existing or new empty Static Collection -------------
---- Very flexible, every possible combination possible ------------------------
--------------------------------------------------------------------------------
procedure add_rem_items_stat(i_collect_id number := null -- obj_id of the collection
,i_collect_key_sym text := '' -- or key of the collection; if both null, create new collection
,i_bu_id number := session.bu_id -- BU of the collection
,i_rem_all text := '-' -- remove all items (before adding new ones)
,i_add_item_id id obj := null -- item to add: single object
,i_add_items_collect id obj_collect := null -- items to add: given in collection
,i_add_items_id_txt_list text := '' -- items to add: given as text-list
,i_add_items_id_obj_list number := null -- items to add: given as number_list-list
,i_add_items_id_mem_nr_list number := null -- items to add: given as mem_db_list_nr-list
,i_not_check_duplicate text := '-' -- Duplicates will be checked anyway with the verify-WFC. However, setting this parameter to '-' prevents an ui_err message, with '+' an ui_err may appear, but is much faster!
,i_rem_item_id id obj := null -- item to remove: single object
,i_rem_items_collect id obj_collect := null -- items to remove: given in collection
,i_rem_items_id_txt_list text := '' -- items to remove: given as text-list
,i_rem_items_id_obj_list number := null -- items to remove: given as number_list-list
,i_rem_items_id_mem_nr_list number := null -- items to remove: given as mem_db_list_nr-list
,i_vfy_no_doc text := '-' -- Use WFC action vfy_no_doc: doesn't create an order! Much faster, but no order and no audit!!
)
is
do_new boolean := true;
t_collect_id id obj_collect;
t_mem_doc_collect_id id mem_doc_obj_collect;
t_item_obj_type_id number := null;
t_list_cnt number := null;
t_item_id number := null;

---- Progress in log (if DO_DEBUG=true): ----
prog_cnt number := 0;
prog_i number := 0;
prog_step number := 0;

procedure log_progress(i_text text)
is
begin
prog_i := prog_i + 1;
if (prog_i < 2) or (prog_i >= prog_cnt) or (round(prog_i mod prog_step) = 0) then
rbsc$pfm_lib.my_debug(i_text ||' ['|| prog_i ||'/'|| prog_cnt ||']', DO_DEBUG);
end if;
end log_progress;

procedure reset_progress(i_cnt number)
is
begin
prog_i := 0;
prog_cnt := i_cnt;
prog_step := round(prog_cnt / 10);
end reset_progress;
---------------------------------------------

begin
-- Get the collection obj_id if i_collect_id or i_collect_key_sym selected, otherwise create new collection:
if i_collect_id is not null then
t_collect_id := i_collect_id;
do_new := false;
elsif i_collect_key_sym is not null then
t_collect_id := lookup.collect_id(key_val=>i_collect_key_sym, bu_id=>i_bu_id, restr_bu=>'+');
do_new := false;
else
do_new := true;
end if;

if (t_collect_id is null) and (do_new = false) then
return;
end if;

rbsc$pfm_lib.my_debug('add_rem_items_stat: START OPEN DOC: t_collect_id: '||coalesce(t_collect_id,'null'), DO_DEBUG);

-- Open collection (modify/new WFC):
if do_new = false then
-- Modify collection:
with new mem_doc_collect(c_open_mdf_wfc_action_id, t_collect_id) as d do
t_mem_doc_collect_id := d.id;
t_item_obj_type_id := d.item_obj_type_id;
end with;
else
-- New collection:
-- Get obj_type_id:
if i_add_item_id is not null then
t_item_obj_type_id := obj(i_add_item_id).obj_type_id;
elsif i_add_items_collect is not null then
t_item_obj_type_id := obj_collect(i_add_items_collect).item_obj_type_id;
elsif i_add_items_id_txt_list is not null then
if text_list.item_cnt(i_add_items_id_txt_list) > 0 then
t_item_obj_type_id := obj(text_list.item(i_add_items_id_txt_list, 1)).obj_type_id;
end if;
elsif i_add_items_id_obj_list is not null then
with new mem_db_list_nr(list_nr_id=>i_add_items_id_obj_list) as mem_list do
for t_item_id in mem_list.item_list loop
t_item_obj_type_id := obj(t_item_id).obj_type_id;
exit;
end loop
end with;
elsif i_add_items_id_mem_nr_list is not null then
with mem_db_list_nr(i_add_items_id_mem_nr_list) as mem_list do
for t_item_id in mem_list.item_list loop
t_item_obj_type_id := obj(t_item_id).obj_type_id;
exit;
end loop
end with;
end if;
if t_item_obj_type_id is null then
session.raise_ui_err(1, 'At least one object to add has to be selected when creating a new collection');
return;
end if;

-- Create new collections:
with new mem_doc_collect(c_open_new_wfc_action_id) as d do
d.item_obj_type_id := t_item_obj_type_id;
d.is_manual_mdf := '+';
d.collect_type_id := 1837; -- static
t_mem_doc_collect_id := d.id;
end with;
end if;

rbsc$pfm_lib.my_debug('add_rem_items_stat: END OPEN DOC: t_mem_doc_collect_id: '||t_mem_doc_collect_id, DO_DEBUG);

---- REMOVE ALL ----

-- removes all items before adding others, if requested
if i_rem_all = '+' then
rbsc$pfm_lib.my_debug('add_rem_items_stat: START REMV ALL', DO_DEBUG);
remv_item_from_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_delete_all => '+');
end if;

---- ADD ----

-- Add item: single object
if i_add_item_id is not null then
if obj(i_add_item_id).obj_type_id = t_item_obj_type_id then
add_item_to_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => i_add_item_id
,i_not_check_duplicate => i_not_check_duplicate);
else
session.raise_ui_err(1,'Wrong collection item object type. '''||session.fld('code_obj_type', t_item_obj_type_id, fld=>'name')||''' expected.')
end if;
end if;

-- Add items: given in collection
if i_add_items_collect is not null then
with obj_collect(i_add_items_collect) as add_coll do
if add_coll.item_obj_type_id = t_item_obj_type_id then
reset_progress(add_coll.item_list.count);
for obj in add_coll.obj_list loop -- use obj_list to allow also dyn collect
t_item_id := obj.id;
log_progress('add_rem_items_stat (i_add_items_collect): t_item_id: '|| t_item_id);
add_item_to_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => t_item_id
,i_not_check_duplicate => i_not_check_duplicate);
end loop;
else
session.raise_ui_err(1,'Wrong collection item object type. '''||session.fld('code_obj_type', t_item_obj_type_id, fld=>'name')||''' expected.')
end if;
end with;
end if;

-- Add items: given as text-list
if i_add_items_id_txt_list is not null then
t_list_cnt := text_list.item_cnt(i_add_items_id_txt_list);
reset_progress(t_list_cnt);
for i in 1..t_list_cnt loop
t_item_id := text_list.item(i_add_items_id_txt_list, i);
if obj(t_item_id).obj_type_id = t_item_obj_type_id then
log_progress('add_rem_items_stat (i_add_items_id_txt_list): t_item_id: '|| t_item_id);
add_item_to_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => t_item_id
,i_not_check_duplicate => i_not_check_duplicate);
else
session.raise_ui_err(1,'Wrong item object type. '''||session.fld('code_obj_type', t_item_obj_type_id, fld=>'name')||''' expected.')
end if;
end loop;
end if;

-- Add items: given as number list
if i_add_items_id_obj_list is not null then
with new mem_db_list_nr(list_nr_id=>i_add_items_id_obj_list) as mem_list do
reset_progress(mem_list.item_list.count);
for t_item_id in mem_list.item_list loop
if obj(t_item_id).obj_type_id = t_item_obj_type_id then
log_progress('add_rem_items_stat (i_add_items_id_obj_list): t_item_id: '|| t_item_id);
add_item_to_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => t_item_id
,i_not_check_duplicate => i_not_check_duplicate);
else
session.raise_ui_err(1,'Wrong item object type. '''||session.fld('code_obj_type', t_item_obj_type_id, fld=>'name')||''' expected.')
end if;
end loop;
end with;
end if;

-- Add items: given as mem_db_list_nr list
if i_add_items_id_mem_nr_list is not null then
with mem_db_list_nr(i_add_items_id_mem_nr_list) as mem_list do
reset_progress(mem_list.item_list.count);
for t_item_id in mem_list.item_list loop
if obj(t_item_id).obj_type_id = t_item_obj_type_id then
log_progress('add_rem_items_stat (i_add_items_id_mem_nr_list): t_item_id: '|| t_item_id);
add_item_to_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => t_item_id
,i_not_check_duplicate => i_not_check_duplicate);
else
session.raise_ui_err(1,'Wrong item object type. '''||session.fld('code_obj_type', t_item_obj_type_id, fld=>'name')||''' expected.')
end if;
end loop;
end with;
end if;

---- REMOVE ----

-- Remove item: single object
if i_rem_item_id is not null then
remv_item_from_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => i_rem_item_id);
end if;

-- Remove items: given in collection
if i_rem_items_collect is not null then
with obj_collect(i_rem_items_collect) as rem_coll do
reset_progress(rem_coll.item_list.count);
for obj in rem_coll.obj_list loop
t_item_id := obj.id;
log_progress('add_rem_items_stat (i_rem_items_collect): t_item_id: '|| t_item_id);
remv_item_from_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => t_item_id);
end loop;
end with;
end if;

-- Remove items: given as text-list
if i_rem_items_id_txt_list is not null then
t_list_cnt := text_list.item_cnt(i_rem_items_id_txt_list);
reset_progress(t_list_cnt);
for i in 1..t_list_cnt loop
t_item_id := text_list.item(i_rem_items_id_txt_list, i);
log_progress('add_rem_items_stat (i_rem_items_id_txt_list): t_item_id: '|| t_item_id);
remv_item_from_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => t_item_id);
end loop;
end if;

-- Remove items: given as number list
if i_rem_items_id_obj_list is not null then
with new mem_db_list_nr(list_nr_id=>i_rem_items_id_obj_list) as mem_list do
reset_progress(mem_list.item_list.count);
for t_item_id in mem_list.item_list loop
log_progress('add_rem_items_stat (i_rem_items_id_obj_list): t_item_id: '|| t_item_id);
remv_item_from_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => t_item_id);
end loop;
end with;
end if;

-- Remove items: given as mem_db_list_nr list
if i_rem_items_id_mem_nr_list is not null then
with mem_db_list_nr(i_rem_items_id_mem_nr_list) as mem_list do
reset_progress(mem_list.item_list.count);
for t_item_id in mem_list.item_list loop
log_progress('add_rem_items_stat (i_rem_items_id_mem_nr_list): t_item_id: '|| t_item_id);
remv_item_from_stat(i_mem_doc_collect_id => t_mem_doc_collect_id
,i_item_id => t_item_id);
end loop;
end with;
end if;

-- Verify/show GUI:
if do_new = false then
rbsc$pfm_lib.my_debug('add_rem_items_stat: START VERIFY: t_collect_id: '||coalesce(t_collect_id,'null')||' t_mem_doc_collect_id: '||t_mem_doc_collect_id, DO_DEBUG);
if i_vfy_no_doc = '+' then
mem_doc_collect(t_mem_doc_collect_id).do_wfc_action(c_verify_no_doc_wfc_action_id);
else
mem_doc_collect(t_mem_doc_collect_id).do_wfc_action(c_verify_direct_wfc_action_id);
end if;
else
rbsc$pfm_lib.my_debug('add_rem_items_stat: START OPEN GUI: t_collect_id: '||coalesce(t_collect_id,'null')||' t_mem_doc_collect_id: '||t_mem_doc_collect_id, DO_DEBUG);
rbsc$pfm_lib.my_debug('add_rem_items_stat: OPEN GUI: ui_mgr_id: '||session.ui_mgr.appl_id, DO_DEBUG);
session.ui_mgr.open_doc(t_mem_doc_collect_id);
end if;

rbsc$pfm_lib.my_debug('add_rem_items_stat: END: t_collect_id: '||coalesce(t_collect_id,'null')||' t_mem_doc_collect_id: '||t_mem_doc_collect_id, DO_DEBUG);

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.add_rem_items_stat');
end add_rem_items_stat;



--------------------------------------------------------------------------------
---- New Static Collection (used for CTX Action) -------------------------------
--------------------------------------------------------------------------------
procedure new_static_ctx (i_item_id_list text -- mult. items text_list obj_id
,i_name text := 'New static collection'
)
is
t_item_id number := null;
t_obj_type_id number := null;
begin
if i_item_id_list is not null then
t_item_id := text_list.item(i_item_id_list, 1);
if t_item_id is not null then
t_obj_type_id := obj(t_item_id).obj_type_id;
end if;
if t_obj_type_id is not null then
new_mod_static(i_bu_id => 0
,i_obj_type_id => t_obj_type_id
,i_name => i_name
,i_key_sym => ''
,i_item_id_list => i_item_id_list
,i_gui => '+');
end if;
end if;

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.new_static_ctx');
end new_static_ctx;



--------------------------------------------------------------------------------
---- Checks if objects are in the collection (used by program) -----------------
--------------------------------------------------------------------------------
procedure obj_in_collect(i_collect_id number -- obj_id of the collection
,i_item_list_id number -- list id of obj id of the item to check
)
is
o_type_coll number;
o_type_obj number;
ret text := '?';
txt text := '';
nl text := '';
begin
if i_item_list_id is not null then
with new mem_db_list_nr(list_nr_id=>i_item_list_id) as mem_list do
for t_item_id in mem_list.item_list loop
-- Check obj types match:
o_type_coll := obj_collect(i_collect_id).item_obj_type_id;
o_type_obj := obj(t_item_id).obj_type_id;
if o_type_coll <> o_type_obj then
session.raise_ui_err(1,'Object types do not match!'||chr(10)||chr(10)||''''||obj(t_item_id).name||''': '||obj(t_item_id).obj_type.name||chr(10)||'Collection object type: '||obj_collect(i_collect_id).item_obj_type.name);
end if;

-- Check obj in collection:
ret := is_item_in_collect(i_collect_id => i_collect_id, i_item_id => t_item_id);
txt := txt || nl || ret || chr(9) || obj(t_item_id).name;
nl := chr(10);
end loop;
end with;
else
session.raise_ui_err(1,'No objects selected!');
end if;

session.ui_mgr.put_client_info('Objects in (+)/not in (-) collection '||obj_collect(i_collect_id).name||':'||chr(10)||chr(10)||
'+/-'||chr(9)||obj_collect(i_collect_id).item_obj_type.name||chr(10)||
txt);

exception
when others then
err.raise_fa('RBSC$COLLECT_LIB.obj_in_collect');
end obj_in_collect;

---------------------------------------------------------------------------
-- Function returns a task parameter value of the current task execution
-- which can be used in dynamic collections.
--
-- task parameter needs to be of data type: date
---------------------------------------------------------------------------
function get_task_def_param_date(i_param_name text
)return date
is
l_res_val date := null;
begin
---- check if task is being run ----
if coalesce(session.curr_task_exec_id, 0) > 0 then
---- check if i_param_name is available -----
if session.curr_task_exec.has_param(i_param_name) = '+' then
l_res_val := session.curr_task_exec.param(i_param_name).date_val;
end if;
end if;

return l_res_val;
exception
when others then
session.raise_fa_err(1, 'Error in rbsc$collect_lib.get_task_def_param_date');
end get_task_def_param_date;

---------------------------------------------------------------------------
-- Function returns a task parameter value of the current task execution
-- which can be used in dynamic collections.
--
-- task parameter needs to be of data type: number
---------------------------------------------------------------------------
function get_task_def_param_number(i_param_name text
)return number
is
l_res_val number := null;
begin
---- check if task is being run ----
if coalesce(session.curr_task_exec_id, 0) > 0 then
---- check if i_param_name is available -----
if session.curr_task_exec.has_param(i_param_name) = '+' then
l_res_val := session.curr_task_exec.param(i_param_name).nr_val;
end if;
end if;

return l_res_val;
exception
when others then
session.raise_fa_err(1, 'Error in rbsc$collect_lib.get_task_def_param_number');
end get_task_def_param_number;

end rbsc$collect_lib;

Besprich das Bocksnip
    Kei Kommentar zur Diskussion gfunde

    Du muesch igloggt si, um über das Bocksnip z'diskutiere
boecki

boecki

Nimmt teil
August 13, 2016

  • 64 Bocksnipa
    gschriebe
  • 0 Likes
    verteilt
  • 1 Kommentär gmacht
Bocksnip Tags
Teil din Code

Organisier und teil all dini Code Snips a eim Platz.