CREATE TABLE LANCACERTO
( 
    NRLANCACERTO      INTEGER     NOT NULL,
    DTLANCACERTO      DATE NOT NULL,
    CDEMPRESA         VARCHAR2(20) NOT NULL,
    CDFILIAL          VARCHAR2(04) NOT NULL, 
    CDFORNECED        VARCHAR2(21)                    NOT NULL,
    CDCENTCUST        VARCHAR2(04) NOT NULL,
    CDFILIALNFPAG     VARCHAR2(04)                    NULL,
    NRLANCTONFPAG     VARCHAR2(20)                    NULL,
    VRLANCACERTO      FLOAT,
    DSRECUSACERTO     VARCHAR2(200),
    IDSTATUS          VARCHAR2(1),
    NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    NRORGINCLUSAO     NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 					NULL,
    NRORGULTATU       NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERULTATU      VARCHAR2(12)    DEFAULT '1',
	    CONSTRAINT CKC_IDATIVO_LANCACERTO CHECK (IDATIVO IN ('S','N')),
        CONSTRAINT PK_LANCACERTO PRIMARY KEY (NRLANCACERTO)
)
/

ALTER TABLE LANCACERTO ADD CONSTRAINT FKFIS00921EMPRESA_LANCACERT FOREIGN KEY (CDEMPRESA)
    REFERENCES EMPRESA (CDEMPRESA)
/

CREATE INDEX FIS00921_FK ON LANCACERTO (CDEMPRESA ASC)
/

ALTER TABLE LANCACERTO ADD CONSTRAINT FKFIS00922FILIAL_LANCACERT FOREIGN KEY (CDFILIAL)
    REFERENCES FILIAL (CDFILIAL)
/

CREATE INDEX FIS00922_FK ON LANCACERTO (CDFILIAL ASC)
/

ALTER TABLE LANCACERTO ADD CONSTRAINT FKFIS00923FORNEC_LANCACERT FOREIGN KEY (CDFORNECED)
    REFERENCES FORNECEDOR (CDFORNECED)
/

CREATE INDEX FIS00923_FK ON LANCACERTO (CDFORNECED ASC)
/

ALTER TABLE LANCACERTO ADD CONSTRAINT FKFIS00924CENTCUST_LANCACERT FOREIGN KEY (CDCENTCUST)
    REFERENCES CENTCUST (CDCENTCUST)
/

CREATE INDEX FIS00924_FK ON LANCACERTO (CDCENTCUST ASC)
/

ALTER TABLE LANCACERTO ADD CONSTRAINT FKFIS00925NOTAFIS_LANCACERT FOREIGN KEY (CDFILIALNFPAG,NRLANCTONFPAG)
    REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF)
/

CREATE INDEX FIS00925_FK ON LANCACERTO (CDFILIALNFPAG ASC, NRLANCTONFPAG ASC)
/

CREATE SEQUENCE SEQ_LANCACERTO START WITH 1 MINVALUE 1 INCREMENT BY 1
/

CREATE TABLE DESPACERTO
( 
    NRDESPACERTO      INTEGER         NOT NULL,
    NRLANCACERTO      INTEGER         NOT NULL, 
    CDTIPODESP        NUMBER          NOT NULL,
    DTDESPESA         DATE            NOT NULL,
    DSDESPESA         VARCHAR2(200)   NOT NULL,
    VRDESPESA         FLOAT,
    NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    NRORGINCLUSAO     NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 					NULL,
    NRORGULTATU       NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERULTATU      VARCHAR2(12)    DEFAULT '1',
	    CONSTRAINT CKC_IDATIVO_DESPACERTO CHECK (IDATIVO IN ('S','N')),
        CONSTRAINT PK_DESPACERTO PRIMARY KEY (NRDESPACERTO),
        CONSTRAINT FKFIS00926DESPACERT_LANCACERT FOREIGN KEY (NRLANCACERTO) REFERENCES LANCACERTO (NRLANCACERTO),
        CONSTRAINT FKFIS00927TPDESPESAS_DESPCERT FOREIGN KEY (CDTIPODESP) REFERENCES TIPODESPESAS(CDTIPODESP)
)
/

CREATE INDEX FIS00926_FK ON DESPACERTO (NRLANCACERTO ASC)
/

CREATE INDEX FIS00927_FK ON DESPACERTO (CDTIPODESP ASC)
/

CREATE SEQUENCE SEQ_DESPACERTO START WITH 1 MINVALUE 1 INCREMENT BY 1
/

CREATE TABLE ANEXOLANDESP
   (    
    NRANEXOLANDESP      NUMBER             NOT NULL, 
    NRLANCACERTO        NUMBER,
    CDTELA              VARCHAR2(20)       NOT NULL, 
    DTANEXOLANDESP      DATE               NOT NULL, 
    NMANEXOLANDESP      VARCHAR2(200)      NOT NULL, 
    NMPATHANEXO         VARCHAR2(200)         NOT NULL, 
    DSANEXOLANDESP      VARCHAR2(1000)      NOT NULL, 
    DSINFOANEXO         VARCHAR2(4000),
    NRORG               NUMBER 	        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO             VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO          DATE            DEFAULT SYSDATE,
    DTULTATU            DATE            DEFAULT SYSDATE,
    NRORGINCLUSAO       NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERINCLUSAO      VARCHAR2(12)    DEFAULT '1' 					NULL,
    NRORGULTATU         NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERULTATU        VARCHAR2(12)    DEFAULT '1',
	    CONSTRAINT CKC_IDATIVO_ANEXOLANDESP CHECK (IDATIVO IN ('S','N')),
        CONSTRAINT PK_ANEXOLANDESP PRIMARY KEY (NRANEXOLANDESP),
        CONSTRAINT FKFIS00928ANXLANDESP_LANCCERT FOREIGN KEY (NRLANCACERTO) REFERENCES LANCACERTO (NRLANCACERTO)
)
/

CREATE INDEX FIS00928_FK ON ANEXOLANDESP (NRLANCACERTO ASC)
/