ALTER TABLE EXPEDICAO ADD IDSTATUSEXP VARCHAR2(06) NULL
/

ALTER TABLE EXPEDICAO ADD CDOPERADOR VARCHAR2(12) NULL
/

CREATE TABLE EXPRELACITEMPPED(
    CDFILIAL     VARCHAR2(04) NOT NULL,
    NREXPEDICAO  VARCHAR2(10) NOT NULL,
    NRPEDIDO     VARCHAR2(10) NOT NULL,
    NRITEMPED    VARCHAR2(10) NOT NULL,
    QTITEMEXP    FLOAT        NOT NULL,
    IDTIPOEXP    VARCHAR2(06) 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_EXPRELACITEMPPED CHECK (IDATIVO IN ('S','N')),
        constraint PK_EXPRELACITEMPPED primary key (CDFILIAL, NREXPEDICAO, NRPEDIDO, NRITEMPED, QTITEMEXP)
)
/

CREATE TABLE ITEMEXPEDICAO(
    CDFILIAL       VARCHAR2(04)   NOT NULL,
    NREXPEDICAO    VARCHAR2(10)   NOT NULL,
    NRPEDIDO       VARCHAR2(10)   NOT NULL,
    NRITEMPED      VARCHAR2(10)   NOT NULL,
    NRSEQITEMEXP   VARCHAR2(10)   NOT NULL,
    CDTIPOOPER     VARCHAR2(02)   NULL,
    IDATUESTTPOP   VARCHAR2(01)   NULL,
    IDDESTINO      VARCHAR2(01)   NULL,
    CDFILIALPED    VARCHAR2(04)   NULL,
    CDCLIENTE      VARCHAR2(21)   NULL,
    CDDESTINO      VARCHAR2(21)   NULL,
    IDTPIJURTRAN   VARCHAR2(01)   NULL,
    NRINSJURTRAN   VARCHAR2(20)   NULL,
    CDTIPTRANS     VARCHAR2(04)   NULL,
    IDPGFRETTRAN   VARCHAR2(01)   NULL,
    NRPLACAVEPED   VARCHAR2(07)   NULL,
    SGUFVEICPED    VARCHAR2(02)   NULL,
    CDVIATURA      VARCHAR2(04)   NULL,
    DTVALIPED      DATE           NULL,
    CDEMPRESA      VARCHAR2(02)   NULL,
    CDINSCESTA     VARCHAR2(16)   NULL,
    CDINSCMUNI     VARCHAR2(16)   NULL,
    CDSERIE        VARCHAR2(05)   NULL,
    IDPEDINDUSTRIA VARCHAR2(01)   NULL,
    CDVENDEDOR     VARCHAR2(04)   NULL,
    CDMODPGTO      VARCHAR2(05)   NULL,
    IDTPFORPGTPED  VARCHAR2(01)   NULL,
    NRDIAPGFIXPED  NUMBER(02)     NULL,
    NRPARCPGTOPED  NUMBER(02)     NULL,
    IDUTDIAPAGPED  VARCHAR2(01)   NULL,
    IDAGRUPAEXP    VARCHAR2(01)   NULL,
    IDGERANFPEDI   VARCHAR2(01)   NULL,
    CDQUEBRANF     VARCHAR2(21)   NULL,
    CDPRODUTO      VARCHAR2(10)   NOT NULL,
    CDPRODMOVI     VARCHAR2(10)   NOT NULL,
    CDPRODEMIS     VARCHAR2(20)   NULL,
    DSPRODEMIS     VARCHAR2(3000) NULL,
    VRFATOCONV     INTEGER        NULL,
    IDCNTRESTOQ    VARCHAR2(01)   NULL,
    IDSITITEMPED   VARCHAR2(01)   NULL,
    QTITEMEXP      FLOAT          NOT NULL,
    QTMAXEXP       FLOAT          NULL,
    QTEXPEDIDA     FLOAT          NULL,
    QTITEMPED      FLOAT          NULL,
    QTITEMPROD     FLOAT          NULL,
    VRPRECOEXP     FLOAT          NOT NULL,
    VRCUSTO        FLOAT          NULL,
    VRDESITEXP     FLOAT          NULL,
    VRFATPRECO     FLOAT          NULL,
    VRPESOLIQ      FLOAT          NULL,
    VRPESOBRUTO    FLOAT          NULL,
    IDUTILALMOX    VARCHAR2(01)   NULL,
    CDALMOXEXP     VARCHAR2(06)   NULL,
    IDUTILLCESTQ   VARCHAR2(01)   NULL,
    CDLOCALEXP     VARCHAR2(06)   NULL,
    IDUTCTRLLOTE   VARCHAR2(01)   NULL,
    NRLOTEEXP      VARCHAR2(20)   NULL,
    NRSUBLOTEEXP   VARCHAR2(04)   NULL,
    IDRESERVA      VARCHAR2(01)   NULL,
    QTRESERVADA    FLOAT          NULL,
    IDITEMPEDTERC  VARCHAR2(01)   NULL,
    IDERRO         VARCHAR2(01)   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_ITEMEXPEDICAO CHECK (IDATIVO IN ('S','N')),
        constraint PK_ITEMEXPEDICAO primary key (CDFILIAL, NREXPEDICAO, NRPEDIDO, NRITEMPED, NRSEQITEMEXP)
)
/

CREATE TABLE ERROITEMEXP(
    CDFILIAL       VARCHAR2(04) NOT NULL,
    NREXPEDICAO    VARCHAR2(10) NOT NULL,
    NRPEDIDO       VARCHAR2(10) NOT NULL,
    NRSEQERROITEM  VARCHAR2(10) NOT NULL,
    CDCLIENTE      VARCHAR2(21) NULL,
    CDFILIALPED    VARCHAR2(04) NULL,
    NRITEMPED      VARCHAR2(10) NULL,
    CDPRODUTO      VARCHAR2(10) NULL,
    QTITEMEXP      FLOAT        NULL,
    QTTOTAITEMPROD FLOAT        NULL,
    QTTOTAESTOQ    FLOAT        NULL,
    DSERRO         VARCHAR2(50) 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_ERROITEMEXP CHECK (IDATIVO IN ('S','N')),
        constraint PK_ERROITEMEXP primary key (CDFILIAL, NREXPEDICAO, NRPEDIDO, NRSEQERROITEM)
)
/

CREATE TABLE NFRELACITEMPED(
    CDFILIAL      VARCHAR2(04) NOT NULL,
    NREXPEDICAO   VARCHAR2(10) NOT NULL,
    NRPEDIDO      VARCHAR2(10) NOT NULL,
    NRITEMPED     VARCHAR2(10) NOT NULL,
    NRLANCTONF    VARCHAR2(10) NOT NULL,
    NRLANCESTQ    VARCHAR2(10) NULL,
    IDATUAESTOQUE VARCHAR2(01) NULL,
    IDERRO        VARCHAR2(01) 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_NFRELACITEMPED CHECK (IDATIVO IN ('S','N')),
        constraint PK_NFRELACITEMPED primary key (CDFILIAL, NREXPEDICAO, NRPEDIDO, NRITEMPED,NRLANCTONF)
)
/