create or replace PACKAGE Catalogos IS

   type cattab is table of date index by binary_integer;

   PBod gen_agente.bodega%type;

   procedure Inicializar(Pcia in char);
   Function HayCatalogo return boolean;
   Function EsCatalogo(pArt in varchar2) return boolean;
   Function Fecha(pArt in varchar2) return date;
   Function Bodega return varchar2;
   Function Raiz   return varchar2;
   Procedure FijarBodega(pCia in char, pSuc in char, pAge in varchar2);
   Function PrimerFactura(pCia in char, pSuc in char, pCli in varchar2, Pdia in date) return boolean;

END;
/

create or replace PACKAGE BODY Catalogos IS

   Tabc cattab;

   vRaiz varchar2(5):='CAT%';

   procedure Inicializar(Pcia in char) is
      cursor catalogos is
         select catalogo, max(fecha) fecmax
         from vencatalogo
         where cia=Pcia
           and fecha<=trunc(sysdate)
         group by catalogo;
   begin
      null;
   end Inicializar;

   Function HayCatalogo return boolean is
   begin
      return false;
   end;

   Function EsCatalogo(pArt in varchar2) return boolean is
   begin
      return false;      
   end;

   Function Fecha(pArt in varchar2) return date is
   begin
      return null;      
   end;

   Function Bodega return varchar2 is
   begin
      return PBod;
   end;

   Function Raiz return varchar2 is
   begin
      return vRaiz;
   end;

   procedure FijarBodega(pCia in char, pSuc in char, pAge in varchar2) is
   begin
      pBod:=null;
   end FijarBodega;
   
   Function PrimerFactura(pCia in char, pSuc in char, pCli in varchar2, Pdia in date) return boolean is
      cursor facturas is
         select '1' from venfactura
         where cia=pCia
           and sucursal=pSuc
           and cliente=pCli
           and fecha>=Trunc(pDia)
           and estado='A';
      pFacts char(1);
   Begin
      return false;
   End PrimerFactura;

END;
/
