create or replace PACKAGE SUP_COTACAO AS
   
   K_S                     CONSTANT VARCHAR2(01) := 'S';
   K_N                     CONSTANT VARCHAR2(01) := 'N';
   K_T                     CONSTANT VARCHAR2(01) := 'T';
   K_A                     CONSTANT VARCHAR2(01) := 'A';
   K_C                     CONSTANT VARCHAR2(01) := 'C';
   K_0                     CONSTANT VARCHAR2(01) := '0';
   K_1                     CONSTANT VARCHAR2(01) := '1';
   K_WW                    CONSTANT VARCHAR2(02) := 'WW';
   K_SUCCESS               CONSTANT VARCHAR2(07) := 'SUCCESS';
   K_ERROR                 CONSTANT VARCHAR2(05) := 'ERROR';
   K_PZOPGTPRFO            CONSTANT VARCHAR2(30) := 'PZOPGTPRFO';
   K_PRAZOPGTFORN          CONSTANT VARCHAR2(30) := 'PRAZOPGTFORN';
   K_COTACAO_CONCLUIDA     CONSTANT VARCHAR2(30) := 'COTACAO_CONCLUIDA_IDCOTCONCLUI';
   K_DSMET_DUPLICA_COTACAO CONSTANT VARCHAR2(30) := 'SUP_COTACAO.DUPLICA_COTACAO';
   K_NRORG                 CONSTANT NUMBER       := NVL(SYS_CONTEXT('nrorg_ctx','nrorg'), 1);

   
   SUBTYPE S_RECORD_COLETAPR     IS COLETAPR%ROWTYPE;
   SUBTYPE S_RECORD_ITEMCOLE     IS ITEMCOLE%ROWTYPE;
   SUBTYPE S_RECORD_LOGCOLETAPR  IS LOGCOLETAPR%ROWTYPE;
   SUBTYPE S_RECORD_LOGITEMCOLE  IS LOGITEMCOLE%ROWTYPE;
   SUBTYPE S_RECORD_PZOPGTITMCOL IS PZOPGTITMCOL%ROWTYPE;

   PROCEDURE INSERT_COLETAPR(P_REGISTRO      IN OUT S_RECORD_COLETAPR,
                             P_PARASUPRI     IN PARASUPRI%ROWTYPE,
                             P_ERROR        OUT VARCHAR2);

   PROCEDURE INSERT_ITEMCOLE(P_REGISTRO     IN OUT S_RECORD_ITEMCOLE,
                             P_PARASUPRI    IN PARASUPRI%ROWTYPE,
                             P_FORNECEDORES IN FORNECEDOR%ROWTYPE,
                             P_ERROR       OUT VARCHAR2);

   PROCEDURE DELETE_PZOPGTITMCOL(P_REGISTRO IN S_RECORD_ITEMCOLE,
                                 P_ERROR   OUT VARCHAR2);

   PROCEDURE INSERT_PZOPGTITMCOL(P_REGISTRO   IN S_RECORD_ITEMCOLE,
                                 P_CDPRODFORN IN PRODFORN.CDPRODUTO%TYPE DEFAULT NULL,
                                 P_ERROR     OUT VARCHAR2);

   PROCEDURE INSERT_LOGCOLETAPR(P_COLETAPR      IN S_RECORD_COLETAPR,
                                P_DSENDUSULOG   IN LOGCOLETAPR.DSENDUSULOG%TYPE,
                                P_DSNMUSULOG    IN LOGCOLETAPR.DSNMUSULOG%TYPE,
                                P_DSRDMUSULOG   IN LOGCOLETAPR.DSRDMUSULOG%TYPE,
                                P_DSMETUSULOG   IN LOGCOLETAPR.DSMETUSULOG%TYPE,
                                P_CDOPERINCLOG  IN LOGCOLETAPR.CDOPERINCLOG%TYPE,
                                P_IDOPERCOTLOG  IN LOGCOLETAPR.IDOPERCOTLOG%TYPE,
                                P_DSMESSAGERROR IN LOGCOLETAPR.DSMESSAGERROR%TYPE); 

   PROCEDURE INSERT_LOGITEMCOLE(P_ITEMCOLE      IN S_RECORD_ITEMCOLE,
                                P_DSENDUSULIC   IN LOGITEMCOLE.DSENDUSULIC%TYPE,
                                P_DSNMUSULIC    IN LOGITEMCOLE.DSNMUSULIC%TYPE,
                                P_DSRDMUSULIC   IN LOGITEMCOLE.DSRDMUSULIC%TYPE,
                                P_DSMETUSULIC   IN LOGITEMCOLE.DSMETUSULIC%TYPE,
                                P_CDOPERLIC     IN LOGITEMCOLE.CDOPERLIC%TYPE,
                                P_IDOPERALIC    IN LOGITEMCOLE.IDOPERALIC%TYPE,
                                P_DSMESSAGERROR IN LOGITEMCOLE.DSMESSAGERROR%TYPE);

   PROCEDURE COTACAO_OPL(P_CDFILIAL    IN COLETAPR.CDFILIAL%TYPE,
                         P_NRCOLEORIG  IN COLETAPR.NRCOLEPRECO%TYPE,
                         P_NRCOLEPRECO IN COLETAPR.NRCOLEPRECO%TYPE,
                         P_FORNOL      IN VARCHAR2,
                         P_CDREGIAOL   IN VARCHAR2,
                         P_REAJUSTE    IN NUMBER,
                         P_DTNOVINIVAL IN COLETAPR.DTINIVALCOL%TYPE,
                         P_DTNOVFINVAL IN COLETAPR.DTFINVALCOL%TYPE,
                         P_CDOPERINCL  IN OPERADOR.CDOPERADOR%TYPE,
                         P_ERROR      OUT VARCHAR2);

   PROCEDURE DUPLICA_COTACAO(P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE,
                             P_CDFILIPROC   IN FILIAL.CDFILIAL%TYPE,
                             P_NRCOLEPRECO  IN COLETAPR.NRCOLEPRECO%TYPE,
                             P_NRSEMAINIC   IN COLETAPR.NRSEMAINIC%TYPE,
                             P_NRSEMAFINAL  IN COLETAPR.NRSEMAFINAL%TYPE,
                             P_DTNOVINIVAL  IN COLETAPR.DTINIVALCOL%TYPE,
                             P_DTNOVFINVAL  IN COLETAPR.DTFINVALCOL%TYPE,
                             P_DTINIVALCOL  IN COLETAPR.DTINIVALCOL%TYPE,
                             P_DTFINVALCOL  IN COLETAPR.DTFINVALCOL%TYPE,
                             P_DTCOLEPREC   IN COLETAPR.DTCOLEPREC%TYPE,
                             P_REAJUSTE     IN NUMBER,
                             P_NRCOLEDUP    IN COLETAPR.NRCOLEPRECO%TYPE,
                             P_IDDUPLICA    IN VARCHAR2,
                             P_CDOPERADOR   IN VARCHAR2 DEFAULT NULL,
                             P_TCDOPERADOR  IN VARCHAR2,
                             P_CDOPERINCL   IN VARCHAR2,
                             P_CDREGIAO     IN VARCHAR2 DEFAULT NULL,
                             P_DUPLICAOL    IN VARCHAR2 DEFAULT 'N',
                             P_CDFORNOL     IN VARCHAR2 DEFAULT NULL,
                             P_CDREGIAOL    IN VARCHAR2 DEFAULT NULL,
                             P_COTA_N_DUP   OUT VARCHAR2);

   PROCEDURE GRAVA_COTWEB(P_CDFILIAL     IN PEDCOLETA.CDFILIAL%TYPE,
                          P_NRPEDCOLETA  IN PEDCOLETA.NRPEDCOLETA%TYPE,
                          P_CDREGIAO     IN PEDCOLETA.CDREGIAO%TYPE,
                          P_CDFORNECED   IN PEDCOLETA.CDFORNECED%TYPE,
                          P_NRSEMINI     IN COLETAPR.NRSEMAINIC%TYPE,
                          P_NRSEMFIN     IN COLETAPR.NRSEMAFINAL%TYPE,
                          P_ENTRALISTA   IN VARCHAR2,
                          P_COTA_N_GER  OUT VARCHAR2,
                          P_CDOPERINCL   IN VARCHAR2 DEFAULT NULL,
                          P_TRANSACAO    IN VARCHAR2 DEFAULT 'S');
END SUP_COTACAO;
/