CREATE TABLE LANCSALDCAIXA 
( 
  NRSEQLANCSALD     NUMBER,
  CDEMPRESA         VARCHAR2(02) 					NOT NULL,
  DTLANCSALD        DATE 							NOT NULL,
  CDFILIAL          VARCHAR2(04) 					NOT NULL,
  CDCENTCUST        VARCHAR2(04) 					NOT NULL,
  VRLANCSALD        FLOAT,
  NRORG             NUMBER 			DEFAULT 	 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO           VARCHAR2(1) 	DEFAULT 'S' 	NOT NULL ,
  DTINCLUSAO 		DATE,
  DTULTATU 			DATE,
  NRORGINCLUSAO  	NUMBER 			DEFAULT 1,
  CDOPERINCLUSAO 	VARCHAR2(12) 	DEFAULT '1',
  NRORGULTATU    	NUMBER 			DEFAULT 1,
  CDOPERULTATU   	VARCHAR2(12) 	DEFAULT '1',
    CONSTRAINT CKC_IDATIVO_LANCSALDCAIXA CHECK (IDATIVO IN ('S','N')) ,
    CONSTRAINT PK_LANCSALDCAIXA PRIMARY KEY (NRSEQLANCSALD) 
)
/
CREATE TABLE TIPODESPESAS
( 
  CDTIPODESP        NUMBER 							NOT NULL,
  NMDESPESA         VARCHAR2(4000) 					NOT NULL,
  CDHISTPADR        VARCHAR2(04) 					NULL, 
  CDCONTCTBL        VARCHAR2(20) 					NULL,
  IDCTBLDESP        VARCHAR2(1) 	DEFAULT 'N' 	NOT NULL ,
  NRORG             NUMBER 			DEFAULT 	 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO           VARCHAR2(1) 	DEFAULT 'S' 	NOT NULL ,
  DTINCLUSAO 		DATE,
  DTULTATU 			DATE,
  NRORGINCLUSAO  	NUMBER 			DEFAULT 1,
  CDOPERINCLUSAO 	VARCHAR2(12) 	DEFAULT '1',
  NRORGULTATU    	NUMBER 			DEFAULT 1,
  CDOPERULTATU   	VARCHAR2(12) 	DEFAULT '1',
    CONSTRAINT CKC_IDATIVO_TIPODESPESAS CHECK (IDATIVO IN ('S','N')) ,
    CONSTRAINT CKC_IDCTBLDESP_TIPODESPESAS CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT PK_TIPODESPESAS PRIMARY KEY (CDTIPODESP) 
)
/
CREATE TABLE LANCDESPCAIXA
( 
  NRSEQLANCDESP     NUMBER 							NOT NULL,
  CDTIPODESP        NUMBER 							NOT NULL,
  DSLANCDESP        VARCHAR2(4000),
  CDEMPRESA         VARCHAR2(20) 					NOT NULL,
  DTLANCDESP        DATE 							NOT NULL,
  CDFILIAL          VARCHAR2(04) 					NOT NULL,
  CDCENTCUST        VARCHAR2(04) 					NOT NULL,
  VRLANCDESP        FLOAT,
  NRORG             NUMBER 			DEFAULT 	 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO           VARCHAR2(1) 	DEFAULT 'S' 	NOT NULL ,
  DTINCLUSAO        DATE,
  DTULTATU          DATE,
  NRORGINCLUSAO     NUMBER 			DEFAULT 1,
  CDOPERINCLUSAO    VARCHAR2(12) 	DEFAULT '1',
  NRORGULTATU       NUMBER 			DEFAULT 1,
  CDOPERULTATU      VARCHAR2(12) 	DEFAULT '1',
    CONSTRAINT CKC_IDATIVO_LANCDESPCAIXA CHECK (IDATIVO IN ('S','N')) ,
    CONSTRAINT PK_LANCDESPCAIXA PRIMARY KEY (NRSEQLANCDESP) 
)
/
CREATE TABLE RELACSALDCAIXADESP
(
  NRSEQRELACLANCDESP NUMBER,
  NRSEQLANCDESP      NUMBER,
  NRSEQLANCSALD      NUMBER,
  CDEMPRESA          VARCHAR2(20) 					NOT NULL,
  DTRELACSALDDESP    DATE 							NOT NULL,
  CDFILIAL           VARCHAR2(04) 					NOT NULL,
  CDCENTCUST         VARCHAR2(04) 					NOT NULL,
  VRRELACSALDCAIX    FLOAT,
  NRORG              NUMBER 		DEFAULT 	 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO            VARCHAR2(1) 	DEFAULT 'S' 	NOT NULL ,
  DTINCLUSAO         DATE,
  DTULTATU           DATE,
  NRORGINCLUSAO      NUMBER 		DEFAULT 1,
  CDOPERINCLUSAO     VARCHAR2(12) 	DEFAULT '1',
  NRORGULTATU        NUMBER 		DEFAULT 1,
  CDOPERULTATU       VARCHAR2(12) 	DEFAULT '1',
    CONSTRAINT CKC_IDATIVO_RELACSALDCAIXA CHECK (IDATIVO IN ('S','N')) ,
    CONSTRAINT PK_RELACSALDCAIXADESP PRIMARY KEY (NRSEQRELACLANCDESP) 
)
/
ALTER TABLE LANCSALDCAIXA ADD VRLANCSALDUTIL FLOAT NULL
/
ALTER TABLE LANCSALDCAIXA ADD VRLANCSALDDISP FLOAT NULL
/
ALTER TABLE RELACSALDCAIXADESP ADD CDTIPODESP NUMBER NOT NULL
/
alter table RELACSALDCAIXADESP
    add constraint FKFIN00398 foreign key  (NRSEQLANCDESP)
       references LANCDESPCAIXA   (NRSEQLANCDESP) on delete cascade
/
alter table RELACSALDCAIXADESP
    add constraint FKFIN00399 foreign key  (NRSEQLANCSALD)
       references LANCSALDCAIXA   (NRSEQLANCSALD) on delete cascade