-- Alt.: 12471 - Tabela de cadastro equipamentos CF-e
create table VEF_BASE_TEQUIPASAT (
BDCODEMP             INTEGER                        not null,
BDCODEQUIPSAT        INTEGER                        not null,
BDNRSERIE            VARCHAR(9),
BDNRCAIXA            INTEGER,
BDDATAINIOBRI        DATE,
BDDATAFIMOBRI        DATE,
constraint PK_VEF_BASE_TEQUIPASAT primary key (BDCODEMP, BDCODEQUIPSAT)
);

alter table VEF_BASE_TEQUIPASAT
   add constraint FK_VEF_BASE_FKEF00383_TEMPRESA foreign key (BDCODEMP)
      references TEMPRESAS (BDCODEMP) ON DELETE CASCADE;
-- FIM: 12471

-- Alt.: 12472 - Lançamento de CF-e, tabela de saídas
ALTER TABLE VEF_EMP_TMOVSAI ADD BDCODEQUIPSAT INTEGER;
ALTER TABLE VEF_EMP_TMOVSAI ADD BDCNPJDESTCFE VARCHAR(18);

ALTER TABLE VEF_EMP_TMOVSAI
   ADD CONSTRAINT FK_VEF_EMP__FKEF00382_VEF_BASE FOREIGN KEY (BDCODEMP, BDCODEQUIPSAT)
      REFERENCES VEF_BASE_TEQUIPASAT (BDCODEMP, BDCODEQUIPSAT);
-- FIM: 12472

-- Alt.: 12468 - Lançamento de processo referenciado C890
create table VEF_EMP_TPROCREFC890 (
BDCODEMP             INTEGER                        not null,
BDCHAVE              INTEGER                        not null,
BDCODEQUIPSAT        INTEGER,
BDORDEMINDORIG       INTEGER,
BDORDEMACAO          INTEGER,
BDNUMPROC            VARCHAR(20),
BDDTINIVIG           DATE,
BDDTFINVIG           DATE,
BDINDSECJUDICIARIA   VARCHAR(500),
BDIDVARA             VARCHAR(2),
BDDATASENTENCA       DATE,
BDDESCACAO           VARCHAR(100),
constraint PK_VEF_EMP_TPROCREFC890 primary key (BDCODEMP, BDCHAVE)
);

alter table VEF_EMP_TPROCREFC890
   add constraint FK_VEF_EMP__FKEF00388_TEMPRESA foreign key (BDCODEMP)
      references TEMPRESAS (BDCODEMP)
      on delete cascade;

alter table VEF_EMP_TPROCREFC890
   add constraint FK_VEF_EMP__FKEF00389_VEF_BASE foreign key (BDCODEMP, BDCODEQUIPSAT)
      references VEF_BASE_TEQUIPASAT (BDCODEMP, BDCODEQUIPSAT);

alter table VEF_EMP_TPROCREFC890
   add constraint FK_VEF_EMP__FKEF00390_VEF_BASE foreign key (BDORDEMINDORIG)
      references VEF_BASE_TTABINDORIG (BDORDEMINDORIG);

alter table VEF_EMP_TPROCREFC890
   add constraint FK_VEF_EMP__FKEF00391_VEF_BASE foreign key (BDORDEMINDORIG, BDORDEMACAO)
      references VEF_BASE_TNATACAO_1010_1020 (BDORDEMINDORIG, BDORDEMACAO);
-- FIM: 12468

--Sol: 6170 Patrick T. Sá 16/09/2015. Juros por periodo.
create table TIMPOSTO_JUROS_PER (
BDCODIMP             INTEGER                        not null,
BDCODJUROS           INTEGER                        not null,
BDCODIND             INTEGER,
BDDATAINI            DATE,
BDDATAFIM            DATE,
BDJUROS              DM_NUMERIC_7_4_ALIQ,
BDJURDIA             INTEGER,
constraint PK_TIMPOSTO_JUROS_PER primary key (BDCODIMP, BDCODJUROS)
);

alter table TIMPOSTO_JUROS_PER
   add constraint FK_TIMPOSTO_RELATIONS_TIMPOSTO foreign key (BDCODIMP)
      references TIMPOSTO (BDCODIMP);

alter table TIMPOSTO_JUROS_PER
   add constraint FK_TIMPOSTO_RELATIONS_TINDICES foreign key (BDCODIND)
      references TINDICES (BDCODIND);
	  
--Sol: 6170 Fim.	

-- Lucas - Sol. 11562 - Informe de rendimentos para autônomos transportadores.
ALTER TABLE VRHF_EMP_TFICHAIRRF_TERC ADD BDBASEIRTOT NUMERIC(18,6);
ALTER TABLE VRHF_BASE_CALC_TERC ADD BDBASEIRTOT NUMERIC(18,6);

--Sol: 6170
ALTER TABLE TIMPOSTO_JUROS_PER DROP CONSTRAINT FK_TIMPOSTO_RELATIONS_TIMPOSTO;
ALTER TABLE TIMPOSTO_JUROS_PER ADD CONSTRAINT FK_TIMPOSTO_RELATIONS_TIMPOSTO FOREIGN KEY (BDCODIMP) REFERENCES TIMPOSTO(BDCODIMP) ON DELETE CASCADE USING INDEX FK_TIMPOSTO_RELATIONS_TIMPOSTO;
--Sol: 6170 Fim.

-- Lucas - Sol. 12506 - Simples Nacional - Empregador Doméstico.
ALTER TABLE VRHF_BASE_TEMPGPS ADD BDINDCOMP NUMERIC(18,6);

-- Alt.: 12429 - Campos da tabela temporaria da importacao
ALTER TABLE TMP_VEF_EMP_TMOVSAI ADD BDCODEQUIPSAT INTEGER;
ALTER TABLE TMP_VEF_EMP_TMOVSAI ADD BDCNPJDESTCFE VARCHAR(18);
-- FIM: 12429

--Sol: 12653 Patrick T. Sá 20/10/2015. Excluir o campo BDCOMUNIADOPROD da tabela TPERSONALIZACAO
ALTER TABLE TPERSONALIZACAO DROP BDCOMUNICADOPROD;
--Fim: 12653
