CREATE OR REPLACE TRIGGER OAC_SPN_BRI
BEFORE INSERT ON OAC_STG_PARTNERS FOR EACH ROW
DECLARE
  --
  --  declaration section
  --
  cn_module  varchar2(2000) := 'OAC_SPN_BRI';
  v_result NUMBER(10);
  --
BEGIN

  v_result := CONN.CONN_PARTNERS.verwerk_partner 
               ( :new.id
               , :new.Pnr_Type
               , :new.Pnr_Partnernummer
               , :new.Pnr_Naam
               , :new.Pnr_Telefoon
               , :new.Pnr_Mobiel
               , :new.Pnr_Fax
               , :new.Pnr_Email
               , :new.Pnr_Betalingsconditie
               , :new.Pnr_Mutatie_Ind
               , :new.Pst_Adres
               , :new.Pst_Postcode
               , :new.Pst_Plaats
               , :new.Pst_Land
               , :new.Pst_Mutatie_Ind
               , :new.Bzk_Adres
               , :new.Bzk_Postcode
               , :new.Bzk_Plaats
               , :new.Bzk_Land
               , :new.Bzk_Mutatie_Ind);
               
  IF v_result > 0 THEN
  
    :new.Verwerkt_Facilitor := sysdate;
    
    -- Force trigger
    UPDATE OAC_STG_CONTACTPERSOON
    SET    ID = ID
    WHERE  PARTNER_ID = :new.id;
    
  END IF;
               
EXCEPTION WHEN OTHERS THEN
  raise_application_error(-20000, sqlerrm||' '||cn_module);
END;
/

CREATE OR REPLACE TRIGGER OAC_STG_AFU
AFTER UPDATE ON OAC_STG_CONTACTPERSOON FOR EACH ROW
DECLARE
  --
  --  declaration section
  --
  cn_module  varchar2(2000) := 'OAC_STG_AFU';
  v_result NUMBER(10);
  v_Pnr_Partnernummer VARCHAR(10);
  --
BEGIN

  v_result := CONN.CONN_PARTNERS.verwerk_contactpersoon 
  (:new.PARTNER_ID
  ,:new.id
  ,:new.Ctn_Functie
  ,:new.Ctn_Naam
  ,:new.Ctn_Tussenvoegsel
  ,:new.Ctn_Voornaam
  ,:new.Ctn_Voorletters
  ,:new.Ctn_Titel
  ,:new.Ctn_Aanhef
  ,:new.Ctn_Telefoon
  ,:new.Ctn_Mobiel
  ,:new.Ctn_Fax
  ,:new.Ctn_Email
  ,:new.Ctn_Mutatie_Ind);
  
  /*

  IF v_result <= 0 THEN
  
    UPDATE OAC_STG_PARTNERS
    SET    Verwerkt_Facilitor = TO_DATE(NULL)
    WHERE  Id = :new.PARTNER_ID;
  
  END IF;
  */

  EXCEPTION WHEN OTHERS THEN
    raise_application_error(-20000, sqlerrm||' '||cn_module);
END;
/

