/*==============================================================*/
/* Table : cmsacuafil                                           */
/*==============================================================*/

create table cmsrecom (
   cia                  CHAR(3)                         not null,
   cliente              VARCHAR2(25)                    not null,
   recomendado          VARCHAR2(25)                    not null,
   fecha                DATE                            not null,
   estado               CHAR(1)                         not null
         constraint CMSRECOM_ESTADO_CK check (estado in ('P','A','N')),
   constraint CMSRECOM_UQ unique (cia, recomendado),
   constraint CMSRECOM_PK primary key (cia, cliente, recomendado)
)
initrans 1
storage
    (
      initial 10K
      next 10K
    )
/


create table cmsrecompre (
   cia                  CHAR(3)                         not null,
   monto                NUMBER(14,2)                    not null
         constraint CMSRECOMPRE_MONTO_CK check (monto>=0),
   articulo             VARCHAR2(25)                    not null,
   cantidad             NUMBER(12,4)                    not null
         constraint CMSRECOMPRE_CANTIDAD_CK check (cantidad>0),
   constraint CMSRECOMPRE_PK primary key (cia, monto, articulo)
)
initrans 1
storage
    (
      initial 10K
      next 10K
    )
/

create table venpremios (
   cia                  CHAR(3)                         not null,
   cliente              VARCHAR2(25)                    not null,
   articulo             VARCHAR2(25)                    not null,
   cantidad             NUMBER(12,4)                    not null
         constraint VENPREMIOS_CANTIDAD_CK check (cantidad>0),
   constraint VENPREMIOS_PK primary key (cia, cliente, articulo)
)
initrans 1
storage
    (
      initial 10K
      next 10K
    )
/

alter table venfactura add(referencia varchar2(10));

alter table venfactura add constraint
   VENFACTURA_REFER_UQ unique (cia, sucursal, referencia);