/* @C:\web_605\sql\end_conv\oracle\8997_SUPTRGO_RETORNA_PEDIDOOL_NENVIADO.SQL */

CREATE OR REPLACE TRIGGER  RETORNA_PEDIDOOL_NENVIADO

AFTER DELETE
ON ITEMPEDIDO FOR EACH ROW
DECLARE
   V_IDENVIOITMPEDOL VARCHAR2(1);
BEGIN
   SELECT NVL(MAX(IDENVIOITMPEDOL), 'N')
     INTO V_IDENVIOITMPEDOL
     FROM PARASUPRI
    WHERE PARASUPRI.CDFILIAL = (SELECT NVL(FILIAL.CDFILCENTCMP, FILIAL.CDFILIAL)
                                  FROM FILIAL
                                 WHERE FILIAL.CDFILIAL = :OLD.CDFILIAL);

   IF (V_IDENVIOITMPEDOL = 'S') THEN
      UPDATE ITEMPEDEXOL
         SET DSINCONITMOLEXP = NULL,
             IDEXPTITMOLEXP  = 'N'
       WHERE DSINCONITMOLEXP = :OLD.CDFILIAL||:OLD.NRPEDIDO||:OLD.NRITEMPED;
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('RETORNA_PEDIDOOL_NENVIADO','5.11.000'); END;
/
