/*==============================================================*/
/* Database name:  Model_3                                      */
/* DBMS name:      ORACLE Version 7                             */
/* Created on:     29/01/2008 02:48:13 p.m.                     */
/*==============================================================*/


/*==============================================================*/
/* Table: "REC_CAJAS"                                           */
/*==============================================================*/
CREATE TABLE "REC_CAJAS" (
   "COD_CIA"            VARCHAR2(3)                     NOT NULL,
   "SUCURSAL"           CHAR(3)                         NOT NULL,
   "COD_LINEA"          VARCHAR2(5)                     NOT NULL,
   "NUM_CAJA"           VARCHAR2(10)                    NOT NULL,
   "COD_CTA"            VARCHAR2(25)                    NOT NULL,
   "NUMDOCTO_INI"       VARCHAR2(10)                    NOT NULL,
   CONSTRAINT "REC_CAJAS_PK" PRIMARY KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA")
);

/*==============================================================*/
/* Table: "REC_CAJDIA"                                          */
/*==============================================================*/
CREATE TABLE "REC_CAJDIA" (
   "COD_CIA"            VARCHAR2(3)                     NOT NULL,
   "SUCURSAL"           CHAR(3)                         NOT NULL,
   "COD_LINEA"          VARCHAR2(5)                     NOT NULL,
   "NUM_CAJA"           VARCHAR2(10)                    NOT NULL,
   "COD_CAJERO"         VARCHAR2(10)                    NOT NULL,
   "FECHA"              DATE                            NOT NULL,
   "ANO_FISCAL"         NUMBER(4)                       NOT NULL,
   "PER_PROCESO"        NUMBER(2)                       NOT NULL,
   "SALDO_INICIAL"      NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_CHEQUES"        NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_EFECTIVO"       NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_TARJETA"        NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_OTROS"          NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "ESTADO"             CHAR(1)                        DEFAULT 'I' NOT NULL
         CONSTRAINT REC_CAJDIA_ESTADO_CK CHECK ("ESTADO" IN ('A','I')),
   CONSTRAINT REC_CAJDIA_PK PRIMARY KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA")
);

/*==============================================================*/
/* Table: "REC_CAJERO"                                          */
/*==============================================================*/
CREATE TABLE "REC_CAJERO" (
   "COD_CIA"            VARCHAR2(3)                     NOT NULL,
   "SUCURSAL"           CHAR(3)                         NOT NULL,
   "COD_LINEA"          VARCHAR2(5)                     NOT NULL,
   "COD_CAJERO"         VARCHAR2(10)                    NOT NULL,
   "USERID"             VARCHAR2(20),
   "ESTADO"             CHAR(1)                        DEFAULT 'A' NOT NULL
         CONSTRAINT REC_CAJERO_ESTADO_CK CHECK ("ESTADO" IN ('A','E')),
   CONSTRAINT "REC_CAJERO_PK" PRIMARY KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "COD_CAJERO")
);

/*==============================================================*/
/* Table: "REC_CHK_CAMBIO"                                      */
/*==============================================================*/
CREATE TABLE "REC_CHK_CAMBIO" (
   "COD_CIA"            VARCHAR2(3)                     NOT NULL,
   "SUCURSAL"           CHAR(3)                         NOT NULL,
   "COD_LINEA"          VARCHAR2(5)                     NOT NULL,
   "NUM_CAJA"           VARCHAR2(10)                    NOT NULL,
   "COD_CAJERO"         VARCHAR2(10)                    NOT NULL,
   "FECHA"              DATE                            NOT NULL,
   "COD_BANCO"          VARCHAR2(12)                    NOT NULL,
   "NUM_CHEQUE"         VARCHAR2(10)                    NOT NULL,
   "MONTO"              NUMBER(14,2)                    NOT NULL,
   "CONSECUTIVO"        NUMBER(10),
   CONSTRAINT REC_CHK_CAMBIO_PK PRIMARY KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA", "COD_BANCO", "NUM_CHEQUE")
);

/*==============================================================*/
/* Table: "REC_CONCEPTO"                                        */
/*==============================================================*/
CREATE TABLE "REC_CONCEPTO" (
   "COD_CONCEPTO"       VARCHAR2(3)                     NOT NULL,
   "DES_CONCEPTO"       VARCHAR2(40)                    NOT NULL,
   "CTA_CONTABLE"       VARCHAR2(25)                    NOT NULL,
   CONSTRAINT "REC_CONCEPTO_PK" PRIMARY KEY ("COD_CONCEPTO")
);

