-- ================================
-- TABLE: FCT_DESCAGRUPESCOPO
-- ================================
CREATE TABLE FCT_DESCAGRUPESCOPO (
   NRDESCAGRUPESCOPO    NUMBER 			NOT NULL,
   DSNOMEAGRUPAMENTO    VARCHAR2(500) 	NOT NULL,
   NRTIPOORCAMENTO      NUMBER 			NOT NULL,
   IDTPFATURA           CHAR(1) 		NOT NULL,
   CDFILIALFATURA       VARCHAR2(4),
   NRPARCFATURA         NUMBER,
   CDTIPOOPERFATURA     VARCHAR2(2),
   CDSERIENF            VARCHAR2(5),
   CDEMPRESA            VARCHAR2(2),
   CDINSCESTA           VARCHAR2(16),
   CDINSCMUNI           VARCHAR2(16),
   NRORG             	NUMBER 	     	DEFAULT         	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO          	VARCHAR2(1)     DEFAULT 'S' 		NOT NULL
      CONSTRAINT CKC_IDATIVO_FCT_DESCAGRUPESC CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO       	DATE                  				NULL,
   DTULTATU          	DATE                  				NULL,
   NRORGINCLUSAO     	NUMBER          DEFAULT 1 			NULL,
   CDOPERINCLUSAO    	VARCHAR2(12)    DEFAULT '1' 		NULL,
   NRORGULTATU       	NUMBER          DEFAULT 1 			NULL,
   CDOPERULTATU      	VARCHAR2(12)    DEFAULT '1'
)
/

ALTER TABLE FCT_DESCAGRUPESCOPO ADD CONSTRAINT PK_FCT_DESCAGRUPESCOPO PRIMARY KEY (NRDESCAGRUPESCOPO)
/

ALTER TABLE FCT_DESCAGRUPESCOPO
      ADD CONSTRAINT FKSM00266FCT_DSAGRPESC_TPORC FOREIGN KEY (NRTIPOORCAMENTO)
          REFERENCES FCT_TIPOORCAMENTO (NRTIPOORCAMENTO)
/
CREATE INDEX FKSM00266 ON "FCT_DESCAGRUPESCOPO" ("NRTIPOORCAMENTO" ASC)
/
ALTER TABLE FCT_DESCAGRUPESCOPO
    ADD CONSTRAINT FKSM00267FCT_DSAGRPESC_FILI FOREIGN KEY (CDFILIALFATURA)
        REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FKSM00267 ON "FCT_DESCAGRUPESCOPO" ("CDFILIALFATURA" ASC)
/
ALTER TABLE FCT_DESCAGRUPESCOPO
    ADD CONSTRAINT FKSM00268FCT_DSAGRPESC_PARCNG FOREIGN KEY (NRPARCFATURA)
        REFERENCES PARCNEGOCIO (NRPARCNEGOCIO)
/
CREATE INDEX FKSM00268 ON "FCT_DESCAGRUPESCOPO" ("NRPARCFATURA" ASC)
/
ALTER TABLE FCT_DESCAGRUPESCOPO
    ADD CONSTRAINT FKSM00269FCT_DSAGRPESC_SERNF FOREIGN KEY (CDEMPRESA, CDINSCESTA, CDINSCMUNI, CDSERIENF)
        REFERENCES SERIENF (CDEMPRESA, CDINSCESTA, CDINSCMUNI, CDSERIE)
/
CREATE INDEX FKSM00269 ON "FCT_DESCAGRUPESCOPO" ("CDEMPRESA" ASC, "CDINSCESTA" ASC, "CDINSCMUNI" ASC, "CDSERIENF" ASC)
/
ALTER TABLE FCT_DESCAGRUPESCOPO
    ADD CONSTRAINT CKC_IDTPFATURA_FCT_DSAGRPESC CHECK (IDTPFATURA IN ('A', 'X', 'P'))