declare 
  column_exists exception;
  pragma exception_init (column_exists , -01430);
begin 
  execute immediate 'ALTER TABLE INSCRICAO_ESTADUAL ADD (EQUIVALENCIAAG NUMBER(7))';
  exception when column_exists then null;
end;
/
declare 
  column_exists exception;
  pragma exception_init (column_exists , -01430);
begin 
  execute immediate 'ALTER TABLE PUNTO_VENTA ADD (INDINTEGRADOAG NUMBER(1) DEFAULT 0)';
  exception when column_exists then null;
end;
/
declare 
  column_exists exception;
  pragma exception_init (column_exists , -01430);
begin 
  execute immediate 'ALTER TABLE PUNTO_VENTA ADD (MOTIVONAOINTEGRADOAG VARCHAR2(256))';
  exception when column_exists then null;
end;
/
declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate
	'CREATE TABLE AG_CONTAS_RECEBER ( 
		AGCONTASRECEBER_ID NUMBER(7) NOT NULL, 
		ESTABELECIMENTO VARCHAR2(4) NOT NULL, 
		CENTRORESULTADOS VARCHAR2(10), 
		CLIENTE VARCHAR2(10) NOT NULL, 
		FCLIENTEIDWS VARCHAR2(30),
		RECEITA VARCHAR2(250) NOT NULL, 
		DOCUMENTO VARCHAR2(20), 
		EMISSAO DATE NOT NULL, 
		OBSERVACAO VARCHAR2(60),
		INDINTEGRADO NUMBER(1) DEFAULT 0 NOT NULL,
		FECINTEGRACION DATE,
		MOTIVONAOINTEGRADO VARCHAR2(255),
		IDWS VARCHAR2(30),
		PRIMARY KEY (AGCONTASRECEBER_ID)
	)';
 exception when object_exists then null;
end;
/
declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate
	'CREATE TABLE AG_SERVICOS_CTAS_RECEBER ( 
		AGSERVICOSCTASRECEBER_ID NUMBER(7) NOT NULL, 
		AGCONTASRECEBER_ID NUMBER(7) NOT NULL,
		SERVICO VARCHAR2(4) NOT NULL, 
		MODALIDADE VARCHAR2(2) NOT NULL,
		VALOR NUMBER(12,2) NOT NULL, 
		INDINTEGRADO NUMBER(1) DEFAULT 0 NOT NULL,
		FECINTEGRACION DATE,
		MOTIVONAOINTEGRADO VARCHAR2(255),
		PRIMARY KEY (AGSERVICOSCTASRECEBER_ID),
		CONSTRAINT FK_AG_SERVICOS_CTASRECEBER FOREIGN KEY (AGCONTASRECEBER_ID) REFERENCES AG_CONTAS_RECEBER (AGCONTASRECEBER_ID) 
	)';
 exception when object_exists then null;
end;
/
declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate
	'CREATE TABLE AG_VENCIMENTOSDIV_CTAS_RECEBER ( 
		AGVENCIMENTOSDIVCTASRECEBER_ID NUMBER(7) NOT NULL, 
		AGCONTASRECEBER_ID NUMBER(7) NOT NULL,
		DATAVENCIMENTO DATE NOT NULL, 
		VALOR NUMBER(12,2) NOT NULL, 
		TIPODOCUMENTO VARCHAR2(3) NOT NULL, 
		TITULO VARCHAR2(20), 
		AGENTECOBRADOR VARCHAR2(4) NOT NULL, 
		DESCONTOPREVISTO NUMBER(12,2) DEFAULT 0 NOT NULL, 
		NUMBOLETO VARCHAR2(20) NOT NULL,
		INDINTEGRADO NUMBER(1) DEFAULT 0 NOT NULL,
		FECINTEGRACION DATE,
		MOTIVONAOINTEGRADO VARCHAR2(255),
		PRIMARY KEY (AGVENCIMENTOSDIVCTASRECEBER_ID),
		CONSTRAINT FK_AG_VENCDIV_CTASRECEBER FOREIGN KEY (AGCONTASRECEBER_ID) REFERENCES AG_CONTAS_RECEBER (AGCONTASRECEBER_ID) 
	)';
 exception when object_exists then null;
