/*
TECNISA - TECNOLOGIA EM INFORMATICA

NOME: APURAC_GESMERENDA

DESCRICAO:
   PROCEDIMENTO PARA APURACAO DE FATURAMENTO DE CLIENTES EM FILIAIS
   QUE UTILIZAM O TIPO DE CONTRATO GESTAO MERENDA.

@C:\WEB_505\SQL\End_Conv\ORACLE\6214_FAISTPO.SQL
*/
CREATE OR REPLACE PROCEDURE APURAC_GESMERENDA ( 
      P_CDFILCENTPME IN FILIAL.CDFILIAL%TYPE, 
      P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE, 
      P_CDCLIENTE    IN CLIENTE.CDCLIENTE%TYPE, 
      P_DATAINI      IN DATE, 
      P_DATAFIM      IN DATE, 
      P_NRAPURACFAT  IN NOTAFISCAL.NRAPURACFAT%TYPE, 
      P_IDGERANOTA   IN VARCHAR DEFAULT 'S', 
      P_DTSAIDAPUR   IN DATE DEFAULT NULL,
      P_SEPARATIPOCARD IN VARCHAR2 DEFAULT 'N') AS 
    
    TYPE GMERENDARECTYPE IS RECORD ( 
        CDFILCENTPME   FILIAL.CDFILCENTPME%TYPE, 
        CDFILIAL       FILIAL.CDFILIAL%TYPE, 
        CDCLIENTE      CLIENTE.CDCLIENTE%TYPE, 
        CDTIPOCARD     TIPOCARD.CDTIPOCARD%TYPE, 
        CDSERVFILI     SERVICO.CDSERVFILI%TYPE, 
        DTFATURAM      DATE, 
        CDPRODUTO      PRODUTO.CDPRODUTO%TYPE, 
        VRSERVICO      NUMBER, 
        QTEFETIVOS     NUMBER, 
        NMSERVICO      SERVICO.NMSERVICO%TYPE); 

    TYPE GMERENDACURTYPE IS REF CURSOR RETURN GMERENDARECTYPE; 

    REC_GMERENDA    GMERENDARECTYPE; 
    CUR_GMERENDA    GMERENDACURTYPE; 

    STIDUTEFEPLA   VARCHAR2(01); 

    V_QTEFETSERV   NUMBER; 
    V_VRSERVICO    NUMBER; 
    V_EXISTE       NUMBER; 
    V_NMSERVICO    SERVICO.NMSERVICO%TYPE; 
    V_CDSERIE      SERIENF.CDSERIE%TYPE; 
    V_TTITENSNF    NUMBER; 
    V_CONTITEM     NUMBER; 
    V_NRLANCTONF   VARCHAR2(20); 
    V_NRSEQITPROD  NUMBER; 
    V_CDEMPRESA    FILIAL.CDEMPRESA%TYPE; 
    V_CDINSCMUNI   FILIAL.CDINSCMUNI%TYPE; 
    V_CDINSCESTA   FILIAL.CDINSCESTA%TYPE; 
    V_IDTPIJURCLIE CLIENTE.IDTPIJURCLIE%TYPE; 
    V_NRINSJURCLIE CLIENTE.NRINSJURCLIE%TYPE; 
    V_IDNOVANOTA   VARCHAR2(01); 
    V_PRXLANCESTQ  VARCHAR2(10); 
    V_IDUTPROPEMIS VARCHAR2(01); 
    V_CDARVPROD    PRODUTO.CDARVPROD%TYPE; 
    V_NMPRODUTO    VARCHAR2(100); 
    V_CDFILIALNF   VARCHAR2(04);

    V_APUR_NA_CENTRAL VARCHAR2(1);
    V_CDTIPOCARD_ATUAL VARCHAR2(10);

    PROCEDURE OPENGMERENDACURSOR(C_GMERENDA  IN OUT GMERENDACURTYPE, 
                                V_UTPLANEJ IN VARCHAR2) IS 
    BEGIN
        OPEN C_GMERENDA FOR
            SELECT CDFILCENTPME, CDFILIAL, CDCLIENTE, CDTIPOCARD, CDSERVFILI, DTFATURAM, CDPRODUTO, 
                VRSERVICO,
                SUM(QTEFETIVOS) AS QTEFETIVOS,
                NMSERVICO
            FROM
            (
            SELECT CDFILCENTPME, CASE WHEN V_APUR_NA_CENTRAL = 'N' THEN CDFILIAL ELSE CDFILCENTPME END AS CDFILIAL, CDCLIENTE, CDTIPOCARD, CDSERVFILI, DTFATURAM, CDPRODUTO, 
                VALOR_SERVICO_MERENDA(CDFILCENTPME, CDTIPOCARD, CDFILIAL, CDSERVFILI, CDCLIENTE, DTFATURAM) AS VRSERVICO,
                QTEFETIVOS,
                NMSERVICO
            FROM
            (
            SELECT EFECLIFATMER.CDFILCENTPME, EFECLIFATMER.CDFILIAL, 
                EFECLIFATMER.CDCLIENTE, EFECLIFATMER.CDTIPOCARD, EFECLIFATMER.CDSERVFILI, EFECLIFATMER.DTEFETFATMER AS DTFATURAM, 
                NVL(SERVTIPOCARD.CDPRODUTO,SERVICO.CDPRODUTO) AS CDPRODUTO, SUM(EFECLIFATMER.QTCOMEFATMER) AS QTEFETIVOS, SERVICO.NMSERVICO 
            FROM EFECLIFATMER, SERVCLIEPME, SERVICO, SERVTIPOCARD 
            WHERE EFECLIFATMER.CDFILCENTPME = SERVCLIEPME.CDFILCENTPME 
            AND EFECLIFATMER.CDFILIAL = SERVCLIEPME.CDFILIAL 
            AND EFECLIFATMER.CDTIPOCARD = SERVCLIEPME.CDTIPOCARD 
            AND EFECLIFATMER.CDCLIENTE = SERVCLIEPME.CDCLIENTE 
            AND EFECLIFATMER.CDSERVFILI = SERVCLIEPME.CDSERVFILI 
            AND SERVICO.CDFILIAL = EFECLIFATMER.CDFILIAL             
            AND SERVICO.CDSERVFILI = EFECLIFATMER.CDSERVFILI 

            AND (SERVTIPOCARD.CDFILCENTPME = SERVCLIEPME.CDFILCENTPME )
            AND (SERVTIPOCARD.CDTIPOCARD = SERVCLIEPME.CDTIPOCARD)
            AND (SERVTIPOCARD.CDSERVFILI = SERVICO.CDSERVFILI)

            AND EFECLIFATMER.DTEFETFATMER BETWEEN P_DATAINI AND P_DATAFIM 
            AND V_UTPLANEJ = 'N' 
            AND ( (V_APUR_NA_CENTRAL = 'N' AND EFECLIFATMER.CDFILIAL = P_CDFILIAL) OR
                 (V_APUR_NA_CENTRAL = 'S' AND EFECLIFATMER.CDFILIAL IN (SELECT CDFILIAL
                                                                        FROM FILIAL 
                                                                       WHERE CDFILCENTPME = P_CDFILCENTPME
                                                                         AND CDFILCENTRALFATU = P_CDFILCENTPME)) )
            AND EFECLIFATMER.CDCLIENTE  = P_CDCLIENTE
            group by EFECLIFATMER.CDFILCENTPME, EFECLIFATMER.CDFILIAL, EFECLIFATMER.CDCLIENTE, EFECLIFATMER.CDTIPOCARD, EFECLIFATMER.CDSERVFILI, EFECLIFATMER.DTEFETFATMER, NVL(SERVTIPOCARD.CDPRODUTO,SERVICO.CDPRODUTO), SERVICO.NMSERVICO 
            HAVING (SUM(EFECLIFATMER.QTCOMEFATMER) <> 0) 
            UNION 
            SELECT EFETCLIEPME.CDFILCENTPME, EFETCLIEPME.CDFILIAL, 
                EFETCLIEPME.CDCLIENTE, EFETCLIEPME.CDTIPOCARD, EFETCLIEPME.CDSERVFILI, EFETCLIEPME.DTEFETCLPME AS DTFATURAM, 
                NVL(SERVTIPOCARD.CDPRODUTO,SERVICO.CDPRODUTO) AS CDPRODUTO, SUM(EFETCLIEPME.QTCOMEFCLPME) AS QTEFETIVOS, SERVICO.NMSERVICO 
            FROM EFETCLIEPME, SERVCLIEPME, SERVICO, SERVTIPOCARD
            WHERE EFETCLIEPME.CDFILCENTPME = SERVCLIEPME.CDFILCENTPME 
            AND EFETCLIEPME.CDFILIAL = SERVCLIEPME.CDFILIAL 
            AND EFETCLIEPME.CDTIPOCARD = SERVCLIEPME.CDTIPOCARD 
            AND EFETCLIEPME.CDCLIENTE = SERVCLIEPME.CDCLIENTE 
            AND EFETCLIEPME.CDSERVFILI = SERVCLIEPME.CDSERVFILI 
            AND SERVICO.CDFILIAL = EFETCLIEPME.CDFILIAL 
            AND SERVICO.CDSERVFILI = EFETCLIEPME.CDSERVFILI 

            AND (SERVTIPOCARD.CDFILCENTPME = SERVCLIEPME.CDFILCENTPME )
            AND (SERVTIPOCARD.CDTIPOCARD = SERVCLIEPME.CDTIPOCARD)
            AND (SERVTIPOCARD.CDSERVFILI = SERVICO.CDSERVFILI)            

            AND EFETCLIEPME.DTEFETCLPME BETWEEN P_DATAINI AND P_DATAFIM 
            AND V_UTPLANEJ = 'S' 
            AND ( (V_APUR_NA_CENTRAL = 'N' AND EFETCLIEPME.CDFILIAL = P_CDFILIAL) OR
                  (V_APUR_NA_CENTRAL = 'S' AND EFETCLIEPME.CDFILIAL IN (SELECT CDFILIAL
                                                                        FROM FILIAL 
                                                                       WHERE CDFILCENTPME = P_CDFILCENTPME
                                                                         AND CDFILCENTRALFATU = P_CDFILCENTPME)) )
            AND EFETCLIEPME.CDCLIENTE  = P_CDCLIENTE
            GROUP BY EFETCLIEPME.CDFILCENTPME, EFETCLIEPME.CDFILIAL, EFETCLIEPME.CDCLIENTE, 
                    EFETCLIEPME.CDTIPOCARD, EFETCLIEPME.DTEFETCLPME, EFETCLIEPME.CDSERVFILI, 
                    NVL(SERVTIPOCARD.CDPRODUTO,SERVICO.CDPRODUTO), SERVICO.NMSERVICO 
            HAVING (SUM(EFETCLIEPME.QTCOMEFCLPME) <> 0)
            ) S ) S
            WHERE VRSERVICO <> 0
            GROUP BY CDFILCENTPME, CDFILIAL, CDCLIENTE, 
                     CDTIPOCARD, CDSERVFILI, DTFATURAM, 
                    CDPRODUTO, VRSERVICO, NMSERVICO;
    END OPENGMERENDACURSOR; 
