CREATE OR REPLACE TRIGGER LOG_VND_GRUPROMOC
AFTER DELETE OR INSERT OR UPDATE
ON GRUPROMOC 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(60);
  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 NVL(:NEW.CDGRUPROMOC ,'NULL') <> NVL(:OLD.CDGRUPROMOC ,'NULL') THEN
			V_DESC   := 'CDGRUPROMOC ' || '' || NVL(:NEW.CDGRUPROMOC,'');
		END IF;

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

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

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

      IF NVL(:NEW.IDMODOEXIBETAA ,'NULL') <> NVL(:OLD.IDMODOEXIBETAA ,'NULL') THEN
			V_DESC := NVL(V_DESC,'') || ' ' || 'IDMODOEXIBETAA ' || '' || NVL(:NEW.IDMODOEXIBETAA,'');
		END IF;
      V_ITPESQ := :OLD.CDGRUPROMOC;
      V_IDTIPOOPER := '2';
   ELSIF INSERTING THEN
      V_DESC   := 'CDGRUPROMOC ' || '' || NVL(:NEW.CDGRUPROMOC,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'NMGRUPROMOC ' || '' || NVL(:NEW.NMGRUPROMOC,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'DSENDEIMGGRUPROMOC ' || '' || NVL(:NEW.DSENDEIMGGRUPROMOC,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'DSGROUPTAA ' || '' || NVL(:NEW.DSGROUPTAA,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'IDMODOEXIBETAA ' || '' || NVL(:NEW.IDMODOEXIBETAA,'');
      V_ITPESQ := :NEW.CDGRUPROMOC;
		V_IDTIPOOPER := '1';
   ELSIF DELETING THEN
      V_DESC   := 'CDGRUPROMOC ' || '' || NVL(:OLD.CDGRUPROMOC,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'NMGRUPROMOC ' || '' || NVL(:OLD.NMGRUPROMOC,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'DSENDEIMGGRUPROMOC ' || '' || NVL(:OLD.DSENDEIMGGRUPROMOC,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'DSGROUPTAA ' || '' || NVL(:OLD.DSGROUPTAA,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'IDMODOEXIBETAA ' || '' || NVL(:OLD.IDMODOEXIBETAA,'');
      V_ITPESQ := :OLD.CDGRUPROMOC;
      V_IDTIPOOPER := '3';
   END IF;
   V_DESC := SUBSTR(V_DESC, 1, 300);
   V_ITPESQ := SUBSTR(V_ITPESQ, 1, 40);
   INSERT INTO LOGOPERAVND
      (NMTABELAVND,
       DTOPERACAOVND,
       NMRESPOPERVND,
       IDTIPOOPERVND,
       DSOPERACAOVND,
       CDPESQITEMVND,
       DSRDMUSUOPERVND,
       DSENDUSUOPERVND,
       DSNMUSUOPERVND,
       DSMETUSUOPERVND,
       CDORESPOPERVND,
       CDFILLOGOPERVND)
   VALUES
      ('GRUPROMOC',
       SYSDATE,
       NVL(V_NMOPERADOR,' '),
       V_IDTIPOOPER,
       NVL(V_DESC,' '),
       V_ITPESQ,
       V_DSSERVERRDM,
       V_DSREMOTEADDR,
       V_DSREMOTEHOST,
       V_DSSERVMETHOD,
       V_DSREMOTEOPER,
       NULL);
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('LOG_VND_GRUPROMOC','6.39.005'); END;
/