end;
/
declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate
	'CREATE TABLE AG_RATEIO_CTAS_RECEBER ( 
		AGRATEIOCTASRECEBER_ID NUMBER(7) NOT NULL, 
		AGCONTASRECEBER_ID NUMBER(7) NOT NULL,
		ESTABELECIMENTO VARCHAR2(4) NOT NULL, 
		CENTRORESULTADOS VARCHAR2(10), 
		RECEITA VARCHAR2(250) NOT NULL, 
		VALOR NUMBER(12,2) NOT NULL, 
		INDINTEGRADO NUMBER(1) DEFAULT 0 NOT NULL,
		FECINTEGRACION DATE,
		MOTIVONAOINTEGRADO VARCHAR2(255),
		PRIMARY KEY (AGRATEIOCTASRECEBER_ID),
		CONSTRAINT FK_AG_RATEIO_CTASRECEBER FOREIGN KEY (AGCONTASRECEBER_ID) REFERENCES AG_CONTAS_RECEBER (AGCONTASRECEBER_ID) 
	)';
 exception when object_exists then null;
end;
/
declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate
	'CREATE TABLE AG_VNCTO_CARTAO_CTAS_RECEBER ( 
		AGVNCTOCARTAOCTASRECEBER_ID NUMBER(7) NOT NULL, 
		AGCONTASRECEBER_ID NUMBER(7) NOT NULL,
		REDE VARCHAR2(20) NOT NULL, 
		BANDEIRA VARCHAR2(20) NOT NULL, 
		VENCIMENTO DATE NOT NULL,
		VALOR NUMBER(12,2) NOT NULL, 
		INDINTEGRADO NUMBER(1) DEFAULT 0 NOT NULL,
		FECINTEGRACION DATE,
		MOTIVONAOINTEGRADO VARCHAR2(255),
		PRIMARY KEY (AGVNCTOCARTAOCTASRECEBER_ID),
		CONSTRAINT FK_AG_VENCCARTAO_CTASRECEBER FOREIGN KEY (AGCONTASRECEBER_ID) REFERENCES AG_CONTAS_RECEBER (AGCONTASRECEBER_ID) 
	)';
 exception when object_exists then null;
end;
/
declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate
	'CREATE TABLE AG_CONTAS_PAGAR ( 
		AGCONTASPAGAR_ID NUMBER(7) NOT NULL, 
		ESTABELECIMENTO VARCHAR2(4) NOT NULL, 
		CENTRORESULTADOS VARCHAR2(10), 
		FORNECEDOR VARCHAR2(6) NOT NULL, 
		DESPESA VARCHAR2(10) NOT NULL, 
		DOCUMENTO VARCHAR2(40), 
		EMISSAO DATE NOT NULL, 
		ENTRADA DATE NOT NULL,
		INDINTEGRADO NUMBER(1) DEFAULT 0 NOT NULL,
		FECINTEGRACION DATE,
		MOTIVONAOINTEGRADO VARCHAR2(255),
		IDWS VARCHAR2(30),
		PRIMARY KEY (AGCONTASPAGAR_ID)
	)';
 exception when object_exists then null;
end;
/
declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate
	'CREATE TABLE AG_VENCIMENTOS_CTAS_PAGAR ( 
		AGVENCIMENTOSCTASPAGAR_ID NUMBER(7) NOT NULL, 
		AGCONTASPAGAR_ID NUMBER(7) NOT NULL,
		VENCIMENTO DATE NOT NULL,
		VALOR NUMBER(12,2) NOT NULL, 
		SEQNUMPARCELA NUMBER(3) DEFAULT 1,
		TITULO VARCHAR2(20), 
		PRIMARY KEY (AGVENCIMENTOSCTASPAGAR_ID),
		CONSTRAINT FK_AG_VENCPAGAR_CTASPAGAR FOREIGN KEY (AGCONTASPAGAR_ID) REFERENCES AG_CONTAS_PAGAR (AGCONTASPAGAR_ID) 
	)';
 exception when object_exists then null;
end;
