CREATE TABLE LINHAPROD
(
    CDFILIAL 			VARCHAR2(4) 	NOT NULL,
    CDLINHAPROD 		NUMBER 			NOT NULL, 
    NMLINHAPROD 		VARCHAR2(50) 	NOT NULL,
    NRPERCDEMANDA 		NUMBER 			DEFAULT 100,
    IDLINHAPRINCIPAL 	VARCHAR2(1) 	DEFAULT 'N',
	NRORG             	NUMBER 	     	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           	VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_LINHAPROD CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        	DATE                  			NULL,
    DTULTATU          	DATE                  			NULL,
    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_LINHAPROD PRIMARY KEY (CDFILIAL, CDLINHAPROD)
) 
/

CREATE TABLE LINHAPRODSETOR
( 
    CDFILIAL 			VARCHAR2(4) 	NOT NULL,
    CDLINHAPROD 		NUMBER 			NOT NULL,
    CDSETOR 			VARCHAR2(4) 	NOT NULL,
    CDSETORCORRESP 		VARCHAR2(4),
	NRORG             	NUMBER 	     	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           	VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_LINHAPRODSETOR CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        	DATE                  			NULL,
    DTULTATU          	DATE                  			NULL,
    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_LINHAPRODSETOR PRIMARY KEY (CDFILIAL, CDLINHAPROD, CDSETOR)
)
/

CREATE TABLE SORTORDERSBYORG
( 
    CDFILIAL 			VARCHAR2(5) 	NOT NULL, 
    IDORIGEMVENDA 		VARCHAR2(10) 	NOT NULL, 
    NRPRIOR 			NUMBER 			NOT NULL , 
    NRTEMPOPRIORSEG 	NUMBER 			DEFAULT 60 NOT NULL ,
	NRORG             	NUMBER 	     	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           	VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_SORTORDERSBYORG CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        	DATE                  			NULL,
    DTULTATU          	DATE                  			NULL,
    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_SORTORDERBYORG PRIMARY KEY(CDFILIAL, IDORIGEMVENDA )
	
)
/

CREATE TABLE ORIGEMVENDA 
( 
    DSORIGEMVENDA 		VARCHAR2(7) 	NOT NULL PRIMARY KEY, 
    DSORIGEM 			VARCHAR2(30) 	NOT NULL, 
    DSMODALIDADE 		VARCHAR2(30) 	NOT NULL,
	NRORG             	NUMBER 	     	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           	VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ORIGEMVENDA CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        	DATE                  			NULL,
    DTULTATU          	DATE                  			NULL,
    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'
	
)
/

INSERT INTO ORIGEMVENDA VALUES('BAL_FOS', 'Balcao', 'For Sale', SYS_CONTEXT('nrorg_ctx','nrorg'), 'S', NULL, NULL, SYS_CONTEXT('nrorg_ctx','nrorg'), '1', SYS_CONTEXT('nrorg_ctx','nrorg'), '1' )
/

INSERT INTO ORIGEMVENDA VALUES('MES_PKR', 'Mesa', 'Tablet', SYS_CONTEXT('nrorg_ctx','nrorg'), 'S', NULL, NULL, SYS_CONTEXT('nrorg_ctx','nrorg'), '1', SYS_CONTEXT('nrorg_ctx','nrorg'), '1' )
/

INSERT INTO ORIGEMVENDA VALUES('MES_MOB', 'Mesa', 'POS Mobile', SYS_CONTEXT('nrorg_ctx','nrorg'), 'S', NULL, NULL, SYS_CONTEXT('nrorg_ctx','nrorg'), '1', SYS_CONTEXT('nrorg_ctx','nrorg'), '1' )
/

INSERT INTO ORIGEMVENDA VALUES('DLV_FOS', 'Delivery', 'For Sale', SYS_CONTEXT('nrorg_ctx','nrorg'), 'S', NULL, NULL, SYS_CONTEXT('nrorg_ctx','nrorg'), '1', SYS_CONTEXT('nrorg_ctx','nrorg'), '1' )
/

INSERT INTO ORIGEMVENDA VALUES('MES_FOS', 'Mesa', 'For Sale', SYS_CONTEXT('nrorg_ctx','nrorg'), 'S', NULL, NULL, SYS_CONTEXT('nrorg_ctx','nrorg'), '1', SYS_CONTEXT('nrorg_ctx','nrorg'), '1' )
/

INSERT INTO ORIGEMVENDA VALUES('DLV_IFO', 'Delivery', 'iFood', SYS_CONTEXT('nrorg_ctx','nrorg'), 'S', NULL, NULL, SYS_CONTEXT('nrorg_ctx','nrorg'), '1', SYS_CONTEXT('nrorg_ctx','nrorg'), '1' )
/

INSERT INTO ORIGEMVENDA VALUES('DLV_APP', 'Delivery', 'Aplicativo', SYS_CONTEXT('nrorg_ctx','nrorg'), 'S', NULL, NULL, SYS_CONTEXT('nrorg_ctx','nrorg'), '1', SYS_CONTEXT('nrorg_ctx','nrorg'), '1' )
/

INSERT INTO ORIGEMVENDA VALUES('T/_APP', 'Viagem', 'Aplicativo', SYS_CONTEXT('nrorg_ctx','nrorg'), 'S', NULL, NULL, SYS_CONTEXT('nrorg_ctx','nrorg'), '1', SYS_CONTEXT('nrorg_ctx','nrorg'), '1' )
/

ALTER TABLE SETORFILIAL ADD IDHABLIBDIRETOEXP VARCHAR2(1) DEFAULT 'N' NOT NULL
/

ALTER TABLE SETORFILIAL ADD IDHABESTGERAL VARCHAR2(1) DEFAULT 'N' NOT NULL
/

ALTER TABLE ITCOMANDAEST ADD  IDINSPEDKDS VARCHAR2(20) DEFAULT 'N' NOT NULL
/

ALTER TABLE LOJA ADD IDCONDPEDPAG VARCHAR2(1) DEFAULT 'N' NOT NULL 
/

-- ============================================================
-- TABLE: IMGPEDIDOFOS
-- ============================================================
CREATE TABLE IMGPEDIDOFOS
(
    DSIMGBASE64 	  VARCHAR2(4000) 	NOT NULL, 
    CDFILIAL 		  VARCHAR2(4) 		NOT NULL,
    NRPEDIDOFOS 	  VARCHAR2(10) 		NOT NULL,
	NRORG             NUMBER 	     	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     	DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_IMGPEDIDOFOS CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          DATE                  			NULL,
    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 FKVND00818CDFL_NRPFOS_IMGPFOS 
			FOREIGN KEY (CDFILIAL, NRPEDIDOFOS) REFERENCES PEDIDOFOS(CDFILIAL, NRPEDIDOFOS) ON DELETE CASCADE 
)
/

CREATE INDEX VND00818_FK ON IMGPEDIDOFOS (CDFILIAL ASC, NRPEDIDOFOS ASC)
/

ALTER TABLE PEDIDOFOS ADD IDCHECKOK VARCHAR(1) DEFAULT 'S' NOT NULL 
/

ALTER TABLE PEDIDOFOS ADD DSRESULTCHECK VARCHAR(500)
/

ALTER TABLE SETORFILIAL ADD DSURLCHECKSERVICE VARCHAR(200)
/

ALTER TABLE SETORFILIAL ADD NRCONCAUTCHECK FLOAT DEFAULT 0 NOT NULL
/