CREATE OR REPLACE PACKAGE BODY amfrw021$ IS
--
-- Text constants
--
c_heading CONSTANT NUMBER := 2154;
c_active_from CONSTANT NUMBER := 2150;
c_active_to CONSTANT NUMBER := 2151;
c_customer_name CONSTANT NUMBER := 1145;
c_include_exclude CONSTANT NUMBER := 1146;
c_submit CONSTANT NUMBER := 1147;
c_selectall CONSTANT NUMBER := 1148;
c_selectallopen CONSTANT NUMBER := 3926;
c_subject CONSTANT NUMBER := 2148;
c_message_text CONSTANT NUMBER := 3535;
c_customers CONSTANT NUMBER := 1045;
c_sms CONSTANT NUMBER := 3959;
c_message_sent_to CONSTANT NUMBER := 3927;
c_system_user CONSTANT NUMBER := 1057;
--
-- Other Constants
--
c_yes CONSTANT VARCHAR2(1) := 'Y';
c_date_format CONSTANT VARCHAR2(255) := g_date_format;
--
-- Global variables
--
g_active_from_lbl VARCHAR2(255) := caco_utilities.get_module_text(c_active_from);
g_active_to_lbl VARCHAR2(255) := caco_utilities.get_module_text(c_active_to);
g_subject_lbl VARCHAR2(255) := caco_utilities.get_module_text(c_subject);
g_customers VARCHAR2(255) := caco_utilities.get_module_text(c_customers);
g_message_text_lbl VARCHAR2(255) := caco_utilities.get_module_text(c_message_text);
g_sms_lbl VARCHAR2(255) := caco_utilities.get_module_text(c_sms);
g_system_user_lbl VARCHAR2(255) := caco_utilities.get_module_text(c_system_user);
--
-- Output contents of an array to debug table
-- useful for debugging..
--
PROCEDURE display_vc_arr(arr_name IN VARCHAR2,
arr IN owa_util.vc_arr) IS
BEGIN
--
IF arr.COUNT > 0 THEN
caco_debug.putline('---------------------------------------');
FOR i IN arr.FIRST..arr.LAST LOOP
caco_debug.putline(arr_name||': '||i||' = '||arr(i));
END LOOP;
caco_debug.putline('---------------------------------------');
END IF;
--
END display_vc_arr;
--
--
-- standard web calendar package
--
PROCEDURE calendar(z_field_name IN VARCHAR2
,z_caller_url IN VARCHAR2
,z_field_value IN VARCHAR2 DEFAULT NULL
,z_field_format IN VARCHAR2 DEFAULT NULL
,z_field_prompt IN VARCHAR2 DEFAULT NULL) IS
--
field_caption VARCHAR2(2000);
--
BEGIN
--
IF z_field_prompt IS NULL THEN
--
field_caption := INITCAP(REPLACE(SUBSTR(z_field_name
,3
,LENGTH(z_field_name) - 2)
,'_'
,' '));
--
ELSE
--
field_caption := INITCAP(REPLACE(z_field_prompt
,'_'
,' '));
--
END IF;
--
wsgl.registerurl(g_package_name || '.calendar');
wsgl.addurlparam('Z_FIELD_NAME'
,z_field_name);
wsgl.addurlparam('Z_CALLER_URL'
,z_caller_url);
--
IF wsgl.notlowercase THEN
RETURN;
END IF;
--
wsgl.output_calendar(z_field_name
,z_field_value
,z_field_format
,wsgl.msggettext(123
,wsglm.dsp128_cal_caption
,field_caption)
,NULL
,g_package_name
,'Close'
,TRUE
,g_date_format);
--
wsgl.output_calendar(z_field_name
,z_field_value
,z_field_format
,wsgl.msggettext(123
,wsglm.dsp128_cal_caption
,field_caption)
,NULL
,g_package_name
,'Close'
,FALSE
,g_date_format);
--
EXCEPTION
WHEN OTHERS THEN
wsgl.displaymessage(wsgl.mess_exception
,SQLERRM
,''
,NULL
,g_package_name || '.calendar');
END calendar;
--
-- Standard web formatting package for submitted dates
--
PROCEDURE format_cal_date(z_field_name IN VARCHAR2
,z_field_format IN VARCHAR2
,DAY IN VARCHAR2
,MONTH IN VARCHAR2
,YEAR IN VARCHAR2) IS
--
field_caption VARCHAR2(2000) := INITCAP(REPLACE(SUBSTR(z_field_name
,3
,LENGTH(z_field_name) - 2)
,'_'
,' '));
l_day VARCHAR2(15) := DAY;
--
PROCEDURE output_format_cal_js(page_header IN VARCHAR2
,body_attributes IN VARCHAR2
,chosen_date IN VARCHAR2
,field_format IN VARCHAR2) IS
--
-- Copied from WSGL
--
the_date DATE := TO_DATE(chosen_date
,'DD-MONTH-YYYY');
--
BEGIN
--
wsgl.openpagehead(page_header);
wsgl.closepagehead;
wsgl.openpagebody(FALSE
,p_attributes => body_attributes);
htp.p('');
wsgl.closepagebody;
--
END output_format_cal_js;
--
BEGIN
--
IF l_day = '0' THEN
l_day := '01';
END IF;
--
output_format_cal_js(wsgl.msggettext(123
,wsglm.dsp128_cal_caption
,field_caption)
,NULL
,l_day || '-' || MONTH || '-' || YEAR
,z_field_format);
--
END format_cal_date;
--
-- Procedure to display the system user poplist
--
PROCEDURE display_system_user
IS
-- Get all possible customers for the person logged in
CURSOR c_syus IS
SELECT syus.syus_id syus_id
,syus.db_username username
FROM system_users syus
WHERE SYSDATE BETWEEN syus.period_start AND
nvl(syus.period_end
,SYSDATE)
AND syus.user_locked = 'N'
AND syus.syus_id NOT IN (SELECT syus2.syus_id
FROM system_users syus2
WHERE upper(syus2.db_username) IN
('SYSTEM'
,'ADVANTICA'))
AND syus_id IN
(SELECT inus.syus_id
FROM intermediary_users inus
WHERE inus.inte_id IN (SELECT cbcv.inte_id
FROM cust_by_cuty_v cbcv))
ORDER BY syus.db_username;
--
BEGIN
--
htp.p('
'||g_system_user_lbl||'
'); -- System User
htp.p('
 
');
--
END display_system_user;
--
-- Output the HTML page head
--
PROCEDURE page_header IS
--
l_header VARCHAR2(255);
--
BEGIN
--
l_header := caco_utilities.get_module_text(c_heading);
--
htp.p('
');
--
END;
--
-- Output the form elements
--
PROCEDURE page_body IS
--
l_cust_name_lbl VARCHAR2(255);
l_inc_exc_lbl VARCHAR2(255);
l_index NUMBER;
l_open VARCHAR2(1);
--
CURSOR c_cont (cp_cust_id NUMBER)IS
SELECT 'Y'
FROM customers cust
,contracts cont
WHERE cust.cust_id = cp_cust_id
AND cont.cust_id = cust.cust_id
AND cont.status = 'O'
AND TRUNC(SYSDATE) BETWEEN cont.valid_from AND cont.valid_until
ORDER BY cust.name;
--
BEGIN
--
l_cust_name_lbl := caco_utilities.get_module_text(c_customer_name);
l_inc_exc_lbl := caco_utilities.get_module_text(c_include_exclude);
--
htp.p('
');
htp.p('
');
htp.p('');
--
htp.p('
');
--
htp.print('
' || l_cust_name_lbl || '
');
htp.print('
' || l_inc_exc_lbl || '
');
--
htp.p('
');
--
htp.p('');
--
htp.p('');
--
l_index := 0;
--
FOR cust_rec IN (SELECT cust.cust_id cust_id
, cust.name name
FROM customers cust
, customer_intermediaries cuin
WHERE cust.cust_id = cuin.cust_id
AND ( EXISTS ( SELECT 1
FROM customer_intermediaries cuin1
, customers cust1
, customer_types cuty
WHERE cuin.inte_id = cuin1.inte_id
AND cust1.cust_id = cuin1.cust_id
AND cust1.cuty_id = cuty.cuty_id
AND cuty.cuty_id = caco_utilities.cuty_id_for_user )
OR caco_utilities.user_has_system = c_yes
OR caco_utilities.user_has_EFT_admin = c_yes)
AND cuin.inte_id <> cout_system_configuration.get_configuration_item('INTE_ID')
GROUP BY cust.cust_id, cust.name
ORDER BY name
) LOOP
--
l_index := l_index + 1;
--
OPEN c_cont(cust_rec.cust_id);
FETCH c_cont INTO l_open;
IF c_cont%NOTFOUND THEN
l_open := 'N';
END IF;
CLOSE c_cont;
htp.p('
');
htp.p('
' || cust_rec.name || '
');
htp.p('
' || '
');
htp.p('
');
--
END LOOP;
--
htp.p('');
htp.p('
');
htp.p('
');
--
END;
--
-- javascript routine to check all check boxes
--
PROCEDURE checkall_js IS
--
--
BEGIN
--
htp.p('
');
--
END;
--
-- javascript routine to check all check boxes which belong to customers with open contracts
--
PROCEDURE checkallopencontracts_js IS
--
--
BEGIN
--
htp.p('
');
--
END;
--
-- Output the standard html page headers including the document type
--
PROCEDURE standard_html_header IS
BEGIN
--
htp.p(' ');
--
wsgl.openpagehead(g_title);
caco_system.content_type;
htp.p('');
--
-- Following required to show a calender screen
--
htp.p(wsgjsl.openscript);
wsgjsl.output_invoke_cal_js(g_package_name
,'scrollbars=no,resizable=no,width=320,height=350');
htp.p(wsgjsl.closescript);
--
checkall_js;
checkallopencontracts_js;
--
htp.p(CHR(10) ||
'');
--
wsgl.closepagehead;
--
wsgl.openpagebody(FALSE);
--
htp.p(caco_system.menu);
--
END;
--
-- Entry procedure
--
PROCEDURE startup IS
--
l_submit_lbl VARCHAR2(255);
l_selectall_lbl VARCHAR2(255);
l_selectallopen_lbl VARCHAR2(255);
--
BEGIN
--
IF NOT caco_security.security_check(g_package_name) THEN
RETURN;
END IF;
--
l_submit_lbl := caco_utilities.get_module_text(c_submit);
l_selectall_lbl := caco_utilities.get_module_text(c_selectall);
l_selectallopen_lbl := caco_utilities.get_module_text(c_selectallopen);
--
standard_html_header;
--
htp.p('
');
--
htp.p(''); -- Submit_form
--
htp.p('
');
--
wsgl.closepagebody;
--
END;
--
-- Function to check the date format
--
FUNCTION invalid_date_format(p_date IN VARCHAR2) RETURN BOOLEAN IS
--
l_date DATE;
--
BEGIN
--
l_date := TO_DATE(p_date
,c_date_format);
--
RETURN(FALSE);
--
EXCEPTION
WHEN OTHERS THEN
RETURN(TRUE);
END;
--
-- Submit procedure called by the form
--
PROCEDURE create_messages(p_subject IN VARCHAR2
,p_message_text IN VARCHAR2
,p_active_from IN VARCHAR2
,p_active_to IN VARCHAR2
,p_syus_id IN VARCHAR2
,p_sms IN VARCHAR2 DEFAULT NULL
,p_cust_id IN owa_util.vc_arr DEFAULT g_empty_vc_array
,p_open IN owa_util.vc_arr DEFAULT g_empty_vc_array) IS
--
missing_params EXCEPTION;
missing_user_or_cust EXCEPTION;
date_in_past EXCEPTION;
dates_overlap EXCEPTION;
l_error_list caco_utilities.g_t_substitution_list;
l_empty_error_list caco_utilities.g_t_substitution_list;
l_error VARCHAR2(255);
l_error_type exception_messages.exme_type%TYPE;
l_cust_tab t_cust_tab;
ex_invalid_date_format EXCEPTION;
l_message_sent_to_lbl VARCHAR2(255);
l_temp_link VARCHAR2(255);
--
CURSOR c_cust(cp_cust_id IN customers.cust_id%TYPE) IS
SELECT NAME
FROM customers
WHERE cust_id = cp_cust_id;
--
l_cust_name customers.NAME%TYPE;
--
BEGIN
--
standard_html_header;
--
l_error_list := l_empty_error_list;
l_message_sent_to_lbl := caco_utilities.get_module_text(c_message_sent_to);
--
-- Check mandatory parameters are entered.
--
IF p_subject IS NULL THEN
--
l_error_list(1) := g_subject_lbl;
RAISE missing_params;
--
ELSIF p_message_text IS NULL THEN
--
l_error_list(1) := g_message_text_lbl;
RAISE missing_params;
--
ELSIF p_active_from IS NULL THEN
--
l_error_list(1) := g_active_from_lbl;
RAISE missing_params;
--
ELSIF p_active_to IS NULL THEN
--
l_error_list(1) := g_active_to_lbl;
RAISE missing_params;
-- a system user or at least 1 customer checkbox must be selected
ELSIF p_cust_id.COUNT < 1 AND p_syus_id IS NULL THEN
--
l_error_list(1) := g_customers;
RAISE missing_user_or_cust;
--
END IF;
--
-- Check dates.
--
IF invalid_date_format(p_active_from) THEN
RAISE ex_invalid_date_format;
END IF;
IF invalid_date_format(p_active_to) THEN
RAISE ex_invalid_date_format;
END IF;
--
IF to_date(p_active_from,c_date_format) < trunc(SYSDATE) THEN
--
RAISE date_in_past;
--
ELSIF to_date(p_active_to,c_date_format) < to_date(p_active_from,c_date_format) THEN
--
RAISE dates_overlap;
--
END IF;
--
-- loop around the customers selected
--
FOR i IN 1 .. p_cust_id.COUNT LOOP
--
OPEN c_cust(p_cust_id(i));
FETCH c_cust
INTO l_cust_name;
CLOSE c_cust;
--
l_cust_tab(i) := l_cust_name;
--
-- Create messages for customers selected
--
amfr_message.create_message(p_subject => p_subject,
p_message => p_message_text,
p_cust_id => p_cust_id(i),
p_sypr_id => NULL,
p_syus_id => NULL,
p_active_from => to_date(p_active_from,c_date_format),
p_active_to => to_date(p_active_to,c_date_format),
p_email_sms => NVL(p_sms,'N'));
--
END LOOP;
--
-- now deal with the system user
--
IF p_syus_id IS NOT NULL THEN
--
-- Create messages for system user selected
--
amfr_message.create_message(p_subject => p_subject,
p_message => p_message_text,
p_cust_id => NULL,
p_sypr_id => NULL,
p_syus_id => p_syus_id,
p_active_from => to_date(p_active_from,c_date_format),
p_active_to => to_date(p_active_to,c_date_format),
p_email_sms => NVL(p_sms,'N'));
--
END IF;
htp.p('
'||caco_utilities.get_module_text(c_heading)||'
');
--
wsgl.displaymessage(p_type => wsgl.mess_success
,p_mess => l_message_sent_to_lbl);
--
IF p_syus_id IS NOT NULL THEN
htp.p(' ');
htp.p('' || g_system_user_lbl || '');
htp.p(' ');
htp.p('
' || caco_utilities.get_syus_name(p_syus_id) || '
');
END IF;
--
IF l_cust_tab.COUNT > 0 THEN
htp.p(' ');
htp.p('' || g_customers || '');
htp.p(' ');
--
FOR r IN 1 .. l_cust_tab.COUNT LOOP
--
htp.p('
' || l_cust_tab(r) || '
');
--
END LOOP;
END IF;
htp.p(' ');
l_temp_link := caco_system.dad_path||'amfrw021$.startup';
--
htp.p('');
--
wsgl.closepagebody;
--
COMMIT;
--
EXCEPTION
WHEN ex_invalid_date_format THEN
--
caco_utilities.get_exception_message(p_exception_number => -20538
,p_message => l_error
,p_exme_type => l_error_type
,p_substitution_list => l_error_list
,p_language => caco_utilities.get_syus_lang);
--
wsgl.displaymessage(p_type => wsgl.mess_error
,p_mess => l_error);
--
WHEN missing_params THEN
--
caco_utilities.get_exception_message(p_exception_number => -20506
,p_message => l_error
,p_exme_type => l_error_type
,p_substitution_list => l_error_list
,p_language => caco_utilities.get_syus_lang);
--
wsgl.displaymessage(p_type => wsgl.mess_error
,p_mess => l_error);
--
WHEN missing_user_or_cust THEN
--
caco_utilities.get_exception_message(p_exception_number => -20553
,p_message => l_error
,p_exme_type => l_error_type
,p_substitution_list => l_error_list
,p_language => caco_utilities.get_syus_lang);
--
wsgl.displaymessage(p_type => wsgl.mess_error
,p_mess => l_error);
--
WHEN date_in_past THEN
--
caco_utilities.get_exception_message(p_exception_number => -20551
,p_message => l_error
,p_exme_type => l_error_type
,p_substitution_list => l_error_list
,p_language => caco_utilities.get_syus_lang);
--
wsgl.displaymessage(p_type => wsgl.mess_error
,p_mess => l_error);
--
WHEN dates_overlap THEN
--
caco_utilities.get_exception_message(p_exception_number => -20552
,p_message => l_error
,p_exme_type => l_error_type
,p_substitution_list => l_error_list
,p_language => caco_utilities.get_syus_lang);
--
wsgl.displaymessage(p_type => wsgl.mess_error
,p_mess => l_error);
--
WHEN OTHERS THEN
--
l_error := 'ERROR in amfrw021$.create_messages: ' || SQLERRM;
--
ROLLBACK;
--
wsgl.displaymessage(p_type => wsgl.mess_error
,p_mess => l_error);
END;
--
-- About procedure
--
FUNCTION about RETURN VARCHAR2 IS
BEGIN
RETURN(g_package_name || chr(10) || g_revision || chr(10) || g_header);
END about;
--
-- Package initialisation
--
BEGIN
-- Initialization
NULL;
END amfrw021$;
/