ALTER TABLE CUSTOMERS DROP COLUMN LETTER_SUBJECT
/
ALTER TABLE CUSTOMERS DROP COLUMN LETTER_CONTENT
/
ALTER TABLE CUSTOMERS DROP COLUMN CONFIRMATION_HEADER
/
ALTER TABLE CUSTOMERS DROP COLUMN CONFIRMATION_ADDRESS
/

PROMPT Altering Table 'CUSTOMERS' 
ALTER TABLE CUSTOMERS 
 ADD (NOM_CONF_SUBJECT VARCHAR2(255)
 ,NOM_CONF_CONTENT VARCHAR2(4000)
 ,COM_CONF_SUBJECT VARCHAR2(255)
 ,COM_CONF_CONTENT VARCHAR2(4000)
 )
/

prompt PL/SQL Developer import file
prompt Created on 02 May 2007 by gilberta
set feedback off
set define off
prompt Deleting MODULE_TEXT...
delete from MODULE_TEXT where text_number IN (2466,2467,2468,2469);
commit;
prompt Loading MODULE_TEXT...
insert into MODULE_TEXT (MTXT_ID, TEXT_NUMBER, TEXT, LANGUAGE)
values (20677, 2466, 'Nom Confirmation Subject*', 'EN');
insert into MODULE_TEXT (MTXT_ID, TEXT_NUMBER, TEXT, LANGUAGE)
values (20678, 2467, 'Nom Confirmation Content*', 'EN');
insert into MODULE_TEXT (MTXT_ID, TEXT_NUMBER, TEXT, LANGUAGE)
values (20679, 2468, 'Com Confirmation Subject*', 'EN');
insert into MODULE_TEXT (MTXT_ID, TEXT_NUMBER, TEXT, LANGUAGE)
values (20680, 2469, 'Com Confirmation Content*', 'EN');
commit;
prompt 4 records loaded
set feedback on
set define on
prompt Done.




PROMPT Creating Trigger 'POI_AUDIT_CUST'
CREATE OR REPLACE TRIGGER POI_AUDIT_CUST
 AFTER INSERT
 ON CUSTOMERS
 FOR EACH ROW
DECLARE

  --   
  CURSOR c_cuty IS
    SELECT description
    FROM   customer_types
    WHERE  cuty_id = :new.cuty_id;
  --
  CURSOR c_syus IS
    SELECT first_name||' '||last_name
    FROM   system_users  
    WHERE  syus_id = :new.kam_manager_syus_id;
  --
  l_cuty_desc customer_types.description%TYPE;
  l_kam_manager_new VARCHAR2(255);
  --
BEGIN
  --
  OPEN c_cuty;
  FETCH c_cuty INTO l_cuty_desc;
  CLOSE c_cuty;
  --
  amfr_journal.log_transaction('INSERT',
                               'CUSTOMERS',
                               amfr_journal.g_name_value_tab, -- Empty table
                               name_value_tab(
                                              name_value_rec('CUSTOMER IDENTIFIER',:new.cust_id),
                                              name_value_rec('CUSTOMER CODE',:new.CODE),                           
                                              name_value_rec('CUSTOMER NAME',:new.NAME),                           
                                              name_value_rec('PERIOD_START',:new.PERIOD_START),                   
                                              name_value_rec('PERIOD_END',:new.PERIOD_END),
                                              name_value_rec('CREATED_BY',:new.CREATED_BY),                     
                                              name_value_rec('CREATED_ON',:new.CREATED_ON),                     
                                              name_value_rec('CUSTOMER DESCRIPTION',:new.DESCRIPTION),                    
                                              name_value_rec('UPDATED_BY',:new.UPDATED_BY),                     
                                              name_value_rec('UPDATED_ON',:new.UPDATED_ON),                     
                                              name_value_rec('EMAIL ADDRESS',:new.EMAIL_ADDRESS),                  
                                              name_value_rec('TELEPHONE',:new.TELEPHONE),                      
                                              name_value_rec('FAX',:new.FAX),                            
                                              name_value_rec('CUSTOMER TYPE',l_cuty_desc),                        
                                              name_value_rec('PRIMARY CONTACT',:new.PRIMARY_CONTACT),                
                                              name_value_rec('KAM MANAGER',l_kam_manager_new),                    
                                              name_value_rec('KAM TELEPHONE',:new.KAM_TELEPHONE),                  
                                              name_value_rec('CUSTOMER STATUS',:new.STATUS),                        
                                              name_value_rec('NOMINATION EMAIL SUBJECT',:new.nom_conf_subject),
                                              name_value_rec('NOMINATION EMAIL CONTENT',:new.nom_conf_content),
                                              name_value_rec('CONFIRMATION EMAIL SUBJECT',:new.com_conf_subject),
                                              name_value_rec('CONFIRMATION EMAIL CONTENT',:new.com_conf_content),
                                              name_value_rec('AUTO GENERATE CONFIRMATION AM',:new.AUTO_GEN_CONF_AM),              
                                              name_value_rec('AUTO GENERATE CONFIRMATION PM',:new.AUTO_GEN_CONF_PM),              
                                              name_value_rec('IND DEADLINE FOR NOM SUBMIS',:new.IND_DEADLINE_FOR_NOM_SUBMIT),
                                              name_value_rec('PRIMARY CONTACT TELEPHONE NO',:new.PRIMARY_CONTACT_TEL)
                                              )
                                 );
  --  
