CREATE INDEX FKGOPFATURAMENTOROP_101 ON FATURAMENTOROP (DTREFERENC, CDFILIAL, IDTPLANCROP)
/

ALTER TABLE ITDETALORCAMESGOP ADD CDFILIAL VARCHAR2(04)
/

ALTER TABLE ITDETALORCAMESGOP ADD QTCOMESTISEG FLOAT
/

ALTER TABLE ITDETALORCAMESGOP ADD QTCOMESTITER FLOAT
/

ALTER TABLE ITDETALORCAMESGOP ADD QTCOMESTIQUA FLOAT
/

ALTER TABLE ITDETALORCAMESGOP ADD QTCOMESTIQUI FLOAT
/

ALTER TABLE ITDETALORCAMESGOP ADD QTCOMESTISEX FLOAT
/

ALTER TABLE ITDETALORCAMESGOP ADD QTCOMESTISAB FLOAT
/

ALTER TABLE ITDETALORCAMESGOP ADD QTCOMESTIDOM FLOAT
/

ALTER TABLE ITDETALORCAMESGOP ADD VRCUSTPADR FLOAT
/

ALTER TABLE PERCDETALPRODGOP ADD CDTPCTPAGAR VARCHAR2(20) NULL
/

CREATE INDEX GOP00742_FK ON PERCDETALPRODGOP (CDTPCTPAGAR)
/

ALTER TABLE PERCDETALPRODGOP ADD CONSTRAINT FKGOP00742ATIPOCTPAGAR FOREIGN KEY (CDTPCTPAGAR) REFERENCES TIPOCTPAGAR (CDTPCTPAGAR)
/

ALTER TABLE PERCDETPRODFILGOP ADD CDTPCTPAGAR VARCHAR2(20) NULL
/

CREATE INDEX GOP00743_FK ON PERCDETPRODFILGOP (CDTPCTPAGAR)
/

ALTER TABLE PERCDETPRODFILGOP ADD CONSTRAINT FKGOP00743TIPOCTPAGAR FOREIGN KEY (CDTPCTPAGAR) REFERENCES TIPOCTPAGAR (CDTPCTPAGAR)
/

ALTER TABLE ORCAMENTOGOP ADD IDVERSORCAGOP VARCHAR2(04) NULL
/

CREATE TABLE HISTORCAMENTOGOP (
  NRHISTORCAMENTOGOP NUMBER(10) NOT NULL,
  NRORCAMENTOGOP     NUMBER(10) NOT NULL,
  NRULTVERSAO        NUMBER(10) NOT NULL,
  NRANOORCAGOP       NUMBER(10) NOT NULL, 
  IDPERIODOORCA      VARCHAR2(30) NOT NULL, 
  NRPERIODOORCA      NUMBER(10) NOT NULL, 
  CDFILIAL           VARCHAR2(4) 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 CKC_IDATIVO_HISTORCAMGOP CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT PK_HISTORCAMENTOGOP PRIMARY KEY(NRHISTORCAMENTOGOP)
)
/

CREATE SEQUENCE SEQ_HISTORCAMENTOGOP MINVALUE 1 INCREMENT BY 1 START WITH 1 CACHE 100 NOCYCLE
/

CREATE TABLE HISTITEMORCAGOP (
  NRHISTITEMORCAGOP  NUMBER(10) NOT NULL,
  NRHISTORCAMENTOGOP NUMBER(10) NOT NULL,
  NRORCAMENTOGOP     NUMBER(10) NOT NULL,
  NRITEMORCAOP       NUMBER(10) NOT NULL,
  NRVERSAO           NUMBER(10) NOT NULL,
  IDENTRSAIDOP       VARCHAR2(1) NULL, 
  CDTIPOOPER         VARCHAR2(2) NULL, 
  CDORCAMENTOMO      VARCHAR2(10) NULL, 
  CDDESPPREV         VARCHAR2(3) NULL, 
  CDFILIAL           VARCHAR2(4) NULL, 
  CDFILIALMO         VARCHAR2(4) NULL, 
  CDSERVFILI         VARCHAR2(5) NULL, 
  CDIMPOSTO          VARCHAR2(2) NULL, 
  DTMESBASEITEM      DATE NULL, 
  IDTIPOORCAOP       VARCHAR2(30) NOT NULL, 
  CDINVEST           VARCHAR2(10) NULL,
  VRTOTALMES         FLOAT(126) 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 CKC_IDATIVO_HISTITEMORCAGOP CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT PK_HISTITEMORCAGOP PRIMARY KEY(NRHISTITEMORCAGOP)
)
/

CREATE SEQUENCE SEQ_HISTITEMORCAGOP MINVALUE 1 INCREMENT BY 1 START WITH 1 CACHE 100 NOCYCLE
/

CREATE TABLE HISTITORCAMESGOP (
  NRHISTITORCAMESGOP NUMBER(10) NOT NULL,
  NRHISTITEMORCAGOP  NUMBER(10) NOT NULL,
  NRITEMORCAOP       NUMBER(10) NOT NULL,
  NRITORCAMESGOP     NUMBER(10) NOT NULL,
  DTORCAMENTO        DATE NOT NULL,
  IDALTMANUAL        VARCHAR2(1) DEFAULT 'N' NOT NULL,
  VRORCAMENTO        DOUBLE PRECISION NULL,
  VRREAJUSTE         DOUBLE PRECISION NULL,
  VRPERCENTUAL       DOUBLE PRECISION NULL,
  QTORCAMENTO        DOUBLE PRECISION NULL,
  VRTOTALMES         DOUBLE PRECISION 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 CKC_IDATIVO_HISTITORCAMESGOP CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT PK_HISTITORCAMESGOP PRIMARY KEY(NRHISTITORCAMESGOP)
)
/

