create or replace package body venpel is

   Type         Toper is record
                ( mensaje       venpeloperacion.mensaje%type,
                  cliente       venpeloperacion.cliente%type,
                  tarjeta       venpeloperacion.tarjeta%type,
                  vence         venpeloperacion.vence%type,
                  nombre        venpeloperacion.nombre%type,
                  consecutivo   venpeloperacion.consecutivo%type,
                  referencia    venpeloperacion.referencia%type,
                  autorizacion  venpeloperacion.autorizacion%type,
                  banda         venpeloperacion.banda%type,
                  monto         venpeloperacion.monto%type
                );

   vcia         venpelcaja.cia%type;
   vcaja        venpelcaja.caja%type;
   Vdia         venpeloperacion.dia%type;
   Vterminal    venpelcaja.terminal%type;
   Vcomercio    venpelcomercio.comercio%type;
   Vservidor    venpelcomercio.servidor%type;
   Vpuerto      venpelcomercio.puerto%type;
   Vminespera   venpelcomercio.minespera%type;
   Vmaxespera   venpelcomercio.maxespera%type;
   Vintervalo   venpelcomercio.intervalo%type;
   Vrespuesta   venpeloperacion.respuesta%type;
   Vdocumento   number(10);
   VSep         char(1):=chr(28);
   --conn         utl_tcp.connection; -- TCP/IP connection to the Web server

   Function TerminalActiva return boolean is
   Begin
      return vterminal is not null and vcomercio is not null;
   End TerminalActiva;

   Function TipoTarjeta(ptarjeta in varchar2) return varchar2 is
   Begin
      return null;
   End TipoTarjeta;

   Function AutoValida(pTarjeta in varchar2, pConc in varchar2) return boolean is
   Begin
      return NULL;
   End AutoValida;

   Function Consecutivo return number is
      Vcons venpelcaja.consecutivo%type;
   Begin
      return Vcons;
   End Consecutivo;

   Function RegistraTransaccion(pmens in varchar2, pfecha in date, pcliente in varchar2, pnombre in varchar2, ptarjeta in varchar2,
                         pvence in varchar2, pbanda in varchar2, pmonto in number) return number is
      Vdoc venpeloperacion.documento%type;
   Begin
      return Vdoc;
   End RegistraTransaccion;

   Procedure inicializar(pcia in char, pcaja in char, pdia in date) is
   Begin
      vcia:=null;
      vcaja:=null;
      vterminal:=null;
   End Inicializar;

   Function Texto(Ptexto in varchar2, plargo in number) return varchar2 is
   begin
      return substr(ptexto, 1, plargo)||vSep;
   End Texto;

   Function Numero(Pnum in number, plargo in number) return varchar2 is
   begin
      return lpad(pnum, plargo, '0')||vSep;
   End numero;

   Procedure EmpacaTrama(Ptrama in out varchar2, pmens in varchar2, pfecha in date, ptarjeta in varchar2,
                         pvence in varchar2, plec in varchar2, pbanda in varchar2, pmonto in varchar2,
                         psyst in varchar2 default null, pref in varchar2 default null, paut in varchar2 default null) is
   Begin
      null;
   End;

   Function ExtraeCampo(ptrama in varchar2, pini in out number, psig in number) return varchar2 is
   Begin
      return null;
   end ExtraeCampo;

   Procedure LeerRespuesta(Ptrama in out varchar2, Plargo in out number) is
   Begin
      null;
   End LeerRespuesta;

   Function AceptaRespuesta(pminespera in number, pmaxespera in number) return varchar2 is
      VTrama  varchar2(256):=null;
   Begin
      return Vtrama;
   End AceptaRespuesta;

   Procedure RegistraRespuesta(pdoc in number, ptarj in varchar2, pcons in varchar2, prefer in varchar2,
                              pauto in varchar2, presp in varchar2, pest in char) is
   begin
      null;
   End RegistraRespuesta;

   Procedure ProcesaRespuesta(Pdoc in number, Ptrama in varchar2, pest in char) is
   begin
      null;
   End;

   Procedure ReintenteRespuesta(presp in out varchar2, pest in char default 'A') is
   Begin
      null;
   End ReintenteRespuesta;

   Function DatosRev(pcia in varchar2, pcaja in varchar2, pdoc in number,
                     pcliente in varchar2, pmonto in number) return Toper is
      voper    Toper;
   Begin
      return voper;
   End DatosRev;

   Procedure Autorizacion(pcliente in varchar2, pnombre in varchar2, ptarjeta in varchar2,
                         pvence in date, plec in varchar2, pbanda in varchar2, pmonto in number,
                         pdoc in out number, presp in out varchar2) is
   Begin
      pdoc:=null;
   End Autorizacion;

   Procedure Reversion(pcia in varchar2, pcaja in varchar2, pdoc in number, pcliente in varchar2,
                       pmonto in number, prever in out number, presp in out varchar2) is
   Begin
      Prever:=null;
   End Reversion;

   Procedure AutoReversion(pcliente in varchar2, pnombre in varchar2, ptarjeta in varchar2,
                           pvence in date, plec in varchar2, pbanda in varchar2, pmonto in number,
                           pRever in out number, presp in out varchar2) is      
   Begin
      Prever:=null;
   End AutoReversion;

   Procedure AnotaPago(Pdoc in number, Ppag in number) is
   Begin
      null;
   End AnotaPago;

   Function DescRespuesta(Presp in varchar2) return varchar2 is
   begin
      return presp;
   end;

   Function TerminalCaja(pcia in varchar2, pcaja in varchar2) return varchar2 is
      vterm  venpelcaja.terminal%type;
   begin
      return vterm;
   end;

   Function ObtTerminal return varchar2 is
   begin
      return Vterminal;
   end ObtTerminal;

   Function ObtComercio return varchar2 is
   begin
      return Vcomercio;
   end ObtComercio;

   Procedure Liberar is
   Begin
      Vterminal:=null;
   End Liberar;

End;
/
