CREATE OR REPLACE TRIGGER LOG_FIS_NOTAFISCAL
AFTER DELETE OR INSERT OR UPDATE
ON NOTAFISCAL FOR EACH ROW
DECLARE
  V_USUARIO      VARCHAR2(40);
  V_TIPO         VARCHAR2(1);
  V_ITPESQ       VARCHAR2(40);
  V_DESC         VARCHAR2(4000);
  V_CDFILLOGOPER VARCHAR2(4);
  V_DSREMOTEADDR VARCHAR2(15);
  V_DSREMOTEHOST VARCHAR2(15);
  V_DSSERVERRDM  VARCHAR2(20);
  V_DSSERVMETHOD VARCHAR2(30);
  V_DSREMOTEOPER VARCHAR2(12);
  V_DTOPER       DATE;
BEGIN
   V_TIPO := '0';
   V_DESC := '';
   V_CDFILLOGOPER := '';

   IF DELETING THEN
      IF :OLD.NRINSJURNF IS NOT NULL THEN
         V_DESC := V_DESC || 'InsJurNF=' || :OLD.NRINSJURNF;
      END IF;

      IF :OLD.IDERROS IS NOT NULL THEN
         V_DESC := V_DESC || ' Erros=' || :OLD.IDERROS;
      END IF;

      IF :OLD.IDAVISOS IS NOT NULL THEN
         V_DESC := V_DESC || ' Avisos=' || :OLD.IDAVISOS;
      END IF;

      IF :OLD.IDBLOQUEADO IS NOT NULL THEN
         V_DESC := V_DESC || ' Bloq=' || :OLD.IDBLOQUEADO;
      END IF;

      IF :OLD.NRNOTAFISC IS NOT NULL THEN
         V_DESC := V_DESC || ' NrNF=' || :OLD.NRNOTAFISC;
      END IF;

      IF :OLD.DTEMISSAO IS NOT NULL THEN
         V_DESC := V_DESC || ' DtEmis=' || :OLD.DTEMISSAO;
      END IF;

      IF :OLD.DTENTRSAID IS NOT NULL THEN
         V_DESC := V_DESC || ' DtEntSai=' || :OLD.DTENTRSAID;
      END IF;

      IF :OLD.VRPRODUTOS IS NOT NULL THEN
         V_DESC := V_DESC || ' VrProd=' || :OLD.VRPRODUTOS;
      END IF;

      IF :OLD.VRNOTAFISC IS NOT NULL THEN
         V_DESC := V_DESC || ' VrNF=' || :OLD.VRNOTAFISC;
      END IF;

      IF :OLD.IDENTRSAIDOP IS NOT NULL THEN
         V_DESC := V_DESC || ' IdEntSai=' || :OLD.IDENTRSAIDOP;
      END IF;

      IF :OLD.CDTIPOOPER IS NOT NULL THEN
         V_DESC := V_DESC || ' TipoOper=' || :OLD.CDTIPOOPER;
      END IF;

      IF :OLD.CDSERIE IS NOT NULL THEN
         V_DESC := V_DESC || ' SerieSai=' || :OLD.CDSERIE;
      END IF;

      IF :OLD.CDFISOPENTF IS NOT NULL THEN
         V_DESC := V_DESC || ' CFOp=' || :OLD.CDFISOPENTF;
      END IF;

      IF :OLD.IDSTATUS IS NOT NULL THEN
         V_DESC := V_DESC || ' Status=' || :OLD.IDSTATUS;
      END IF;

      IF :OLD.NRLANCTBDOC IS NOT NULL THEN
         V_DESC := V_DESC || ' LanCTB=' || :OLD.NRLANCTBDOC;
      END IF;

      IF :OLD.IDSISTEMA IS NOT NULL THEN
         V_DESC := V_DESC || ' Sist=' || :OLD.IDSISTEMA;
      END IF;

      IF :OLD.CDMODDOCFISC IS NOT NULL THEN
         V_DESC := V_DESC || ' ModFisc=' || :OLD.CDMODDOCFISC;
      END IF;

      IF :OLD.CDSERIEENTR IS NOT NULL THEN
         V_DESC := V_DESC || ' SerieEnt=' || :OLD.CDSERIEENTR;
      END IF;

      IF :OLD.CDINTEGRACAO IS NOT NULL THEN
         V_DESC := V_DESC || ' Integr=' || :OLD.CDINTEGRACAO;
      END IF;

      IF :OLD.IDORIGDESTNF IS NOT NULL THEN
         V_DESC := V_DESC || ' OrigDest=' || :OLD.IDORIGDESTNF;
      END IF;

      IF :OLD.IDDOCREPLIC IS NOT NULL THEN
         V_DESC := V_DESC || ' DocReplic=' || :OLD.IDDOCREPLIC;
      END IF;

      IF :OLD.CDFILIEMIT IS NOT NULL THEN
         V_DESC := V_DESC || ' FiliEmit=' || :OLD.CDFILIEMIT;
      END IF;

      IF :OLD.CDFILIRECE IS NOT NULL THEN
         V_DESC := V_DESC || ' FiliRece=' || :OLD.CDFILIRECE;
      END IF;

      IF :OLD.CDALMOXARIFE IS NOT NULL THEN
         V_DESC := V_DESC || ' Almox=' || :OLD.CDALMOXARIFE;
      END IF;

      IF :OLD.CDLOCALESTOQ IS NOT NULL THEN
         V_DESC := V_DESC || ' LcEstoq=' || :OLD.CDLOCALESTOQ;
      END IF;

      IF :OLD.CDVENDEDOR IS NOT NULL THEN
         V_DESC := V_DESC || ' Vendedor=' || :OLD.CDVENDEDOR;
      END IF;

      IF :OLD.NREXPEDICAO IS NOT NULL THEN
         V_DESC := V_DESC || ' Exped=' || :OLD.NREXPEDICAO;
      END IF;

      IF :OLD.NRACESSONFE IS NOT NULL THEN
         V_DESC := V_DESC || ' Chave NFe=' || :OLD.NRACESSONFE;
      END IF;

      IF :OLD.NRLOTENFE IS NOT NULL THEN
         V_DESC := V_DESC || 'NrLote=' || :OLD.NRLOTENFE;
      END IF;

      IF :OLD.IDSTATUSNFE IS NOT NULL THEN
         V_DESC := V_DESC || 'Status=' || :OLD.IDSTATUSNFE;
      END IF;

      IF :OLD.CDEMPLOTENFE IS NOT NULL THEN
         V_DESC := V_DESC || 'EmpLote=' || :OLD.CDEMPLOTENFE;
      END IF;

      IF :OLD.NRPROTOCOLONFE IS NOT NULL THEN
         V_DESC := V_DESC || 'NrProtoc=' || :OLD.NRPROTOCOLONFE;
      END IF;

      IF :OLD.IDIMPRESSODANFE IS NOT NULL THEN
         V_DESC := V_DESC || 'ImpreDanf=' || :OLD.IDIMPRESSODANFE;
      END IF;

      IF :OLD.IDTIPOEMISNFE IS NOT NULL THEN
         V_DESC := V_DESC || 'TpEmiss=' || :OLD.IDTIPOEMISNFE;
      END IF;

      IF :OLD.IDEMAILNFE IS NOT NULL THEN
         V_DESC := V_DESC || 'EmailNfe=' || :OLD.IDEMAILNFE;
      END IF;

      IF :OLD.NRNOTAFISCALELE IS NOT NULL THEN
         V_DESC := V_DESC || 'NrNotaEle=' || :OLD.NRNOTAFISCALELE;
      END IF;

      IF :OLD.IDEMAILNFETRANSP IS NOT NULL THEN
         V_DESC := V_DESC || 'EmailTransp=' || :OLD.IDEMAILNFETRANSP;
      END IF;

      IF :OLD.IDTPAMBNFE IS NOT NULL THEN
         V_DESC := V_DESC || 'AmbNfe=' || :OLD.IDTPAMBNFE;
      END IF;

      IF :OLD.DTHRPROTOCOLNFE IS NOT NULL THEN
         V_DESC := V_DESC || 'DtHrProtoc=' || :OLD.DTHRPROTOCOLNFE;
      END IF;

      IF :OLD.NRSEQCAPADOC IS NOT NULL THEN
         V_DESC := V_DESC || 'CapaDoc(RE)=' || :OLD.NRSEQCAPADOC;
      END IF;

      IF :OLD.CDIBGEORIG IS NOT NULL THEN
         V_DESC := V_DESC || 'Ibge Orig=' || :OLD.CDIBGEORIG;
      END IF;

      IF :OLD.CDIBGEDEST IS NOT NULL THEN
         V_DESC := V_DESC || 'Ibge Dest=' || :OLD.CDIBGEDEST;
      END IF;
	  
	   IF :OLD.SGESTADO IS NOT NULL THEN
         V_DESC := V_DESC || 'Est_Pr_Serv=' || :OLD.SGESTADO;
      END IF;

      IF :OLD.CDMUNICIPIO IS NOT NULL THEN
         V_DESC := V_DESC || 'Mun_Pr_Serv=' || :OLD.CDMUNICIPIO;
      END IF;

      IF :OLD.IDCALCDIFAL IS NOT NULL THEN
         V_DESC := V_DESC || 'Calc_Difal=' || :OLD.IDCALCDIFAL;
      END IF;

      V_TIPO         := '3';
      V_ITPESQ       := :OLD.CDFILIAL||:OLD.NRLANCTONF;
      V_CDFILLOGOPER := :OLD.CDFILIAL;
   ELSE
      IF UPDATING THEN
         IF (:OLD.NRINSJURNF   <> :NEW.NRINSJURNF)   OR
            (:OLD.IDERROS      <> :NEW.IDERROS)      OR
            (:OLD.IDAVISOS     <> :NEW.IDAVISOS)     OR
            (:OLD.IDBLOQUEADO  <> :NEW.IDBLOQUEADO)  OR
            (:OLD.NRNOTAFISC   <> :NEW.NRNOTAFISC)   OR
            (:OLD.DTEMISSAO    <> :NEW.DTEMISSAO)    OR
            (:OLD.DTENTRSAID   <> :NEW.DTENTRSAID)   OR
            (:OLD.VRPRODUTOS   <> :NEW.VRPRODUTOS)   OR
            (:OLD.VRNOTAFISC   <> :NEW.VRNOTAFISC)   OR
            (:OLD.IDENTRSAIDOP <> :NEW.IDENTRSAIDOP) OR
            (:OLD.CDTIPOOPER   <> :NEW.CDTIPOOPER)   OR
            (:OLD.CDSERIE      <> :NEW.CDSERIE)      OR
            (:OLD.CDFISOPENTF  <> :NEW.CDFISOPENTF)  OR
            (:OLD.IDSTATUS     <> :NEW.IDSTATUS)     OR
            (:OLD.NRLANCTBDOC  <> :NEW.NRLANCTBDOC)  OR
            (:OLD.IDSISTEMA    <> :NEW.IDSISTEMA)    OR
            (:OLD.CDMODDOCFISC <> :NEW.CDMODDOCFISC) OR
            (:OLD.CDSERIEENTR  <> :NEW.CDSERIEENTR)  OR
            (:OLD.CDINTEGRACAO <> :NEW.CDINTEGRACAO) OR
            (:OLD.IDORIGDESTNF <> :NEW.IDORIGDESTNF) OR
            (:OLD.IDDOCREPLIC  <> :NEW.IDDOCREPLIC)  OR
            (:OLD.CDFILIEMIT   <> :NEW.CDFILIEMIT)   OR
            (:OLD.CDFILIRECE   <> :NEW.CDFILIRECE)   OR
            (:OLD.CDALMOXARIFE <> :NEW.CDALMOXARIFE) OR
            (:OLD.CDLOCALESTOQ <> :NEW.CDLOCALESTOQ) OR
            (:OLD.CDVENDEDOR   <> :NEW.CDVENDEDOR)   OR
            (:OLD.NREXPEDICAO  <> :NEW.NREXPEDICAO)  OR
            (:OLD.NRACESSONFE  <> :NEW.NRACESSONFE)  OR
            (:OLD.NRLOTENFE    <> :NEW.NRLOTENFE)    OR
            (:OLD.IDSTATUSNFE  <> :NEW.IDSTATUSNFE)  OR
            (:OLD.CDEMPLOTENFE     <> :NEW.CDEMPLOTENFE)     OR
            (:OLD.NRPROTOCOLONFE   <> :NEW.NRPROTOCOLONFE)   OR
            (:OLD.IDIMPRESSODANFE  <> :NEW.IDIMPRESSODANFE)  OR
            (:OLD.IDTIPOEMISNFE    <> :NEW.IDTIPOEMISNFE)    OR
            (:OLD.IDEMAILNFE       <> :NEW.IDEMAILNFE)       OR
            (:OLD.NRNOTAFISCALELE  <> :NEW.NRNOTAFISCALELE)  OR
            (:OLD.IDEMAILNFETRANSP <> :NEW.IDEMAILNFETRANSP) OR
            (:OLD.IDTPAMBNFE       <> :NEW.IDTPAMBNFE)       OR
            (:OLD.NRSEQCAPADOC     <> :NEW.NRSEQCAPADOC)     OR
            (:OLD.DTHRPROTOCOLNFE  <> :NEW.DTHRPROTOCOLNFE)  OR
            (:OLD.IDBLOQNFFIN      <> :NEW.IDBLOQNFFIN)      OR
            (:OLD.CDOPERACTPG      <> :NEW.CDOPERACTPG)      OR
            (:OLD.CDOPERACTPGCAN   <> :NEW.CDOPERACTPGCAN)   OR
            (:OLD.DTLIBERACAOFIN   <> :NEW.DTLIBERACAOFIN)   OR
            (:OLD.CDIBGEORIG       <> :NEW.CDIBGEORIG)       OR
            (:OLD.CDIBGEDEST       <> :NEW.CDIBGEDEST)       OR
    			(:OLD.SGESTADO         <> :NEW.SGESTADO)         OR
	   		(:OLD.CDMUNICIPIO      <> :NEW.CDMUNICIPIO)      OR
            (:OLD.IDCALCDIFAL      <> :NEW.IDCALCDIFAL)    THEN

            V_TIPO         := '2';
            V_ITPESQ       := :OLD.CDFILIAL||:OLD.NRLANCTONF;
            V_CDFILLOGOPER := :OLD.CDFILIAL;
         END IF;
      ELSE
         V_TIPO         := '1';
         V_ITPESQ       := :NEW.CDFILIAL||:NEW.NRLANCTONF;
         V_CDFILLOGOPER := :NEW.CDFILIAL;
      END IF;

      IF NVL(:NEW.NRINSJURNF, '!') <> NVL(:OLD.NRINSJURNF, '!') THEN
         V_DESC := V_DESC || 'InsJurNF=' || :NEW.NRINSJURNF;
      END IF;

      IF NVL(:NEW.IDERROS, '!') <> NVL(:OLD.IDERROS, '!') THEN
         V_DESC := V_DESC || ' Erros=' || :NEW.IDERROS;
      END IF;

      IF NVL(:NEW.IDAVISOS, '!') <> NVL(:OLD.IDAVISOS, '!') THEN
         V_DESC := V_DESC || ' Avisos=' || :NEW.IDAVISOS;
      END IF;

      IF NVL(:NEW.IDBLOQUEADO, '!') <> NVL(:OLD.IDBLOQUEADO, '!') THEN
         V_DESC := V_DESC || ' Bloq=' || :NEW.IDBLOQUEADO;
      END IF;

      IF NVL(:NEW.NRNOTAFISC, '!') <> NVL(:OLD.NRNOTAFISC, '!') THEN
         V_DESC := V_DESC || ' NrNF=' || :NEW.NRNOTAFISC;
      END IF;

      IF (:NEW.DTEMISSAO IS NOT NULL) AND (:NEW.DTEMISSAO <> :OLD.DTEMISSAO) THEN
         V_DESC := V_DESC || ' DtEmis=' || :NEW.DTEMISSAO;
      END IF;

      IF (:NEW.DTENTRSAID IS NOT NULL) AND (:NEW.DTENTRSAID <> :OLD.DTENTRSAID) THEN
         V_DESC := V_DESC || ' DtEntSai=' || :NEW.DTENTRSAID;
      END IF;

      IF (:NEW.VRPRODUTOS IS NOT NULL) AND (:NEW.VRPRODUTOS <> :OLD.VRPRODUTOS) THEN
         V_DESC := V_DESC || ' VrProd=' || :NEW.VRPRODUTOS;
      END IF;

      IF (:NEW.VRNOTAFISC IS NOT NULL) AND (:NEW.VRNOTAFISC <> :OLD.VRNOTAFISC) THEN
         V_DESC := V_DESC || ' VrNF=' || :NEW.VRNOTAFISC;
      END IF;

      IF NVL(:NEW.IDENTRSAIDOP, '!') <> NVL(:OLD.IDENTRSAIDOP, '!') THEN
         V_DESC := V_DESC || ' IdEntSai=' || :NEW.IDENTRSAIDOP;
      END IF;

      IF NVL(:NEW.CDTIPOOPER, '!') <> NVL(:OLD.CDTIPOOPER, '!') THEN
         V_DESC := V_DESC || ' TipoOper=' || :NEW.CDTIPOOPER;
      END IF;

      IF NVL(:NEW.CDSERIE, '!') <> NVL(:OLD.CDSERIE, '!') THEN
         V_DESC := V_DESC || ' SerieSai=' || :NEW.CDSERIE;
      END IF;

      IF NVL(:NEW.CDFISOPENTF, '!') <> NVL(:OLD.CDFISOPENTF, '!') THEN
         V_DESC := V_DESC || ' CFOp=' || :NEW.CDFISOPENTF;
      END IF;

      IF NVL(:NEW.IDSTATUS, '!') <> NVL(:OLD.IDSTATUS, '!') THEN
         V_DESC := V_DESC || ' Status=' || :NEW.IDSTATUS;
      END IF;

      IF NVL(:NEW.NRLANCTBDOC, 1) <> NVL(:OLD.NRLANCTBDOC, 1) THEN
         V_DESC := V_DESC || ' LanCTB=' || :NEW.NRLANCTBDOC;
      END IF;

      IF NVL(:NEW.IDSISTEMA, '!') <> NVL(:OLD.IDSISTEMA, '!') THEN
         V_DESC := V_DESC || ' Sist=' || :NEW.IDSISTEMA;
      END IF;

      IF NVL(:NEW.CDMODDOCFISC, '!') <> NVL(:OLD.CDMODDOCFISC, '!') THEN
         V_DESC := V_DESC || ' ModFisc=' || :NEW.CDMODDOCFISC;
      END IF;

      IF NVL(:NEW.CDSERIEENTR, '!') <> NVL(:OLD.CDSERIEENTR, '!') THEN
         V_DESC := V_DESC || ' SerieEnt=' || :NEW.CDSERIEENTR;
      END IF;

      IF NVL(:NEW.CDINTEGRACAO, '!') <> NVL(:OLD.CDINTEGRACAO, '!') THEN
         V_DESC := V_DESC || ' Integr=' || :NEW.CDINTEGRACAO;
      END IF;

      IF NVL(:NEW.IDORIGDESTNF, '!') <> NVL(:OLD.IDORIGDESTNF, '!') THEN
         V_DESC := V_DESC || ' OrigDest=' || :NEW.IDORIGDESTNF;
      END IF;

      IF NVL(:NEW.IDDOCREPLIC, '!') <> NVL(:OLD.IDDOCREPLIC, '!') THEN
         V_DESC := V_DESC || ' DocReplic=' || :NEW.IDDOCREPLIC;
      END IF;

      IF NVL(:NEW.CDFILIEMIT, '!') <> NVL(:OLD.CDFILIEMIT, '!') THEN
         V_DESC := V_DESC || ' FiliEmit=' || :NEW.CDFILIEMIT;
      END IF;

      IF NVL(:NEW.CDFILIRECE, '!') <> NVL(:OLD.CDFILIRECE, '!') THEN
         V_DESC := V_DESC || ' FiliRece=' || :NEW.CDFILIRECE;
      END IF;

      IF NVL(:NEW.CDALMOXARIFE, '!') <> NVL(:OLD.CDALMOXARIFE, '!') THEN
         V_DESC := V_DESC || ' Almox=' || :NEW.CDALMOXARIFE;
      END IF;

      IF NVL(:NEW.CDLOCALESTOQ, '!') <> NVL(:OLD.CDLOCALESTOQ, '!') THEN
         V_DESC := V_DESC || ' LcEstoq=' || :NEW.CDLOCALESTOQ;
      END IF;

      IF NVL(:NEW.CDVENDEDOR, '!') <> NVL(:OLD.CDVENDEDOR, '!') THEN
         V_DESC := V_DESC || ' Vendedor=' || :NEW.CDVENDEDOR;
      END IF;

      IF NVL(:NEW.NREXPEDICAO, '!') <> NVL(:OLD.NREXPEDICAO, '!') THEN
         V_DESC := V_DESC || ' Exped=' || :NEW.NREXPEDICAO;
      END IF;

      IF NVL(:NEW.NRACESSONFE, '!') <> NVL(:OLD.NRACESSONFE, '!') THEN
         V_DESC := V_DESC || ' Chave NFe=' || :NEW.NRACESSONFE;
      END IF;

      IF NVL(:NEW.NRLOTENFE, '!') <> NVL(:OLD.NRLOTENFE, '!') THEN
         V_DESC := V_DESC || ' NrLote=' || :NEW.NRLOTENFE;
      END IF;

      IF NVL(:NEW.IDSTATUSNFE, '!') <> NVL(:OLD.IDSTATUSNFE, '!') THEN
         V_DESC := V_DESC || ' Status=' || :NEW.IDSTATUSNFE;
      END IF;

      IF NVL(:NEW.CDEMPLOTENFE, '!') <> NVL(:OLD.CDEMPLOTENFE, '!') THEN
         V_DESC := V_DESC || ' EmpLote=' || :NEW.CDEMPLOTENFE;
      END IF;

      IF NVL(:NEW.NRPROTOCOLONFE, '!') <> NVL(:OLD.NRPROTOCOLONFE, '!') THEN
         V_DESC := V_DESC || ' NrProtoc=' || :NEW.NRPROTOCOLONFE;
      END IF;

      IF NVL(:NEW.IDIMPRESSODANFE, '!') <> NVL(:OLD.IDIMPRESSODANFE, '!') THEN
         V_DESC := V_DESC || ' ImpreDanf=' || :NEW.IDIMPRESSODANFE;
      END IF;

      IF NVL(:NEW.IDTIPOEMISNFE, '!') <> NVL(:OLD.IDTIPOEMISNFE, '!') THEN
         V_DESC := V_DESC || ' TpEmiss=' || :NEW.IDTIPOEMISNFE;
      END IF;

      IF NVL(:NEW.IDEMAILNFE, '!') <> NVL(:OLD.IDEMAILNFE, '!') THEN
         V_DESC := V_DESC || ' EmailNfe=' || :NEW.IDEMAILNFE;
      END IF;

      IF NVL(:NEW.NRNOTAFISCALELE, '!') <> NVL(:OLD.NRNOTAFISCALELE, '!') THEN
         V_DESC := V_DESC || ' NrNotaEle=' || :NEW.NRNOTAFISCALELE;
      END IF;

      IF NVL(:NEW.IDEMAILNFETRANSP, '!') <> NVL(:OLD.IDEMAILNFETRANSP, '!') THEN
         V_DESC := V_DESC || ' EmailTransp=' || :NEW.IDEMAILNFETRANSP;
      END IF;

      IF NVL(:NEW.IDTPAMBNFE, '!') <> NVL(:OLD.IDTPAMBNFE, '!') THEN
         V_DESC := V_DESC || ' AmbNfe=' || :NEW.IDTPAMBNFE;
      END IF;
      
      IF (:NEW.DTHRPROTOCOLNFE IS NOT NULL) AND (:NEW.DTHRPROTOCOLNFE <> :OLD.DTHRPROTOCOLNFE) THEN
         V_DESC := V_DESC || ' DtHrProtoc=' || :NEW.DTHRPROTOCOLNFE;
      END IF;

      IF NVL(:NEW.NRSEQCAPADOC, '!') <> NVL(:OLD.NRSEQCAPADOC, '!') THEN
         V_DESC := V_DESC || ' CapaDoc(RE)=' || :NEW.NRSEQCAPADOC;
      END IF;

      IF NVL(:NEW.IDBLOQNFFIN, '!') <> NVL(:OLD.IDBLOQNFFIN, '!') THEN
         V_DESC := V_DESC || ' BloqNfFin=' || :NEW.IDBLOQNFFIN;
      END IF;

      IF NVL(:NEW.CDOPERACTPG, '!') <> NVL(:OLD.CDOPERACTPG, '!') THEN
         V_DESC := V_DESC || ' OperaLibeCtPag=' || :NEW.CDOPERACTPG;
      END IF;

      IF NVL(:NEW.CDOPERACTPGCAN, '!') <> NVL(:OLD.CDOPERACTPGCAN, '!') THEN
         V_DESC := V_DESC || ' OperaCanLibeCtPg=' || :NEW.CDOPERACTPGCAN;
      END IF;

      IF (:NEW.DTLIBERACAOFIN IS NOT NULL) AND (:NEW.DTLIBERACAOFIN <> :OLD.DTLIBERACAOFIN) THEN
         V_DESC := V_DESC || ' DtLiberacaoFin=' || :NEW.DTLIBERACAOFIN;
      END IF;

      IF NVL(:NEW.CDIBGEORIG, '!') <> NVL(:OLD.CDIBGEORIG, '!') THEN
         V_DESC := V_DESC || ' Ibge Orig=' || :NEW.CDIBGEORIG;
      END IF;

      IF NVL(:NEW.CDIBGEDEST, '!') <> NVL(:OLD.CDIBGEDEST, '!') THEN
         V_DESC := V_DESC || ' Ibge Dest=' || :NEW.CDIBGEDEST;
      END IF;

	   IF NVL(:NEW.SGESTADO, '!') <> NVL(:OLD.SGESTADO, '!') THEN
         V_DESC := V_DESC || ' Est_Pr_Serv=' || :NEW.SGESTADO;
      END IF;

      IF NVL(:NEW.CDMUNICIPIO, '!') <> NVL(:OLD.CDMUNICIPIO, '!') THEN
         V_DESC := V_DESC || ' Mun_Pr_Serv=' || :NEW.CDMUNICIPIO;
      END IF;

      IF NVL(:NEW.IDCALCDIFAL, '!') <> NVL(:OLD.IDCALCDIFAL, '!') THEN
         V_DESC := V_DESC || ' Calc_Difal=' || :NEW.IDCALCDIFAL;
      END IF;

   END IF;

   IF V_TIPO <> '0' THEN
      NMUSUARIO(V_USUARIO);
      WEBTUNNING(V_DSREMOTEADDR,
                 V_DSREMOTEHOST,
                 V_DSSERVERRDM,
                 V_DSSERVMETHOD,
                 V_DSREMOTEOPER);
      IF NOT V_DESC IS NULL THEN
         IF NOT V_USUARIO IS NULL THEN
            V_DTOPER := SYSDATE;

            INSERT INTO LOGOPERA
               (NMTABELA,
                DTOPERACAO,
                NMRESPOPER,
                IDTIPOOPER,
                CDPESQITEM,
                DSOPERACAO,
                CDFILLOGOPER,
                DSRDMUSUOPER,
                DSENDUSUOPER,
                DSNMUSUOPER,
                DSMETUSUOPER,
                CDORESPOPER)
            VALUES
               ('NOTAFISCAL',
                V_DTOPER,
                V_USUARIO,
                V_TIPO,
                V_ITPESQ,
                SUBSTR(V_DESC,1,700),
                V_CDFILLOGOPER,
                V_DSSERVERRDM,
                V_DSREMOTEADDR,
                V_DSREMOTEHOST,
                V_DSSERVMETHOD,
                V_DSREMOTEOPER);
         END IF;
      END IF;
   END IF;
END;
/