CREATE OR REPLACE TRIGGER 
ALTERA_TAREFA
AFTER INSERT ON SOLIBASELINE FOR EACH ROW
DECLARE
   V_SITUACAO PROJETO.IDSITPROJETO%TYPE;
   V_TIPO PROJETO.IDTIPOPROJETO%TYPE;
BEGIN
   SELECT MAX(IDSITPROJETO), MAX(IDTIPOPROJETO)
     INTO V_SITUACAO, V_TIPO
     FROM PROJETO
    WHERE CDFILIAL = :NEW.CDFILIAL
      AND CDPROJETO = :NEW.CDPROJETO;
   IF V_SITUACAO = 'A' AND V_TIPO = '2' THEN
      FOR C_TAREFA IN 
        (SELECT TA.CDFILIAL, TA.NRTAREFA
           FROM SOLISERV SO, TAREFA TA
          WHERE SO.CDFILIAL   = :NEW.CDFILIAL
            AND SO.NRSOLISERV = :NEW.NRSOLISERV
            AND SO.CDFILIAL   = TA.CDFILIAL
            AND SO.NRSOLISERV = TA.NRSOLISERV
            AND TA.IDORIGTARE = '5') LOOP
         UPDATE TAREFA
            SET IDORIGTARE = '1'
          WHERE CDFILIAL = C_TAREFA.CDFILIAL
            AND NRTAREFA = C_TAREFA.NRTAREFA;
      END LOOP;
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('ATUALIZA_PROJETO','4.11.046'); END;
/

