CREATE OR REPLACE TRIGGER LOG_EST_PARAMFILIAL
AFTER DELETE OR INSERT OR UPDATE
ON PARAMFILIAL FOR EACH ROW
DECLARE
  V_USUARIO      VARCHAR2(40);
  V_TIPO         VARCHAR2(1);
  V_ITPESQ       VARCHAR2(40);
  V_DESC         VARCHAR2(1500);
  V_CDFILLOGOPER VARCHAR2(4);
  V_DTOPER       DATE;
  V_DSREMOTEADDR VARCHAR2(15);
  V_DSREMOTEHOST VARCHAR2(15);
  V_DSSERVERRDM  VARCHAR2(20);
  V_DSSERVMETHOD VARCHAR2(30);
  V_DSREMOTEOPER VARCHAR2(12);

BEGIN
   V_TIPO         := '0';
   V_DESC         := '';
   V_CDFILLOGOPER := '';

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

   IF DELETING THEN
      IF :OLD.DTPROCESSA IS NOT NULL THEN
         V_DESC := V_DESC || 'DtProc=' || TO_CHAR(:OLD.DTPROCESSA,'DD/MM/YYYY');
      END IF;

      IF :OLD.IDCTRLESTQ IS NOT NULL THEN
         V_DESC := V_DESC || ' CtrEst=' || :OLD.IDCTRLESTQ;
      END IF;

      IF :OLD.IDESTONLINE IS NOT NULL THEN
         V_DESC := V_DESC || ' EstOnL=' || :OLD.IDESTONLINE;
      END IF;

      IF :OLD.IDPERMESTNEG IS NOT NULL THEN
         V_DESC := V_DESC || ' EstNeg=' ||  :OLD.IDPERMESTNEG;
      END IF;

      IF :OLD.IDORDIMPLANT IS NOT NULL THEN
         V_DESC := V_DESC || ' OrdImp=' || :OLD.IDORDIMPLANT;
      END IF;

      IF :OLD.IDORDAJUINVE IS NOT NULL THEN
         V_DESC := V_DESC || ' OrdAju=' || :OLD.IDORDAJUINVE;
      END IF;

      IF :OLD.IDTCUSNFROMA IS NOT NULL THEN
         V_DESC := V_DESC || ' CustSa=' || :OLD.IDTCUSNFROMA;
      END IF;

      IF :OLD.IDUTILALMOX IS NOT NULL THEN
         V_DESC := V_DESC || ' UtAlmo=' || :OLD.IDUTILALMOX;
      END IF;

      IF :OLD.IDUTILLCESTQ IS NOT NULL THEN
         V_DESC := V_DESC || ' UtLoca=' || :OLD.IDUTILLCESTQ;
      END IF;

      IF :OLD.IDUTILLOTE IS NOT NULL THEN
         V_DESC := V_DESC || ' UtLote=' || :OLD.IDUTILLOTE;
      END IF;

      IF :OLD.CDTIPCUSTEST IS NOT NULL THEN
         V_DESC := V_DESC || ' TipoCustEst=' || :OLD.CDTIPCUSTEST;
      END IF;

      IF :OLD.NRTAMNUMNFUT IS NOT NULL THEN
         V_DESC := V_DESC || ' TamNumNF=' || :OLD.NRTAMNUMNFUT;
      END IF;

      IF :OLD.IDUTILALLONF IS NOT NULL THEN
         V_DESC := V_DESC || ' UtilAlLocNF=' || :OLD.IDUTILALLONF;
      END IF;

      IF SUBSTR(:OLD.DSPARFILFIS,2,1) IS NOT NULL THEN
         V_DESC := V_DESC || ' BloqNFAF=' || SUBSTR(:OLD.DSPARFILFIS,2,1);
      END IF;

      IF SUBSTR(:OLD.DSPARFILFIS,1,1) IS NOT NULL THEN
         V_DESC := V_DESC || ' VerProdDifAF=' || SUBSTR(:OLD.DSPARFILFIS,1,1);
      END IF;

      IF :OLD.IDPERFORNECO IS NOT NULL THEN
         V_DESC := V_DESC || ' PermEntrForsemPermCompVend=' || :OLD.IDPERFORNECO;
      END IF;

      IF :OLD.CDFILIAL IS NOT NULL THEN
         V_DESC := V_DESC || ' Cod=' || :OLD.CDFILIAL;
      END IF;

      IF :OLD.CDCONFORNFI IS NOT NULL THEN
         V_DESC := V_DESC || ' Fornecedor=' || :OLD.CDCONFORNFI;
      END IF;

      IF :OLD.CDCONCLIEFI IS NOT NULL THEN
         V_DESC := V_DESC || ' Cliente=' || :OLD.CDCONCLIEFI;
      END IF;

      IF :OLD.CDCONTDIFEFI IS NOT NULL THEN
         V_DESC := V_DESC || ' VendDif=' || :OLD.CDCONTDIFEFI ;
      END IF;

      IF :OLD.CDCTBLPERDFI IS NOT NULL THEN
         V_DESC := V_DESC || ' LucPer=' || :OLD.CDCTBLPERDFI;
      END IF;

      IF :OLD.CDGRUPOFISC IS NOT NULL THEN
         V_DESC := V_DESC || ' GrupoFiscal=' || :OLD.CDGRUPOFISC;
      END IF;

      IF :OLD.IDPERPROINAT IS NOT NULL THEN
         V_DESC := V_DESC || ' PerProdInat=' || :OLD.IDPERPROINAT;
      END IF;

      IF :OLD.CDSERVBAIESTCEG IS NOT NULL THEN
         V_DESC := V_DESC || ' ServBaiEstCego=' || :OLD.CDSERVBAIESTCEG;
      END IF;

      IF :OLD.IDINVESTCEGO IS NOT NULL THEN
         V_DESC := V_DESC || ' InvEstCego=' || :OLD.IDINVESTCEGO;
      END IF;

      IF :OLD.CDTPRETBXESTCEG IS NOT NULL THEN
         V_DESC := V_DESC || ' PretEstCego=' || :OLD.CDTPRETBXESTCEG;
      END IF;

      IF :OLD.IDCONDESBONFORN IS NOT NULL THEN
         V_DESC := V_DESC || ' DescBoni=' || :OLD.IDCONDESBONFORN;
      END IF;

      IF :OLD.IDPARAMEMISREFI IS NOT NULL THEN
         V_DESC := V_DESC || ' ConsParEmisREFi=' || :OLD.IDPARAMEMISREFI;
      END IF;

      IF :OLD.IDBLOQCMPSAFFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' BloqNFCmpSemAFForn=' || :OLD.IDBLOQCMPSAFFIL;
      END IF;

      IF :OLD.IDUTBLOQOPAFPF IS NOT NULL THEN
         V_DESC := V_DESC || ' UtiBloqTpOpeAf=' || :OLD.IDUTBLOQOPAFPF;
      END IF;

      IF :OLD.NRMAXDIAANTDTAF IS NOT NULL THEN
         V_DESC := V_DESC || ' NumMaxDiaAntImpoAF=' || :OLD.NRMAXDIAANTDTAF;
      END IF;

      IF :OLD.NRMAXDIAPOSDTAF IS NOT NULL THEN
         V_DESC := V_DESC || ' NumMaxDiaPosImpoAF=' || :OLD.NRMAXDIAPOSDTAF;
      END IF;

      IF :OLD.NRTAMNUMNFUTDFE IS NOT NULL THEN
         V_DESC := V_DESC || ' TamNumNfDfe=' || :OLD.NRTAMNUMNFUTDFE;
      END IF;

      IF :OLD.CDREDUCONTPAG IS NOT NULL THEN
         V_DESC := V_DESC || ' NumContCorren=' ||  :OLD.CDREDUCONTPAG;
      END IF;

      IF :OLD.CDTPBAIXAPAG IS NOT NULL THEN
         V_DESC := V_DESC || ' TipoBaixa=' || :OLD.CDTPBAIXAPAG;
      END IF;

      IF :OLD.IDUTCTRLFIS IS NOT NULL THEN
      	V_DESC := V_DESC || ' UtCtrFis=' || :OLD.IDUTCTRLFIS;
      END IF;

      IF :OLD.IDUTLIBERANF IS NOT NULL THEN
      	V_DESC := V_DESC || ' UtLibNF=' || :OLD.IDUTLIBERANF;
      END IF;

      IF :OLD.IDUTCTRLFISENTR IS NOT NULL THEN
         V_DESC := V_DESC || ' ContFiscalEnt=' || :OLD.IDUTCTRLFISENTR;
      END IF;

      IF :OLD.IDUTCTRLFISSAID IS NOT NULL THEN
         V_DESC := V_DESC || ' ContFiscalSai=' || :OLD.IDUTCTRLFISSAID;
      END IF;

      IF :OLD.IDCANCEXTMPNFE IS NOT NULL THEN
         V_DESC := V_DESC || ' CancExTmp=' || :OLD.IDCANCEXTMPNFE;
      END IF;

      IF :OLD.IDLANCDTMENFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' LDtMen=' || :OLD.IDLANCDTMENFIL;
      END IF;

      IF :OLD.NRDIASENTRFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' DiaEntr=' || :OLD.NRDIASENTRFIL;
      END IF;

      IF :OLD.NRDIASSAIDFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' DiaSaid=' || :OLD.NRDIASSAIDFIL;
      END IF;

      IF :OLD.NRDIASAJUSFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' DiaAjus=' || :OLD.NRDIASAJUSFIL;
      END IF;

      IF :OLD.IDLANCDTMAIFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' LanDtMai=' || :OLD.IDLANCDTMAIFIL;
      END IF;

      IF :OLD.NRDIASENTRPDFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' DEntrPos=' || :OLD.NRDIASENTRPDFIL;
      END IF;

      IF :OLD.NRDIASSAIDPDFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' DSaidPos=' || :OLD.NRDIASSAIDPDFIL;
      END IF;

      IF :OLD.NRDIASAJUSPDFIL IS NOT NULL THEN
         V_DESC := V_DESC || ' DAjusPos=' || :OLD.NRDIASAJUSPDFIL;
      END IF;

      IF :OLD.IDBLOQFECDIA IS NOT NULL THEN
         V_DESC := V_DESC || ' BloqFechDiaMesNInf=' || :OLD.IDBLOQFECDIA;
      END IF;

      IF :OLD.IDBLOQFECHNF IS NOT NULL THEN
         V_DESC := V_DESC || ' BloqFechDiaEntSNF=' || :OLD.IDBLOQFECHNF;
      END IF;

      IF :OLD.DSPARFILFIS IS NOT NULL THEN
         V_DESC := V_DESC || ' BloqFechMesEstNeg=' || SUBSTR(:OLD.DSPARFILFIS,4,1);
      END IF;

      IF :OLD.IDBLOFERTNEV IS NOT NULL THEN
         V_DESC := V_DESC || ' BloqFechDiaRetNEvol=' || :OLD.IDBLOFERTNEV;
      END IF;

      IF :OLD.IDBLFECHSNFE IS NOT NULL THEN
         V_DESC := V_DESC || ' BloqFechDiaNFSaiNEmit=' || :OLD.IDBLFECHSNFE;
      END IF;

      IF :OLD.IDBLOFECHMES IS NOT NULL THEN
         V_DESC := V_DESC || ' BloqFechDiaSemRet=' || :OLD.IDBLOFECHMES;
      END IF;

      IF :OLD.IDCONSDIAUTFEC IS NOT NULL THEN
         V_DESC := V_DESC || ' ConsCalDiaNUtilFechDia=' || :OLD.IDCONSDIAUTFEC;
      END IF;

      IF :OLD.IDENTRUNILOTE IS NOT NULL THEN
         V_DESC := V_DESC || ' EntrUniLote=' || :OLD.IDENTRUNILOTE;
      END IF;

      IF :OLD.IDINFLOTFOREMI IS NOT NULL THEN
         V_DESC := V_DESC || ' IdInfLotForEmi=' || :OLD.IDINFLOTFOREMI;
      END IF;

      IF :OLD.IDUTCDEXTPRONF IS NOT NULL THEN
         V_DESC := V_DESC || ' IdUtCdExtProNF=' || :OLD.IDUTCDEXTPRONF;
      END IF;

      IF :OLD.IDUTVRCONTPRORIG IS NOT NULL THEN
         V_DESC := V_DESC || ' IdUtVrContPrOrig=' || :OLD.IDUTVRCONTPRORIG;
      END IF;

      IF :OLD.IDDESPADUBCII IS NOT NULL THEN
         V_DESC := V_DESC || ' GeraRatDespAduBCII=' || :OLD.IDDESPADUBCII;
      END IF;

      IF :OLD.IDCODEXTERNONF IS NOT NULL THEN
         V_DESC := V_DESC || ' IdCodExternoNF=' || :OLD.IDCODEXTERNONF;
      END IF;

      V_TIPO := '3';
      V_ITPESQ       := :OLD.CDFILIAL;
      V_CDFILLOGOPER := :OLD.CDFILIAL;
   ELSE
      IF UPDATING THEN
         IF (NVL(:OLD.DTPROCESSA, TO_DATE(SYSDATE-365)) <> NVL(:NEW.DTPROCESSA, TO_DATE(SYSDATE-365)))   OR
            (:OLD.IDCTRLESTQ      <> :NEW.IDCTRLESTQ)   OR
            (:OLD.NRTAMNUMNFUTDFE <> :NEW.NRTAMNUMNFUTDFE)  OR
            (NVL(:OLD.CDSERVBAIESTCEG,'NULO') <> NVL(:NEW.CDSERVBAIESTCEG,'NULO')) OR
            (NVL(:OLD.IDINVESTCEGO,'NULO') <> NVL(:NEW.IDINVESTCEGO,'NULO')) OR
            (NVL(:OLD.CDTPRETBXESTCEG,'NULO') <> NVL(:NEW.CDTPRETBXESTCEG,'NULO')) OR
            (:OLD.IDESTONLINE     <> :NEW.IDESTONLINE)  OR
            (:OLD.IDPERMESTNEG    <> :NEW.IDPERMESTNEG) OR
            (:OLD.IDORDIMPLANT    <> :NEW.IDORDIMPLANT) OR
            (:OLD.IDORDAJUINVE    <> :NEW.IDORDAJUINVE) OR
            (:OLD.IDTCUSNFROMA    <> :NEW.IDTCUSNFROMA) OR
            (:OLD.IDCONDESBONFORN <> :NEW.IDCONDESBONFORN) OR
            (:OLD.IDPARAMEMISREFI <> :NEW.IDPARAMEMISREFI) OR
            (:OLD.IDBLOQCMPSAFFIL <> :NEW.IDBLOQCMPSAFFIL) OR
            (:OLD.IDUTBLOQOPAFPF  <> :NEW.IDUTBLOQOPAFPF)  OR
            (:OLD.IDUTILALMOX     <> :NEW.IDUTILALMOX)  OR
            (:OLD.IDUTILLCESTQ    <> :NEW.IDUTILLCESTQ) OR
            (NVL(:OLD.NRMAXDIAANTDTAF,0) <> NVL(:NEW.NRMAXDIAANTDTAF,0)) OR
            (NVL(:OLD.NRMAXDIAPOSDTAF,0) <> NVL(:NEW.NRMAXDIAPOSDTAF,0)) OR
            (:OLD.IDUTILLOTE      <> :NEW.IDUTILLOTE)   OR
            (NVL(:OLD.CDTIPCUSTEST,'NULO') <> NVL(:NEW.CDTIPCUSTEST,'NULO')) OR
            (NVL(:OLD.NRTAMNUMNFUT,0) <> NVL(:NEW.NRTAMNUMNFUT,0)) OR
            (:OLD.IDUTILALLONF    <> :NEW.IDUTILALLONF) OR
            (:OLD.DSPARFILFIS     <> :NEW.DSPARFILFIS)  OR
            (:OLD.IDPERFORNECO    <> :NEW.IDPERFORNECO) OR
            (:OLD.CDFILIAL        <> :NEW.CDFILIAL)     OR
            (NVL(:OLD.IDPERPROINAT,'!') <> NVL(:NEW.IDPERPROINAT,'!')) OR
            (NVL(:OLD.CDCONFORNFI,'!')  <> NVL(:NEW.CDCONFORNFI,'!'))  OR
            (NVL(:OLD.CDCONCLIEFI,'!')  <> NVL(:NEW.CDCONCLIEFI,'!'))  OR
            (NVL(:OLD.CDCONTDIFEFI,'!') <> NVL(:NEW.CDCONTDIFEFI,'!')) OR
            (NVL(:OLD.CDCTBLPERDFI,'!') <> NVL(:NEW.CDCTBLPERDFI,'!')) OR
            (NVL(:OLD.CDREDUCONTPAG,'!')<> NVL(:NEW.CDREDUCONTPAG,'!'))OR
            (NVL(:OLD.CDTPBAIXAPAG,'!') <> NVL(:NEW.CDTPBAIXAPAG,'!')) OR
            (NVL(:OLD.CDGRUPOFISC,'!')  <> NVL(:NEW.CDGRUPOFISC,'!'))  OR
            (NVL(:OLD.IDUTLIBERANF,'!')  <> NVL(:NEW.IDUTLIBERANF,'!')) OR
            (NVL(:OLD.IDUTCTRLFISENTR, '!') <> NVL(:NEW.IDUTCTRLFISENTR, '!')) OR
            (NVL(:OLD.IDUTCTRLFISSAID, '!') <> NVL(:NEW.IDUTCTRLFISSAID, '!')) OR
            (NVL(:OLD.IDCANCEXTMPNFE,'!')   <> NVL(:NEW.IDCANCEXTMPNFE,'!')) OR
            (NVL(:OLD.IDCONSREFECH,'!')     <> NVL(:NEW.IDCONSREFECH,'!'))   OR
            (NVL(:OLD.IDLANCDTMENFIL,'!')   <> NVL(:NEW.IDLANCDTMENFIL,'!')) OR
            (NVL(:OLD.NRDIASENTRFIL,0)      <> NVL(:NEW.NRDIASENTRFIL,0))    OR
            (NVL(:OLD.NRDIASSAIDFIL,0)      <> NVL(:NEW.NRDIASSAIDFIL,0))    OR
            (NVL(:OLD.NRDIASAJUSFIL,0)      <> NVL(:NEW.NRDIASAJUSFIL,0))    OR
            (NVL(:OLD.IDLANCDTMAIFIL,'!')   <> NVL(:NEW.IDLANCDTMAIFIL,'!')) OR
            (NVL(:OLD.NRDIASENTRPDFIL,0)    <> NVL(:NEW.NRDIASENTRPDFIL,0))  OR
            (NVL(:OLD.NRDIASSAIDPDFIL,0)    <> NVL(:NEW.NRDIASSAIDPDFIL,0))  OR
            (NVL(:OLD.NRDIASAJUSPDFIL,0)    <> NVL(:NEW.NRDIASAJUSPDFIL,0))  OR
            (NVL(:OLD.IDENTRUNILOTE,'!')    <> NVL(:NEW.IDENTRUNILOTE,'!'))  OR
	         (NVL(:OLD.IDUTCTRLFIS, '!')     <> NVL(:NEW.IDUTCTRLFIS, '!'))   OR
	         (NVL(:OLD.IDBLOQFECDIA, '!')    <> NVL(:NEW.IDBLOQFECDIA, '!'))  OR
	         (NVL(:OLD.IDBLOQFECHNF, '!')    <> NVL(:NEW.IDBLOQFECHNF, '!'))  OR
	         --(NVL(:OLD.(DSPARFILFIS, '!')    <> NVL(:NEW.DSPARFILFIS, '!'))  OR
	         (NVL(:OLD.IDBLOFERTNEV, '!')    <> NVL(:NEW.IDBLOFERTNEV, '!'))  OR
	         (NVL(:OLD.IDBLFECHSNFE, '!')    <> NVL(:NEW.IDBLFECHSNFE, '!'))  OR
	         (NVL(:OLD.IDBLOFECHMES, '!')    <> NVL(:NEW.IDBLOFECHMES, '!'))  OR
	         (NVL(:OLD.IDCONSDIAUTFEC, '!')  <> NVL(:NEW.IDCONSDIAUTFEC, '!')) OR 
            (NVL(:OLD.IDINFLOTFOREMI, '!')  <> NVL(:NEW.IDINFLOTFOREMI, '!')) OR
            (NVL(:OLD.IDUTVRCONTPRORIG, '!') <> NVL(:NEW.IDUTVRCONTPRORIG, '!')) OR
            (NVL(:OLD.IDUTCDEXTPRONF, '!') <> NVL(:NEW.IDUTCDEXTPRONF, '!')) OR
            (NVL(:OLD.IDDESPADUBCII, '!') <> NVL(:NEW.IDDESPADUBCII, '!')) OR
            (NVL(:OLD.IDCODEXTERNONF, '!') <> NVL(:NEW.IDCODEXTERNONF, '!'))THEN

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

      IF (:OLD.DTPROCESSA IS NULL) AND (NOT :NEW.DTPROCESSA IS NULL) THEN
         V_DESC := V_DESC || 'DtProc = ' || TO_CHAR(:OLD.DTPROCESSA,'DD/MM/YYYY') || ' - ' || TO_CHAR(:NEW.DTPROCESSA,'DD/MM/YYYY') || ' - Fechou Dia';
      END IF;

      IF (NOT :OLD.DTPROCESSA IS NULL) AND (:NEW.DTPROCESSA IS NULL) THEN
         V_DESC := V_DESC || 'DtProc = ' || TO_CHAR(:OLD.DTPROCESSA,'DD/MM/YYYY') || ' - ' || TO_CHAR(:NEW.DTPROCESSA,'DD/MM/YYYY') || ' - Apagou Dia';
      END IF;

      IF NVL(:OLD.DTPROCESSA,'') > NVL(:NEW.DTPROCESSA,'') THEN
         V_DESC := V_DESC || 'DtProc = ' || TO_CHAR(:OLD.DTPROCESSA,'DD/MM/YYYY') || ' - ' || TO_CHAR(:NEW.DTPROCESSA,'DD/MM/YYYY') || ' - Voltou';
      ELSE
         IF NVL(:OLD.DTPROCESSA,'') <> NVL(:NEW.DTPROCESSA,'') THEN
            V_DESC := V_DESC || 'DtProc = ' || TO_CHAR(:OLD.DTPROCESSA,'DD/MM/YYYY') || ' - ' || TO_CHAR(:NEW.DTPROCESSA,'DD/MM/YYYY') || ' - Fechou Dia';
         END IF;
      END IF;

      IF NVL(:OLD.IDCTRLESTQ,'') <> NVL(:NEW.IDCTRLESTQ,'') THEN
         V_DESC := V_DESC || ' CtrEst=' || :NEW.IDCTRLESTQ;
      END IF;

      IF NVL(:OLD.IDESTONLINE,'') <> NVL(:NEW.IDESTONLINE,'') THEN
         V_DESC := V_DESC || ' EstOnL=' || :NEW.IDESTONLINE;
      END IF;

      IF NVL(:OLD.IDPERMESTNEG,'') <> NVL(:NEW.IDPERMESTNEG,'') THEN
         V_DESC := V_DESC || ' EstNeg=' ||  :NEW.IDPERMESTNEG;
      END IF;

      IF NVL(:OLD.IDORDIMPLANT,'') <> NVL(:NEW.IDORDIMPLANT,'') THEN
         V_DESC := V_DESC || ' OrdImp=' || :NEW.IDORDIMPLANT;
      END IF;

      IF NVL(:OLD.IDORDAJUINVE,'') <> NVL(:NEW.IDORDAJUINVE,'') THEN
         V_DESC := V_DESC || ' OrdAju=' || :NEW.IDORDAJUINVE;
      END IF;

      IF NVL(:OLD.IDTCUSNFROMA,'') <> NVL(:NEW.IDTCUSNFROMA,'') THEN
         V_DESC := V_DESC || ' CustSa=' || :NEW.IDTCUSNFROMA;
      END IF;

      IF NVL(:OLD.IDUTILALMOX,'') <> NVL(:NEW.IDUTILALMOX,'') THEN
         V_DESC := V_DESC || ' UtAlmo=' || :NEW.IDUTILALMOX;
      END IF;

      IF NVL(:OLD.IDUTILLCESTQ,'') <> NVL(:NEW.IDUTILLCESTQ,'') THEN
         V_DESC := V_DESC || ' UtLoca=' || :NEW.IDUTILLCESTQ;
      END IF;

      IF NVL(:OLD.IDUTILLOTE,'') <> NVL(:NEW.IDUTILLOTE,'') THEN
         V_DESC := V_DESC || ' UtLote=' || :NEW.IDUTILLOTE;
      END IF;

      IF NVL(:OLD.CDTIPCUSTEST,'NULO') <> NVL(:NEW.CDTIPCUSTEST,'NULO') THEN
         V_DESC := V_DESC || ' TipoCustEst=' || NVL(:NEW.CDTIPCUSTEST,'NULO');
      END IF;

      IF NVL(:OLD.NRTAMNUMNFUT,0) <> NVL(:NEW.NRTAMNUMNFUT,0) THEN
         V_DESC := V_DESC || ' TamNumNF=' || :NEW.NRTAMNUMNFUT;
      END IF;

      IF NVL(:OLD.IDUTILALLONF,'') <> NVL(:NEW.IDUTILALLONF,'') THEN
         V_DESC := V_DESC || ' UtilAlLocNF=' || :NEW.IDUTILALLONF;
      END IF;

      IF NVL(SUBSTR(:OLD.DSPARFILFIS,2,1),'') <> NVL(SUBSTR(:NEW.DSPARFILFIS,2,1),'') THEN
         V_DESC := V_DESC || ' BloqNFAF=' || SUBSTR(:NEW.DSPARFILFIS,2,1);
      END IF;

      IF NVL(SUBSTR(:OLD.DSPARFILFIS,1,1),'') <> NVL(SUBSTR(:NEW.DSPARFILFIS,1,1),'') THEN
         V_DESC := V_DESC || ' VerProdDifAF=' || SUBSTR(:NEW.DSPARFILFIS,1,1);
      END IF;

      IF NVL(:OLD.IDPERFORNECO,'') <> NVL(:NEW.IDPERFORNECO,'') THEN
         V_DESC := V_DESC || ' PerESCmpCot=' || :NEW.IDPERFORNECO;
      END IF;

      IF NVL(SUBSTR(:NEW.DSPARFILFIS,1,2),'') <> NVL(SUBSTR(:NEW.DSPARFILFIS,1,2),'') THEN
         V_DESC := V_DESC || ' VerPrAF_BloqNF=' || SUBSTR(:NEW.DSPARFILFIS,1,2);
      END IF;

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

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

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

      IF NVL(:OLD.CDCTBLPERDFI,'!') <> NVL(:NEW.CDCTBLPERDFI,'!') THEN
         V_DESC := V_DESC || ' LucPer=' || :NEW.CDCTBLPERDFI;
      END IF;
      
      IF NVL(:OLD.CDGRUPOFISC,'!') <> NVL(:NEW.CDGRUPOFISC,'!') THEN
         V_DESC := V_DESC || ' GrupoFiscal=' || :NEW.CDGRUPOFISC;
      END IF;
      
      IF NVL(:OLD.IDPERPROINAT,'!') <> NVL(:NEW.IDPERPROINAT,'!') THEN
         V_DESC := V_DESC || ' PerProdInat=' || :NEW.IDPERPROINAT;
      END IF;
      
      IF NVL(:OLD.CDSERVBAIESTCEG,'!') <> NVL(:NEW.CDSERVBAIESTCEG,'!') THEN
         V_DESC := V_DESC || ' ServBaiEstCego=' || :NEW.CDSERVBAIESTCEG;
      END IF;
      
      IF NVL(:OLD.IDINVESTCEGO,'!') <> NVL(:NEW.IDINVESTCEGO,'!') THEN
         V_DESC := V_DESC || ' InvEstCego=' || :NEW.IDINVESTCEGO;
      END IF;
      
      IF NVL(:OLD.CDTPRETBXESTCEG,'!') <> NVL(:NEW.CDTPRETBXESTCEG,'!') THEN
         V_DESC := V_DESC || ' PretEstCego=' || :NEW.CDTPRETBXESTCEG;
      END IF;

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

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

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

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

      IF NVL(:OLD.NRMAXDIAANTDTAF,0) <> NVL(:NEW.NRMAXDIAANTDTAF,0) THEN
         V_DESC := V_DESC || ' NumMaxDiaAntImpoAF=' || :NEW.NRMAXDIAANTDTAF;
      END IF;

      IF NVL(:OLD.NRMAXDIAPOSDTAF,0) <> NVL(:NEW.NRMAXDIAPOSDTAF,0) THEN
         V_DESC := V_DESC || ' NumMaxDiaPosImpoAF=' || :NEW.NRMAXDIAPOSDTAF;
      END IF;

      IF NVL(:OLD.NRTAMNUMNFUTDFE,0) <> NVL(:NEW.NRTAMNUMNFUTDFE,0) THEN
         V_DESC := V_DESC || ' TamNumNfDfe=' || :NEW.NRTAMNUMNFUTDFE;
      END IF;

      IF NVL(:OLD.CDREDUCONTPAG,0) <> NVL(:NEW.CDREDUCONTPAG,0) THEN
         V_DESC := V_DESC || ' NumContCorren=' || :NEW.CDREDUCONTPAG;
      END IF;
     
      IF NVL(:OLD.CDTPBAIXAPAG,0) <> NVL(:NEW.CDTPBAIXAPAG,0) THEN
         V_DESC := V_DESC || ' TipoBaixa=' || :NEW.CDTPBAIXAPAG;
      END IF;

      IF NVL(:OLD.IDUTCTRLFIS,'') <> NVL(:NEW.IDUTCTRLFIS,'') THEN
         V_DESC := V_DESC || ' UtCtrFis='  || :NEW.IDUTCTRLFIS;
      END IF;

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

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

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

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

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

      IF NVL(:OLD.IDLANCDTMENFIL, '') <> NVL(:NEW.IDLANCDTMENFIL, '') THEN
         V_DESC := V_DESC || ' LDtMen=' || :NEW.IDLANCDTMENFIL;
      END IF;

      IF NVL(:OLD.NRDIASENTRFIL, 0) <> NVL(:NEW.NRDIASENTRFIL, 0) THEN
         V_DESC := V_DESC || ' DiaEnt=' || :NEW.NRDIASENTRFIL;
      END IF;

      IF NVL(:OLD.NRDIASSAIDFIL, 0) <> NVL(:NEW.NRDIASSAIDFIL, 0) THEN
         V_DESC := V_DESC || ' DiaSai=' || :NEW.NRDIASSAIDFIL;
      END IF;

      IF NVL(:OLD.NRDIASAJUSFIL, 0) <> NVL(:NEW.NRDIASAJUSFIL, 0) THEN
         V_DESC := V_DESC || ' DiaAju=' || :NEW.NRDIASAJUSFIL;
      END IF;

      IF NVL(:OLD.IDLANCDTMAIFIL, '') <> NVL(:NEW.IDLANCDTMAIFIL, '') THEN
         V_DESC := V_DESC || ' LDtMai=' || :NEW.IDLANCDTMAIFIL;
      END IF;

      IF NVL(:OLD.NRDIASENTRPDFIL, 0) <> NVL(:NEW.NRDIASENTRPDFIL, 0) THEN
         V_DESC := V_DESC || ' EntPos=' || :NEW.NRDIASENTRPDFIL;
      END IF;

      IF NVL(:OLD.NRDIASSAIDPDFIL, 0) <> NVL(:NEW.NRDIASSAIDPDFIL, 0) THEN
         V_DESC := V_DESC || ' SaiPos=' || :NEW.NRDIASSAIDPDFIL;
      END IF;

      IF NVL(:OLD.NRDIASAJUSPDFIL, 0) <> NVL(:NEW.NRDIASAJUSPDFIL, 0) THEN
         V_DESC := V_DESC || ' AjuPos=' || :NEW.NRDIASAJUSPDFIL;
      END IF;
      
      IF NVL(:OLD.IDBLOQFECDIA, '') <> NVL(:NEW.IDBLOQFECDIA, '') THEN
         V_DESC := V_DESC || ' BloqDiaFechMesNInf=' || :NEW.IDBLOQFECDIA;
      END IF;

      IF NVL(:OLD.IDBLOQFECHNF, '') <> NVL(:NEW.IDBLOQFECHNF, '') THEN
         V_DESC := V_DESC || ' BloqFechDiaEntSNF=' || :NEW.IDBLOQFECHNF;
      END IF;
      
      IF NVL(:OLD.DSPARFILFIS, '') <> NVL(:NEW.DSPARFILFIS, '') THEN
         V_DESC := V_DESC || ' BloqFechMesEstNeg=' || SUBSTR(:NEW.DSPARFILFIS,4,1);
      END IF;

      IF NVL(:OLD.IDBLOFERTNEV, '') <> NVL(:NEW.IDBLOFERTNEV, '') THEN
         V_DESC := V_DESC || ' BloqFechDiaRetNEvol=' || :NEW.IDBLOFERTNEV;
      END IF;

      IF NVL(:OLD.IDBLFECHSNFE, '') <> NVL(:NEW.IDBLFECHSNFE, '') THEN
         V_DESC := V_DESC || ' BloqFechDiaNFSaiNEmit=' || :NEW.IDBLFECHSNFE;
      END IF;

      IF NVL(:OLD.IDBLOFECHMES, '') <> NVL(:NEW.IDBLOFECHMES, '') THEN
         V_DESC := V_DESC || ' BloqFechDiaSemRet=' || :NEW.IDBLOFECHMES;
      END IF;

      IF NVL(:OLD.IDCONSDIAUTFEC, '') <> NVL(:NEW.IDCONSDIAUTFEC, '') THEN
         V_DESC := V_DESC || ' ConsCalDiaNUtilFechDia=' || :NEW.IDCONSDIAUTFEC;
      END IF;         

      IF NVL(:OLD.IDENTRUNILOTE, '') <> NVL(:NEW.IDENTRUNILOTE, '') THEN
         V_DESC := V_DESC || ' EntrUniLote=' || :NEW.IDENTRUNILOTE;
      END IF;
      
      IF NVL(:OLD.IDINFLOTFOREMI, '') <> NVL(:NEW.IDINFLOTFOREMI, '') THEN
         V_DESC := V_DESC || ' IdInfLotForEmi=' || :NEW.IDINFLOTFOREMI;
      END IF;

      IF NVL(:OLD.IDUTCDEXTPRONF, '') <> NVL(:NEW.IDUTCDEXTPRONF, '') THEN
         V_DESC := V_DESC || ' IdUtCdExtProNF=' || :NEW.IDUTCDEXTPRONF;
      END IF;

      IF NVL(:OLD.IDUTVRCONTPRORIG, '') <> NVL(:NEW.IDUTVRCONTPRORIG, '') THEN
         V_DESC := V_DESC || ' IdUtVrContPrOrig=' || :NEW.IDUTVRCONTPRORIG;
      END IF;

      IF NVL(:OLD.IDDESPADUBCII, '') <> NVL(:NEW.IDDESPADUBCII, '') THEN
         V_DESC := V_DESC || ' GeraRatDespAduBCII=' || :NEW.IDDESPADUBCII;
      END IF;

      IF NVL(:OLD.IDCODEXTERNONF, '') <> NVL(:NEW.IDCODEXTERNONF, '') THEN
         V_DESC := V_DESC || ' IdCodExternoNF=' || :NEW.IDCODEXTERNONF;
      END IF;
   END IF;
   IF V_TIPO <> '0' THEN
      IF NOT V_DESC IS NULL THEN
         NMUSUARIO(V_USUARIO);
         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
               ('PARAMFILIAL',  V_DTOPER, V_USUARIO,
                V_TIPO,         V_ITPESQ, SUBSTR(V_DESC, 1, 700), V_CDFILLOGOPER,
                V_DSREMOTEADDR, V_DSREMOTEHOST, V_DSSERVERRDM,
                V_DSSERVMETHOD, V_DSREMOTEOPER);
         END IF;
      END IF;
   END IF;
END;
/
