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

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

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

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

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

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

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

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

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

      IF NVL(:NEW.DTFINVGGRPROFIL,TO_DATE('01/01/0001','DD/MM/YYYY'))  <> NVL(:OLD.DTFINVGGRPROFIL,TO_DATE('01/01/0001','DD/MM/YYYY'))  THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'DTFINVGGRPROFIL ' || ' ' || NVL(:NEW.DTFINVGGRPROFIL,'');
		END IF;

      IF NVL(:NEW.DTINIVGGRPROFIL, TO_DATE('01/01/0001','DD/MM/YYYY'))  <> NVL(:OLD.DTINIVGGRPROFIL, TO_DATE('01/01/0001','DD/MM/YYYY'))  THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'DTINIVGGRPROFIL ' || ' ' || NVL(:NEW.DTINIVGGRPROFIL,'');
		END IF;

      IF NVL(:NEW.NRSEQGRPROMOFIL ,'NULL') <> NVL(:OLD.NRSEQGRPROMOFIL ,'NULL') THEN
			V_DESC := NVL(V_DESC,'') || ' ' || 'NRSEQGRPROMOFIL ' || '' || NVL(:NEW.NRSEQGRPROMOFIL,'');
      END IF;
      V_ITPESQ := :OLD.CDFILIAL||:OLD.CDPRODPROMOCAO||:OLD.CDGRUPROMOC;
      V_IDTIPOOPER := '2';
   ELSIF INSERTING THEN
      V_DESC   := 'CDFILIAL ' || '' || NVL(:NEW.CDFILIAL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'CDPRODPROMOCAO ' || '' || NVL(:NEW.CDPRODPROMOCAO,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'CDGRUPROMOC ' || '' || NVL(:NEW.CDGRUPROMOC,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'QTPRGRUPPROMFIL ' || '' || NVL(:NEW.QTPRGRUPPROMFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'NRORDPROMOGRUPFIL ' || '' || NVL(:NEW.NRORDPROMOGRUPFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'CDGRUPMUTEXFIL ' || '' || NVL(:NEW.CDGRUPMUTEXFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'QTPRGRUPROMINFIL ' || '' || NVL(:NEW.QTPRGRUPROMINFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'IDAPLICADESCFIL ' || '' || NVL(:NEW.IDAPLICADESCFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'IDIMPGRPROMOFIL ' || '' || NVL(:NEW.IDIMPGRPROMOFIL,'');
		V_DESC := NVL(V_DESC, '') || ' ' || 'DTFINVGGRPROFIL ' || ' ' || NVL(:NEW.DTFINVGGRPROFIL,'');
		V_DESC := NVL(V_DESC, '') || ' ' || 'DTINIVGGRPROFIL ' || ' ' || NVL(:NEW.DTINIVGGRPROFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'NRSEQGRPROMOFIL ' || '' || NVL(:NEW.NRSEQGRPROMOFIL,'');
      V_ITPESQ := :NEW.CDFILIAL||:NEW.CDPRODPROMOCAO||:NEW.CDGRUPROMOC;
      V_IDTIPOOPER := '1';
   ELSIF DELETING THEN
      V_DESC   := 'CDFILIAL ' || '' || NVL(:OLD.CDFILIAL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'CDPRODPROMOCAO ' || '' || NVL(:OLD.CDPRODPROMOCAO,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'CDGRUPROMOC ' || '' || NVL(:OLD.CDGRUPROMOC,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'QTPRGRUPPROMFIL ' || '' || NVL(:OLD.QTPRGRUPPROMFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'NRORDPROMOGRUPFIL ' || '' || NVL(:OLD.NRORDPROMOGRUPFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'CDGRUPMUTEXFIL ' || '' || NVL(:OLD.CDGRUPMUTEXFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'QTPRGRUPROMINFIL ' || '' || NVL(:OLD.QTPRGRUPROMINFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'IDAPLICADESCFIL ' || '' || NVL(:OLD.IDAPLICADESCFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'IDIMPGRPROMOFIL ' || '' || NVL(:OLD.IDIMPGRPROMOFIL,'');
		V_DESC := NVL(V_DESC, '') || ' ' || 'DTFINVGGRPROFIL ' || ' ' || NVL(:OLD.DTFINVGGRPROFIL,'');
		V_DESC := NVL(V_DESC, '') || ' ' || 'DTINIVGGRPROFIL ' || ' ' || NVL(:OLD.DTINIVGGRPROFIL,'');
		V_DESC := NVL(V_DESC,'') || ' ' || 'NRSEQGRPROMOFIL ' || '' || NVL(:OLD.NRSEQGRPROMOFIL,'');
      V_IDTIPOOPER := '3';
      V_ITPESQ := :OLD.CDFILIAL||:OLD.CDPRODPROMOCAO||:OLD.CDGRUPROMOC;
   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
      ('GRUPROMOCPRFIL',
       SYSDATE,
       NVL(V_NMOPERADOR,' '),
       V_IDTIPOOPER,
       NVL(V_DESC,' '),
       V_ITPESQ,
       V_DSSERVERRDM,
       V_DSREMOTEADDR,
       V_DSREMOTEHOST,
       V_DSSERVMETHOD,
       V_DSREMOTEOPER,
       NVL(:NEW.CDFILIAL, :OLD.CDFILIAL));
END;
/

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