CREATE OR REPLACE TRIGGER LOG_TIPOCTRECEBER
BEFORE DELETE OR INSERT OR UPDATE 
ON TIPOCTRECEBER FOR EACH ROW
DECLARE
  V_DSREMOTEADDR VARCHAR2(15);
  V_DSREMOTEHOST VARCHAR2(15);
  V_DSSERVERRDM  VARCHAR2(20);
  V_DSSERVMETHOD VARCHAR2(30);
  V_DSREMOTEOPER VARCHAR2(12);
  V_DESC         VARCHAR2(500);
  V_ITPESQ       VARCHAR2(40);
  V_NMOPERADOR   VARCHAR2(40);
  V_IDTIPOOPER   VARCHAR2(1);
BEGIN
/* IDTIPOOPER - '1' - Inclusao, '2' - Alteracao, '3' - Exclusao*/
   V_DESC       := '';
   V_ITPESQ     := '';
   V_NMOPERADOR := '';
   V_IDTIPOOPER := '';
   NMUSUARIO(V_NMOPERADOR);

   WEBTUNNING(V_DSREMOTEADDR,
              V_DSREMOTEHOST,
              V_DSSERVERRDM,
              V_DSSERVMETHOD,
              V_DSREMOTEOPER);

   IF DELETING THEN
      V_IDTIPOOPER   := '3';
      V_ITPESQ       := :OLD.CDTPCTRECEB;
      V_DESC         := 'Cod '       || '' || NVL(:OLD.CDTPCTRECEB,'')||' '||
                        'ContContabil '  || '' || NVL(:OLD.CDCONTCTBL,'')||' '||
                        'ClasFin ' || '' || nvl(:OLD.CDCLASSFINA,'');

   ELSE
      IF UPDATING THEN
         V_DESC         := 'Cod '       || '' || NVL(:NEW.CDTPCTRECEB,'')||' '||
                           'ContContabil '  || '' || NVL(:NEW.CDCONTCTBL,'') ||' '||
                           'CtbLanc: '||:NEW.IDCTBLCTREC||' '||
                           'CtbBaixa: '||:NEW.IDCTBTPCNTBREC||' '||
                           'ClasFin Ant '||'' || nvl(:OLD.CDCLASSFINA,'')||' '||
                           'ClasFin Nov '||'' || nvl(:NEW.CDCLASSFINA,'');
         V_ITPESQ := :NEW.CDTPCTRECEB;
         V_IDTIPOOPER := '2';
      ELSE
         V_IDTIPOOPER   := '1';
         V_ITPESQ       := :NEW.CDTPCTRECEB;
         V_DESC         := 'Cod '       || '' || NVL(:NEW.CDTPCTRECEB,'')||' '||
                           'ContContabil '  || '' || NVL(:NEW.CDCONTCTBL,'') ||' '||
                           'CtbLanc: '||:NEW.IDCTBLCTREC||' '||
                           'CtbBaixa: '||:NEW.IDCTBTPCNTBREC||' '||
                           'ClasFin:  '||:NEW.CDCLASSFINA;
      END IF;
  END IF;
   V_DESC := SUBSTR(V_DESC, 1, 300);
   INSERT INTO LOGOPERA
      (NMTABELA,
       DTOPERACAO,
       NMRESPOPER,
       IDTIPOOPER,
       DSOPERACAO,
       CDPESQITEM,
       DSRDMUSUOPER,
       DSENDUSUOPER,
       DSNMUSUOPER,
       DSMETUSUOPER,
       CDORESPOPER)
   VALUES
      ('TIPOCTRECEBER',
       SYSDATE,
       NVL(V_NMOPERADOR,' '),
       V_IDTIPOOPER,
       V_DESC,
       V_ITPESQ,
       V_DSSERVERRDM,
       V_DSREMOTEADDR,
       V_DSREMOTEHOST,
       V_DSSERVMETHOD,
       V_DSREMOTEOPER);
END;


/