/*==============================================================*/
/* Table: "REC_DEPOSITO"                                        */
/*==============================================================*/
CREATE TABLE "REC_DEPOSITO" (
   "COD_CIA"            VARCHAR2(3)                     NOT NULL,
   "SUCURSAL"           CHAR(3)                         NOT NULL,
   "COD_LINEA"          VARCHAR2(5)                     NOT NULL,
   "NUM_CAJA"           VARCHAR2(10)                    NOT NULL,
   "COD_BANCO"          VARCHAR2(12)                    NOT NULL,
   "NUM_DOCTO"          VARCHAR2(10)                    NOT NULL,
   "FECHA"              DATE                            NOT NULL,
   "COD_CAJERO"         VARCHAR2(10)                    NOT NULL,
   "MONTO"              NUMBER(14,2)                    NOT NULL,
   "COD_MOVTO_BAN"      VARCHAR2(3),
   "NUM_DOCTO_BAN"      VARCHAR2(10),
   "ESTADO"             CHAR(1)                        DEFAULT 'P' NOT NULL
         CONSTRAINT REC_DEPOSITO_ESTADO_CK CHECK ("ESTADO" IN ('A','P')),
   CONSTRAINT REC_DEPOSITO_PK PRIMARY KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_BANCO", "NUM_DOCTO", "FECHA")
);

/*==============================================================*/
/* Table: "REC_DETMOVTO"                                        */
/*==============================================================*/
CREATE TABLE "REC_DETMOVTO" (
   "CONSECUTIVO"        NUMBER(10)                      NOT NULL,
   "COD_CTA_AFECTA"     VARCHAR2(25)                    NOT NULL,
   "MONTO"              NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   CONSTRAINT REC_DETMOVTO_PK PRIMARY KEY ("CONSECUTIVO", "COD_CTA_AFECTA")
);

/*==============================================================*/
/* Table: "REC_DIFERENCIA"                                      */
/*==============================================================*/
CREATE TABLE "REC_DIFERENCIA" (
   "COD_CIA"            VARCHAR2(3)                     NOT NULL,
   "SUCURSAL"           CHAR(3)                         NOT NULL,
   "COD_LINEA"          VARCHAR2(5)                     NOT NULL,
   "COD_RUTA"           VARCHAR2(4)                     NOT NULL,
   "COD_VENDEDOR"       VARCHAR2(10)                    NOT NULL,
   "FECHA"              DATE                            NOT NULL,
   "NUM_CAJA"           VARCHAR2(10)                    NOT NULL,
   "COD_CAJERO"         VARCHAR2(10)                    NOT NULL,
   "ANO_FISCAL"         NUMBER(4)                       NOT NULL,
   "PER_PROCESO"        NUMBER(2)                       NOT NULL,
   "SALDO_INICIAL"      NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_CARGOS"         NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_CREDITOS"       NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "ESTADO"             CHAR(1)                        DEFAULT 'F' NOT NULL
         CONSTRAINT REC_DIFERENCIA_ESTADO_CK CHECK ("ESTADO" IN ('F','S')),
   CONSTRAINT "REC_DIFERENCIA_PK" PRIMARY KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "COD_RUTA", "COD_VENDEDOR", "FECHA")
);

