
/*------ ATD 371618 ------*/
DECLARE v_count NUMBER:=0;

BEGIN
	SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'CONTROLETRANSACAOTEFDEDICADO';
	IF v_count = 0 THEN
		EXECUTE IMMEDIATE 'CREATE TABLE CONTROLETRANSACAOTEFDEDICADO(
			ID INT NOT NULL , 
			Cupom VARCHAR2(30) NOT NULL, 
			Hora VARCHAR2(10) NOT NULL, 
			Estacao VARCHAR2(100) NOT NULL,
			NumPed INT,
			NumOrdVenda INT,
			OIDDocVenda INT,
			ValorVendaRecebimento NUMBER(15,2),
			Recebimento NUMBER(1),
			TransacaoConfirmada NUMBER(1))';

		EXECUTE IMMEDIATE 'ALTER TABLE CONTROLETRANSACAOTEFDEDICADO ADD CONSTRAINT PK_CTTEFDEDICADO PRIMARY KEY (ID)';
		EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX CTTEFDEDICADO_IDX1 ON CONTROLETRANSACAOTEFDEDICADO(Estacao, Cupom, Hora)';
		EXECUTE IMMEDIATE 'CREATE SEQUENCE CTTEFDEDICADO_SEQ MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
		EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER CONTROLETRANSACAOTEFDEDICADO_I 
		BEFORE INSERT ON CONTROLETRANSACAOTEFDEDICADO FOR EACH ROW
			WHEN (new.ID IS NULL)
			BEGIN
				SELECT CTTEFDEDICADO_SEQ.NEXTVAL INTO :new.ID FROM dual;
			END;';

		EXECUTE IMMEDIATE 'CREATE TABLE COMPLEMENTOCTTEFDEDICADO(
			ID INT,
			CodPro CHAR(5),
			Quant NUMBER(13,3),
			Codigo CHAR(254),
			OIDContaReceber INT)';
		EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX COMPLCTTEFDEDICADO_IDX1 ON COMPLEMENTOCTTEFDEDICADO(ID)';

	END IF;
END;

/*------ ATD 371618 ------*/
DECLARE v_count NUMBER:=0;

BEGIN
	SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'CONTROLETRANSACAOTEFDEDICADO';
	IF v_count = 0 THEN
		EXECUTE IMMEDIATE 'CREATE TABLE CONTROLETRANSACAOTEFDEDICADO(
			ID INT NOT NULL , 
			Cupom VARCHAR2(30) NOT NULL, 
			Hora VARCHAR2(10) NOT NULL, 
			Estacao VARCHAR2(100) NOT NULL,
			NumPed INT,
			NumOrdVenda INT,
			OIDDocVenda INT,
			ValorVendaRecebimento NUMBER(15,2),
			Recebimento NUMBER(1),
			TransacaoConfirmada NUMBER(1))';

		EXECUTE IMMEDIATE 'ALTER TABLE CONTROLETRANSACAOTEFDEDICADO ADD CONSTRAINT PK_CTTEFDEDICADO PRIMARY KEY (ID)';
		EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX CTTEFDEDICADO_IDX1 ON CONTROLETRANSACAOTEFDEDICADO(Estacao, Cupom, Hora)';
		EXECUTE IMMEDIATE 'CREATE SEQUENCE CTTEFDEDICADO_SEQ MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
		EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER CONTROLETRANSACAOTEFDEDICADO_I 
		BEFORE INSERT ON CONTROLETRANSACAOTEFDEDICADO FOR EACH ROW
			WHEN (new.ID IS NULL)
			BEGIN
				SELECT CTTEFDEDICADO_SEQ.NEXTVAL INTO :new.ID FROM dual;
			END;';

		EXECUTE IMMEDIATE 'CREATE TABLE COMPLEMENTOCTTEFDEDICADO(
			ID INT,
			CodPro CHAR(5),
			Quant NUMBER(13,3),
			Codigo CHAR(254),
			OIDContaReceber INT)';
		EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX COMPLCTTEFDEDICADO_IDX1 ON COMPLEMENTOCTTEFDEDICADO(ID)';

	END IF;
END;
