CREATE TABLE PEDALTCARD
(
    NRPEDALTCARD      NUMBER NOT NULL,
    CDPEDALTCARD      VARCHAR2(10) NOT NULL,
    DTPEDALTCARD      DATE NOT NULL,
    CDOPERADOR        VARCHAR2(12) NOT NULL,
    CDFILIAL          VARCHAR2(4) NOT NULL,
    CDSERVFILI        VARCHAR2(5) NOT NULL,
    DTMESCARD         DATE NOT NULL,
    IDSITUACAO        VARCHAR2(1) DEFAULT 'E' NOT NULL,
    IDSOLEXTRA        VARCHAR2(1) DEFAULT 'N' NOT NULL,
    IDRECEMCONCLUIDO  VARCHAR2(1) DEFAULT 'N' NOT NULL,
    IDRECEMAPROVREPR  VARCHAR2(1) DEFAULT 'N' NOT NULL,
    DTAPROVREPR       DATE NULL,
    CDOPERAPROVREPR   VARCHAR2(12) NULL,
    DTAPROVREPRGO     DATE NULL,
    CDOPERAPROVREPRGO VARCHAR2(12) NULL,
    DSJUSTICATIVA     VARCHAR2(1000) NULL,
    DSRESPOSTA        VARCHAR2(1000) NULL,
    IDPEDIDOREFEITO   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            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 PK_PEDALTCARD PRIMARY KEY (NRPEDALTCARD),
		CONSTRAINT UN_PEDALTCARD UNIQUE(CDPEDALTCARD),
		CONSTRAINT CKC_IDSITUACAO_PEDALTCARD CHECK (IDSITUACAO IN ('E', 'C','A','R')),
		CONSTRAINT CKC_IDSOLEXTRA_PEDALTCARD CHECK (IDSOLEXTRA IN ('N', 'S')),
		CONSTRAINT CKC_IDRECCONCLUIDO_PEDALTCARD CHECK (IDRECEMCONCLUIDO IN ('N', 'S')),
		CONSTRAINT CKC_IDRECAPROVREPR_PEDALTCARD CHECK (IDRECEMAPROVREPR IN ('N', 'S')),
		CONSTRAINT CKC_IDPEDIDOREFEITO_PEDALTCARD CHECK (IDRECEMAPROVREPR IN ('N', 'S')),
		CONSTRAINT CKC_IDATIVO_PEDALTCARD CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE PEDALTCARD
    ADD CONSTRAINT FKPLA01325PEDALTCARD FOREIGN KEY  (CDOPERADOR)
       REFERENCES OPERADOR (CDOPERADOR)
/
CREATE INDEX PLA01325_FK ON PEDALTCARD (CDOPERADOR)
/
ALTER TABLE PEDALTCARD
    ADD CONSTRAINT FKPLA01326PEDALTCARD FOREIGN KEY  (CDFILIAL, CDSERVFILI)
       REFERENCES SERVICO (CDFILIAL, CDSERVFILI)
/
CREATE INDEX PLA01326_FK ON PEDALTCARD (CDFILIAL, CDSERVFILI)
/
ALTER TABLE PEDALTCARD
    ADD CONSTRAINT FKPLA01327PEDALTCARD FOREIGN KEY  (CDOPERAPROVREPR)
       REFERENCES OPERADOR (CDOPERADOR)
/
CREATE INDEX PLA01327_FK ON PEDALTCARD (CDOPERAPROVREPR)
/
ALTER TABLE PEDALTCARD
    ADD CONSTRAINT FKPLA01328PEDALTCARD FOREIGN KEY  (CDOPERAPROVREPRGO)
       REFERENCES OPERADOR (CDOPERADOR)
/
CREATE INDEX PLA01328_FK ON PEDALTCARD (CDOPERAPROVREPRGO)
/
CREATE TABLE EMAILPEDALTCARD(
    CDFILIAL 		  VARCHAR2(4) NOT NULL, 
    DSEMAIL 	  	  VARCHAR2(1000) NOT NULL,
	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 PK_EMAILPEDALTCARD PRIMARY KEY (CDFILIAL),
		CONSTRAINT CKC_IDATIVO_EMAILPEDALTCARD CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE EMAILPEDALTCARD ADD CONSTRAINT FKPLA01329EMAILPEDALTCARD 
	FOREIGN KEY  (CDFILIAL) REFERENCES FILIAL (CDFILIAL)
/
CREATE TABLE PEDALTCARDDIA
(
    NRPEDALTCARDDIA   NUMBER NOT NULL,
    NRPEDALTCARD 	  NUMBER NOT NULL,
    CDFILIAL 		  VARCHAR2(4) NOT NULL,
    NRCARDAPIO 		  VARCHAR2(10) NULL,
    DTCARDAPIO 		  DATE NOT NULL,
    QTCLIESTICAR 	  FLOAT NULL,
    QTFUNESTICAR 	  FLOAT NULL,
    QTDOAESTICAR 	  FLOAT NULL,
    QTESTITURNO1 	  FLOAT NULL,
    QTESTITURNO2 	  FLOAT NULL,
    QTESTITURNO3 	  FLOAT NULL,
    QTESTITURNO4 	  FLOAT NULL,
    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 PK_PEDALTCARDDIA PRIMARY KEY (NRPEDALTCARDDIA),
		CONSTRAINT CKC_IDATIVO_PEDALTCARDDIA CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE PEDALTCARDDIA ADD CONSTRAINT FKPLA01330PEDALTCARDDIA FOREIGN KEY  (NRPEDALTCARD)
       REFERENCES PEDALTCARD (NRPEDALTCARD) ON DELETE CASCADE
/
CREATE INDEX PLA01330_FK ON PEDALTCARDDIA (NRPEDALTCARD)
/
CREATE TABLE PEDALTCARDCLI
(
    NRPEDALTCARDCLI   NUMBER 		  NOT NULL,
    NRPEDALTCARD 	  NUMBER 		  NOT NULL,
    CDFILIAL 		  VARCHAR2(4) 	  NOT NULL,
    NRCARDAPIO 		  VARCHAR2(10)    NULL,
    DTCARDAPIO 		  DATE 			  NOT NULL,
    CDCLIENTE 		  VARCHAR2(21)	  NOT NULL,
    CDDESTFILI 		  VARCHAR2(3) 	  NOT NULL,
    QTCOMESTICLI 	  FLOAT			  NOT NULL,
    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 PK_PEDALTCARDCLI PRIMARY KEY (NRPEDALTCARDCLI),
		CONSTRAINT CKC_IDATIVO_PEDALTCARDCLI CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE PEDALTCARDCLI ADD CONSTRAINT FKPLA01331PEDALTCARDCLI FOREIGN KEY  (NRPEDALTCARD)
      REFERENCES PEDALTCARD (NRPEDALTCARD) ON DELETE CASCADE
/
CREATE INDEX PLA01331_FK ON PEDALTCARDCLI (NRPEDALTCARD)
/
CREATE TABLE PEDALTCARDCOMP
(
    NRPEDALTCARDCOMP  NUMBER NOT NULL,
    NRPEDALTCARD 	  NUMBER NOT NULL,
    CDFILIAL 	  	  VARCHAR2(4) NOT NULL,
    NRCARDAPIO 	  	  VARCHAR2(10) NULL,
    DTCARDAPIO 	  	  DATE NOT NULL,
    NRSEQPRATCAR 	  NUMBER(3) NOT NULL,
    CDFILAUXPRAT 	  VARCHAR2(4) NULL,
    CDPRATO 	      VARCHAR2(10) NULL,
    VRPECONSCARD 	  FLOAT NULL,
    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 PK_PEDALTCARDCOMP PRIMARY KEY (NRPEDALTCARDCOMP),
		CONSTRAINT CKC_IDATIVO_PEDALTCARDCOMP CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE PEDALTCARDCOMP
    ADD CONSTRAINT FKPLA01332PEDALTCARDCOMP FOREIGN KEY  (NRPEDALTCARD)
       REFERENCES PEDALTCARD (NRPEDALTCARD) ON DELETE CASCADE
/
CREATE INDEX PLA01332_FK ON PEDALTCARDCOMP (NRPEDALTCARD)
/
ALTER TABLE PEDALTCARDCOMP
    ADD CONSTRAINT FKPLA01333PEDALTCARDCOMP FOREIGN KEY  (CDFILAUXPRAT, CDPRATO)
       REFERENCES PRATO (CDFILAUXPRAT, CDPRATO)
/
CREATE INDEX PLA01333_FK ON PEDALTCARDCOMP (CDFILAUXPRAT, CDPRATO)