CREATE OR REPLACE TRIGGER LOG_VND_TIPOCONSLOJA
AFTER DELETE OR INSERT OR UPDATE
ON TIPOCONSLOJA 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' - Inclusão, '2' - Alteração, '3' - Exclusão*/
   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   := 'Filial ' || '' || NVL(:NEW.CDFILIAL,''    );
		END IF;
		IF NVL(:NEW.CDLOJA ,'NULL') <> NVL(:OLD.CDLOJA , 'NULL') THEN
			V_DESC := NVL(V_DESC, '') || ' ' || 'Loja '|| '' || NVL(:NEW.CDLOJA,'');
		END IF;
		IF NVL(:NEW.CDTIPOCONS ,'NULL') <> NVL(:OLD.CDTIPOCONS ,'NULL') THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'Tipo Cons '     || '' || NVL(:NEW.CDTIPOCONS,''  );
		END IF;
		IF NVL(:NEW.VRMAXCONSDIAC ,999999) <> NVL(:OLD.VRMAXCONSDIAC ,999999) THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'Vr max dia Cred '  || '' || NVL(:NEW.VRMAXCONSDIAC,'');
		END IF;
		IF NVL(:NEW.VRMAXCONSDIAD ,999999) <> NVL(:OLD.VRMAXCONSDIAD ,999999) THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'Vr max dia Deb '  || '' || NVL(:NEW.VRMAXCONSDIAD,'');
		END IF;
		IF NVL(:NEW.VRMAXCONSMESC ,999999) <> NVL(:OLD.VRMAXCONSMESC ,999999) THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'Vr max mes Cred '  || '' || NVL(:NEW.VRMAXCONSMESC,'');
		END IF;
		IF NVL(:NEW.VRMAXCONSMESD ,999999) <> NVL(:OLD.VRMAXCONSMESD ,999999) THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'Vr max mes Deb '  || '' || NVL(:NEW.VRMAXCONSMESD,'');
		END IF;
      V_ITPESQ := :NEW.CDFILIAL||:NEW.CDLOJA||:NEW.CDTIPOCONS;
      V_IDTIPOOPER := '2';
   ELSE
      IF INSERTING THEN
      V_DESC   := 'Filial '               || '' || NVL(:NEW.CDFILIAL,''     )  ||   
	   ' ' || 'Loja '|| '' || NVL(:NEW.CDLOJA,''       )  || 
	   ' ' || 'Tipo Cons '         || '' || NVL(:NEW.CDTIPOCONS,''   )  || 
	   ' ' || 'Vr max dia Cred '|| '' || NVL(:NEW.VRMAXCONSDIAC,'')  ||
       ' ' || 'Vr max dia Deb '|| '' || NVL(:NEW.VRMAXCONSDIAD,'') ||
	   ' ' || 'Vr max mes Cred '|| '' || NVL(:NEW.VRMAXCONSMESC,'') ||
	   ' ' || 'Vr max mes Deb '|| '' || NVL(:NEW.VRMAXCONSMESD,'');
      V_ITPESQ := :NEW.CDFILIAL||:NEW.CDLOJA||:NEW.CDTIPOCONS;
      V_IDTIPOOPER := '1';
      ELSE
         IF DELETING THEN
			V_DESC   := 'Filial '               || '' || NVL(:OLD.CDFILIAL,''    )  || ' ' ||
						'Loja '                || '' || NVL(:OLD.CDLOJA,''      )  || ' ' ||
						'Tipo Cons '     || '' || NVL(:OLD.CDTIPOCONS,''  )  || ' ' ||
						'Vr max dia Cred '  || '' || NVL(:OLD.VRMAXCONSDIAC,'')|| ' ' ||
						'Vr max dia Deb '|| '' || NVL(:OLD.VRMAXCONSDIAD,'') || ' ' ||
						'Vr max mes Cred '|| '' || NVL(:OLD.VRMAXCONSMESC,'') || ' ' ||
						'Vr max mes Deb '|| '' || NVL(:OLD.VRMAXCONSMESD,'');
			V_ITPESQ := :OLD.CDFILIAL||:OLD.CDLOJA||:OLD.CDTIPOCONS;
			V_IDTIPOOPER := '3';
         END IF;
      END IF;
   END IF;
   V_DESC := SUBSTR(V_DESC, 1, 300);
   INSERT INTO LOGOPERAVND
      (NMTABELAVND,
       DTOPERACAOVND,
       NMRESPOPERVND,
       IDTIPOOPERVND,
       DSOPERACAOVND,
       CDPESQITEMVND,
       DSRDMUSUOPERVND,
       DSENDUSUOPERVND,
       DSNMUSUOPERVND,
       DSMETUSUOPERVND,
       CDORESPOPERVND,
       CDFILLOGOPERVND)
   VALUES
      ('TIPOCONSLOJA',
       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_TIPOCONSLOJA','6.02.000'); END;
/