284 lines
9.5 KiB
Plaintext
284 lines
9.5 KiB
Plaintext
CREATE OR REPLACE PACKAGE BODY amfr_message IS
|
|
--
|
|
--
|
|
--
|
|
g_suca_id subscription_categories.suca_id%TYPE := efno_msgsubs.get_suca_id( p_suca_group => 'Notification'
|
|
, p_suca_name => 'Commercial');
|
|
--
|
|
PROCEDURE send_messages ( p_bubm_id bulletin_board_messages.bubm_id%TYPE
|
|
, p_syus_id system_users.syus_id%TYPE
|
|
) IS
|
|
--
|
|
--
|
|
BEGIN
|
|
--
|
|
FOR bubm_rec IN ( SELECT bubm.subject
|
|
,bubm.message_text
|
|
FROM bulletin_board_messages bubm
|
|
WHERE bubm.bubm_id = p_bubm_id
|
|
) LOOP
|
|
--
|
|
-- Should only loop once
|
|
--
|
|
efno_msgsubs.send_messages( p_syus_id => p_syus_id
|
|
, p_suca_id => g_suca_id
|
|
, p_email_subject_en => bubm_rec.subject
|
|
, p_email_content_en => bubm_rec.message_text
|
|
, p_sms_content_en => bubm_rec.subject
|
|
);
|
|
--
|
|
END LOOP;
|
|
--
|
|
END send_messages;
|
|
--
|
|
FUNCTION check_unread_messages ( p_syus_id IN system_users.syus_id%TYPE ) RETURN BOOLEAN IS
|
|
--
|
|
lb_found BOOLEAN;
|
|
--
|
|
BEGIN
|
|
--
|
|
-- Default indicator to not found
|
|
--
|
|
lb_found := FALSE;
|
|
--
|
|
-- Loop around all active unread messages for the current user
|
|
--
|
|
FOR cur_mere_rec IN (SELECT NULL
|
|
FROM message_recipient mere
|
|
,bulletin_board_messages bbme
|
|
WHERE mere.bubm_id = bbme.bubm_id
|
|
AND mere.syus_id = p_syus_id
|
|
AND mere.message_read = 'N'
|
|
AND SYSDATE BETWEEN bbme.active_from AND bbme.active_to) LOOP
|
|
--
|
|
-- We've found a record, set indicator to true
|
|
--
|
|
lb_found := TRUE;
|
|
--
|
|
EXIT;
|
|
--
|
|
END LOOP;
|
|
--
|
|
-- Return the indicator
|
|
--
|
|
RETURN lb_found;
|
|
--
|
|
END check_unread_messages;
|
|
--
|
|
PROCEDURE mark_message_as_read ( p_bubm_id IN bulletin_board_messages.bubm_id%TYPE
|
|
, p_syus_id IN system_users.syus_id%TYPE ) IS
|
|
--
|
|
--
|
|
BEGIN
|
|
--
|
|
--
|
|
--
|
|
UPDATE message_recipient
|
|
SET message_recipient.message_read = 'Y'
|
|
WHERE message_recipient.bubm_id = p_bubm_id
|
|
AND message_recipient.syus_id = p_syus_id
|
|
AND message_recipient.message_read = 'N'
|
|
AND p_syus_id = caco_utilities.get_syus_id
|
|
;
|
|
--
|
|
END mark_message_as_read;
|
|
--
|
|
PROCEDURE create_message ( p_bubm_id IN bulletin_board_messages.bubm_id%TYPE
|
|
, p_cust_id IN customers.cust_id%TYPE
|
|
, p_sypr_id IN system_profiles.sypr_id%TYPE
|
|
, p_syus_id IN system_users.syus_id%TYPE
|
|
, p_email_sms IN VARCHAR2 DEFAULT 'Y' ) IS
|
|
--
|
|
--
|
|
BEGIN
|
|
--
|
|
--
|
|
--
|
|
FOR i IN ( SELECT DISTINCT syus.syus_id
|
|
FROM system_users syus
|
|
, user_profiles uspr
|
|
, intermediary_users inus
|
|
, customer_intermediaries cuin
|
|
WHERE syus.syus_id = uspr.syus_id
|
|
AND ( uspr.sypr_id = p_sypr_id
|
|
OR p_sypr_id IS NULL )
|
|
AND syus.syus_id = inus.syus_id
|
|
AND inus.inte_id = cuin.inte_id
|
|
AND ( cuin.cust_id = p_cust_id
|
|
OR p_cust_id IS NULL )
|
|
AND ( syus.syus_id = p_syus_id
|
|
OR p_syus_id IS NULL )
|
|
AND syus.syus_id <> caco_utilities.get_system_user
|
|
AND syus.period_start < SYSDATE
|
|
AND ( syus.period_end > SYSDATE
|
|
OR syus.period_end IS NULL)
|
|
AND syus.user_locked = 'N'
|
|
AND inus.inte_id <> caco_utilities.get_system_intermediary
|
|
AND cuin.cust_id <> caco_utilities.get_system_customer
|
|
AND cuin.cust_id IN (SELECT cust_id
|
|
FROM cust_by_cuty_v)
|
|
) LOOP
|
|
--
|
|
-- Inser the message recipient records for the supplied parameters
|
|
--
|
|
INSERT INTO message_recipient ( bubm_id
|
|
, syus_id
|
|
, message_read
|
|
)
|
|
VALUES ( p_bubm_id
|
|
, i.syus_id
|
|
, 'N'
|
|
);
|
|
--
|
|
-- Now send via email or SMS
|
|
--
|
|
IF p_email_sms = 'Y' THEN
|
|
send_messages ( p_bubm_id => p_bubm_id
|
|
, p_syus_id => i.syus_id
|
|
);
|
|
END IF;
|
|
--
|
|
END LOOP;
|
|
--
|
|
END create_message;
|
|
--
|
|
PROCEDURE create_message ( p_subject IN bulletin_board_messages.subject%TYPE
|
|
, p_message IN bulletin_board_messages.message_text%TYPE
|
|
, p_cust_id IN customers.cust_id%TYPE
|
|
, p_sypr_id IN system_profiles.sypr_id%TYPE
|
|
, p_syus_id IN system_users.syus_id%TYPE
|
|
, p_active_from IN bulletin_board_messages.active_from%TYPE DEFAULT TRUNC(SYSDATE)
|
|
, p_active_to IN bulletin_board_messages.active_to%TYPE DEFAULT TRUNC(SYSDATE) + 14
|
|
, p_email_sms IN VARCHAR2 DEFAULT 'Y' ) IS
|
|
--
|
|
bbme_row cg$bulletin_board_messages.cg$row_type;
|
|
bbme_ind cg$bulletin_board_messages.cg$ind_type;
|
|
--
|
|
BEGIN
|
|
--
|
|
-- Check parameters
|
|
--
|
|
IF p_subject IS NULL
|
|
OR p_message IS NULL
|
|
OR p_active_from IS NULL
|
|
OR p_active_to IS NULL
|
|
OR ( p_cust_id IS NULL
|
|
AND p_sypr_id IS NULL
|
|
AND p_syus_id IS NULL ) THEN
|
|
--
|
|
-- Mandatory parameter missing
|
|
--
|
|
caco_utilities.raise_exception_error(-20100);
|
|
--
|
|
ELSE
|
|
--
|
|
-- Parameters OK, continuing
|
|
--
|
|
bbme_row.sypr_id := p_sypr_id;
|
|
bbme_row.cust_id := p_cust_id;
|
|
bbme_row.active_from := p_active_from;
|
|
bbme_row.active_to := p_active_to;
|
|
bbme_row.subject := p_subject;
|
|
bbme_row.message_text := p_message;
|
|
--
|
|
cg$bulletin_board_messages.ins(cg$rec => bbme_row
|
|
,cg$ind => bbme_ind
|
|
,do_ins => TRUE);
|
|
--
|
|
create_message ( p_bubm_id => bbme_row.bubm_id
|
|
, p_cust_id => bbme_row.cust_id
|
|
, p_sypr_id => bbme_row.sypr_id
|
|
, p_syus_id => p_syus_id
|
|
, p_email_sms => p_email_sms
|
|
);
|
|
--
|
|
END IF;
|
|
--
|
|
END create_message;
|
|
--
|
|
PROCEDURE create_message ( p_subject IN bulletin_board_messages.subject%TYPE
|
|
, p_message IN bulletin_board_messages.message_text%TYPE
|
|
, p_cust_name IN customers.name%TYPE
|
|
, p_sypr_id IN system_profiles.sypr_id%TYPE
|
|
, p_syus_id IN system_users.syus_id%TYPE
|
|
, p_active_from IN bulletin_board_messages.active_from%TYPE DEFAULT TRUNC(SYSDATE)
|
|
, p_active_to IN bulletin_board_messages.active_to%TYPE DEFAULT TRUNC(SYSDATE) + 14 ) IS
|
|
--
|
|
l_cust_id customers.cust_id%TYPE := NULL;
|
|
lb_found BOOLEAN := FALSE;
|
|
--
|
|
BEGIN
|
|
--
|
|
-- Check parameters
|
|
--
|
|
IF p_subject IS NULL
|
|
OR p_message IS NULL
|
|
OR p_active_from IS NULL
|
|
OR p_active_to IS NULL
|
|
OR ( p_cust_name IS NULL
|
|
AND p_sypr_id IS NULL
|
|
AND p_syus_id IS NULL ) THEN
|
|
--
|
|
-- Mandatory parameter missing
|
|
--
|
|
caco_utilities.raise_exception_error(-20100);
|
|
--
|
|
ELSE
|
|
--
|
|
-- Parameters OK, continuing
|
|
--
|
|
IF p_cust_name IS NOT NULL THEN
|
|
--
|
|
-- Check that the customer name is valid
|
|
--
|
|
FOR i IN (SELECT cust.cust_id
|
|
FROM customers cust
|
|
WHERE cust.name = p_cust_name ) LOOP
|
|
--
|
|
l_cust_id := i.cust_id;
|
|
lb_found := TRUE;
|
|
--
|
|
END LOOP;
|
|
--
|
|
IF NOT lb_found THEN
|
|
--
|
|
-- Customer was not found
|
|
--
|
|
caco_utilities.raise_exception_error(-20508); -- This specified customer does not exist.
|
|
--
|
|
END IF;
|
|
--
|
|
END IF;
|
|
--
|
|
create_message( p_subject => p_subject
|
|
, p_message => p_message
|
|
, p_cust_id => l_cust_id
|
|
, p_sypr_id => p_sypr_id
|
|
, p_syus_id => p_syus_id
|
|
, p_active_from => p_active_from
|
|
, p_active_to => p_active_to );
|
|
--
|
|
END IF;
|
|
--
|
|
END create_message;
|
|
--
|
|
FUNCTION about RETURN VARCHAR2 IS
|
|
--
|
|
--
|
|
BEGIN
|
|
--
|
|
--
|
|
--
|
|
RETURN ( g_revision || CHR(10) || g_header );
|
|
--
|
|
END about;
|
|
--
|
|
BEGIN
|
|
/**
|
|
-- Initialization
|
|
*/
|
|
NULL;
|
|
--
|
|
END amfr_message;
|
|
/
|