END;
/
SHOW ERROR


PROMPT Creating Trigger 'POU_AUDIT_CUST'
CREATE OR REPLACE TRIGGER POU_AUDIT_CUST
 AFTER UPDATE OF KAM_TELEPHONE
, AUTO_GEN_CONF_PM
, COM_CONF_SUBJECT
, AUTO_GEN_CONF_AM
, PRIMARY_CONTACT
, CREATED_ON
, CUTY_ID
, NOM_CONF_CONTENT
, DESCRIPTION
, NOM_CONF_SUBJECT
, FAX
, IND_DEADLINE_FOR_NOM_SUBMIT
, TELEPHONE
, CODE
, UPDATED_ON
, PERIOD_END
, CREATED_BY
, STATUS
, NAME
, CUST_ID
, EMAIL_ADDRESS
, KAM_MANAGER_SYUS_ID
, PERIOD_START
, PRIMARY_CONTACT_TEL
, UPDATED_BY
, COM_CONF_CONTENT
 ON CUSTOMERS
 FOR EACH ROW
DECLARE

  --   
  CURSOR c_cuty_old IS
    SELECT description
    FROM   customer_types
    WHERE  cuty_id = :old.cuty_id;
  --  
  CURSOR c_cuty_new IS
    SELECT description
    FROM   customer_types
    WHERE  cuty_id = :old.cuty_id;
  --
  CURSOR c_syus(cp_syus_id IN NUMBER) IS
    SELECT first_name||' '||last_name
    FROM system_users
    WHERE  syus_id = cp_syus_id;
  --
  l_cuty_desc_old customer_types.description%TYPE;
  l_cuty_desc_new customer_types.description%TYPE;
  l_kam_manager_old VARCHAR2(255);
  l_kam_manager_new VARCHAR2(255);
  --
