CREATE OR REPLACE TRIGGER LOG_SUP_AUTGRUPOPSOLI
AFTER DELETE OR INSERT OR UPDATE
ON AUTGRUPOPSOLI 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(40);
  V_NMOPERADOR   VARCHAR2(40);
  V_IDTIPOOPER   VARCHAR2(1);
BEGIN
/* IDTIPOOPER - '1' - Inclusao, '2' - Alteracao, '3' - Exclusao*/
   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(:OLD.NRAUTGRUPOPSOLI, '!') <> NVL(:NEW.NRAUTGRUPOPSOLI, '!')    THEN
         V_DESC   := V_DESC || 'Sequencial: ' || '' || NVL(:NEW.NRAUTGRUPOPSOLI,  '')  || ' ';
      END IF;
      IF NVL(:OLD.IDAUTNECECOMP, '!')   <> NVL(:NEW.IDAUTNECECOMP, '!')   THEN
         V_DESC   := V_DESC || 'Nec. Compras: ' || '' || NVL(:NEW.IDAUTNECECOMP, '')  || ' ';
      END IF;
      IF NVL(:OLD.IDAUTLANCSOLI, '!')   <> NVL(:NEW.IDAUTLANCSOLI, '!')   THEN
         V_DESC   := V_DESC || 'Lanc Soli Compras: ' || '' || NVL(:NEW.IDAUTLANCSOLI, '')  || ' ';
      END IF;
      IF NVL(:OLD.IDAUTALTEPRODSOLI, '!')   <> NVL(:NEW.IDAUTALTEPRODSOLI, '!')   THEN
         V_DESC   := V_DESC || 'Alt Prod Soli: ' || '' || NVL(:NEW.IDAUTALTEPRODSOLI, '')  || ' ';
      END IF;
      IF NVL(:OLD.IDAUTALTESOLI, '!') <> NVL(:NEW.IDAUTALTESOLI, '!')      THEN
         V_DESC   := V_DESC || 'Alt Solicitacao: ' || '' || :NEW.IDAUTALTESOLI              || ' ';
      END IF;
      IF NVL(:OLD.PEALTEQTDESOLI, '0')   <> NVL(:NEW.PEALTEQTDESOLI, '0')   THEN
         V_DESC   := V_DESC || 'Perc Alt Qtde Soli: '  || '' || :NEW.PEALTEQTDESOLI           || ' ';
      END IF;
      IF NVL(:OLD.CDFILCENTCMP, '!') <> NVL(:NEW.CDFILCENTCMP, '!') THEN
         V_DESC   := V_DESC || 'Central de Compras: '         || '' || :NEW.CDFILCENTCMP    || ' ';
      END IF;
     
      V_ITPESQ       := NVL(:OLD.CDGRUPOPER, '');
      V_IDTIPOOPER   := '2';
   ELSE
      IF INSERTING THEN
         V_DESC   := 'Sequencial: '         || '' || NVL(:NEW.NRAUTGRUPOPSOLI,   '') || ' ' ||
                     'Nec. Compras: '       || '' || NVL(:NEW.IDAUTNECECOMP,     '') || ' ' ||
                     'Lanc Soli Compras: '  || '' || NVL(:NEW.IDAUTLANCSOLI,     '') || ' ' ||
                     'Alt Prod Soli: '      || '' || NVL(:NEW.IDAUTALTEPRODSOLI, '') || ' ' ||
                     'Alt Solicitacao: '    || '' || NVL(:NEW.IDAUTALTESOLI,     '') || ' ' ||
                     'Perc Alt Qtde Soli: ' || '' || NVL(:NEW.PEALTEQTDESOLI,    '') || ' ' ||
                     'Central de Compras: ' || '' || NVL(:NEW.CDFILCENTCMP,      '');
         V_ITPESQ       := :NEW.CDGRUPOPER;
         V_IDTIPOOPER   := '1';
      ELSE
         IF DELETING THEN
            V_DESC   := 'Sequencial: '         || '' || NVL(:OLD.NRAUTGRUPOPSOLI,   '') || ' ' ||
                        'Nec. Compras'         || '' || NVL(:OLD.IDAUTNECECOMP,     '') || ' ' ||
                        'Lanc Soli Compras: '  || '' || NVL(:OLD.IDAUTLANCSOLI,     '') || ' ' ||
                        'Alt Prod Soli: '      || '' || NVL(:OLD.IDAUTALTEPRODSOLI, '') || ' ' ||
                        'Alt Solicitacao: '    || '' || NVL(:OLD.IDAUTALTESOLI,     '') || ' ' ||
                        'Perc Alt Qtde Soli: ' || '' || NVL(:OLD.PEALTEQTDESOLI,    '') || ' ' ||
                        'Central de Compras: ' || '' || NVL(:OLD.CDFILCENTCMP,      '');
            V_ITPESQ       := NVL(:OLD.CDGRUPOPER, '');
            V_IDTIPOOPER   := '3';
         END IF;
      END IF;
   END IF;
   V_DESC := SUBSTR(V_DESC, 1, 300);
   INSERT INTO LOGOPERA
      (NMTABELA,
       DTOPERACAO,
       NMRESPOPER,
       IDTIPOOPER,
       DSOPERACAO,
       CDPESQITEM,
       DSRDMUSUOPER,
       DSENDUSUOPER,
       DSNMUSUOPER,
       DSMETUSUOPER,
       CDORESPOPER)
    VALUES
      ('AUTGRUPOPSOLI',
       SYSDATE,
       NVL(V_NMOPERADOR,' '),
       V_IDTIPOOPER,
       V_DESC,
       V_ITPESQ,
       V_DSSERVERRDM,
       V_DSREMOTEADDR,
       V_DSREMOTEHOST,
       V_DSSERVMETHOD,
       V_DSREMOTEOPER);
END;
/