CREATE SEQUENCE SEQ_HISTITORCAMESGOP MINVALUE 1 INCREMENT BY 1 START WITH 1 CACHE 100 NOCYCLE
/

CREATE TABLE HISTITDETALORCAMESGOP (
  NRHISTITDETALORCAMESGOP NUMBER(10) NOT NULL,
  NRHISTITORCAMESGOP      NUMBER(10) NOT NULL,
  NRITORCAMESGOP          NUMBER(10) NOT NULL,
  NRITDETALORCAMESGOP     NUMBER(10) NOT NULL,
  VRORCAMENTO             DOUBLE PRECISION DEFAULT NULL,
  VRPERCENTUAL            DOUBLE PRECISION DEFAULT NULL,
  QTORCAMENTO             DOUBLE PRECISION DEFAULT NULL,
  CDPRODUTO               VARCHAR2(10) NULL,
  CDTIPOOPER              VARCHAR2(2) NULL,
  CDFILIALMO              VARCHAR2(4) NULL,
  IDENTRSAIDOP            VARCHAR2(1) NULL,
  CDORCAMENTOMO           VARCHAR2(10) NULL,
  CDDESPADMFAT            VARCHAR2(2) NULL,
  CDSERVFILI              VARCHAR2(5) NULL,
  VRPRECOBASE             FLOAT(126) NULL,
  NRDIASUTEIS             FLOAT(126) NULL,
  CDCONTCTBL              VARCHAR2(20) NULL,
  CDINVEST                VARCHAR2(10) NULL,
  CDTPCTPAGAR             VARCHAR2(6) NULL,
  NMDESCRICAO             VARCHAR2(50) NULL,
  CDSUBGRPROD             VARCHAR2(10) NULL,
  CDDESPPREV              VARCHAR2(3) NULL,
  CDIMPOSTO               VARCHAR2(2) NULL,
  NMDESPESA               VARCHAR2(100) NULL,
  VRTOTALGRUP             FLOAT(126) NULL,
  CDGRUPPROD              VARCHAR2(10) NULL,
  CDFATUDIVER             VARCHAR2(2) NULL,
  CDFILICONTRIB           VARCHAR2(4) NULL,
  CDFILIAL                VARCHAR2(4) NULL,
  QTCOMESTISEG            FLOAT(126) NULL,
  QTCOMESTITER            FLOAT(126) NULL,
  QTCOMESTIQUA            FLOAT(126) NULL,
  QTCOMESTIQUI            FLOAT(126) NULL,
  QTCOMESTISEX            FLOAT(126) NULL,
  QTCOMESTISAB            FLOAT(126) NULL,
  QTCOMESTIDOM            FLOAT(126) NULL,
  VRCUSTPADR              FLOAT(126) 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 CKC_IDATIVO_HISTITDETORCESGOP CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT PK_HISTITDETALORCAMESGOP PRIMARY KEY(NRHISTITDETALORCAMESGOP)
)
/

CREATE SEQUENCE SEQ_HISTITDETALORCAMESGOP MINVALUE 1 INCREMENT BY 1 START WITH 1 CACHE 100 NOCYCLE
/

CREATE TABLE HISTDIETSERVORCAGOP (
  NRHISTDIETSERVORCAGOP   NUMBER    NOT NULL,
  NRHISTITDETALORCAMESGOP NUMBER(10) NOT NULL,
  NRDIETSERVORCAGOP       NUMBER    NOT NULL,
  NRITDETALORCAMESGOP     NUMBER    NOT NULL,
  CDDIETPAD               VARCHAR2(4) NOT NULL,
  CDFILIAL                VARCHAR2(4) NOT NULL,
  CDSERVFILI              VARCHAR2(5) NOT NULL,
  QTCOMDIETSEG            FLOAT, 
  QTCOMDIETTER            FLOAT,
  QTCOMDIETQUA            FLOAT,
  QTCOMDIETQUI            FLOAT,
  QTCOMDIETSEX            FLOAT,
  QTCOMDIETSAB            FLOAT,
  QTCOMDIETDOM            FLOAT,
  VRCUSTPADR              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_HISDIETSERORCGOP CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT PK_HISTDIETSERVORCAGOP PRIMARY KEY(NRHISTDIETSERVORCAGOP)
)
/

CREATE SEQUENCE SEQ_HISTDIETSERVORCAGOP MINVALUE 1 INCREMENT BY 1 START WITH 1 CACHE 100 NOCYCLE
/

CREATE TABLE DIETSERVORCAGOP (
  NRDIETSERVORCAGOP   NUMBER    NOT NULL,
  NRITDETALORCAMESGOP NUMBER    NOT NULL,
  CDDIETPAD         VARCHAR2(4) NOT NULL,
  CDFILIAL          VARCHAR2(4) NOT NULL,
  CDSERVFILI        VARCHAR2(5) NOT NULL,
  QTCOMDIETSEG      FLOAT, 
  QTCOMDIETTER      FLOAT,
  QTCOMDIETQUA      FLOAT,
  QTCOMDIETQUI      FLOAT,
  QTCOMDIETSEX      FLOAT,
  QTCOMDIETSAB      FLOAT,
  QTCOMDIETDOM      FLOAT,
  VRCUSTPADR        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_DIETSERVORCAGOP CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT PK_DIETSERVORCAGOP PRIMARY KEY(NRDIETSERVORCAGOP)
)
/

CREATE SEQUENCE SEQ_DIETSERVORCAGOP MINVALUE 1 INCREMENT BY 1 START WITH 1 CACHE 100 NOCYCLE
/