CREATE OR REPLACE PROCEDURE GETDATAPEDIDOCOLETA(P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE,
                                                P_CDFILIPROC   IN FILIAL.CDFILIAL%TYPE,
                                                P_CDCOMPRADOR  IN VARCHAR2,
                                                P_CDPRODINI    IN VARCHAR2,
                                                P_CDPRODFIN    IN VARCHAR2,
                                                P_CDFORNECED   IN VARCHAR2,
                                                P_CDREGIAO     IN VARCHAR2,
                                                P_CDMARCA      IN VARCHAR2,
                                                P_DTINI        IN DATE,
                                                P_DTFIN        IN DATE,
                                                P_TIPOPEDIDO   IN VARCHAR2,
                                                P_NRCOLEPRECO  IN ITEMCOLE.NRCOLEPRECO%TYPE,
                                                P_DESCFORNCOT  IN VARCHAR2,
                                                P_NRCOMPRA     IN ITEMCOLE.NRCOLEPRECO%TYPE,
                                                P_CDLEILAO     IN PEDCOLETA.CDLEILAO%TYPE,
                                                P_NRSEQPRELIST IN ITEMCOLE.NRSEQPRELIST%TYPE,
                                                P_CDOPERLANC   IN OPERADOR.CDOPERADOR%TYPE,
                                                P_NRPEDCOL     IN OUT PEDIDOCOLETA_TMP.NRPEDCOL%TYPE,
                                                P_ERROR       OUT VARCHAR2) IS
    V_NRORG FILIAL.NRORG%TYPE;
BEGIN
    SELECT NVL(MAX(NRORG), 1)
      INTO V_NRORG
      FROM PARAMGERAL;
    PEDIDO_COLETA.GETDATAPEDIDOCOLETA(P_CDFILIAL     => P_CDFILIAL,
                                      P_CDFILIPROC   => P_CDFILIPROC,
                                      P_CDCOMPRADOR  => P_CDCOMPRADOR,
                                      P_CDPRODINI    => P_CDPRODINI,
                                      P_CDPRODFIN    => P_CDPRODFIN,
                                      P_CDFORNECED   => P_CDFORNECED,
                                      P_CDREGIAO     => P_CDREGIAO,
                                      P_CDMARCA      => P_CDMARCA,
                                      P_DTINI        => P_DTINI,
                                      P_DTFIN        => P_DTFIN,
                                      P_TIPOPEDIDO   => P_TIPOPEDIDO,
                                      P_NRCOLEPRECO  => P_NRCOLEPRECO,
                                      P_DESCFORNCOT  => P_DESCFORNCOT,
                                      P_NRCOMPRA     => P_NRCOMPRA,
                                      P_CDLEILAO     => P_CDLEILAO,
                                      P_NRSEQPRELIST => P_NRSEQPRELIST,
                                      P_CDOPERLANC   => P_CDOPERLANC,
                                      P_NRORG        => V_NRORG,
                                      P_NRPEDCOL     => P_NRPEDCOL,
                                      P_ERROR        => P_ERROR);

END GETDATAPEDIDOCOLETA;
/