CREATE OR REPLACE TRIGGER DTULTATU_CONFTELACAIXA_CASCADE
BEFORE INSERT OR UPDATE OR DELETE
ON CONFTELACAIXA FOR EACH ROW

DECLARE
   V_NRCONFTELA VARCHAR2(05);
   V_CDFILIAL VARCHAR2(04);
   V_DTINIVIGENCIA VARCHAR2(10);
   V_DSCHAVE VARCHAR2(100);

BEGIN
   IF INSERTING OR UPDATING THEN
      UPDATE CONFTELA
         SET DTULTATUCFTE = SYSDATE
       WHERE NRCONFTELA = :NEW.NRCONFTELA
         AND CDFILIAL = :NEW.CDFILIAL
         AND DTINIVIGENCIA = :NEW.DTINIVIGENCIA;

	  V_NRCONFTELA := NVL(:NEW.NRCONFTELA, :OLD.NRCONFTELA);
     V_CDFILIAL   := NVL(:NEW.CDFILIAL, :OLD.CDFILIAL);
     V_DTINIVIGENCIA := TO_CHAR(NVL(:NEW.DTINIVIGENCIA, :OLD.DTINIVIGENCIA), 'DD/MM/YYYY');
	  V_DSCHAVE   := V_CDFILIAL||'|'||V_NRCONFTELA||'|'||V_DTINIVIGENCIA;

	   UPDATE CTRLATUALTAB
            SET DTULTATU = SYSDATE
          WHERE NMTABELA = 'ITMENUCONFTE'
            AND DSCHAVE LIKE V_DSCHAVE||'%';

      UPDATE SUGESTAOVENDA
	 SET DTULTATU = SYSDATE
       WHERE CDFILIAL = :NEW.CDFILIAL
         AND NRCONFTELA = :NEW.NRCONFTELA;

   END IF;
END;

/