BEGIN
  --
  OPEN c_cuty_old;
  FETCH c_cuty_old INTO l_cuty_desc_old;
  CLOSE c_cuty_old;
  --
  OPEN c_cuty_new;
  FETCH c_cuty_new INTO l_cuty_desc_new;
  CLOSE c_cuty_new;
  --
  OPEN c_syus(:old.KAM_MANAGER_SYUS_ID);
  FETCH c_syus INTO l_kam_manager_old;
  CLOSE c_syus;
  --
  OPEN c_syus(:new.KAM_MANAGER_SYUS_ID);
  FETCH c_syus INTO l_kam_manager_new;
  CLOSE c_syus;
  --
  amfr_journal.log_transaction('UPDATE',
                               'CUSTOMERS',
                               name_value_tab(
                                              name_value_rec('CUSTOMER IDENTIFIER',:old.cust_id),
                                              name_value_rec('CUSTOMER CODE',:old.CODE),                           
                                              name_value_rec('CUSTOMER NAME',:old.NAME),                           
                                              name_value_rec('PERIOD_START',:old.PERIOD_START),                   
                                              name_value_rec('PERIOD_END',:old.PERIOD_END),
                                              name_value_rec('CREATED_BY',:old.CREATED_BY),                     
                                              name_value_rec('CREATED_ON',:old.CREATED_ON),                     
                                              name_value_rec('CUSTOMER DESCRIPTION',:old.DESCRIPTION),                    
                                              name_value_rec('UPDATED_BY',:old.UPDATED_BY),                     
                                              name_value_rec('UPDATED_ON',:old.UPDATED_ON),                     
                                              name_value_rec('EMAIL ADDRESS',:old.EMAIL_ADDRESS),                  
                                              name_value_rec('TELEPHONE',:old.TELEPHONE),                      
                                              name_value_rec('FAX',:old.FAX),                            
                                              name_value_rec('CUSTOMER TYPE',l_cuty_desc_old),
                                              name_value_rec('PRIMARY CONTACT',:old.PRIMARY_CONTACT),                
                                              name_value_rec('KAM MANAGER',l_kam_manager_old),                    
                                              name_value_rec('KAM TELEPHONE',:old.KAM_TELEPHONE),                  
                                              name_value_rec('CUSTOMER STATUS',:old.STATUS),                        
                                              name_value_rec('NOMINATION EMAIL SUBJECT',:old.nom_conf_subject),
                                              name_value_rec('NOMINATION EMAIL CONTENT',:old.nom_conf_content),
                                              name_value_rec('CONFIRMATION EMAIL SUBJECT',:old.com_conf_subject),
                                              name_value_rec('CONFIRMATION EMAIL CONTENT',:old.com_conf_content),      
                                              name_value_rec('AUTO GENERATE CONFIRMATION AM',:old.AUTO_GEN_CONF_AM),              
                                              name_value_rec('AUTO GENERATE CONFIRMATION PM',:old.AUTO_GEN_CONF_PM),              
                                              name_value_rec('IND DEADLINE FOR NOM SUBMIS',:old.IND_DEADLINE_FOR_NOM_SUBMIT),
                                              name_value_rec('PRIMARY CONTACT TELEPHONE NO',:old.PRIMARY_CONTACT_TEL)
                                              ),
                               name_value_tab(
                                              name_value_rec('CUSTOMER IDENTIFIER',:new.cust_id),
                                              name_value_rec('CUSTOMER CODE',:new.CODE),                           
                                              name_value_rec('CUSTOMER NAME',:new.NAME),                           
                                              name_value_rec('PERIOD_START',:new.PERIOD_START),                   
                                              name_value_rec('PERIOD_END',:new.PERIOD_END),
                                              name_value_rec('CREATED_BY',:new.CREATED_BY),                     
                                              name_value_rec('CREATED_ON',:new.CREATED_ON),                     
                                              name_value_rec('CUSTOMER DESCRIPTION',:new.DESCRIPTION),                    
                                              name_value_rec('UPDATED_BY',:new.UPDATED_BY),                     
                                              name_value_rec('UPDATED_ON',:new.UPDATED_ON),                     
                                              name_value_rec('EMAIL ADDRESS',:new.EMAIL_ADDRESS),                  
                                              name_value_rec('TELEPHONE',:new.TELEPHONE),                      
                                              name_value_rec('FAX',:new.FAX),                            
                                              name_value_rec('CUSTOMER TYPE',l_cuty_desc_new),                        
                                              name_value_rec('PRIMARY CONTACT',:new.PRIMARY_CONTACT),                
                                              name_value_rec('KAM MANAGER',l_kam_manager_new),                    
                                              name_value_rec('KAM TELEPHONE',:new.KAM_TELEPHONE),                  
                                              name_value_rec('CUSTOMER STATUS',:new.STATUS),                        
                                              name_value_rec('NOMINATION EMAIL SUBJECT',:new.nom_conf_subject),
                                              name_value_rec('NOMINATION EMAIL CONTENT',:new.nom_conf_content),
                                              name_value_rec('CONFIRMATION EMAIL SUBJECT',:new.com_conf_subject),
                                              name_value_rec('CONFIRMATION EMAIL CONTENT',:new.com_conf_content),                                              name_value_rec('AUTO GENERATE CONFIRMATION AM',:new.AUTO_GEN_CONF_AM),              
                                              name_value_rec('AUTO GENERATE CONFIRMATION PM',:new.AUTO_GEN_CONF_PM),              
                                              name_value_rec('IND DEADLINE FOR NOM SUBMIS',:new.IND_DEADLINE_FOR_NOM_SUBMIT),
                                              name_value_rec('PRIMARY CONTACT TELEPHONE NO',:new.PRIMARY_CONTACT_TEL)
                                              )
                              );
  --  
END;
/
SHOW ERROR

