CREATE OR REPLACE PROCEDURE EXCLUI_CLASSE_PLANOVOOM
(
P_CDFILIAL IN VARCHAR2,
P_CDCIA IN VARCHAR2,
P_NRVOO IN VARCHAR2,
P_CDTRECHO IN VARCHAR2,
P_DTHRPLAVOOPV IN DATE,
P_CLASSE IN VARCHAR2,
P_CDOPERADOR IN VARCHAR2,
P_NRORG IN NUMBER DEFAULT 1
)
AS
BEGIN
   VALIDA_NF_DELIVERYS_PLANOVOOM(P_CDFILIAL, P_CDCIA, P_NRVOO, P_CDTRECHO,
                                 P_DTHRPLAVOOPV, P_CLASSE, 'N', P_NRORG);
   
   DELETE FROM CONEXAOSUBGRUPO
    WHERE (CDFILIAL = P_CDFILIAL) AND
          (CDCIA = P_CDCIA) AND
          (NRVOO = P_NRVOO) AND
          (CDTRECHO = P_CDTRECHO) AND
          (DTHRPLAVOOPV = P_DTHRPLAVOOPV) AND
          (CDCLASSESP = P_CLASSE);

   /*Apaga os servicos do plano de voo e classe*/
   DELETE FROM SERVPLANOM
    WHERE (CDFILIAL = P_CDFILIAL) AND
          (CDCIA = P_CDCIA) AND
          (NRVOO = P_NRVOO) AND
          (CDTRECHO = P_CDTRECHO) AND
          (DTHRPLAVOOPV = P_DTHRPLAVOOPV) AND
          (CDCLASSE = P_CLASSE);

   /*Apaga a previsao de passageiros*/
   DELETE FROM PREVISAOPAXM
    WHERE CDFILIAL = P_CDFILIAL
      AND CDCIA = P_CDCIA
      AND NRVOO = P_NRVOO
      AND CDTRECHO = P_CDTRECHO
      AND DTHRPLAVOOPV = P_DTHRPLAVOOPV
      AND CDCLASSE = P_CLASSE;

   /* Revalida o status do plano de voo */
   REVALIDA_STATUS_PLANOVOOM(P_CDFILIAL, P_CDCIA, P_NRVOO, P_CDTRECHO, 
                             P_DTHRPLAVOOPV, P_CDOPERADOR, P_NRORG);
END;
/