/*==============================================================*/
/* Table: "REC_ENCABMOVTO"                                      */
/*==============================================================*/
CREATE TABLE "REC_ENCABMOVTO" (
   "CONSECUTIVO"        NUMBER(10)                      NOT NULL,
   "COD_CIA"            VARCHAR2(3)                     NOT NULL,
   "SUCURSAL"           CHAR(3)                         NOT NULL,
   "COD_LINEA"          VARCHAR2(5)                     NOT NULL,
   "NUM_CAJA"           VARCHAR2(10)                    NOT NULL,
   "COD_CAJERO"         VARCHAR2(10)                    NOT NULL,
   "NUM_DOCTO"          VARCHAR2(10)                    NOT NULL,
   "IND_AFECTA"         CHAR(1)                        DEFAULT 'C' NOT NULL
         CONSTRAINT "REC_ENCABMOVTO_IND_AFECTA_CK" CHECK ("IND_AFECTA" IN ('C','E','P','O','T')),
   "COD_CTA_AFECTA"     VARCHAR2(25)                    NOT NULL,
   "COD_RUTA"           CHAR(4),
   "COD_MOVTO"          VARCHAR2(3)                     NOT NULL,
   "NOMBRE"             VARCHAR2(40)                    NOT NULL,
   "COD_CONCEPTO"       VARCHAR2(3)                     NOT NULL,
   "FECHA"              DATE                            NOT NULL,
   "DETALLE"            VARCHAR2(60)                    NOT NULL,
   "ANO_FISCAL"         NUMBER(4)                       NOT NULL,
   "PER_PROCESO"        NUMBER(2)                       NOT NULL,
   "MON_EFECTIVO"       NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_CHEQUES"        NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_TARJETA"        NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "MON_OTROS"          NUMBER(14,2)                   DEFAULT 0 NOT NULL,
   "CTA_CONTABLE"       VARCHAR2(25)                    NOT NULL,
   "NUM_DEPOSITO"       VARCHAR2(10),
   "ESTADO"             CHAR(1)                        DEFAULT 'P' NOT NULL
         CONSTRAINT REC_ENCAMOVTO_ESTADO_CK CHECK ("ESTADO" IN ('P','A','E')),
   CONSTRAINT REC_ENCABMOVTO_PK PRIMARY KEY ("CONSECUTIVO")
);

/*==============================================================*/
/* Table: "RECPARTIDA"                                          */
/*==============================================================*/
CREATE TABLE "RECPARTIDA" (
   COD_CIA              VARCHAR2(3)                     NOT NULL,
   "SUCURSAL"           CHAR(3)                         NOT NULL,
   "COD_LINEA"          VARCHAR2(5)                     NOT NULL,
   "FECHA"              DATE                            NOT NULL,
   "COD_CTA"            VARCHAR2(25)                    NOT NULL,
   "DEBITO"             NUMBER(14,2)                    NOT NULL,
   "CREDITO"            NUMBER(14,2),
   CONSTRAINT "RECPARTIDA" PRIMARY KEY (COD_CIA, "SUCURSAL", "COD_LINEA", "FECHA", "COD_CTA")
);

ALTER TABLE "REC_CAJDIA"
   ADD CONSTRAINT "REC_CAJAS_CAJDIA_FK" FOREIGN KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA")
      REFERENCES "REC_CAJAS" ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA");

ALTER TABLE "REC_CAJDIA"
   ADD CONSTRAINT "REC_CAJERO_CAJDIA_FK" FOREIGN KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "COD_CAJERO")
      REFERENCES "REC_CAJERO" ("COD_CIA", "SUCURSAL", "COD_LINEA", "COD_CAJERO");

ALTER TABLE "REC_CHK_CAMBIO"
   ADD CONSTRAINT "REC_CAJDIA_CHKCAMBIO_FK" FOREIGN KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA")
      REFERENCES "REC_CAJDIA" ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA");

ALTER TABLE "REC_DEPOSITO"
   ADD CONSTRAINT "REC_CAJDIA_DEPOSITO_FK" FOREIGN KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA")
      REFERENCES "REC_CAJDIA" ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA");

ALTER TABLE "REC_DETMOVTO"
   ADD CONSTRAINT "REC_ENCMOVTO_DETMOVTO_FK" FOREIGN KEY ("CONSECUTIVO")
      REFERENCES "REC_ENCABMOVTO" ("CONSECUTIVO");

ALTER TABLE "REC_DIFERENCIA"
   ADD CONSTRAINT "REC_CAJDIA_DIFERENCIA_FK" FOREIGN KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA")
      REFERENCES "REC_CAJDIA" ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA");

ALTER TABLE "REC_ENCABMOVTO"
   ADD CONSTRAINT "REC_CAJDIA_ENCMOVTO_FK" FOREIGN KEY ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA")
      REFERENCES "REC_CAJDIA" ("COD_CIA", "SUCURSAL", "COD_LINEA", "NUM_CAJA", "COD_CAJERO", "FECHA");

ALTER TABLE "REC_ENCABMOVTO"
   ADD CONSTRAINT "REC_CONCEPTO_ENCMOVTO_FK" FOREIGN KEY ("COD_CONCEPTO")
      REFERENCES "REC_CONCEPTO" ("COD_CONCEPTO");

