CREATE OR REPLACE TRIGGER LOG_PARAMGERALECOMMERCE
AFTER DELETE OR INSERT OR UPDATE
ON PARAMGERALECOMMERCE 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 UPDATING THEN
      IF NVL(:OLD.IDPERMVISUDADOSFORN, '!') <> NVL(:NEW.IDPERMVISUDADOSFORN, '!')    THEN
         V_DESC   := V_DESC || 'Visualizar Dados:' || '' || NVL(:NEW.IDPERMVISUDADOSFORN,  '')  || ' ';
      END IF;
      IF NVL(:OLD.DSLINKFALECONOSCO, '!')   <> NVL(:NEW.DSLINKFALECONOSCO, '!')   THEN
         V_DESC   := V_DESC || 'Fale Conosco:' || '' || NVL(:NEW.DSLINKFALECONOSCO, '')  || ' ';
      END IF;
      IF NVL(:OLD.DSNOMELINKAUX, '!')   <> NVL(:NEW.DSNOMELINKAUX, '!')   THEN
         V_DESC   := V_DESC || 'Nome Link Aux.:' || '' || NVL(:NEW.DSNOMELINKAUX, '')  || ' ';
      END IF;
      IF NVL(:OLD.DSLINKAUXILIAR, '!')   <> NVL(:NEW.DSLINKAUXILIAR, '!')   THEN
         V_DESC   := V_DESC || 'Link Aux.:' || '' || NVL(:NEW.DSLINKAUXILIAR, '')  || ' ';
      END IF;
      IF NVL(:OLD.CDEMPRESA, '!') <> NVL(:NEW.CDEMPRESA, '!')      THEN
         V_DESC   := V_DESC || 'Empresa:' || '' || :NEW.CDEMPRESA              || ' ';
      END IF;
      IF NVL(:OLD.IDEXIBEQTDCMP, '!')   <> NVL(:NEW.IDEXIBEQTDCMP, '!')   THEN
         V_DESC   := V_DESC || 'Exibe Qtde:'  || '' || :NEW.IDEXIBEQTDCMP           || ' ';
      END IF;
      IF NVL(:OLD.DSLINKECOMMERCE, '!') <> NVL(:NEW.DSLINKECOMMERCE, '!') THEN
         V_DESC   := V_DESC || 'Link Eco:'         || '' || :NEW.DSLINKECOMMERCE    || ' ';
      END IF;
      IF NVL(:OLD.IDGRAVAITEMZERADO, '!') <> NVL(:NEW.IDGRAVAITEMZERADO, '!') THEN
         V_DESC  := V_DESC || 'Grava Itm Zero:' || '' || :NEW.IDGRAVAITEMZERADO;
      END IF;
      IF NVL(:OLD.IDCOTUNICAPEDCOL, '!') <> NVL(:NEW.IDCOTUNICAPEDCOL, '!') THEN
         V_DESC   := V_DESC || 'Unica Cot:' || '' || :NEW.IDCOTUNICAPEDCOL    || ' ';
      END IF;
      IF NVL(:OLD.TXMSGFORNECEDOR, '!') <> NVL(:NEW.TXMSGFORNECEDOR, '!') THEN
         V_DESC  := V_DESC || 'CBC ALTERADO'    || ' ';
      END IF;
      IF NVL(:OLD.DSMANUALFILESERV , '!') <> NVL(:NEW.DSMANUALFILESERV , '!') THEN
         V_DESC  := V_DESC || 'Manual: '|| :NEW.DSMANUALFILESERV;
      END IF;
       IF NVL(:OLD.IDUTLAPROVMASSA , '!') <> NVL(:NEW.IDUTLAPROVMASSA , '!') THEN
         V_DESC  := V_DESC || 'Aprov Massa: '|| :NEW.IDUTLAPROVMASSA;
      END IF;
      V_ITPESQ       := NVL(:OLD.CDFILIAL, '');
      V_IDTIPOOPER   := '2';
   ELSE
      IF INSERTING THEN
         V_DESC   := 'Visualizar Dados  '  || '' || NVL(:NEW.IDPERMVISUDADOSFORN, '')    || ' ' ||
                     'Fale Conosco '       || '' || NVL(:NEW.DSLINKFALECONOSCO,   '')    || ' ' ||
                     'Nome Link Aux. '     || '' || NVL(:NEW.DSNOMELINKAUX,   '')        || ' ' ||
                     'Link Aux. '          || '' || NVL(:NEW.DSLINKAUXILIAR,   '')       || ' ' ||
                     'Empresa '            || '' || NVL(:NEW.CDEMPRESA,      '')         || ' ' ||
                     'Exibe Qtde '         || '' || NVL(:NEW.IDEXIBEQTDCMP,   '')        || ' ' ||
                     'Link Eco '           || '' || NVL(:NEW.DSLINKECOMMERCE, '')        || ' ' ||
                     'Grava Itm Zero '     || '' || NVL(:NEW.IDGRAVAITEMZERADO, '')      || ' ' ||
                     'Unica Cot '          || '' || NVL(:NEW.IDCOTUNICAPEDCOL, '')       || ' ' ||
                     'Manual'              || '' || NVL(:NEW.DSMANUALFILESERV, '')       || ' ' ||
                     'Aprov Massa'         || '' || NVL(:NEW.IDUTLAPROVMASSA, '');
         V_ITPESQ       := :NEW.CDFILIAL;
         V_IDTIPOOPER   := '1';
      ELSE
         IF DELETING THEN
            V_DESC   :=  'Visualizar Dados  '  || '' || NVL(:OLD.IDPERMVISUDADOSFORN, '')    || ' ' ||
                         'Fale Conosco '       || '' || NVL(:OLD.DSLINKFALECONOSCO,   '')    || ' ' ||
                         'Nome Link Aux. '     || '' || NVL(:OLD.DSNOMELINKAUX,   '')        || ' ' ||
                         'Link Aux. '          || '' || NVL(:OLD.DSLINKAUXILIAR,   '')       || ' ' ||
                         'Empresa '            || '' || NVL(:OLD.CDEMPRESA,      '')         || ' ' ||
                         'Exibe Qtde '         || '' || NVL(:OLD.IDEXIBEQTDCMP,   '')        || ' ' ||
                         'Link Eco '           || '' || NVL(:OLD.DSLINKECOMMERCE, '')        || ' ' ||
                         'Grava Itm Zero '     || '' || NVL(:OLD.IDGRAVAITEMZERADO, '')      || ' ' ||
                         'Unica Cot '          || '' || NVL(:OLD.IDCOTUNICAPEDCOL, '')       || ' ' ||
                         'Manual'              || '' || NVL(:OLD.DSMANUALFILESERV, '')       || ' ' ||
                         'Aprov Massa'         || '' || NVL(:OLD.IDUTLAPROVMASSA, '');
            V_ITPESQ       := NVL(:OLD.CDFILIAL, '');
            V_IDTIPOOPER   := '3';
         END IF;
      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
      ('PARAMGERALECOMMERCE',
       SYSDATE,
       NVL(V_NMOPERADOR,' '),
       V_IDTIPOOPER,
       V_DESC,
       V_ITPESQ,
       V_DSSERVERRDM,
       V_DSREMOTEADDR,
       V_DSREMOTEHOST,
       V_DSSERVMETHOD,
       V_DSREMOTEOPER);
END;
/