CREATE OR REPLACE PROCEDURE CONTROLE_SOLIVERANT
AS
BEGIN
   FOR C IN
   (SELECT DISTINCT L.CDFILIAL, L.NRSOLISERV, S.CDCLIENTE, S.CDPRODGRUP
    FROM LOGFASETRAM L, SOLISERV S
    WHERE S.CDFILIAL = L.CDFILIAL
      AND S.NRSOLISERV = L.NRSOLISERV
      AND L.CDFASETRAM IN ('270', '070')
      AND TRUNC(L.DTALFASETRAM) = TRUNC(SYSDATE)
      AND NOT EXISTS (SELECT O.CDFILIAL
                      FROM SOLISERV O
                      WHERE O.CDFILIAL = S.CDFILIAL
                        AND O.NRSOLIORIG = S.NRSOLISERV)
      AND L.DTALFASETRAM = (SELECT MAX(DTALFASETRAM)
                            FROM LOGFASETRAM D
                            WHERE D.CDFILIAL = L.CDFILIAL
                              AND D.NRSOLISERV = L.NRSOLISERV
                              AND D.CDFASETRAM IN ('270', '070')))
   LOOP

      IF C.CDPRODGRUP <> '0000000413' THEN
         IF (C.CDCLIENTE = 'J02905110000128') THEN
            DUPLICA_SOLICITACAO(C.CDFILIAL, C.NRSOLISERV, 'S');
         ELSE
            DUPLICA_SOLICITACAO(C.CDFILIAL, C.NRSOLISERV);
         END IF;
      END IF;
   END LOOP;
END;
/
-- VERSAO --
BEGIN ATUVEROBJ('CONTROLE_SOLIVERANT','4.11.046'); END;
/

