CREATE OR REPLACE TRIGGER GRAVA_LOGAPROVACAO
BEFORE UPDATE ON NOTAFISCAL FOR EACH ROW
DECLARE
   V_DSSERVERRDM  VARCHAR2(50);
   V_DSREMOTEADDR VARCHAR2(50);
   V_DSREMOTEHOST VARCHAR2(50);
   V_DSSERVMETHOD VARCHAR2(50);
   V_DSREMOTEOPER VARCHAR2(250);

   V_NMUSUARIO    VARCHAR2(12);
   V_DESC         VARCHAR2(300);
BEGIN
   IF ((:OLD.IDSTATUS) <> (:NEW.IDSTATUS) OR
      (:OLD.IDBLOQUEADO) <> (:NEW.IDBLOQUEADO)) AND
      (:NEW.IDENTRSAIDOP = 'E') THEN

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

      V_DESC := V_DESC||'SISTEMA: '||:OLD.IDSISTEMA||' FILIAL: '||:OLD.CDFILIAL;
      V_DESC := V_DESC||' LANCAMENTO: '||:OLD.NRLANCTONF;
      V_DESC := V_DESC||' NF: '||:OLD.NRNOTAFISC;
      V_DESC := V_DESC||'   STATUS DE: '||:OLD.IDSTATUS||' PARA: '||:NEW.IDSTATUS;
      V_DESC := V_DESC||'   BLOQUEADO DE: '||:OLD.IDBLOQUEADO||' PARA: '||:NEW.IDBLOQUEADO;
      V_DESC := V_DESC||'   DT.APROVACAO DE: '||:OLD.DTAPROVACAO||' PARA: '||:NEW.DTAPROVACAO;

      INSERT INTO LOGOPERA
         (NMTABELA,
          DTOPERACAO,
          NMRESPOPER,
          IDTIPOOPER,
          DSOPERACAO,
          CDPESQITEM,
          DSRDMUSUOPER,
          DSENDUSUOPER,
          DSNMUSUOPER,
          DSMETUSUOPER,
          CDORESPOPER)
      VALUES
         ('NOTAFISCAL',
          SYSDATE,
          NVL(V_NMUSUARIO,' '),
          '2',
          V_DESC,
          '1',
          V_DSSERVERRDM,
          V_DSREMOTEADDR,
          V_DSREMOTEHOST,
          V_DSSERVMETHOD,
          SUBSTR(V_DSREMOTEOPER,1,12));
   END IF;

END;
/

-- VERSAO --
BEGIN ATUVEROBJ('GRAVA_LOGAPROVACAO','4.09.050'); END;
/

