create or replace TRIGGER LOG_FIN_GERAL_BCO
AFTER DELETE OR INSERT OR UPDATE
ON GERAL_BCO FOR EACH ROW
DECLARE
  V_USUARIO      VARCHAR2(40);
  V_TIPO         VARCHAR2(1);
  V_ITPESQ       VARCHAR2(40);
  V_DESC         VARCHAR2(300);
  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_CDFILLOGOPER := '';
	V_TIPO := '0';
   IF DELETING THEN
      V_TIPO   := '3';
      V_DESC   := ' IDCTBTRANS '    || :OLD.IDCTBTRANS   || 
		            ' IDCTBLCCOR '    || :OLD.IDCTBLCCOR   ||
						' QTDIAANTTRAN '  || :OLD.QTDIAANTTRAN ||
						' QTDIAAPOTRAN '  || :OLD.QTDIAAPOTRAN ||
						' QTDIAANTLANC '  || :OLD.QTDIAANTLANC ||
						' QTDIAAPOLANC '  || :OLD.QTDIAAPOLANC ||
						' IDTPIMPRUTL  '  || :OLD.IDTPIMPRUTL  ||
						' IDTPPORTIMPR '  || :OLD.IDTPPORTIMPR ||
						' IDPERTRANSCCOR '|| :OLD.IDPERTRANSCCOR;    
             

      V_ITPESQ       := :OLD.CDGERALBCO;
   ELSE
		V_DESC   := ' IDCTBTRANS '    || :NEW.IDCTBTRANS   || 
						' IDCTBLCCOR '    || :NEW.IDCTBLCCOR   ||
						' QTDIAANTTRAN '  || :NEW.QTDIAANTTRAN ||
						' QTDIAAPOTRAN '  || :NEW.QTDIAAPOTRAN ||
						' QTDIAANTLANC '  || :NEW.QTDIAANTLANC ||
						' QTDIAAPOLANC '  || :NEW.QTDIAAPOLANC ||
						' IDTPIMPRUTL  '  || :NEW.IDTPIMPRUTL  ||
						' IDTPPORTIMPR '  || :NEW.IDTPPORTIMPR ||
						' IDPERTRANSCCOR '|| :NEW.IDPERTRANSCCOR;  
      IF UPDATING THEN
			V_TIPO   := '2';
         V_ITPESQ := :OLD.CDGERALBCO;	 
      ELSE
         V_TIPO   := '1';
         V_ITPESQ := :NEW.CDGERALBCO;	
      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,
                DSRDMUSUOPER, DSENDUSUOPER,
                DSNMUSUOPER, DSMETUSUOPER, CDORESPOPER)
            VALUES
               ('GERAL_BCO', V_DTOPER, V_USUARIO,
                V_TIPO,      V_ITPESQ, V_DESC,
                 V_DSSERVERRDM, V_DSREMOTEADDR,
                V_DSREMOTEHOST, V_DSSERVMETHOD, V_DSREMOTEOPER);
         END IF;
      END IF;
   END IF;
END;
/
-- VERSAO --
BEGIN ATUVEROBJ('LOG_FIN_GERAL_BCO','6.10.xxx'); END;
/