diff --git a/Modules/mip_parties.pck b/Modules/mip_parties.pck index fc4da0e..8e0e8da 100644 --- a/Modules/mip_parties.pck +++ b/Modules/mip_parties.pck @@ -10,6 +10,16 @@ CREATE OR REPLACE PACKAGE mip_parties AS FUNCTION get_user_id(p_username IN VARCHAR2) RETURN NUMBER; FUNCTION get_user_role(p_username IN VARCHAR2) RETURN VARCHAR2; -- + /* + FUNCTION check_user_role + - checks the role keycode given exists for a supplied username. + - This function searches the parties table for a matching username and role + - if found then true is returned. + %param p_username - the name of the user you want to get the id for. + %param p_role - the role you wish to check against + */ + FUNCTION check_user_role(p_username IN VARCHAR2, p_role IN VARCHAR2) RETURN BOOLEAN; + -- /** get the password created date for the given username and password %return DATE the date the password was created for authenticated username and password combination @@ -85,6 +95,7 @@ CREATE OR REPLACE PACKAGE mip_parties AS p_comments IN VARCHAR2, p_id IN INTEGER, p_prty_type IN VARCHAR2, + p_tripartite_member IN VARCHAR2, p_password IN VARCHAR2, p_expire_pword IN NUMBER); -- @@ -124,6 +135,18 @@ CREATE OR REPLACE PACKAGE mip_parties AS p_contact_value IN VARCHAR2); -- + /** + PROCEDURE - update_contact_details + allows the contact mechanisms to be updated, setting the old mechanism's end date + %param p_prty_id - the ID of the party + %param p_contact_mech_type - the type of contact mechanism being created + %param p_contact_value - the value of the contact mechanism + + */ + PROCEDURE update_contact_details(p_prty_id IN parties.id%TYPE, + p_contact_mech_type IN VARCHAR2, + p_contact_value IN VARCHAR2); + /** allows a role to be assigned to a party @@ -143,6 +166,20 @@ CREATE OR REPLACE PACKAGE mip_parties AS p_to_prty_id IN VARCHAR2, p_to_prty_role IN VARCHAR2); -- + + /** + expires any old addresses without an end date. To be used when a new address is assigned to a party + The address's end date is set to today as that is when the new address is valid from. No setting + addresses to be used in the future. + + %param p_prty_id the ID of the party + %param p_addr_code the code of the new address. + %param p_addr_type the type of address HOME/OFFICE + */ + PROCEDURE expire_old_addresses(p_prty_id IN parties.id%TYPE, + p_addr_code IN addresses.code%TYPE, + p_paddr_type IN party_address_roles.rt_code%TYPE); + -- END mip_parties; / CREATE OR REPLACE PACKAGE BODY mip_parties AS @@ -194,6 +231,33 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS RETURN NULL; END get_user_role; + /* + FUNCTION check_user_role + - checks the role keycode given exists for a supplied username. + - This function searches the parties table for a matching username and role + - if found then true is returned. + %param p_username - the name of the user you want to get the id for. + %param p_role - the role you wish to check against + */ + FUNCTION check_user_role(p_username IN VARCHAR2, p_role IN VARCHAR2) RETURN BOOLEAN AS + rolecode VARCHAR2(80); + CURSOR c_userrole IS + SELECT rt_code + FROM party_roles + WHERE prty_id = get_user_id(p_username) + AND upper(rt_code) = upper(p_role); + BEGIN + OPEN c_userrole; + FETCH c_userrole + INTO rolecode; + CLOSE c_userrole; + + RETURN TRUE; + EXCEPTION + WHEN OTHERS THEN + RETURN NULL; + END check_user_role; + -- -- /** get the password created date for the given username and password @@ -512,6 +576,7 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS p_comments IN VARCHAR2, p_id IN INTEGER, p_prty_type IN VARCHAR2, + p_tripartite_member IN VARCHAR2, p_password IN VARCHAR2, p_expire_pword IN NUMBER) IS -- @@ -534,7 +599,8 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS last_name, personal_title, comments, - prty_type) + prty_type, + tripartite_member) VALUES (p_id, p_manu_ref, @@ -552,7 +618,8 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS p_last_name, p_personal_title, p_comments, - p_prty_type); + p_prty_type, + p_tripartite_member); -- if we created a user they need a password creating IF upper(p_prty_type) = 'PERS' THEN @@ -680,6 +747,47 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS END create_party_contact_details; -- + /** + PROCEDURE - update_contact_details + allows the contact mechanisms to be updated, setting the old mechanism's end date + %param p_prty_id - the ID of the party + %param p_contact_mech_type - the type of contact mechanism being created + %param p_contact_value - the value of the contact mechanism + + */ + PROCEDURE update_contact_details(p_prty_id IN parties.id%TYPE, + p_contact_mech_type IN VARCHAR2, + p_contact_value IN VARCHAR2) IS + l_current_come_id contact_mechanisms.id%TYPE; + l_current_come_value VARCHAR2(100); + BEGIN + BEGIN + SELECT vccm.come_id, vccm.Contact_value + INTO l_current_come_id, l_current_come_value + FROM v_current_contact_mechanisms vccm + WHERE vccm.PRTY_ID = p_prty_id + AND vccm.CODE = p_contact_mech_type; + EXCEPTION + WHEN no_data_found THEN --no current come exists, therefore just create one. + create_party_contact_details(p_prty_id => p_prty_id, + p_contact_mech_type => p_contact_mech_type, + p_contact_value => p_contact_value); + END; + + --check if it's a different value, if so, end this one and create a new one. + IF l_current_come_value = p_contact_value THEN + NULL; -- no change to store + ELSE + UPDATE party_contact_mechanisms pcome + SET pcome.end_date = SYSDATE + WHERE pcome.come_id = l_current_come_id; + + create_party_contact_details(p_prty_id => p_prty_id, + p_contact_mech_type => p_contact_mech_type, + p_contact_value => p_contact_value); + END IF; + END update_contact_details; + /** allows a role to be assigned to a party @@ -759,5 +867,30 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS NULL); END create_relationship; -- + + /** + expires any old addresses without an end date. To be used when a new address is assigned to a party + The address's end date is set to today as that is when the new address is valid from. No setting + addresses to be used in the future. + + %param p_prty_id the ID of the party + %param p_addr_code the code of the new address. + %param p_addr_type the type of address HOME/OFFICE + */ + PROCEDURE expire_old_addresses(p_prty_id IN parties.id%TYPE, + p_addr_code IN addresses.code%TYPE, + p_paddr_type IN party_address_roles.rt_code%TYPE) IS + BEGIN + UPDATE party_addresses paddr + SET paddr.end_date = SYSDATE, + paddr.comments = paddr.comments ||' Address end date set by '||v('APP_USER') + WHERE paddr.prty_id = p_prty_id + AND NOT paddr.addr_code = p_addr_code --don't want to update the new one!!! + AND paddr.end_date IS NULL + AND paddr.addr_code IN (SELECT paddr_roles.paddr_addr_code + FROM party_address_roles paddr_roles + WHERE paddr_roles.rt_code = p_paddr_type); + + END expire_old_addresses; END mip_parties; /