CREATE OR REPLACE TRIGGER LOG_PARAMFISCAL
AFTER DELETE OR INSERT OR UPDATE
ON PARAMFISCAL 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(300);
   V_ITPESQ       VARCHAR2(80);
   V_NMOPERADOR   VARCHAR2(40);
   V_IDTIPOOPER   VARCHAR2(1);

BEGIN
   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 (:NEW.CDTPCTPAGAR <> :OLD.CDTPCTPAGAR) THEN
         V_DESC := V_DESC || 'CodContPG= ' || NVL(:NEW.CDTPCTPAGAR,'') || ' ' ;
      END IF;

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

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

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

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

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

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

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

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

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

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

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

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

      V_ITPESQ := :NEW.CDPARFISCAL;
      V_IDTIPOOPER := '2';
   END IF;

   IF NOT (V_DESC IS NULL) THEN
      INSERT INTO LOGOPERA
        (NMTABELA,     DTOPERACAO,   NMRESPOPER,   IDTIPOOPER,   DSOPERACAO,
         CDPESQITEM,   DSRDMUSUOPER, DSENDUSUOPER, DSNMUSUOPER,  DSMETUSUOPER,
         CDORESPOPER)
      VALUES
         ('PARAMFISCAL', SYSDATE,       NVL(V_NMOPERADOR,' '), V_IDTIPOOPER,    V_DESC,
          V_ITPESQ,      V_DSSERVERRDM, V_DSREMOTEADDR,        V_DSREMOTEHOST,  V_DSSERVMETHOD,
          V_DSREMOTEOPER);
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('LOG_PARAMFISCAL','6.45.042'); END;
/