BEGIN
   V_APUR_NA_CENTRAL := 'N';
   IF P_CDFILCENTPME = P_CDFILIAL THEN
      V_APUR_NA_CENTRAL := 'S';
   END IF;

   SELECT MAX(SUBSTR(DSPARAMFATFI,15,1))  
   INTO STIDUTEFEPLA 
   FROM PARAMFILIAL 
   WHERE CDFILIAL = P_CDFILCENTPME; 
   SELECT NVL(MAX(IDUTPROPEMIS),'N') 
   INTO V_IDUTPROPEMIS 
   FROM PARAMGERAL; 

   DELETE FROM TRAB_APURAC_GM 
   WHERE CDFILCENTAPGM  = P_CDFILCENTPME 
     AND CDFILIALAPGM = P_CDFILIAL 
     AND NRAPURACGM = P_NRAPURACFAT 
     AND CDCLIENTEAPGM = P_CDCLIENTE; 
   IF (STIDUTEFEPLA IS NULL) OR (STIDUTEFEPLA = ' ') THEN 
      STIDUTEFEPLA := 'N'; 
   END IF; 

   OPENGMERENDACURSOR(CUR_GMERENDA, STIDUTEFEPLA); 
   LOOP 
      FETCH CUR_GMERENDA INTO REC_GMERENDA; 
      EXIT WHEN CUR_GMERENDA%NOTFOUND; 
      V_VRSERVICO  := REC_GMERENDA.VRSERVICO; 
      V_QTEFETSERV := REC_GMERENDA.QTEFETIVOS; 
      V_NMSERVICO  := REC_GMERENDA.NMSERVICO; 

      SELECT COUNT(*) 
        INTO V_EXISTE 
        FROM TRAB_APURAC_GM 
       WHERE CDFILCENTAPGM   = P_CDFILCENTPME 
         AND CDFILIALAPGM   = REC_GMERENDA.CDFILIAL 
         AND NRAPURACGM     = P_NRAPURACFAT 
         AND CDCLIENTEAPGM  = REC_GMERENDA.CDCLIENTE 
         AND CDTIPOCARDAPGM   = REC_GMERENDA.CDTIPOCARD 
         AND CDSERVFILIAPGM = REC_GMERENDA.CDSERVFILI 
         AND ROUND(VRPRECUNITAPGM,2) = ROUND(REC_GMERENDA.VRSERVICO,2); 
      IF (V_EXISTE = 0) THEN 
         INSERT INTO TRAB_APURAC_GM 
           (CDFILCENTAPGM, CDFILIALAPGM, NRAPURACGM, CDCLIENTEAPGM, 
            CDTIPOCARDAPGM, CDSERVFILIAPGM, DTAPURACFATGM, CDPRODUTOAPGM, 
            NREFETIVOSAPGM, VRPRECUNITAPGM, NMSERVICOGM) 
         VALUES (P_CDFILCENTPME, REC_GMERENDA.CDFILIAL, P_NRAPURACFAT, REC_GMERENDA.CDCLIENTE, 
                 REC_GMERENDA.CDTIPOCARD, REC_GMERENDA.CDSERVFILI, P_DATAINI, REC_GMERENDA.CDPRODUTO, 
                 REC_GMERENDA.QTEFETIVOS, REC_GMERENDA.VRSERVICO, REC_GMERENDA.NMSERVICO); 
      ELSE 
         UPDATE TRAB_APURAC_GM 
            SET NREFETIVOSAPGM = NREFETIVOSAPGM + V_QTEFETSERV 
          WHERE CDFILCENTAPGM    = P_CDFILCENTPME 
            AND CDFILIALAPGM   = REC_GMERENDA.CDFILIAL 
            AND NRAPURACGM     = P_NRAPURACFAT 
            AND CDCLIENTEAPGM  = REC_GMERENDA.CDCLIENTE 
            AND CDTIPOCARDAPGM   = REC_GMERENDA.CDTIPOCARD 
            AND CDSERVFILIAPGM = REC_GMERENDA.CDSERVFILI 
            AND ROUND(VRPRECUNITAPGM,2) = ROUND(REC_GMERENDA.VRSERVICO,2); 
      END IF; 
      IF STIDUTEFEPLA = 'S' THEN 
         UPDATE EFETCLIEPME 
            SET CDFILIFATU  = NULL, 
                NRAPURACFAT = NULL 
          WHERE CDCLIENTE   = P_CDCLIENTE 
            AND DTEFETCLPME >= P_DATAINI
            AND ( (V_APUR_NA_CENTRAL = 'N' AND CDFILIAL = P_CDFILIAL) OR
                  (V_APUR_NA_CENTRAL = 'S' AND CDFILIAL IN (SELECT CDFILIAL
                                                                        FROM FILIAL 
                                                                       WHERE CDFILCENTPME = P_CDFILCENTPME
                                                                         AND CDFILCENTRALFATU = P_CDFILCENTPME)) ); 
      ELSE  
         UPDATE EFECLIFATMER 
            SET CDFILIFATU  = NULL, 
                NRAPURACFAT = NULL 
          WHERE CDCLIENTE  = P_CDCLIENTE  AND 
                DTEFETFATMER >= P_DATAINI AND
                ( (V_APUR_NA_CENTRAL = 'N' AND CDFILIAL = P_CDFILIAL) OR
                  (V_APUR_NA_CENTRAL = 'S' AND CDFILIAL IN (SELECT CDFILIAL
                                                                        FROM FILIAL 
                                                                       WHERE CDFILCENTPME = P_CDFILCENTPME
                                                                         AND CDFILCENTRALFATU = P_CDFILCENTPME)) ); 
      END IF;           
   END LOOP; 
   CLOSE CUR_GMERENDA; 

   IF NVL(P_IDGERANOTA,'S') <> 'N' THEN 
      SELECT MAX(IDTPIJURCLIE), MAX(NRINSJURCLIE) 
      INTO V_IDTPIJURCLIE, V_NRINSJURCLIE 
      FROM CLIENTE 
      WHERE CDCLIENTE = P_CDCLIENTE; 

      FOR CURS_NF IN (SELECT CDFILIAL, NRLANCTONF 
                      FROM NOTAFISCAL 
                      WHERE (CDFILIAL    = P_CDFILIAL) 
                        AND (NRAPURACFAT = P_NRAPURACFAT) 
                        AND (CDCLIENTE   = P_CDCLIENTE)) LOOP 
         DELETA_NF(CURS_NF.CDFILIAL, CURS_NF.NRLANCTONF); 
      END LOOP; 
      V_IDNOVANOTA := 'N'; 
      V_CONTITEM := NULL;
      V_CDTIPOCARD_ATUAL := 'XXXXXXXXXX';
      FOR CURS_APURAC IN (SELECT CDFILCENTAPGM, CDFILIALAPGM,  CDCLIENTEAPGM, CDTIPOCARDAPGM, 
                                 CDSERVFILIAPGM, CDPRODUTOAPGM, NREFETIVOSAPGM, VRPRECUNITAPGM, 
                                 NMSERVICOGM AS NMSERVICO 
                            FROM TRAB_APURAC_GM 
                           WHERE (TRAB_APURAC_GM.CDFILCENTAPGM = P_CDFILCENTPME) 
                             AND (TRAB_APURAC_GM.CDFILIALAPGM = P_CDFILIAL) 
                             AND (TRAB_APURAC_GM.NRAPURACGM   = P_NRAPURACFAT) 
                             AND (TRAB_APURAC_GM.CDCLIENTEAPGM  = P_CDCLIENTE) 
                          ORDER BY CDFILCENTAPGM, CDFILIALAPGM, CDCLIENTEAPGM, CDTIPOCARDAPGM, CDSERVFILIAPGM) LOOP 

         SELECT MAX(F.CDEMPRESA), MAX(F.CDINSCESTA), MAX(F.CDINSCMUNI), MAX(F.CDSERIE), NVL(MAX(NRMAXITNF),10) 
           INTO V_CDEMPRESA, V_CDINSCESTA, V_CDINSCMUNI, V_CDSERIE, V_TTITENSNF 
           FROM FILIAL F, SERIENF S 
          WHERE CDFILIAL = CURS_APURAC.CDFILIALAPGM 
            AND F.CDEMPRESA = S.CDEMPRESA(+) 
            AND F.CDINSCESTA = S.CDINSCESTA(+) 
            AND F.CDINSCMUNI = S.CDINSCMUNI(+) 
            AND F.CDSERIE = S.CDSERIE(+); 
         IF V_CONTITEM IS NULL THEN 
            V_CONTITEM   := V_TTITENSNF; 
         END IF; 
         IF STIDUTEFEPLA = 'S' THEN 
            UPDATE EFETCLIEPME 
               SET CDFILIFATU  = P_CDFILIAL, 
                   NRAPURACFAT = P_NRAPURACFAT 
             WHERE CDCLIENTE  = P_CDCLIENTE 
               AND DTEFETCLPME BETWEEN P_DATAINI AND P_DATAFIM
               AND ( (V_APUR_NA_CENTRAL = 'N' AND CDFILIAL = P_CDFILIAL) OR
                  (V_APUR_NA_CENTRAL = 'S' AND CDFILIAL IN (SELECT CDFILIAL
                                                                        FROM FILIAL 
                                                                       WHERE CDFILCENTPME = P_CDFILCENTPME
                                                                         AND CDFILCENTRALFATU = P_CDFILCENTPME)) ); 
         ELSE  
            UPDATE EFECLIFATMER 
               SET CDFILIFATU  = P_CDFILIAL, 
                   NRAPURACFAT = P_NRAPURACFAT 
             WHERE CDCLIENTE  = P_CDCLIENTE 
               AND DTEFETFATMER BETWEEN P_DATAINI AND P_DATAFIM
               AND ( (V_APUR_NA_CENTRAL = 'N' AND CDFILIAL = P_CDFILIAL) OR
                  (V_APUR_NA_CENTRAL = 'S' AND CDFILIAL IN (SELECT CDFILIAL
                                                                        FROM FILIAL 
                                                                       WHERE CDFILCENTPME = P_CDFILCENTPME
                                                                         AND CDFILCENTRALFATU = P_CDFILCENTPME)) ); 
         END IF;       
         IF (V_CONTITEM = V_TTITENSNF OR (P_SEPARATIPOCARD = 'S' AND V_CDTIPOCARD_ATUAL <> CURS_APURAC.CDTIPOCARDAPGM)) THEN 
            V_CDTIPOCARD_ATUAL := CURS_APURAC.CDTIPOCARDAPGM;
            IF (V_IDNOVANOTA = 'S') THEN 
               GERA_NOTAFISCAL_FECHAMENTO(CURS_APURAC.CDFILIALAPGM, V_NRLANCTONF); 
            END IF; 
            V_IDNOVANOTA := 'S'; 
            V_CONTITEM   := 0; 
            NOVO_CODIGO('LANCNF/FILIAL' || CURS_APURAC.CDFILIALAPGM,V_NRLANCTONF); 
            V_NRLANCTONF := SUBSTR(V_NRLANCTONF,11,10); 
            V_NRSEQITPROD := 0; 
            GERA_NOTAFISCAL_CORPO(CURS_APURAC.CDFILIALAPGM, CURS_APURAC.CDFILIALAPGM, V_CDEMPRESA, 
                                  '01', V_CDSERIE,    P_CDCLIENTE, NVL(P_DTSAIDAPUR,P_DATAFIM), 
                                  'FAI', V_NRLANCTONF, V_PRXLANCESTQ, 'N', P_NRAPURACFAT, 
                                   V_NRLANCTONF,  NULL,         NULL, 
                                   NULL,          NULL,         NULL, 
                                   NULL,          NULL,         NULL, 
                                   NULL,          NULL,         NULL, 
                                   NULL,          NULL,         NULL, 
                                   NULL,          P_DATAFIM,    NULL); 
         END IF; 
         V_NRSEQITPROD := V_NRSEQITPROD + 1; 
         V_CONTITEM := V_CONTITEM + 1; 
         IF V_IDUTPROPEMIS = 'S' THEN 
            SELECT MAX(CDARVPROD), MAX(NMPRODUTO) 
              INTO V_CDARVPROD, V_NMPRODUTO 
              FROM PRODUTO 
             WHERE CDPRODUTO = CURS_APURAC.CDPRODUTOAPGM; 
            IF P_SEPARATIPOCARD = 'S' THEN
               V_NMPRODUTO := V_NMPRODUTO || '( ' || V_CDTIPOCARD_ATUAL || ' )';
            END IF;
            GERA_NOTAFISCAL_PRODUTO(CURS_APURAC.CDFILIALAPGM, V_NRLANCTONF, CURS_APURAC.CDPRODUTOAPGM, 
                                    V_CDARVPROD, V_NMPRODUTO, CURS_APURAC.NREFETIVOSAPGM, CURS_APURAC.VRPRECUNITAPGM); 
         ELSE
            IF P_SEPARATIPOCARD = 'S' THEN
               V_NMPRODUTO := CURS_APURAC.NMSERVICO || '( ' || V_CDTIPOCARD_ATUAL || ' )'; 
            ELSE
               V_NMPRODUTO := CURS_APURAC.NMSERVICO;
            END IF;
            GERA_NOTAFISCAL_PRODUTO(CURS_APURAC.CDFILIALAPGM, V_NRLANCTONF, CURS_APURAC.CDPRODUTOAPGM, 
                                    CURS_APURAC.CDSERVFILIAPGM, V_NMPRODUTO, 
                                    CURS_APURAC.NREFETIVOSAPGM, CURS_APURAC.VRPRECUNITAPGM); 
         END IF; 
         V_CDFILIALNF := CURS_APURAC.CDFILIALAPGM;
      END LOOP; 
      IF (V_CONTITEM > 0) THEN 
         GERA_NOTAFISCAL_FECHAMENTO(V_CDFILIALNF, V_NRLANCTONF);
      END IF;

      DELETE FROM TRAB_APURAC_GM 
      WHERE CDFILCENTAPGM  = P_CDFILCENTPME 
        AND CDFILIALAPGM = P_CDFILIAL 
        AND NRAPURACGM    = P_NRAPURACFAT 
        AND CDCLIENTEAPGM = P_CDCLIENTE;

      COMMIT; 
   END IF; 
END; 
/

-- EXECUTE APURAC_GESMERENDA('0751', '0712', 'F01162619864', '20/10/2008', '20/10/2008', '0000000001', 'S', '20/10/2008');
-- RAISE_APPLICATION_ERROR(-20501, 'MENSAGEM', TRUE);


-- VERSAO --
BEGIN ATUVEROBJ('APURAC_GESMERENDA','6.49.003'); END;
/
